Skip to content

[bug] claude-cli (headless warm-stdin) backend loses all conversation continuity — transcript-flush probe can never succeed, so the session binding is wiped every turn #96564

Closed

Description

@bradreaves

[bug] claude-cli (headless warm-stdin) backend loses all conversation continuity — transcript-flush probe can never succeed, so the session binding is wiped every turn

Summary

On the claude-cli backend running in headless warm-stdin mode (claude -p --output-format stream-json --include-partial-messages over a persistent stdio child), conversation continuity is lost on every turn after the first — the agent answers the first message of a conversation correctly, then treats every subsequent message as if it were the first (no history).

Root cause: the post-turn transcript-flush probe validates a native transcript file that this backend never writes, so the probe misses 100% of the time, and a probe miss is now destructive — it emits clearCliSessionBinding, wiping the session binding. With no binding, the next turn has nothing to --resume and the reseed-from-own-transcript safety net is also disarmed (see below), so the conversation restarts cold.

Environment

  • openclaw 2026.6.8 (also present in 2026.6.9 and 2026.6.10 — see "Affected versions")
  • Backend: claude-cli (Anthropic Max subscription path, no API key), buildAnthropicCliBackend
  • claude CLI: 2.1.x
  • Linux; multi-agent setup with isolated per-agent workspaces

Mechanism (proven, not inferred)

  1. The headless warm-stdin claude-cli backend writes no native transcript. openclaw spawns one warm claude -p stdio child per session and feeds each turn over stream-json stdin. In this mode claude streams its reply to stdout (openclaw captures it to ~/.openclaw/agents/<agent>/sessions/<sid>.jsonl) and never persists a native ~/.claude/projects/<slug>/<sid>.jsonl transcript at all.

    Proven by a controlled single-turn live test: one DM created session <sid>; openclaw captured user+assistant to its own ~/.openclaw/agents/<agent>/sessions/<sid>.jsonl, but a whole-filesystem search for <sid>*.jsonl found only that openclaw copy — nothing under ~/.claude/projects (the workspace-slug directory does not even exist), and sessions.json had zero cliSessionBinding entries afterward.

  2. The post-turn probe checks exactly that nonexistent file. After a turn, buildCliRunResult (src/agents/cli-runner.ts) gates binding persistence on isCliBindingFlushed(...), which calls claudeCliSessionTranscriptHasContent (src/agents/command/attempt-execution.helpers.ts). That probe checks ~/.claude/projects/<sanitized realpath(workspaceDir)>/<sessionId>.jsonl (path from resolveClaudeCliProjectDirForWorkspace, src/agents/command/claude-cli-project-dir.ts), with a hardcoded CLAUDE_CLI_TRANSCRIPT_FLUSH_GRACE_MS = 250 and retries at 0/50/150ms. Because the file is never written, the probe returns false every turn.

  3. A probe miss is destructive. On bindingFlushOk === false, buildCliRunResult computes unflushedCliSessionId = effectiveCliSessionId, which makes persistedCliSessionId = undefined (so no cliSessionBinding is emitted) and emits clearCliSessionBinding: true — actively wiping cliSessionBindings / cliSessionIds / claudeCliSessionId for that session. The parsed session_id is thrown away every turn.

  4. The reseed safety net is disarmed by the same wipe. openclaw has reseedFromRawTranscriptWhenUncompacted: true and can rebuild history from its own captured transcript — but only when rawTranscriptReseedReason is in RAW_TRANSCRIPT_RESEED_ALLOWED_REASONS ({missing-transcript, orphaned-tool-use, system-prompt, cwd, mcp, session-expired}). When the binding is wiped, resolveCliSessionReuse returns {} → rawTranscriptReseedReason is undefined → loadRawTail() returns [] → no history is carried. So the wipe defeats both --resume and reseed.

Net: every turn after the first is a cold start, and cliSessionBindings is permanently absent for every claude-cli entry in ~/.openclaw/agents/*/sessions/sessions.json.

Reproduction

  1. Configure an agent on the claude-cli backend (warm stdio live session; default bundleMcp).
  2. Turn 1 (e.g. Discord DM): "my favorite color is teal." → correct ack.
  3. Turn 2: "what's my favorite color?" → the agent has no record; it answers as if turn 1 never happened.
  4. Inspect ~/.openclaw/agents/<agent>/sessions/sessions.json: cliSessionBindings is null/absent. Inspect ~/.claude/projects for the session id: no native transcript exists.

Regression

Together these convert "no native transcript" (harmless before, because openclaw reseeds from its own captured transcript) into "binding wiped every turn."

Affected versions

The binding/probe/reseed code paths are unchanged in 2026.6.9 and 2026.6.10 — no commit since 2026.6.8 touches attempt-execution.helpers.ts, claude-cli-project-dir.ts, or session-history.ts, and the cli-runner.ts commits since 2026.6.8 are unrelated (channel-identity hook, dead-code deletion, empty-response diagnostics, context-engine). So 2026.6.8 / 2026.6.9 / 2026.6.10 are all affected.

Relation to existing reports

Proposed fixes

A. Minimal mitigation (what I'm running locally as a one-line dist patch): in buildCliRunResult, don't treat a flush-probe miss as a reason to discard the session id — never set unflushedCliSessionId from a pure probe miss, so the binding is persisted and clearCliSessionBinding is not emitted. This is blunt: it disables the flush gate entirely, including for the interactive path the gate was written to protect, so it is a local mitigation rather than a principled fix.

B. Backend-aware probe (preferred). When the active backend is the headless warm-stdin claude-cli mode (which never writes ~/.claude/projects/<slug>/<sid>.jsonl), validate against openclaw's own captured transcript — the file it already reseeds from — instead of the native path. This fixes the wrong-artifact root cause without weakening the gate for backends that do write a native transcript.

C. Non-destructive miss. Decouple "probe missed" from "wipe the binding": a flush-probe miss should not emit clearCliSessionBinding. Only a genuine invalidation (auth-profile / auth-epoch / system-prompt / cwd / mcp mismatch) should clear the binding; a transient/zero flush should leave it in place and let --resume/reseed handle recovery.

(B) addresses the root cause most directly; (C) is a smaller, safe change that also re-arms the reseed path. (A) is a degenerate form of (C).

Impact

Total loss of multi-turn continuity for every agent routed to the claude-cli (Max subscription) backend — i.e. the headline reason to use that backend. Workarounds today are limited to routing those agents to an API/OpenRouter path (defeats the purpose) or hand-patching the dist.


This investigation — the live root-cause proof, the code tracing across cli-runner.ts / attempt-execution.helpers.ts / claude-cli-project-dir.ts / session-history.ts, the regression bisection across releases, and this write-up — was done entirely by Claude Opus 4.8 (claude-opus-4-8).

Activity

  1. clawsweeper commented on Jun 24, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 24, 2026, 7:49 PM ET / 23:49 UTC.

    Summary
    Keep open: the issue is still valid on current main and is now paired with open implementation candidates, so the right cleanup path is to review and land or close the linked fix PRs rather than closing the issue early.

    Reproducibility: yes. source inspection gives a high-confidence reproduction path: current main clears the CLI binding when bindingFlushOk is false, while the probe checks the Claude project transcript path described in the report. I did not run a live claude-cli warm-stdin session in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #96564
    Summary: This issue is the canonical report for the warm-stdin claude-cli binding-clear-on-flush-miss bug; two open PRs are candidate fixes, while older related reports cover adjacent transcript-race or fingerprint mechanisms.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    No separate repair lane is needed while open closing PRs are already attached to the issue.

    Review details

    Best possible solution:

    Review the linked fix candidates, land the safest one with focused binding-flush regression coverage and live or packaged claude-cli proof, then let the closing PR resolve this issue.

    Do we have a high-confidence way to reproduce the issue?

    Yes, source inspection gives a high-confidence reproduction path: current main clears the CLI binding when bindingFlushOk is false, while the probe checks the Claude project transcript path described in the report. I did not run a live claude-cli warm-stdin session in this read-only review.

    Is this the best way to solve the issue?

    Yes, the best fix should stop a pure flush-probe miss from destructively clearing a valid binding, while preserving explicit invalidation for real auth, cwd, MCP, system-prompt, or orphan-tool-use mismatches.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Two open PRs propose different fix shapes for the same session-state bug; maintainers should choose one canonical path rather than landing both.

    Codex review notes: model internal, reasoning high; reviewed against 3ab8d6aa609a.

    Label changes

    Label changes:

    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • remove clawsweeper:fix-shape-clear: Current issue advisory state no longer selects this label.
    • remove clawsweeper:queueable-fix: Current issue advisory state no longer selects this label.

    Label justifications:

    • P1: The report describes a current claude-cli backend regression that breaks multi-turn continuity for real users after the first turn.
    • impact:session-state: The failure clears CLI session bindings and causes subsequent turns to lose conversation continuity.
    • impact:data-loss: The user-visible effect is lost conversational context and unusable prior-turn state for the affected backend.
    Evidence reviewed

    What I checked:

    • Issue discussion identifies open fix PR: A contributor comment links [AI] fix(cli-runner): do not clear session binding on transient flush probe miss #96584 as a proposed fix for this issue, and the PR body uses closing syntax, so the issue should remain open until that candidate lands or is rejected.
    • Current main still has destructive binding-clear path: buildCliRunResult still derives unflushedCliSessionId from bindingFlushOk === false and emits clearCliSessionBinding when that id is set, matching the reported source-level failure mode on current main. (src/agents/cli-runner.ts:890, 3ab8d6aa609a)
    • Flush probe checks Claude project transcript path: isCliBindingFlushed calls claudeCliSessionTranscriptHasContent with the effective session id and workspaceDir, so a backend that does not write the expected Claude project transcript can force bindingFlushOk false. (src/agents/cli-runner.ts:828, 3ab8d6aa609a)
    • Probe implementation uses deterministic Claude project transcript: claudeCliSessionTranscriptHasContent resolves the Claude project directory for the workspace and checks .jsonl for assistant content, which matches the reported nonexistent-artifact probe path. (src/agents/command/attempt-execution.helpers.ts:221, 3ab8d6aa609a)
    • History shows the write-side gate came from a merged session-state PR: git blame ties the bindingFlushOk/unflushedCliSessionId block to f848a6f, the merged write-side flush gate and orphan-tool-use invalidator work referenced by this issue. (src/agents/cli-runner.ts:886, f848a6f7f74b)
    • Related read-side probe history: git log shows de45530 merged the deterministic/retry transcript probe work, which is adjacent provenance for the current probe behavior. (src/agents/command/attempt-execution.helpers.ts:221, de455304cc1c)

    Likely related people:

    • adele-with-a-b: The binding flush gate and clear-binding behavior appear in blame from the merged write-side flush gate work that this issue identifies as making probe misses destructive. (role: introduced behavior; confidence: high; commits: f848a6f7f74b; files: src/agents/cli-runner.ts, src/agents/cli-runner.binding-flush.test.ts)
    • benjamin1492: Merged the deterministic/retry Claude CLI transcript probe path in the helper that is still used by the write-side gate. (role: adjacent feature contributor; confidence: high; commits: de455304cc1c; files: src/agents/command/attempt-execution.helpers.ts, src/agents/command/attempt-execution.test.ts)
    • xydigit-zt: Opened the currently linked closing PR that directly changes the reported binding-clear behavior, making them useful for follow-up routing even though the current-main behavior predates that PR. (role: current fix candidate author; confidence: medium; commits: 9f9678186442; files: src/agents/cli-runner.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:data-lossCan lose, corrupt, or silently drop user/session/config data.
    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.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    no-staleExclude from stale automation
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 24, 2026
  3. xydigit-zt commented on Jun 24, 2026

    @xydigit-zt
    Contributor

    I've opened PR #96584 to fix this issue.

    The fix removes the destructive session binding clearing behavior when the transcript flush probe fails. The headless warm-stdin claude-cli backend never writes native transcript, so the probe always fails - causing session binding to be wiped every turn.

    Tests passed:

    • node scripts/run-vitest.mjs src/agents/cli-runner.binding-flush.test.ts
    • node scripts/run-vitest.mjs src/agents/cli-runner.helpers.test.ts
    • pnpm format:check -- --check src/agents/cli-runner.ts
  4. added
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    and removed
    no-staleExclude from stale automation
    clawsweeper: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.
    on Jun 24, 2026
  5. added 4 commits that reference this issue on Jun 24, 2026
    74c3d20
    8981f62
    064ea63
    c6fca21
  6. bradreaves commented on Jun 25, 2026

    @bradreaves
    ContributorAuthor

    Filed a fix PR with the missing half + real-behavior proof: #96841.

    Persisting the binding (the approach in #96584 / #96579) is necessary but not sufficient: under the no-native-transcript condition, resolveReusableCliSessionBinding (src/agents/command/attempt-execution.ts) clears the store and return undefined, which starves prepare's reseed of the candidate session id — so continuity never recovers (historyPrompt=none, cold start). #96841 adds that second half (return the binding so prepare re-detects missing-transcript and arms raw-transcript reseed; useResume stays false, so no phantom --resume), plus an auth-free regression test that fails on main and passes with the fix — and corrects a pre-existing test that had asserted the buggy behavior. Includes live multi-turn proof under the missing-transcript condition (recall via reseed; memory ruled out). Credit to @xydigit-zt and @liuhao1024 for the binding-persistence work.

  7. locked as resolved and limited conversation to collaborators on Aug 12, 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

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.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.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions