Repository navigation
Conversation
hooks.d/after_save/60-git-reconcile.sh is off by default behind git_reconcile.enabled, so 50-git-backup.sh's commit-and-push-only promise (#253) and 50-git-restore.sh's fast-forward-only promise are unchanged with it off. Enabled, it fetches, fast-forwards when purely behind, and rebases onto the remote tip and pushes (one retry) when both ahead and behind; a real conflict aborts the rebase, changes nothing else, and names the conflicting files through a git-reconcile-notice. It never resets, force-pushes or creates a merge commit, and declines while the slug's own consolidation is rewriting recent.md/archive.md. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Self-review (Explore + oss:auditor) on commit b004341 found: - The reconcile hook's own instance lock recorded the short-lived foreground process's PID, which is already dead by the time a second invocation's staleness check looks at it -- the real work runs in a detached background subshell under a different PID. Fixed by correcting the lock's recorded holder to the actual worker PID right after it is forked, closing the window to the same few shell instructions lib-lock.sh's own `_lock_try_adopt` already tolerates elsewhere. - git-reconcile-notice was written on a conflict but never consumed: scripts/user-prompt-hook.sh's notice loop did not name it, so the conflict report this hook exists to surface would sit in tmp/ forever. Wired into that loop, the same way git-restore-notice is. docs/configuration.md's "visible in /remember:doctor" claim was false (doctor.sh surfaces none of these notices, restore's included) -- corrected to describe the actual mechanism. - Stale prose in user-prompt-hook.sh's own doc comment ("nothing will merge or rebase it for you") is no longer true when git_reconcile.enabled is set; updated. - The new test's own conflict-check reproduced the exact --git-path bug class the hook was fixed against (missing --path-format=absolute), so it always asserted true regardless of what the hook left behind. Fixed the same way. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Second-pass audit (oss:auditor) on fix commit 9074a49 found two more: - The parent's post-fork `echo "$RC_WORKER_PID" > "$RC_LOCK_DIR/pid"` raced the subshell's own cleanup trap on the fast-decline path (consolidation lock already held): if the subshell released the lock before that outside write landed, lock_release's self-id check failed (pid still the dead foreground's), leaving the lock held by a dead pid until the next instance's stale-takeover logic recovered it. Removed the outside write entirely -- the subshell now records its OWN pid as its first action, before anything can exit, so there is no ordering to race. - TestNoticeIsWired asserted only that the string "git-reconcile- notice" appeared anywhere in user-prompt-hook.sh, which the new doc comment alone already satisfies -- it would stay green even if the loop entry itself were reverted. Anchored on the `for _notice_name in ...` line specifically; confirmed by simulating that exact revert and watching the assertion fail. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…kip triage PR #924's CI (pytest ubuntu-latest 3.9) failed on two checks unrelated to the hook's own behavior: - .github/scripts/check_release_tree.py's NETWORK_WORD_ALLOWLIST named the two sibling hooks (50-git-backup.sh, 50-git-restore.sh) as shipped files allowed to contain network-command words (fetch, push, rebase), but not the new 60-git-reconcile.sh, which legitimately calls all three. Added it, following the exact existing pattern -- no suppression, no change to the check itself. - tests/test_windows_skip_triage_497.py requires every win32 blanket-skip test module to be triaged in docs/windows-skip-triage.md. tests/test_git_reconcile_903.py skips on win32 for the same reason (#79) as the sibling hook test files whose fixtures it imports directly, and was missing a row. Added one with the identical reason string and verdict (not-convertible) those sibling files already carry. Both confirmed locally: the release-tree check test and the triage test now pass for this file; the full targeted+guard set (20 tests across the touched files) passes. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #903
Adds an optional, off-by-default reconcile step for a memory store written from two machines, in its own hook file so the two existing promises are unchanged:
50-git-backup.shstill only commits and pushes (#253), and50-git-restore.shstays fast-forward only.Shape
hooks.d/after_save/60-git-reconcile.sh, gated by a newgit_reconcile.enabledconfig key (default off). When enabled: fetch; fast-forward when behind; push when ahead (left to50-git-backup.sh); rebase onto origin then push, one retry, when both ahead and behind; on conflict, abort the rebase, change nothing else, and surface the file names through the existing diverged-notice mechanism. Never resets, force-pushes, or creates a merge commit. Takes the same consolidation lockrecent.md/archive.mdrewrites use (viascripts/lib-lock.sh), or skips and says so when it is held.Commits
b004341-- initial implementation (hook, tests against a bare origin + two clones covering fast-forward / ahead / both-sides-rebase / conflict-aborts-and-leaves-tree-unchanged, docs, changelog fragment).9074a49-- round-1 self-review fixes (Explore + oss:auditor spawned together against b004341): switched the lock from a reinvented flock/noclobber copy tolib-lock.sh's mkdir+stale-PID-takeover primitive, since the original recorded the short-lived foreground's PID while the real work ran in a detached background subshell under a different PID -- a second invocation's staleness check could wrongly declare the lock stale mid-flight; wiredgit-reconcile-noticeintoscripts/user-prompt-hook.sh's existing notice-to-systemMessage loop, since it was written on conflict but never consumed anywhere; corrected a stale doc-comment aboutgit-restore-notice; fixed a--path-format=absolutebug in the test's own rebase-in-progress check that mirrored a bug briefly present in the hook itself during development.3c60358-- round-2 self-review fixes (oss:auditor alone against 9074a49, a second pass required because that commit touched 4 files): closed a narrow TOCTOU where the parent's post-fork PID write could race the background subshell's own cleanup trap, by having the subshell record its own PID as the first action after installing the trap instead of depending on the parent's write landing first; tightenedTestNoticeIsWiredto anchor on the literal loop line rather than matching anywhere in the file, since the prior assertion stayed green even if the loop wiring were reverted while the doc-comment alone survived (verified the tightened assertion actually catches that exact revert before trusting it).Review findings (7 total, all disposed
fixed)Round 1 (Explore, 5 findings): (1) lock PID recorded by the wrong process -- fixed via lib-lock.sh; (2) the same reinvented-lock-primitive issue; (3)
git-reconcile-noticewritten but never consumed, anddocs/configuration.md's claim that conflict state is "visible in /remember:doctor" was false sincescripts/doctor.shhas zero visibility into any of the three git hooks' notices -- fixed by wiring the notice into the real consuming loop and correcting the docs claim to describe that mechanism instead; (4) stale doc-comment about git-restore-notice; (5) the test's own conflict-check had the same--path-format=absolutebug as the hook.Round 2 (oss:auditor, 2 findings): (1) a lock-PID TOCTOU between the parent's post-fork write and the subshell's cleanup trap; (2) a notice-wiring test that checked the whole file's text rather than the specific loop line it claimed to pin.
oss:auditor's own round-1 pass returned NO FINDINGS across 4 classes (silent absence, guard that did not run, untrusted text forging a boundary, platform band).
Below-bar, not filed as its own issue
scripts/doctor.shhas zero visibility into any of the three git hooks' state (backup, restore, and now reconcile notices, rejected-push counters, diverged counters) -- true of the two existing sibling hooks (#253/#723) as much as this new one, so it predates this diff rather than being a regression it introduces. The maintainer's review comment asked specifically for git_reconcile's conflict state to be visible in/remember:doctor; this PR does not add newdoctor.shintegration for it, because there is no existing pattern to extend safely within this lane's scope and building one from scratch risks scope creep intodoctor.sh's own large, unfamiliar structure -- instead it corrects the docs claim to describe the real mechanism (the systemMessage notice loop, which now genuinely works) rather than the false one. Fixingdoctor.sh's blanket lack of hook-state visibility properly would mean adding support forgit_backup's andgit_restore's existing notices too, which is out of scope for #903.Tests
python3 -m pytest tests/test_git_reconcile_903.py -q-- 8 passed. Full targeted + guard set (tests/test_git_reconcile_903.py tests/test_scanner_shapes_source_898.py tests/test_config_contract.py tests/test_post_tool_hook_spawns.py) -- 420 passed, 0 failed. The full repositorypytestsuite was not run locally, per this repo's own doctrine that CI (3 OSes x 4 interpreters) is the gate rather than a local full run.Platform claims
Reasoned, not observed, for Linux and Windows: no new path/separator, encoding, or line-ending-sensitive code, and the PID handling is the same portable shell already used elsewhere in this file and in
lib-lock.sh. The new test file is skipped on win32 via the existing convention (#79), same as every otherhooks.d/*.shtest file in this repo. Only macOS was actually run.[AI-generated]