Skip to content

False "previous session was not captured" warning fires on every /clear #206

Closed

Description

@fdaviddpt

Symptom

Right after /clear, the next user prompt is annotated with:

remember: your previous session was not captured. If you just installed or enabled the plugin, that is expected — capture starts now. Otherwise its hooks were not registered for that session; run /remember:doctor.

Capture was healthy. Observed 2026-07-27 23:08 in the DVSI project; at that moment .remember/now.md had been written 23:07:48 and today-2026-07-27.md 22:50:53. Nothing was missed.

Mechanism

scripts/session-start-hook.sh:139-148:

PREV_JSONL=$(ls -t "$(claude_projects_dir)/${PREV_SLUG}"/*.jsonl 2>/dev/null | tail -n +2 | head -1)
PREV_ID=$(basename "$PREV_JSONL" .jsonl)
SEEN_ID=$(cat "$CAPTURE_ALIVE" 2>/dev/null)
if [ -n "$PREV_ID" ] && [ "$SEEN_ID" != "$PREV_ID" ] && grep -q '"tool_use"' "$PREV_JSONL"; then
    # warn
fi

The check assumes SessionStart means "a new session id started, so capture-alive still holds the previous one".

/clear does not mint a new session id. It fires SessionStart with source=clear while the transcript, the session id, and the .jsonl file all stay the same. Confirmed in the incident: the newest .jsonl (b0a76ca7…, 513K — far too large to be a just-created session) is the current session, and tmp/capture-alive already contained b0a76ca7… because that session had made tool calls before the clear. PREV_ID resolved to the genuinely older c1ab365b….

So on a /clear, SEEN_ID != PREV_ID is structurally guaranteed:

before /clear at SessionStart(source=clear)
newest jsonl current session current session (unchanged)
capture-alive current session id current session id
computed PREV_ID — second-newest = an older session

The comparison can never hold, whatever the capture state. Same reasoning applies to compact and fork — every same-session SessionStart source.

Root enabler

session-start-hook.sh never reads its stdin JSON, so it has access to neither source nor session_id. It cannot distinguish a same-session restart from a fresh start, and it cannot exclude the current session from the "previous session" computation. The PREV_ID heuristic (second-newest file) is a stand-in for a session id the hook could simply be told.

The comment at lines 110-132 is aware a plugin-enable is indistinguishable from a fresh start and deliberately accepts a one-off false positive there. This is a different case: recurring, once per /clear, forever.

Secondary defect

tmp/capture-alive stores a single id (post-tool-hook.sh:111-113, last-write-wins). It can answer "which session most recently made a tool call", not "was session X captured". Once X is superseded the evidence is gone, so even with the /clear case fixed the detector stays fragile — e.g. two rapid sessions, or any ordering where the file advances before SessionStart reads it.

Repro

  1. In a project with the plugin active, run some tool calls (so capture-alive = current session id).
  2. /clear.
  3. Send any prompt.
  4. Warning appears — attached to the user prompt, since SessionStart writes tmp/capture-gap-notice (session-start-hook.sh:147) and user-prompt-hook.sh:46 emits it on the next turn.

Proposed fix

  1. Parse the SessionStart stdin JSON and run the gap check only for source in startup/resume. Kills this false positive on its own.
  2. Also use session_id from that JSON to exclude the current session when picking PREV_JSONL, instead of relying on "second-newest by mtime".
  3. Optional, for the secondary defect: make capture-alive a short append-only ring of recent session ids and test membership rather than equality.

Tests

  • source=clear (and compact, fork) with capture-alive == current session id ⇒ no notice written.
  • source=startup, previous session has "tool_use" and was never seen ⇒ notice written (existing behaviour preserved).
  • source=startup, previous session captured ⇒ no notice.
  • Previous session with zero tool calls ⇒ no notice (existing guard).

Activity

  1. added
    bug
    on Jul 27, 2026
  2. ca-sringert commented on Jul 27, 2026

    @ca-sringert

    Second repro of the secondary defect (recovery-saved session still flagged)

    Confirming the "secondary defect" noted above independently of the /clear case — this one hits it via a genuinely distinct previous session, not a same-session restart.

    Session d9dd5dcd-3bee-4e65-b3ba-180f87fd1211 (72 lines, contains tool_use) ended normally. It never crossed thresholds.delta_lines_trigger / cooldowns.save_seconds during its own life, so it was never live-saved — it was captured entirely via the next session's SessionStart recovery block:

    memory-2026-07-27.log:
    19:18:44 [extract] session d9dd5dcd-3bee-4e65-b3ba-180f87fd1211
    23:11:36 [extract] session d9dd5dcd-3bee-4e65-b3ba-180f87fd1211
    

    tmp/last-save.json afterward:

    {"sessions": {..., "d9dd5dcd-3bee-4e65-b3ba-180f87fd1211": 72, ...}, "session": "d9dd5dcd-3bee-4e65-b3ba-180f87fd1211", "line": 72}

    72/72 lines — fully captured.

    But tmp/capture-alive at that same moment still held an unrelated older session id (the last one that had a live PostToolUse fire), since save-session.sh's recovery path never touches capture-alive — only post-tool-hook.sh does. Next SessionStart computed PREV_ID=d9dd5dcd-..., compared against capture-alive, found a mismatch, saw tool_use in the transcript, and wrote the notice — despite the recovery block in that exact same hook run having just successfully saved it.

    So this isn't only a /clear/resume/compact/fork problem: it fires on any short session that ends before its own live-save thresholds are hit and gets picked up by the next session's recovery instead — which, per the thresholds discussion elsewhere in this repo (delta_lines_trigger: 50, save_seconds: 120), is probably the common case for short sessions, not an edge case.

    This seems to support prioritizing proposed fix §3 (make capture-alive a membership-testable record of saved sessions, e.g. checked against last-save.json's sessions map — the same source the recovery block's own SAVED_QUERY already trusts) rather than treating it as optional — §1/§2 alone (stdin source/session_id filtering) wouldn't catch this case, since a genuinely fresh startup also triggers it.

    Plugin v0.8.9.

  3. added a commit that references this issue on Jul 28, 2026
    e14b244
  4. added 2 commits that reference this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions