Repository navigation
Merged
Conversation
…s printed lines ASCII (#373, #367) #373: handoff_mode: "per_session" wrote one remember.delivered.<session_id> record per session into $REMEMBER_DIR/tmp and nothing removed it -- the same directory and class of leak #362 already fixed once, under a different filename. session-start-hook.sh now prunes a session's record once that session's own transcript is confirmed gone from Claude Code's session directory. Deliberately NOT coupled to the paired remember.<session_id>.md handoff, which survives forever on purpose (#221) -- that coupling would have reintroduced unbounded growth under a new name. When the session directory itself cannot be read, nothing is pruned: could-not-tell must never render as pruned. #367: four echo lines in the same file printed a U+2014 em-dash to stdout/stderr, with what a cp1252 Windows console does with them left unestablished. Decided file-wide, as the issue argued: this file's printed (echo/printf) lines may not carry non-ASCII at all, so the four are now plain ASCII. The file's ~94 other em-dashes, all in comments that never reach a stream, are untouched. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two findings from the post-commit review of c320cee: - scripts/log.sh's log() falls back to a bare `echo ... >&2` when $MEMORY_LOG_FILE cannot be written. Two `log` calls in session-start-hook.sh still carried a U+2014 em-dash, which is exactly the #367 file-wide rule this same commit exists to apply -- fixed the same way as the four echo lines, and the new #367 regression test now scans `log` calls too, not just echo/printf. - The #373 sweep was gated on $PER_SESSION_HANDOFF (the CURRENT session's own resolved mode), so a record left behind during an earlier per_session period leaked forever once a user switched handoff_mode back to "single" -- the same class of unbounded growth #373 exists to fix, just behind a config toggle. The sweep now runs whenever $SESSIONS_DIR and $REMEMBER_DIR/tmp are both available, independent of the current session's own mode; legacy (single-mode) records are still never matched, because the glob requires a trailing session-id segment the shared "remember.delivered" file does not have. Both changes are covered by new/adjusted tests, confirmed red against a manual revert before being confirmed green against the fix. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Summary
Fixes two adjacent issues in
scripts/session-start-hook.sh:handoff_mode: per_session writes one remember.delivered.<session_id> per session into $REMEMBER_DIR/tmp and nothing ever removes them #373 -- with
handoff_mode: "per_session", every session left aremember.delivered.<session_id>record behind in$REMEMBER_DIR/tmpandnothing ever removed it -- the same directory, and the same class of leak,
that lib-memory-dir.sh's EXIT-trap cleanup leaks remember-config-*.json on Windows — 23,908 found in one %TEMP% #362 already fixed once under a different filename. A new sweep
prunes a session's delivery record once that session's own transcript is
confirmed gone from Claude Code's own session directory
(
$SESSIONS_DIR/<id>.jsonl).session-start-hook.sh prints em-dashes to stdout/stderr on four lines, and nothing establishes what a cp1252 console does with them #367 -- four
echolines (plus twologcalls found in self-review,see below) printed a U+2014 em-dash to stdout/stderr, with what a cp1252
Windows console does with them left unestablished by the issue (the issue
explicitly doubts the originally-reported
UnicodeEncodeErrormechanism,since bash's
echoperforms no encode step). Decided file-wide as theissue argued for: this file's printed lines may not carry non-ASCII at
all. The file's ~94 other em-dashes, all in comments that never reach a
stream, are untouched.
Design decisions (the judgment calls the brief flagged)
#367 is file-wide, not per-line. Fixing only the newest line would leave
the file's own convention inconsistent. Neither candidate Windows outcome
(cosmetic mojibake vs. a decode failure one layer up) was observed -- no
Windows machine was available -- so this ships as a decision under
uncertainty in the safe direction (ASCII), not as a claim that either
outcome was reproduced.
#373's coupling is to the session's own transcript, not to the paired
handoff. Coupling the delivery record's lifetime to its paired
remember.<session_id>.mdhandoff was considered and rejected, per theissue's own reasoning: that handoff survives forever ON PURPOSE (#221), so
tying the record's life to it would reintroduce unbounded growth under a
new name. Instead the record is pruned once
$SESSIONS_DIR/<id>.jsonl-- theone fact that actually answers "is this session over" -- is confirmed
absent. Three states, matching the issue's own framing: transcript
confirmed absent -> pruned; transcript confirmed present -> kept (correct,
not a bug);
$SESSIONS_DIRitself unreadable -> nothing touched(could-not-tell must never render as pruned).
The sweep runs independent of the CURRENT session's own
handoff_mode(added during self-review, see below) -- gating it on the live mode would
leak every record from a past
per_sessionperiod the moment a userswitched back to
single.Self-review findings
Two agents (
Exploreandoss:auditor) reviewed the first commitindependently. Three findings surfaced; two were fixed in a follow-up
commit, one is recorded here as below the intake bar rather than filed or
coded around:
log()(scripts/log.sh) falls back to a bareecho ... >&2when
$MEMORY_LOG_FILEcan't be written -- a degraded-store conditionthis hook is built to tolerate. Two
logcalls in this file stillcarried an em-dash and were invisible to the original session-start-hook.sh prints em-dashes to stdout/stderr on four lines, and nothing establishes what a cp1252 console does with them #367 regression
test's echo/printf-only scan. Fixed the same way as the four echo lines;
the test now scans
logcalls too.$PER_SESSION_HANDOFF(thissession's own resolved mode), so a record from an earlier
per_sessionperiod leaked forever after a switch back to
single. Gate removed; newregression test added and confirmed red against a manual revert before
being confirmed green.
[ -e "$SESSIONS_DIR/$id.jsonl" ]cannot distinguish "transcript truly gone" (ENOENT) from a permission
failure on the file itself (EACCES) -- bash's
[ -e ]does not surfaceerrno. In principle this could prune a record under a false negative that
ought to read as could-not-tell. In practice
stat()needs executepermission only on parent DIRECTORIES, not read permission on the target
file, and
$SESSIONS_DIR(a directory Claude Code itself creates andmanages, entirely under the current user's own account) is already gated
by
[ -d "$SESSIONS_DIR" ]before the loop runs -- so reaching this falsenegative needs the user to have made a subdirectory of their own,
single-user Claude Code data store inaccessible to themselves, which no
ordinary operation of this plugin produces. Pinning it with a portable
cross-platform test would need permission-bit tricks that behave
differently enough on Windows/git-bash to widen the existing win32 skip
for real complexity against a scenario nobody hits outside deliberately
sabotaging their own store.
Test plan
tests/test_delivery_record_pruning_373.py-- 5 tests: prune whentranscript is confirmed gone (red before the fix, green after), keep
when transcript still exists (positive control), leave untouched when
$SESSIONS_DIRcannot be read at all (could-not-tell), never prunethe running session's own just-written record, and (added in
self-review) still prune a leftover record after switching back to
handoff_mode: "single"(confirmed red against the old gatedcondition, green against the fix).
tests/test_printed_lines_ascii_367.py-- 3 tests: no printed(echo/printf/log) line carries non-ASCII, comment em-dashes are
untouched (scope boundary), and a positive control that the scan
actually read the real file (found >40 echo/printf/log lines).
bash -n scripts/session-start-hook.shafter every edit.pytest): 1674 passed, 43 skipped, 0 failed (run after arebase-equivalent full pass covering the mode-gate fix too).
python3 .oss/assemble_changelog.py --check --check-links --dir changelog.d --changelog CHANGELOG.md-- ok.Closes #373, closes #367.