Skip to content

fix: doctor.sh's SessionEnd check no longer FAILs on prior Claude Code history it never had a chance to service (#392) - #400

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/392
Aug 28, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/392

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

doctor.sh's SessionEnd liveness check (#370) FAILed on a healthy install that merely had prior Claude Code history in the project -- a quiet transcript predating the plugin's own store was read as proof SessionEnd never fired, when the hook was never even registered for that session. That FAIL also displaced the correct, actionable fresh-install remediation ("PostToolUse has never fired; restart Claude Code") behind a less useful SessionEnd message. A second, independent defect: an unreadable transcript mtime was counted into the transcript total and continued past the staleness question, so the WARN made a claim about files whose quietness was never established.

A transcript now only counts as evidence once it is at least as recent as $REMEMBER_DIR/.gitignore's own mtime -- written exactly once by bootstrap-dirs.sh, gated on it not already existing, and never rewritten by ordinary hook activity. Both fixtures from the issue's own before/after table are in the suite, each paired with a must-fire control. The genuine failure -- a session that ended after the store existed, with no session-end-*.log to show for it -- still FAILs and still outranks the generic "capture is working" verdict.

Self-review found two more defects, both fixed in this PR

  • Round 1 (Explore reviewer): the first version of this fix used REMEMBER_DIR's own mtime as the install baseline. That's wrong -- save-session.sh writes now.md via mktemp directly inside REMEMBER_DIR followed by mv, and both operations bump the directory's own mtime, not just now.md's. On any actively-captured project the baseline would have read as "time since last save", silently turning genuine SessionEnd failures back into the exact false positive this PR exists to close. Fixed by switching to $REMEMBER_DIR/.gitignore's mtime instead, with a new regression test (test_ongoing_saves_do_not_mask_a_genuine_failure) that reproduces the churn directly and is confirmed to fail against the old baseline.
  • Round 2 (oss:auditor): the .gitignore marker is also not permanently stable -- hooks.d/after_save/50-git-backup.sh deletes that exact file as a one-time cleanup of the legacy bootstrap artifact, reachable when a legacy (in-project) store is migrated to external mode with git backup enabled. Functionally this doesn't make the fix worse than already documented (the safe fallback when the baseline is unavailable was already WARN, never a false FAIL), but the comment/README/changelog claim that "nothing else writes to it" was wrong and is now corrected in all three places. See Known follow-up below -- not fixed in this PR, since the fix belongs in a file outside this issue's own footprint.

Known follow-up (not fixed here, filed for the maintainer)

hooks.d/after_save/50-git-backup.sh deletes $REMEMBER_DIR/.gitignore under legacy-to-external migration with git backup enabled, which permanently disables SessionEnd's FAIL path for that store (WARN forever, never crashing, never false-FAILing, but never catching a real failure either). Fixing it needs either changing 50-git-backup.sh to stop deleting the marker (or recreate a substitute) or giving doctor.sh a baseline that survives that cleanup -- both design decisions, both outside scripts/doctor.sh and this issue's declared lane. No existing sibling issue found. Below-bar note: this is a real, reachable gap, not filed as a blocking finding against this PR -- it does not regress anything this PR touches, it only means the WARN-only limitation this PR already documents for external-mode-from-the-start stores also applies, via a different path, to migrated-and-backed-up ones.

Test plan

  • pytest tests/test_doctor_session_end_370.py -- 11 passed (red/green shown separately in the commit history and the agent report)
  • Full suite: pytest -- 1703 passed, 43 skipped, run twice (once per fix commit) on macOS/darwin, Python 3.13.15
  • Changelog fragment checked: python3 .oss/assemble_changelog.py --check -- ok
  • CI (ubuntu-latest, windows-latest legs not run locally; this test file is skipped entirely on Windows)

Closes #392

fdaviddpt and others added 3 commits August 28, 2026 12:22
… never had a chance to service (#392)

Two defects in doctor.sh's SessionEnd arm (#370), both found by the
release audit measured against v0.22.0 on identical fixtures:

1. A quiet transcript predating this project's own .remember store was
   counted as proof SessionEnd never fired, when the hook was never even
   registered for that session. This both false-positived a healthy
   PostToolUse-working install and displaced the correct, actionable
   fresh-install remediation ("PostToolUse has never fired; restart Claude
   Code") behind a less useful SessionEnd message.

2. An unreadable transcript mtime was counted into the transcript total
   and `continue`d past the staleness question, so the WARN made a claim
   about files whose quietness was never established.

REMEMBER_DIR's own mtime -- set once, the first time any hook bootstraps
it for this project, and never touched by doctor.sh itself (a read-only
report) -- is the earliest "remember became active here" signal available
without new marker infrastructure. A transcript now only counts as
evidence once it is at least that recent; an unreadable one is excluded
and named separately rather than folded into either bucket. The genuine
failure -- a session that ended after the store existed, with no
session-end-*.log to show for it -- still FAILs and still outranks the
generic "capture is working" verdict.

Both fixtures from the issue's table are in the suite now, each paired
with its must-fire control (the same transcript shape with the store
correctly backdated ahead of it).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…aseline, not REMEMBER_DIR's own (#392)

Self-review (Explore reviewer) caught a defect in the previous commit
before it was pushed anywhere: REMEMBER_DIR's own mtime is not a stable
"install time" signal. save-session.sh writes now.md via a mktemp
created directly inside REMEMBER_DIR followed by mv over the existing
file, and both operations update the directory's own mtime -- not just
now.md's. On any project with ongoing captures this reads as "time
since the last save", not "time since install", reopening almost the
exact false-negative window the previous commit exists to close:
verified locally that a genuinely 2-day-old store with one ordinary
save 5 minutes prior read as installed 5 minutes ago.

$REMEMBER_DIR/.gitignore is the fix: bootstrap-dirs.sh writes it
exactly once, gated on it not already existing, and grepping the
codebase turns up no other writer. Its mtime survives ordinary hook
activity in a way nothing else under REMEMBER_DIR does. In external
storage mode that file is never written at all ("no gitignore to
write"), so the SessionEnd arm can currently only WARN there, never
FAIL -- documented as a known gap rather than silently accepted.

Adds a regression test (test_ongoing_saves_do_not_mask_a_genuine_failure)
that reproduces the churn scenario directly and confirmed, against a
scratch copy of doctor.sh with the REMEMBER_DIR-mtime baseline restored,
that it fails exactly as expected -- pinning the defect the review
caught rather than only the fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…etes it under migration (#392)

Second review round (oss:auditor, re-spawned after a classifier flagged
the first pass as referring to findings without stating them) found the
previous commit's own comment overstated: "nothing else in this
codebase writes to it" is false.
hooks.d/after_save/50-git-backup.sh deletes exactly
$REMEMBER_DIR/.gitignore as a one-time cleanup of the legacy bootstrap
artifact, reachable whenever a legacy (in-project) store is later
migrated to external mode with git backup enabled -- at which point
git-backup's own "legacy mode never runs" guard no longer applies.
bootstrap-dirs.sh's write is gated on the store being inside the
project, so once external the file is never recreated.

Functionally this does not make the fix worse than already documented:
the fallback when the baseline is unavailable was already "no
transcript can be attributed to after install" -> safe WARN, never a
false FAIL, which is exactly what happens here too. What was wrong was
the CLAIM that the marker survives forever -- it doesn't, in this one
reachable shape -- and that claim was public in doctor.sh's own
comment, README.md, and the changelog fragment. All three are
corrected to describe the actual, narrower invariant and to name the
gap explicitly rather than imply it cannot happen.

The underlying capability gap (SessionEnd's genuine-failure detection
is unavailable, not just for external-from-the-start stores but also
for legacy-then-migrated-and-backed-up ones) is not fixed here: the fix
belongs either in hooks.d/after_save/50-git-backup.sh (stop deleting
the marker) or in a new marker doctor.sh could read that survives that
cleanup, and hooks.d/after_save/50-git-backup.sh is outside this arm's
own file and this lane. Filed for the maintainer rather than patched
into an unrelated hook mid-lane.

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.

doctor.sh's SessionEnd arm FAILs on a healthy install that has prior Claude Code history, and displaces the fresh-install remediation

1 participant