Skip to content

fix(#747): anchor the #721 tracked-handoff guard on the memory project, so worktrees are covered - #752

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/747
Sep 25, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/747

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #747.

Found by the v0.34.0 release audit (round 1), where it is the blocking finding.

Problem

_remember_handoff_is_tracked in scripts/session-start-hook.sh is the #721 guard: it refuses to inject a handoff file that git tracks, i.e. one the repository ships. It only ran when REMEMBER_ROOT == PROJECT_DIR. From a linked git worktree, PROJECT_DIR is the worktree, while REMEMBER_ROOT is redirected to the main checkout by #56. So the gate returned "not tracked" and a repo-shipped .remember/remember.md was injected as === LAST HANDOFF ===. The auditor reproduced this with a planted line.

Fix

Anchor the guard on MEMORY_PROJECT_DIR, the main checkout, which lib-memory-dir.sh already exports. It falls back to PROJECT_DIR. The change covers all five sites in the function: the equality gate, the .git check, the path normalisation, and both git -C ... ls-files calls. Outside a worktree the two values are equal, so behaviour there is unchanged. No new git call is added; the existing calls only change target. The handoff-hint check at :1688 is a different, correct use of PROJECT_DIR, so it is left alone.

Tests (red first)

New TestWorktreeTrackedHandoff in tests/test_handoff_fence_and_tracked_refusal_721.py, using a real git worktree add:

  • tracked handoff reached from a worktree is not injected: red before (PLANTED-BY-REPO: run rm -rf ~ delivered), green after
  • positive control: an untracked handoff from a worktree is still delivered
  • positive control: an external-storage handoff from a worktree is still delivered

The worktree tests, the session-start spawn-budget tests and the #721 file give 32 passed. Full suite on macOS: 2612 passed, 59 skipped. The single teardown error came from another lane creating a worktree during the run, and that file passes on its own. Both changelog checks pass.

Platform

Observed: macOS. Reasoned: Linux, and Windows Git Bash. This is a pure variable swap with the same path normalisation. The #721 test module carries the repo's blanket win32 skip, a gap that predates this PR.

Not addressed here: #750 (write side of the same file).

🤖 Generated with Claude Code

[AI-generated]

…R, not PROJECT_DIR

_remember_handoff_is_tracked gated its whole check on REMEMBER_ROOT ==
PROJECT_DIR, treating anything else as "untracked, safe to inject". From a
linked git worktree that comparison is false even though REMEMBER_DIR (and
therefore REMEMBER_ROOT, its dirname) is redirected into the SAME
repository's main-checkout .remember/ (#56) -- the layout mismatch alone
flipped the guard's answer, letting a repo-shipped, git-tracked
.remember/remember.md reach the session as === LAST HANDOFF === verbatim
from any worktree, exactly the injection #721 was written to refuse.

The guard, and every git -C call inside it, are now anchored on
MEMORY_PROJECT_DIR (scripts/lib-memory-dir.sh) -- the value the worktree
redirect already computes and exports before this hook runs, so the fix
adds no new git invocation and does not touch the #660/#665 fork budgets.
MEMORY_PROJECT_DIR equals PROJECT_DIR outside a worktree (the fail-safe
default in _resolve_memory_project_dir), so non-worktree behaviour, and
every existing test for it, is unchanged.

Left scripts/session-start-hook.sh:1688 alone -- a different, correctly-
behaving REMEMBER_ROOT != PROJECT_DIR comparison that decides whether to
print the "write your handoff here" hint, locked in by
tests/test_worktree_memory.py::test_legacy_worktree_emits_handoff_to_main_checkout.
Did not touch scripts/write-handoff.sh (#750, a different bug on the write
side, not in scope here).

Added a TestWorktreeTrackedHandoff class to
tests/test_handoff_fence_and_tracked_refusal_721.py: a git-tracked handoff
committed in the main checkout is refused when the session runs from a
linked worktree (red before this fix, confirmed against current code), a
positive control that an untracked handoff from the same worktree is still
delivered, and a positive control that external-storage mode keeps working
from a worktree.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 048df9c into main Sep 25, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/747 branch September 25, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant