Skip to content

Heartbeat turns silently drop claude-cli session bindings — CLI context lost after every heartbeat (regression in 0314819f918) #98895

Description

@obviyus

What happened

Heartbeat turns silently drop claude-cli session-binding updates, losing CLI-side conversation context and orphaning forked sessions under ~/.claude/projects.

src/auto-reply/reply/session-usage.ts:148-151 computes preserveSessionModelState = params.isHeartbeat === true || ... and both persist blocks (:237-239, :288-290) skip applyCliSessionIdToSessionPatch entirely when it is set — discarding both cliSessionBinding and clearCliSessionBinding produced by the run.

Claude CLI print-mode --resume mints a new session id every turn (this is why buildCliRunResult rewrites the binding each turn, and why the isCliBindingFlushed probe exists — see 07c1245). A heartbeat therefore resumes session id_N, advances the conversation into new id_H, and the stored binding stays at id_N. The next user turn resumes the pre-heartbeat session: everything the agent did or learned during heartbeat turns is silently absent from CLI context, and every heartbeat leaves an orphaned forked session on disk.

Provenance

  • 0eca3a9 (May 16) deliberately preserved only model/modelProvider for heartbeats and kept the binding write.
  • f55e986 gated the binding skip on preserveUserFacingRunState (internal handoffs only).
  • 0314819 (Jun 15, "fix(agents): replace prose terminal classifiers") widened the gate to preserveSessionModelState, capturing heartbeats and preserveRuntimeModel runs. Regression.

Expected behavior

Heartbeats preserve model-display fields only; the CLI session binding (and binding clears) from the run must still persist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions