Repository navigation
Merged
Conversation
…the pre-quit snapshot `_grc_report_conflict` in `hooks.d/after_save/60-git-reconcile.sh` (since d431fb2, #952/#962) restores every path touched by this run's own commits and the remote's commits since their common base, not scoped to `$SLUG/` as #943 originally promised. `git checkout HEAD --` and `git rm -f` ran over that whole set unconditionally, with only this slug's own consolidation lock held -- not another slug's. A different slug writing a tracked file the remote side also changed, in the TOCTOU window while this slug's `git rebase --quit` runs, was silently discarded, while the hook still logged "aborted, the tree is unchanged". `git rebase --quit` touches neither the working tree, the index, nor HEAD (git-rebase(1)) -- it only drops the rebase-merge/rebase-apply state directory. So a content snapshot of every touched path taken immediately before that call, compared against the same paths right before the restore runs, can only ever differ because something else wrote to one of them in between. The restore now only acts on the subset whose content still matches that snapshot; a path that changed is left exactly as the concurrent write put it, which the existing `_grc_foreign_changes` porcelain scan already reports correctly once that write is no longer clobbered. New regression test test_write_in_the_toctou_window_inside_the_restore_set_survives_the_abort puts the foreign path INSIDE the restore set (the remote side's own commit also touches it), unlike the existing TOCTOU test which only covers a foreign path outside it -- confirmed red against current main, green after the fix. The sibling tests in TestScopedAbort (positive control: a normal scoped abort with no race) and the rest of test_git_reconcile_903.py (24/24) still pass unchanged. Co-Authored-By: Claude Sonnet 5 <[email protected]>
… claim, log residual gap
Self-review (Explore + oss:auditor spawns) on the previous commit found:
- A could-not-hash sentinel ("HASH-ERROR") compared equal to itself was
being treated as "content provably unchanged", so a path whose
`git hash-object` failed identically before and after `rebase --quit`
(e.g. a static permission/IO problem) would still be restored instead
of being treated as unverifiable and left alone. Fixed: either side
reading HASH-ERROR now excludes the path from the safe set.
- The code comment and changelog fragment overclaimed the guarantee --
"can only ever differ because of something else writing ... in
between" is only true for the window from immediately-before
`rebase --quit` through the restore, not for the whole function or the
rebase attempt that precedes it. Reworded both to say what is actually
covered, and logged the un-closed, wider window (plus a second, much
narrower gap between each path's own hash check and its own
checkout/rm) to trap.d/966.residual-race.md for /oss:curate to weigh,
rather than silently shipping a broader claim than the fix delivers.
Re-verified: bash -n clean, python3 .oss/assemble_changelog.py --check
passes (11 fragments, all parse), tests/test_git_reconcile_903.py 24/24
still green.
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.
_grc_report_conflictinhooks.d/after_save/60-git-reconcile.shpreviously restored (via unconditionalgit checkout HEAD --/git rm -f) every path in_GRC_TOUCHED_PATHS-- not scoped to$SLUG/. Only this slug's ownRC_LOCK_DIR/CONSOLIDATION_LOCK_DIRlocks were held, never another slug's. A different slug writing a tracked file the remote side also changed, in the TOCTOU window whilegit rebase --quitran, was silently discarded, while the hook still logged "aborted, the tree is unchanged".Adds
_grc_path_hash(git hash-object, no-w, so it never writes to the object store; returns the sentinelABSENTif the path doesn't exist,HASH-ERRORif the hash call itself fails). Right before callinggit rebase --quit, every touched path's hash is snapshotted. After quit, only the subset of_GRC_TOUCHED_PATHSwhose current hash still equals the pre-quit snapshot -- and where neither hash is theHASH-ERRORsentinel, so a could-not-hash reading never compares equal to itself and reads as "provably unchanged" -- feeds the restore/remove steps. A path whose content changed (or could not be verified) during that window is left exactly as it was.git rebase --quittouches neither the working tree, the index, nor HEAD (git-rebase(1)) -- only the rebase-merge/rebase-apply state directory -- so a difference between the pre-quit and post-quit snapshot can only come from something else writing to that path during that specific window.New test:
tests/test_git_reconcile_903.py::TestScopedAbort::test_write_in_the_toctou_window_inside_the_restore_set_survives_the_abort, with fixture_diverged_with_in_set_foreign_write(the remote-side divergent commit also touchesother-slug/now.md, landing INSIDE the restore set, unlike the sibling pre-existing TOCTOU test which uses a foreign path outside the restore set entirely).RED (against the pre-fix hook, new test only):
AssertionError: a write landing in the TOCTOU window on a path that IS inside the restore set was discarded by the unconditional checkout/rm over the whole set -- #966.GREEN:
python3 -m pytest tests/test_git_reconcile_903.py -q --no-cov-> 24 passed (also re-verified green after the follow-up commit).Also green:
bash -n hooks.d/after_save/60-git-reconcile.sh;python3 .oss/assemble_changelog.py --check(11 fragments, all parse).Self-review (two spawns, Explore + oss:auditor, both confirmed
cleanvia tree-snapshot): both independently found the same HASH-ERROR sentinel-collision class, fixed in the follow-up commit. Both also independently found that the fix only narrows the race to therebase --quitcall itself and does not close the wider window from this run's own rebase attempt starting through the conflict firing -- deliberately not moved earlier, since snapshotting before the rebase attempt would also capture this run's own legitimate pre-rebase content and make every touched path look "changed", defeating the restore entirely. This residual gap, plus a second narrower one (per-path hashes are all read before any path's own checkout/rm runs), is logged intrap.d/966.residual-race.mdfor/oss:curaterather than fixed here -- does not close this residual race, only the pre-quit-to-post-quit window named above. Also confirmed: the guardedgit diff --diff-filter=A/checkout HEAD --branches correctly skip when_grc_safe_pathsis empty (an unguarded, pathspec-lessgit diff --diff-filter=A HEAD --would diff the whole tree); the win32pytestmarkskip still applies; macOS/Linux CI legs run this file with no GNU/BSD divergence in the new bash constructs; no.gitattributes/core.autocrlfto introduce a byte-level hashing gap.docs_targets (
README.md): checked, no mention of "reconcile" or restore-scope behavior exists to update -- no-change-needed.Closes #966.
[AI-generated]