Skip to content

Stop hook: scope auto-capture commit to memory/+tasks/ only (data-loss fix) - #3

Open
netdust wants to merge 1 commit into
mainfrom
claude/netdust-flow-agent-merge-h0k2yk
Open

Stop hook: scope auto-capture commit to memory/+tasks/ only (data-loss fix)#3
netdust wants to merge 1 commit into
mainfrom
claude/netdust-flow-agent-merge-h0k2yk

Conversation

@netdust

@netdust netdust commented Aug 18, 2026

Copy link
Copy Markdown
Owner

The bug (data loss, all sessions)

The session-end memory Stop hook (session-stop.py → git_commit_memory) committed the whole staged index. The git add was correctly 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 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_memory now path-scopes every git verb to memory/+tasks/ (only the dirs that exist, so a non-matching pathspec can't abort the commit):

  • the guard (git diff --cached --quiet -- <paths>) fires only on our changes;
  • the commit (git commit … -- <paths>) is structurally incapable of touching anything else — other staged changes stay staged, untouched.

Regression test

tests/test_stop_hook_commit_scope.py pins both halves, with an unrelated deletion pre-staged before the hook fires:

  • A. No memory content → the hook creates no commit and the staged deletion never enters HEAD.
  • B. Real memory content → the commit contains only 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

…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
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant