Skip to content

Prune stale per-session delivery records; keep session-start-hook.sh's printed lines ASCII (#373, #367) - #386

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

fdaviddpt merged 2 commits into
mainfrom
fix/367

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Fixes two adjacent issues in scripts/session-start-hook.sh:

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>.md handoff was considered and rejected, per the
issue'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 -- the
one 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_DIR itself 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_session period the moment a user
switched back to single.

Self-review findings

Two agents (Explore and oss:auditor) reviewed the first commit
independently. 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:

  • Fixed: log() (scripts/log.sh) falls back to a bare echo ... >&2
    when $MEMORY_LOG_FILE can't be written -- a degraded-store condition
    this hook is built to tolerate. Two log calls in this file still
    carried 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 log calls too.
  • Fixed: the handoff_mode: per_session writes one remember.delivered.<session_id> per session into $REMEMBER_DIR/tmp and nothing ever removes them #373 sweep was gated on $PER_SESSION_HANDOFF (this
    session's own resolved mode), so a record from an earlier per_session
    period leaked forever after a switch back to single. Gate removed; new
    regression test added and confirmed red against a manual revert before
    being confirmed green.
  • Below the intake bar, not fixed: [ -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 surface
    errno. In principle this could prune a record under a false negative that
    ought to read as could-not-tell. In practice stat() needs execute
    permission only on parent DIRECTORIES, not read permission on the target
    file, and $SESSIONS_DIR (a directory Claude Code itself creates and
    manages, entirely under the current user's own account) is already gated
    by [ -d "$SESSIONS_DIR" ] before the loop runs -- so reaching this false
    negative 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 when
    transcript is confirmed gone (red before the fix, green after), keep
    when transcript still exists (positive control), leave untouched when
    $SESSIONS_DIR cannot be read at all (could-not-tell), never prune
    the 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 gated
    condition, 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.sh after every edit.
  • Full suite (pytest): 1674 passed, 43 skipped, 0 failed (run after a
    rebase-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.

fdaviddpt and others added 2 commits August 28, 2026 08:23
…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]>
@fdaviddpt
fdaviddpt merged commit 59bd41c into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/367 branch August 28, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant