Stop hook: scope auto-capture commit to memory/+tasks/ only (data-loss fix) - #3
Open
netdust wants to merge 1 commit into
Open
Stop hook: scope auto-capture commit to memory/+tasks/ only (data-loss fix)#3netdust wants to merge 1 commit into
netdust wants to merge 1 commit into
Conversation
…s fix) The session-end memory hook committed the WHOLE staged index: git add was scoped to memory/ tasks/, but the git diff --cached guard and the git commit had no pathspec. So any change staged elsewhere during a session — a mid-build `git rm` of source, a half-staged edit — was swept into a "memory(...): auto-capture session end" commit and lost from where it belonged. Observed: 308 lines of source PHP templates deleted from HEAD under a memory label with no memory content, forcing a rewrite to recover them. git_commit_memory now path-scopes every verb to memory/+tasks/ (only the dirs that exist): the guard fires only on OUR changes, and the commit is structurally incapable of touching anything else — other staged changes stay staged, untouched. Regression test (test_stop_hook_commit_scope.py) pins both halves: with an unrelated deletion pre-staged, (A) no memory content → no commit and the deletion never enters HEAD; (B) real memory content → the commit contains only memory/ and the staged deletion stays pending. Fails red on the old hook (commits the deletion, drops the source), green on the fix. Full stop-hook family green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018h5WidEqAHFL6vFYCvKcm4
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
The bug (data loss, all sessions)
The session-end memory Stop hook (
session-stop.py → git_commit_memory) committed the whole staged index. Thegit addwas correctly scoped tomemory/ tasks/, but thegit diff --cachedguard and thegit commithad no pathspec — so any change staged elsewhere during a session (a mid-buildgit rmof source, a half-staged edit) was swept into amemory(...): auto-capture session endcommit and lost from where it belonged.Observed in the wild: 308 lines of source PHP templates deleted from HEAD under a memory label, with no memory content — the deletion had been staged mid-session, memory/tasks were unchanged, but the unscoped guard still fired and the unscoped commit captured the deletion. The templates were absent from HEAD afterward, forcing a rewrite of the completion modal to recover.
The fix
git_commit_memorynow path-scopes every git verb tomemory/+tasks/(only the dirs that exist, so a non-matching pathspec can't abort the commit):git diff --cached --quiet -- <paths>) fires only on our changes;git commit … -- <paths>) is structurally incapable of touching anything else — other staged changes stay staged, untouched.Regression test
tests/test_stop_hook_commit_scope.pypins both halves, with an unrelated deletion pre-staged before the hook fires:memory/, the staged deletion is not swept in, and it stays pending.Verified red on the old hook (Case B's commit contains
src/template.php, source drops from HEAD) and green on the fix. The full stop-hook family stays green (test_no_auto_memory,test_stop_hook_dedup,test_stop_hook_idempotency, plus the new module). The one unrelated suite failure (test_integration_contract) is a pre-existing environmental skip, untouched by this change.🤖 Generated with Claude Code
Generated by Claude Code