Skip to content

doctor.sh: add a SessionEnd liveness check, three states not two - #387

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

fdaviddpt merged 2 commits into
mainfrom
fix/370

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #370.

What

/remember:doctor (scripts/doctor.sh) had a detailed alive-marker check for PostToolUse but said nothing about SessionEnd at all, so a user whose SessionEnd hook is unregistered, dying before it forks, or simply never invoked by Claude Code on an undocumented exit path (crash, killed terminal) saw the exact same "capture is working" verdict as a user whose last-chance flush actually runs.

PostToolUse's freshness-window reading (how old is the marker) doesn't transfer to SessionEnd, which fires at most once per session. No new marker is introduced anywhere: session-end-hook.sh (untouched by this PR) already leaves usable evidence of its own accord -- a logs/autonomous/session-end-<HHMMSS>.log file, written unconditionally by its own existing background flush once it gets past its SAVE_SCRIPT-missing check. doctor.sh now reads that.

Three states, not two:

  • fired -- at least one such log exists. OK.
  • never fired despite a prior session having demonstrably ended -- a transcript other than the one currently growing in this project's Claude Code session directory has gone quiet for over 15 minutes. FAIL, and it now outranks the generic "capture is working" VERDICT arm -- a healthy PostToolUse must not mask a broken SessionEnd.
  • no session has had the chance to end yet -- the third state the issue calls out by name. WARN, renders as neither of the other two.

The staleness threshold (not a raw transcript count) is deliberate: an earlier cut of this fix counted *.jsonl files and treated two-or-more as proof a session had ended, which two ordinary, simultaneously open Claude Code windows on the same project also produce with nothing broken. Self-review (an Explore agent against the committed diff) caught this as a real false-positive with a reproduction; it's fixed in a second commit, along with two smaller findings (a stale file-header description, and a missing test for the exact-one-transcript boundary).

Tests

tests/test_doctor_session_end_370.py, 7 tests, one per state plus positive controls for each FAIL/WARN pairing and a VERDICT-ladder-ordering test. Full suite (pytest) run green twice (before and after the self-review fix): 1673 passed, 43 skipped, 0 failed.

Docs

README.md's "## Diagnostics" section (docs_targets) also describes what /remember:doctor prints and should gain a mention of the new SessionEnd check. That file is held by open PR #382 (fix/369) and was not touched here -- exact replacement text is in this PR's companion agent report (blocked), for whoever lands it.

Below-bar finding from review

The auditor separately flagged that scripts/doctor.sh's DESCRIPTION header undersold what the tool checks even before this PR (only ever mentioned PostToolUse) -- fixed here as part of the same header update, so nothing is left below-bar from this diff.

Co-Authored-By: Claude Opus 5 (1M context) [email protected]

fdaviddpt and others added 2 commits August 28, 2026 08:23
PostToolUse's alive-marker check answers "how old is the marker", which
only makes sense because that hook fires many times inside a live session.
SessionEnd fires at most once per session, so that reading does not
transfer -- and until now doctor.sh said nothing about SessionEnd at all, so
a user whose SessionEnd hook is unregistered or dying before it forks saw
the same "capture is working" verdict as one whose last-chance flush
actually runs.

No new marker is introduced. session-end-hook.sh already leaves usable
evidence of its own accord -- a logs/autonomous/session-end-*.log file,
written unconditionally by its own background flush once it gets past its
SAVE_SCRIPT-missing check -- and doctor.sh now reads that instead of
inventing a second signal.

Three states: fired (OK, at least one such log exists); never fired despite
evidence a prior session has ended, i.e. 2+ transcripts in this project's
Claude Code session directory (FAIL, and it now outranks the generic
"capture is working" verdict -- a healthy PostToolUse must not mask a
broken SessionEnd); and no session has had the chance to end yet (WARN,
renders as neither of the other two).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…liveness (#370)

Self-review turned up a false-positive in the first cut: counting *.jsonl
files in the project's Claude Code session directory as "a prior session
ended" breaks the moment two Claude Code windows are open on the same
project at once -- an ordinary workflow, not a broken install, and it was
producing a hard FAIL/VERDICT: problem for it.

Replaced the count with a staleness check: a transcript other than the one
currently growing has to have gone quiet for over 15 minutes before it
counts as evidence a session ended. A currently-open window keeps touching
its own transcript far more often than that, so two live windows no longer
false-positive, while a genuinely finished session still does after the
grace period. False negatives here only delay a real FAIL; false positives
were the actual failure mode.

Also: added coverage for the transcript-count boundary at exactly one file
(fresh and stale), and folded the new check into doctor.sh's own top-of-file
capture-health description, which the first commit left unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@fdaviddpt
fdaviddpt merged commit 206e151 into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/370 branch August 28, 2026 07:11
fdaviddpt added a commit that referenced this pull request Aug 28, 2026
…ss check (#390) (#391)

PR #387 (closing #370) gave scripts/doctor.sh a second liveness check, for
SessionEnd, alongside the existing PostToolUse one. README.md's Diagnostics
section still described only the PostToolUse check, drafted before #387
landed and blocked at the time because #382 held README.md. Both PRs have
since merged; verified the wording against the merged doctor.sh (three
states, and "has ever fired" correctly describes the log-presence check
rather than a transcript count) before applying it unchanged.
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.

doctor.sh has no SessionEnd liveness check, so a SessionEnd hook that never fires reads as a healthy install

1 participant