Repository navigation
Description
[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)
-
The headless warm-stdin claude-cli backend writes no native transcript. openclaw spawns one warm
claude -pstdio child per session and feeds each turn over stream-json stdin. In this modeclaudestreams its reply to stdout (openclaw captures it to~/.openclaw/agents/<agent>/sessions/<sid>.jsonl) and never persists a native~/.claude/projects/<slug>/<sid>.jsonltranscript 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>*.jsonlfound only that openclaw copy — nothing under~/.claude/projects(the workspace-slug directory does not even exist), andsessions.jsonhad zerocliSessionBindingentries afterward. -
The post-turn probe checks exactly that nonexistent file. After a turn,
buildCliRunResult(src/agents/cli-runner.ts) gates binding persistence onisCliBindingFlushed(...), which callsclaudeCliSessionTranscriptHasContent(src/agents/command/attempt-execution.helpers.ts). That probe checks~/.claude/projects/<sanitized realpath(workspaceDir)>/<sessionId>.jsonl(path fromresolveClaudeCliProjectDirForWorkspace,src/agents/command/claude-cli-project-dir.ts), with a hardcodedCLAUDE_CLI_TRANSCRIPT_FLUSH_GRACE_MS = 250and retries at 0/50/150ms. Because the file is never written, the probe returns false every turn. -
A probe miss is destructive. On
bindingFlushOk === false,buildCliRunResultcomputesunflushedCliSessionId = effectiveCliSessionId, which makespersistedCliSessionId = undefined(so nocliSessionBindingis emitted) and emitsclearCliSessionBinding: true— actively wipingcliSessionBindings/cliSessionIds/claudeCliSessionIdfor that session. The parsedsession_idis thrown away every turn. -
The reseed safety net is disarmed by the same wipe. openclaw has
reseedFromRawTranscriptWhenUncompacted: trueand can rebuild history from its own captured transcript — but only whenrawTranscriptReseedReasonis inRAW_TRANSCRIPT_RESEED_ALLOWED_REASONS({missing-transcript, orphaned-tool-use, system-prompt, cwd, mcp, session-expired}). When the binding is wiped,resolveCliSessionReusereturns{}→rawTranscriptReseedReasonisundefined→loadRawTail()returns[]→ no history is carried. So the wipe defeats both--resumeand 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
- Configure an agent on the
claude-clibackend (warm stdio live session; defaultbundleMcp). - Turn 1 (e.g. Discord DM): "my favorite color is teal." → correct ack.
- Turn 2: "what's my favorite color?" → the agent has no record; it answers as if turn 1 never happened.
- Inspect
~/.openclaw/agents/<agent>/sessions/sessions.json:cliSessionBindingsisnull/absent. Inspect~/.claude/projectsfor the session id: no native transcript exists.
Regression
- fix(command): retry claude-cli transcript probe to close flush race #81048 (merged 2026-05-29) replaced a tolerant
~/.claude/projects/*directory-fanout scan (which would match any slug/path) with a single deterministic path viaresolveClaudeCliProjectDirForWorkspace. For a backend that writes no native transcript, deterministic resolution turns an occasional miss into a 100% miss. - fix(cli-runner): write-side flush gate + orphan-tool-use invalidator #84234 (merged 2026-05-30) made a flush-probe miss destructive by emitting
clearCliSessionBinding.
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
- fix(cli-runner): drop volatile systemPromptHash from claude-cli live fingerprint #81047 (open) — drops the volatile
systemPromptHashfrom the claude-cli live fingerprint. That addresses a different mechanism (per-turn fingerprint phantom-restart) that can produce a similar "every message looks like the first" symptom; it does not address the transcript-flush-probe miss / destructiveclearCliSessionBindingdescribed here. The two are complementary. - Same-class symptom reports: claude-cli Telegram DM context loss from missing-transcript race before transcript flush #77974, [Bug]:
claudeCliSessionTranscriptHasContentraces claude-cli's transcript flush, returning false negatives that force cold session starts #81042, [Bug]: Discord channel sessions lose recent conversation context after reset, breaking organic continuity #94750, [Bug]: 2026.6.x regression cascade — memory search broken, then sessions lost on every reconnect (multi-agent deployment broken) #95042.
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).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 24, 2026
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:
canonicalCanonical: #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:
fixed_by_candidate: [AI] fix(cli-runner): do not clear session binding on transient flush probe miss #96584 - Open PR explicitly closes this issue by making flush-probe misses non-destructive.fixed_by_candidate: fix(agents): skip binding-flush probe for warm-stdin claude-cli backends (fixes #96564) (AI-assisted) #96579 - Open PR references this issue and proposes skipping the binding-flush probe for warm-stdin claude-cli backends.adjacent_distinct: fix(command): retry claude-cli transcript probe to close flush race #81048 - Merged read-side retry/deterministic probe work for claude-cli transcript flush races, but it does not address the warm-stdin no-native-transcript destructive clear described here.adjacent_distinct: fix(cli-runner): write-side flush gate + orphan-tool-use invalidator #84234 - Merged write-side flush gate introduced the binding clear behavior involved here, but the PR itself is historical provenance rather than an open remaining-work tracker.adjacent_distinct: fix(cli-runner): drop volatile systemPromptHash from claude-cli live fingerprint #81047 - Open PR addresses a separate live-session fingerprint restart mechanism that can produce similar context-loss symptoms.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:
Codex review notes: model internal, reasoning high; reviewed against 3ab8d6aa609a.
Label changes
Label changes:
clawsweeper:linked-pr-open: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state no longer selects this label.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:
src/agents/cli-runner.ts:890, 3ab8d6aa609a)src/agents/cli-runner.ts:828, 3ab8d6aa609a)src/agents/command/attempt-execution.helpers.ts:221, 3ab8d6aa609a)src/agents/cli-runner.ts:886, f848a6f7f74b)src/agents/command/attempt-execution.helpers.ts:221, de455304cc1c)Likely related people:
src/agents/cli-runner.ts,src/agents/cli-runner.binding-flush.test.ts)src/agents/command/attempt-execution.helpers.ts,src/agents/command/attempt-execution.test.ts)src/agents/cli-runner.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.xydigit-zt commentedon Jun 24, 2026
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.tsnode scripts/run-vitest.mjs src/agents/cli-runner.helpers.test.tspnpm format:check -- --check src/agents/cli-runner.tsfix(cli-runner): preserve session binding for warm-stdin sessions
fix(cli-runner): skip transcript check for warm-stdin sessions at pre…
fix(cli-runner): skip transcript check for warm-stdin sessions at pre…
fix(cli-runner): skip post-turn flush probe for warm-stdin sessions
bradreaves commentedon Jun 25, 2026
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 andreturn undefined, which starvesprepare's reseed of the candidate session id — so continuity never recovers (historyPrompt=none, cold start). #96841 adds that second half (return the binding sopreparere-detectsmissing-transcriptand arms raw-transcript reseed;useResumestaysfalse, so no phantom--resume), plus an auth-free regression test that fails onmainand passes with the fix — and corrects a pre-existing test that had asserted the buggy behavior. Includes live multi-turn proof under themissing-transcriptcondition (recall via reseed; memory ruled out). Credit to @xydigit-zt and @liuhao1024 for the binding-persistence work.