Skip to content

Preserve the handoff until a replacement lands, and label re-deliveries (#221) - #222

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/221-handoff-consume-clear
Jul 29, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/221-handoff-consume-clear

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

The bug

scripts/session-start-hook.sh emitted remember.md and then truncated it, unconditionally, on every SessionStart:

if [ -f "$REMEMBER_HANDOFF" ] && [ -s "$REMEMBER_HANDOFF" ]; then
    echo "=== LAST HANDOFF ==="
    cat "$REMEMBER_HANDOFF"
    echo ""
    : > "$REMEMBER_HANDOFF"
fi

Correct only if every session that starts eventually calls /remember. Plenty do not — a scheduled task whose prompt is read-only and has no reason to know this plugin exists, a claude -p one-shot, a session abandoned before the handoff is written. Each passes through, consumes the note, leaves 0 bytes, and says nothing.

Which option, and why the others lose

The report offered two directions. They are not equivalent.

(1) Detect the non-interactive session and skip the consume-clear. Rejected. There is no signal to detect. REMEMBER_NESTED_SUMMARIZER (#202/#205) is a positive marker pipeline/haiku.py sets on the one child process this plugin spawns itself — checked in resolve-paths.sh, and it already correctly stops that child. An arbitrary scheduled task sets nothing, and nothing distinguishes it from a human at the moment SessionStart fires. Any detector is therefore a guess about who is starting the session, and a guess wrong in the unsafe direction destroys data silently — which is the bug.

(2) Do not truncate until a replacement lands. Chosen. It needs no detection at all, so it cannot be wrong about who started the session. /remember writes to this same path; the new content is what retires the old.

The three failure modes, weighed

Handoff destroyed silently Today's bug. Unbounded, invisible, and worst on exactly the sessions that mattered — the ones whose nuance existed only in the /remember synthesis and was never spoken aloud, so the durable pipeline never saw it.
Handoff re-delivered forever, indistinguishable from fresh The naive version of (2), and rejected too. A reader who cannot tell a stale note from a new one acts twice on work already done. Same defect class as the bug — a quiet lie — wearing new clothes.
Handoff preserved but never surfaced again A guard conservative enough to stop re-emitting turns a visible loss into an invisible one. The file survives, but nobody is ever told, which is indistinguishable from losing it.

Chosen: (2), with re-delivery labelled. Its cost is noise — a stale note may be re-emitted. That is the loud failure, and it is the one we want: it is visible, self-describing, and one /remember clears it.

How infinite re-delivery is prevented from lying

A delivery record, remember.delivered, sits beside the slot: content fingerprint (cksum, with a size fallback), first-delivery timestamp, delivery count. On session start:

  • fingerprint differs from the record (or no record) → fresh handoff, emitted exactly as before, record reset to count 1;
  • fingerprint matches → already delivered, emitted under
    [already delivered N times since ‹ts› — no new handoff has been written since, so this is pending replacement, not news. You may already have acted on it. Running /remember replaces it.]

The === LAST HANDOFF === header is unchanged, so the position-first-in-output behaviour that survives context-preview truncation still holds. An emptied slot deletes the record, so a future handoff cannot inherit a stale label. A corrupt count degrades to 0 rather than erroring inside a hook documented never to block session startup.

The note is never bounded off — it keeps being delivered while it is genuinely pending, honestly labelled, until a replacement retires it.

What I re-derived from the report and found different

The core mechanism holds exactly as reported. Two things did not survive as stated:

  • "no signal available to distinguish who/what is starting the session" — nearly right, but the repo does have one marker of this shape (REMEMBER_NESTED_SUMMARIZER), and it is already wired through resolve-paths.sh for all three hooks. It covers the plugin's own Haiku child, not scheduled tasks, so it does not fix SessionStart's handoff consume-clear silently destroys a pending remember.md when a scheduled/non-interactive task shares the project #221 — but the report's framing would have you build a detector from nothing, when the honest finding is that the existing detector is correct and structurally cannot be extended to arbitrary sessions. That is what makes (2) the right call rather than merely the convenient one.
  • The cron/log correlation and version claims — not re-derived. Nothing in the fix depends on them: the defect is legible in the four lines of the hook and reproducible from an empty temp dir, which is how it is tested here. I neither confirm nor rely on the reporter's environment.

Everything the issue proposed as a dependency, flag or command to run was ignored on principle; the fix adds no dependency and runs nothing new (cksum is POSIX, already assumed present everywhere else this plugin runs).

TDD

Red — new tests against the unfixed hook:

FAILED tests/test_handoff_preservation.py::TestHandoffSurvivesPassThroughSession::test_pass_through_session_does_not_destroy_pending_handoff
FAILED tests/test_handoff_preservation.py::TestRedeliveryIsLabelled::test_second_delivery_is_marked_already_delivered
FAILED tests/test_handoff_preservation.py::TestRedeliveryIsLabelled::test_redelivery_notice_counts_deliveries
3 failed, 2 passed in 6.45s

The two that passed are the characterization tests — test_fresh_handoff_replaces_the_old_one_and_is_delivered_once and test_empty_handoff_slot_emits_nothing. They pinned the ordinary interactive path before the implementation existed and still pass after it: a session receives its handoff, /remember replaces it, the next session gets the new one and never the old, and nothing is re-read forever. They were never red, and are not presented as such.

Green — full suite:

967 passed, 41 skipped in 574.95s (0:09:34)
Required test coverage of 80% reached. Total coverage: 93.98%

tests/test_path_resolution.py::TestEdgeCases::test_handoff_consumed_after_session_start asserted the old destructive contract (remaining.strip() == ""). It is rewritten, not deleted, to the new one: content preserved, deliveries=1 on record.

Docs

CHANGELOG.md under ## [Unreleased] / ### Fixed; README.md's handoff section now states the slot is not emptied on read and what the staleness line means, plus a remember.delivered row in the data-file table.

Closes #221

)

SessionStart read remember.md and truncated it unconditionally, so any
session that never writes a handoff back — a scheduled task passing
through, a `claude -p` one-shot, an abandoned session — silently ate the
note meant for the next human session.

Detection was rejected: there is no signal for "this session will write a
handoff back" (REMEMBER_NESTED_SUMMARIZER covers only the plugin's own
child), and a guess wrong in the unsafe direction destroys data silently,
which is the bug. Nothing is discarded until /remember overwrites the slot.

Delivery is recorded instead, in remember.delivered (fingerprint, first
delivery, count), so a re-delivered note is labelled as already delivered
and pending replacement rather than reading as fresh forever.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit fc97f08 into main Jul 29, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/221-handoff-consume-clear branch July 29, 2026 17:12
fdaviddpt added a commit that referenced this pull request Aug 27, 2026
…ng each other's remember.md (#366)

* feat: per-session handoff files stop interactive sessions from clobbering 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

* fix: never withhold the HANDOFF hint on degrade -- it stays accurate (#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

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

SessionStart's handoff consume-clear silently destroys a pending remember.md when a scheduled/non-interactive task shares the project

2 participants