Repository navigation
Conversation
…#483) session-end-hook.sh redirects save-session.sh --force's output into a fresh, empty logs/autonomous/session-end-HHMMSS.log before backgrounding the flush. save-session.sh's own NDC step sweeps that same directory for stale logs with `find ... -empty -delete`, and on an ordinary successful run nothing ever writes into that log -- save-session.sh logs to its own daily file, not stdout/stderr -- so the sweep, run from inside the very process writing it, matched and deleted its own log. A later failure's WARNING then named a path already gone, and a healthy flush left no trace it had run (164 surviving zero-byte logs and the two failure logs the report named were absent entirely). Fixed by seeding the log with a header line before the flush starts and appending rather than truncating into it, so it is never -empty for its own run's housekeeping to catch. A genuinely stale, still-empty log from an earlier abandoned run is untouched and keeps getting swept exactly as before -- proven by a paired positive control in the new test. doctor.sh's SessionEnd-liveness check (#370) already reads presence of session-end-*.log as its evidence a flush ran; this fix repairs that derivation directly, so no change to doctor.sh was needed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UzPdCd7V7PLChyZbRd4pjV
Review of 45e887b (self-review, Explore agent) found that the fix's own header write -- `printf ... > "$_END_LOG"` -- opened $_END_LOG with a truncating redirect, in the foreground, before the flush subshell was even forked. $_END_LOG has second-granularity naming only (no PID, no session id), and scripts/doctor.sh's own SessionEnd-liveness comments already treat two Claude Code windows on one project as an ordinary workflow -- so two SessionEnd hooks computing the identical path inside the same wall-clock second is a real, if narrow, case. A truncating `>` there would silently discard whatever a sibling session's own already-backgrounded subshell had appended by that instant: not the #483 empty-file bug, a new loss this line would otherwise have added. Switched to `>>`, which creates the file exactly as well when it does not yet exist and changes nothing about #483's own fix (the file is still never `-empty` for save-session.sh's housekeeping sweep to catch). $_END_LOG's underlying collision risk -- no PID/session-id in the filename at all -- is pre-existing, not introduced by #483, and is not resolved here: it is filed as a follow-up rather than fixed inline, since a filename-scheme change would also need to update scripts/doctor.sh's `session-end-*.log` glob, which is outside this lane. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UzPdCd7V7PLChyZbRd4pjV
This was referenced Sep 1, 2026
This was referenced Sep 1, 2026
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 #483.
What was broken
session-end-hook.sh redirects save-session.sh --force's output into a fresh, empty logs/autonomous/session-end-HHMMSS.log before backgrounding the flush. save-session.sh's own NDC step runs housekeeping -- find "${REMEMBER_DIR}/logs/autonomous" -name "*.log" -empty -delete -- and on an ordinary successful run nothing ever writes into that redirect target (save-session.sh logs to its own daily narrative file, never to stdout/stderr), so that same sweep, run from inside the very process holding the redirect open, matched the still-empty log and deleted it. A later failure's WARNING then named a path already gone, and a healthy flush left no trace on disk that it had run at all -- the 164 surviving zero-byte logs and the two absent failure logs the issue reported.
Fix
session-end-hook.sh now seeds $_END_LOG with a one-line header before the flush subshell starts, so the file is never -empty by the time the sweep runs. A genuinely stale, still-empty log left behind by an earlier, abandoned run is untouched and keeps getting swept exactly as before -- covered by a paired positive-control test.
doctor.sh's own SessionEnd-liveness check (#370) already treats presence of session-end-*.log as its proof a flush ran; this fix repairs that derivation directly, so doctor.sh itself needed no change (confirmed by reading scripts/doctor.sh's SessionEnd-liveness section and its own test file, which stubs the marker rather than exercising the real hook, so it stays green either way).
Self-review finding, fixed in a follow-up commit
The spawned Explore reviewer flagged that the header-seed write itself opened $_END_LOG with a truncating redirect in the foreground, before the subshell forked -- and $_END_LOG's filename is second-granularity only (no PID, no session id), so two SessionEnd hooks for the same project ending in the same wall-clock second (an ordinary case per doctor.sh's own SessionEnd-liveness comments about concurrently open windows) could have one hook's header write clobber a sibling's already-appended output. Fixed by switching that write to append as well.
Not fixed here, filed as a follow-up: $_END_LOG's underlying filename collision -- no PID or session id at all, second-granularity naming only -- is pre-existing, not introduced by this diff. Closing it (e.g. adding a PID or session-id suffix) would also require updating scripts/doctor.sh's session-end-*.log glob in its SessionEnd-liveness check (#370), which is outside this pull request's two files (scripts/save-session.sh, scripts/session-end-hook.sh). Recommend a small follow-up issue: uniquify $_END_LOG's filename (PID or session id) and update doctor.sh's glob to match.
Testing
tests/test_session_end_log_swept_483.py (new): drives the real hook end to end through the real housekeeping sweep. test_must_fire_own_log_survives_a_successful_flush is red without the fix (assert [] -- confirmed by both my own pre-fix run and, independently, the auditor reverting the fix in a scratch copy and re-running). Paired with test_must_fire_a_genuinely_stale_empty_log_is_still_swept as a positive control, proving the sweep still runs and still does its job.
Full suite: 1899 passed, 43 skipped, 10m43s wall clock, macOS/darwin, Python 3.13.15 (observed on this platform only; Linux/Windows legs are CI's to confirm, per this repo's own convention).
Changelog fragment: changelog.d/483.fixed.md, validated with .oss/assemble_changelog.py --check -> ok.
Verified by the maintainer
Independent of the lane, at review of this pull request.
The retention gap this opens, filed as #487. I grepped
scripts/*.shandpipeline/*.pyfor anything besidessave-session.sh:1022that deletes, prunes or ages out files underlogs/autonomous/. There is nothing: no mtime sweep, no count cap, no rotation. That-empty -deleteis the directory's only retention mechanism, so makingsession-end-*.lognon-empty by construction means nothing ever reclaims one again -- a file per session, unbounded. Measured in two live stores on this machine on 2026-09-01:~/.remember/logs/autonomousholds 3 files, allsession-end-*, none non-empty; the project store holds 17, of which 15 aresave-*and only 3 are non-empty -- so the sweep is doing real work on thesave-*class and will keep doing it, while this class moves permanently out of its reach.This does not block the merge. The fix is correct, the files are one line each, and emptiness was always a proxy for staleness -- which is the proxy that produced #483 in the first place. It is filed rather than left implicit because the next person reading that directory needs to know the sweep no longer covers it.
The lane's recommended follow-up, filed as #488 --
$_END_LOG's second-granularity naming with no PID or session id. This pull request hardened the consequence (both writes append rather than truncate) but the collision itself is pre-existing and untouched, and closing it has to movescripts/doctor.sh's #370 liveness glob at the same time. Correctly left out of a two-file lane.Accepted as reported: the red run, the paired positive control, and the reviewer finding fixed in
773c9c3. I did not re-run the suite; CI is the gate across the matrix, and the lane's own run was macOS-only, as its body says.