Skip to content

Per-session handoff files stop two interactive sessions from clobbering each other's remember.md - #366

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/363
Aug 27, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/363

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Problem

Two or more interactive Claude Code sessions share one project's .remember store by design, even across git worktrees (_resolve_memory_project_dir, #56). But every session wrote its /remember handoff note to the same fixed path, remember.md (session-start-hook.sh:795), with no namespacing or locking -- the second session's /remember silently overwrote the first's, which then survived only in that session's own transcript. Distinct from #221/#222, which protect a pending handoff from a session that never writes one back; this is two sessions that each do write one, to the same name.

Fix

A new handoff_mode config key:

The handoff-delivery/re-delivery-labelling record (tmp/remember.delivered) is namespaced the same way in per_session mode, so two sessions never race one shared fingerprint file; the pre-existing legacy-record migration is correctly skipped in that mode.

If per_session is requested but no usable session_id reaches the hook, the session falls back to the shared file -- the === HANDOFF === hint still points at it (that path is still correct, including in external storage mode, where it is the only real path), but a visible second line now says the fallback happened, so it never reads as isolation that never applied.

A first version of this fix withheld the hint outright on that fallback -- an Explore review caught that this also silently suppressed the pre-existing, correct external-mode hint, reintroducing the exact misdirection bug that hint exists to prevent. Fixed in a follow-up commit; see commit messages for the full account.

Scope decision: no automatic pruning of stale remember.<session_id>.md files ships with this change. A handoff is the user's own writing with no copy anywhere else, and a delete keyed on "the transcript looks gone" can misfire for reasons other than the transcript actually being gone. Stale per-session files accumulate until removed by hand -- a legitimate, deliberately conservative outcome per the brief, not an oversight.

Feature scope, not a bugfix -- this does not qualify for auto-merge under this repo's release gates and is expected to wait for a maintainer's manual merge decision.

Below-bar finding, not fixed here: the new degraded-mode notice line contains an em-dash written to stdout, which could raise UnicodeEncodeError under a Windows console using cp1252 -- reasoned, not observed (no Windows box available). This is not a fresh risk: three pre-existing lines in the same file already print em-dashes to stdout/stderr unconditionally, so fixing only the new line would leave the file's own Unicode-to-stdout convention inconsistent rather than settled. That is a design decision (whether this file should ever print non-ASCII to stdout on a console that may be cp1252) spanning the whole file, not this one new line, so it is filed rather than fixed here.

Tests

TDD: red before the fix (4 failed, 1 passed), green after (5 passed, later 7 passed once the review-driven correction rewrote the withheld-hint test into three: the corrected path, the notice's presence when degraded, and its absence when not -- a positive control). Full suite run once (mandatory: this touches a core shared hook) caught one unrelated cross-cutting guard failure (test_pep604_floor_guard.py, tripped by this PR's own test file using str | None syntax below this repo's Python 3.9 floor) and it was fixed.

Closes #363

fdaviddpt and others added 2 commits August 27, 2026 12:41
…ring each other's remember.md (#363)

Two interactive sessions sharing one project store (by design, even across
worktrees, #56) both wrote the same fixed remember.md with no namespacing or
locking, so the second /remember silently overwrote the first's handoff.
Distinct from #221/#222, which protect a pending handoff from a session that
never writes one back.

Add `handoff_mode` ("single", default, unchanged; "per_session", keyed by
the SessionStart payload's own session_id) so each session gets its own
remember.<session_id>.md. The delivery record is namespaced the same way to
avoid two sessions racing one fingerprint file. A per_session request with
no usable session_id withholds the === HANDOFF === hint rather than
silently pointing the /remember skill at the shared file under a mode the
user believes is isolating them. No pruning ships with this change -- a
stale per-session handoff is the user's own writing with no copy anywhere
else.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
…363 review)

The Explore review of the first commit caught a real regression: when
per_session mode degraded to the shared file (no usable session_id), the
hint was withheld outright -- including in external storage mode, where
that shared path is still the one true handoff location. Withholding it
there reintroduced the exact bug the external-mode hint exists to prevent:
the /remember skill falling back to its own hardcoded, project-relative
default instead of the real external path.

The hint now always fires whenever it would have before (external mode, or
a resolved per-session path), and a degraded per_session request adds a
second, visible line saying the fallback happened, instead of either
silence or a misleading absence. Tests, README, config.example.json and the
changelog fragment updated to match; the old "withholds the hint" test is
replaced with tests asserting the corrected path plus the presence/absence
of the notice line (positive control).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
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.

Per-session handoff files: concurrent interactive sessions clobber remember.md (last-writer-wins)

1 participant