Skip to content

fix: the #373 delivery-record sweep can no longer prune a live session's record - #397

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/393
Aug 28, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/393

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #393.

With handoff_mode: "per_session", the #373 sweep in scripts/session-start-hook.sh treated "transcript absent under $SESSIONS_DIR" as proof a session was over, and pruned its remember.delivered.<session_id> record on that signal alone. But at source=startup, Claude Code creates a session's own transcript only after this hook has already run and already written that session's delivery record (the #270 comment at lines 100-108 of the same file states this independently). For that window a live session's record is indistinguishable from a dead one's on the transcript check alone -- a concurrent session starting inside the window would delete a record still in active use, resetting the delivery counter so an already-shown handoff read as news again.

Fix

The sweep now also checks the record's own mtime when the transcript is absent, adding a third state: a record younger than a 5-minute grace window (GRACE_MIN) is left untouched even with no transcript, since that is exactly what a session still starting up looks like. A record old enough to be outside the window is pruned exactly as before -- nothing is lost, pruning is only deferred past the window. GRACE_MIN is reasoned, not measured against real Claude Code startup timing: there is no instrumented figure for how long that gap runs, so the value is chosen wide enough that no plausible delay approaches it while staying bounded.

The age check reads the mtime directly via stat -c ... || stat -f ... (GNU-first, BSD-fallback -- the same order already used at doctor.sh:257 and lib-lock.sh:183 for the identical portability split), not find -mmin. That swap was made after review (see below).

Tests

tests/test_delivery_record_pruning_373.py gained a fourth case pairing with the original three: test_fresh_record_with_no_transcript_yet_survives is the #393 positive control -- a freshly-written record with no transcript yet must survive a concurrent session start. test_record_for_a_session_with_no_transcript_is_pruned and test_records_left_over_after_switching_back_to_single_mode_are_still_pruned were updated to backdate their records past the grace window, since a fresh record with no transcript is now the ambiguous case rather than an automatic prune.

Review

Two spawned reviews ran against the first commit. Both returned states-findings under scripts/review_return.py.

Reviewer (Explore): stale docstring in the test module -- it still described "three states" after this change added a fourth. Fixed: the docstring now names all four.

Auditor (oss:auditor): the original find -mmin arbiter carries a genuine Windows Git-Bash risk -- System32's find.exe can resolve ahead of MinGW's find on PATH depending on invocation, which would silently degrade the grace check to an unconditional keep with nothing surfaced (reasoned, not observed -- no Windows box was available). CI would not have caught it either way, since the whole test file is already skipped on win32 from #373/#79. Fixed anyway rather than filed, since it was cheap and in-scope: replaced find -mmin entirely with the stat-based mtime read described above, which has no such PATH-shadowing surface and matches this repo's own established fallback order.

No item in this pull request is below-bar -- both findings were fixed before this commit was opened.

Docs

No README.md change: the #373 PR that introduced this sweep did not touch README.md either (the sweep is bookkeeping, not user-facing behavior), and the delivery-record section of README.md (around line 303) does not describe internal pruning timing.

Test plan

  • pytest tests/test_delivery_record_pruning_373.py -v -- 6 passed
  • pytest tests/test_arith_base_lint_332.py -q -- 10 passed (the new arithmetic is 10#-guarded)
  • Full suite: pytest -q -- 1700 passed, 43 skipped
  • python3 .oss/assemble_changelog.py --check -- ok

…n's record (#393)

An absent transcript alone does not mean a session is over -- at
source=startup, Claude Code creates a session's own transcript only after
this hook has already run and already written that session's delivery
record. A concurrent session start inside that window could prune a
record still in active use. The sweep now also checks the record's own
mtime: a record younger than a short grace window is left untouched even
when the transcript is absent, adding the third state the sweep needs.
Nothing is lost -- a genuinely dead session's record is still pruned once
it ages past the window.

Co-Authored-By: Max <noreply>
Review findings on the #393 fix, applied before commit:

- The auditor flagged a real Windows Git-Bash risk in the `find -mmin`
  arbiter: System32's find.exe can resolve ahead of MinGW's find on PATH,
  silently turning the grace check into an unconditional keep with nothing
  surfaced (reasoned, not observed -- the whole hook test file is already
  skipped on win32, so nothing in CI would have caught it). Replaced with
  a direct mtime read via `stat -c ... || stat -f ...`, the same
  GNU-first-then-BSD-fallback order already used by doctor.sh:257 and
  lib-lock.sh:183 for exactly this split, arithmetic guarded with `10#`
  per #332.
- The reviewer flagged the test module's docstring, which still described
  three states after #393 added a fourth. Updated to describe all four.

Six of six targeted tests pass, the #332 arithmetic-base lint passes, and
the full suite (1700 passed, 43 skipped) is green after this change.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit d9361a3 into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/393 branch August 28, 2026 10:49
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.

The #373 delivery-record sweep can delete a live session's record, because a session's transcript does not exist yet when the hook runs

1 participant