Repository navigation
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #393.
With
handoff_mode: "per_session", the #373 sweep inscripts/session-start-hook.shtreated "transcript absent under$SESSIONS_DIR" as proof a session was over, and pruned itsremember.delivered.<session_id>record on that signal alone. But atsource=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_MINis 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 atdoctor.sh:257andlib-lock.sh:183for the identical portability split), notfind -mmin. That swap was made after review (see below).Tests
tests/test_delivery_record_pruning_373.pygained a fourth case pairing with the original three:test_fresh_record_with_no_transcript_yet_survivesis 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_prunedandtest_records_left_over_after_switching_back_to_single_mode_are_still_prunedwere 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-findingsunderscripts/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 -mminarbiter carries a genuine Windows Git-Bash risk --System32'sfind.execan resolve ahead of MinGW'sfindon 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: replacedfind -mminentirely with thestat-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.mdchange: the #373 PR that introduced this sweep did not touchREADME.mdeither (the sweep is bookkeeping, not user-facing behavior), and the delivery-record section ofREADME.md(around line 303) does not describe internal pruning timing.Test plan
pytest tests/test_delivery_record_pruning_373.py -v-- 6 passedpytest tests/test_arith_base_lint_332.py -q-- 10 passed (the new arithmetic is10#-guarded)pytest -q-- 1700 passed, 43 skippedpython3 .oss/assemble_changelog.py --check-- ok