openclaw - ✅(Solved) Fix [Bug]: claude-cli fallback turn loses prior session context even though Claude session file still has full history [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#69973Fetched 2026-04-23 07:30:51
View on GitHub
Comments
2
Participants
3
Timeline
4
Reactions
0
Author
Timeline (top)
commented ×2cross-referenced ×1labeled ×1

When using claude-cli/claude-sonnet-4-6, a turn that falls back away from Claude can lose all prior context for the fallback model, even though the original Claude local session file still contains the fuller history and later Claude turns continue writing to that same file.

This makes the fallback turn behave as if the conversation just started with the first post-fallback message.

Error Message

02:05:09+00:00 warn model-fallback/decision {"subsystem":"model-fallback/decision"} {"event":"model_fallback_decision","tags":["error_handling","model_fallback","candidate_failed"],"runId":"fc48945f-bf07-481d-bf19-c472d07c859c","decision":"candidate_failed","requestedProvider":"claude-cli","requestedModel":"claude-sonnet-4-6","candidateProvider":"claude-cli","candidateModel":"claude-sonnet-4-6","attempt":1,"total":10,"reason":"billing","status":402,"errorPreview":"You're out of extra usage · resets 11pm (America/New_York)","errorHash":"sha256:9f33328f03be","nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.4","isPrimary":true,"requestedModelMatched":true,"fallbackConfigured":true} model fallback decision 02:05:09+00:00 warn model-fallback/decision {"subsystem":"model-fallback/decision"} {"event":"model_fallback_decision","tags":["error_handling","model_fallback","candidate_failed"],"runId":"fc48945f-bf07-481d-bf19-c472d07c859c","decision":"candidate_failed","requestedProvider":"claude-cli","requestedModel":"claude-sonnet-4-6","candidateProvider":"claude-cli","candidateModel":"claude-sonnet-4-6","attempt":1,"total":10,"reason":"billing","status":402,"errorPreview":"You're out of extra usage · resets 11pm (America/New_York)","errorHash":"sha256:9f33328f03be","nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.4","isPrimary":true,"requestedModelMatched":true,"fallbackConfigured":true} model fallback decision

Root Cause

When using claude-cli/claude-sonnet-4-6, a turn that falls back away from Claude can lose all prior context for the fallback model, even though the original Claude local session file still contains the fuller history and later Claude turns continue writing to that same file.

This makes the fallback turn behave as if the conversation just started with the first post-fallback message.

Fix Action

Fixed

PR fix notes

PR #68388: fix(cli-backend): restore compaction lifecycle and rotate claude-cli sessions after compaction

Description (problem / solution / changelog)

Summary

Fixes #68329 — CLI-backed sessions skipped both pre-turn native compaction checks and post-turn context-engine/plugin maintenance, so context grew unbounded. For claude-cli specifically, compacting only OpenClaw's local transcript was not enough: Claude Code maintains its own resumed session history on disk, so the next turn re-loaded the pre-compaction context.

This PR:

  • Runs the pre-turn native compaction lifecycle for CLI-backed runs.
  • Runs post-turn context-engine / plugin maintenance for CLI-backed runs.
  • Rotates Claude CLI sessions after compaction by seeding a new resumed session JSONL from the compacted transcript history and using the new session id for subsequent turns.
  • Falls back to a prompt-based reseed if Claude seeded-session creation fails, so the turn still proceeds with compacted context.

Files changed

  • src/agents/cli-runner.ts
  • src/agents/cli-runner/execute.ts
  • src/agents/cli-runner/types.ts
  • src/agents/cli-runner/prepare.ts
  • src/agents/command/attempt-execution.ts
  • src/agents/agent-command.ts
  • src/agents/cli-runner.compaction.test.ts (new)
  • src/agents/command/attempt-execution.cli.test.ts
  • src/commands/agent.test.ts

Validation

Run locally on the patched checkout:

  • pnpm exec vitest run src/agents/command/attempt-execution.cli.test.ts src/agents/cli-runner.compaction.test.ts src/commands/agent.test.tspassed
  • NODE_OPTIONS=--max-old-space-size=8192 pnpm exec tsc -p tsconfig.json --noEmitpassed

Test plan

  • CI green on the PR
  • Manual verification: long-running CLI-backed session now triggers compaction and subsequent turns resume against the rotated Claude CLI session id
  • Verify prompt-based reseed path when seeded-session creation is forced to fail

Closes #68329

Changed files

  • src/agents/agent-command.ts (modified, +57/-0)
  • src/agents/cli-runner.compaction.test.ts (added, +283/-0)
  • src/agents/cli-runner.ts (modified, +469/-1)
  • src/agents/cli-runner/execute.ts (modified, +3/-2)
  • src/agents/cli-runner/prepare.ts (modified, +4/-1)
  • src/agents/cli-runner/types.ts (modified, +7/-0)
  • src/agents/command/attempt-execution.cli.test.ts (modified, +3/-0)
  • src/agents/command/attempt-execution.ts (modified, +24/-0)
  • src/commands/agent.test.ts (modified, +69/-0)

Code Example

02:05:07+00:00 info agent/cli-backend {"subsystem":"agent/cli-backend"} cli exec: provider=claude-cli model=sonnet promptChars=1034
02:05:09+00:00 warn model-fallback/decision {"subsystem":"model-fallback/decision"} {"event":"model_fallback_decision","tags":["error_handling","model_fallback","candidate_failed"],"runId":"fc48945f-bf07-481d-bf19-c472d07c859c","decision":"candidate_failed","requestedProvider":"claude-cli","requestedModel":"claude-sonnet-4-6","candidateProvider":"claude-cli","candidateModel":"claude-sonnet-4-6","attempt":1,"total":10,"reason":"billing","status":402,"errorPreview":"You're out of extra usage · resets 11pm (America/New_York)","errorHash":"sha256:9f33328f03be","nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.4","isPrimary":true,"requestedModelMatched":true,"fallbackConfigured":true} model fallback decision

### Session file observations
- `~/.claude/projects/*/*.jsonl` contains the fuller current Claude session history
- `~/.openclaw/agents/*/sessions/` only shows the newer truncated current session plus older sessions
- The fallback model behaved as if only the first post-fallback message existed
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

When using claude-cli/claude-sonnet-4-6, a turn that falls back away from Claude can lose all prior context for the fallback model, even though the original Claude local session file still contains the fuller history and later Claude turns continue writing to that same file.

This makes the fallback turn behave as if the conversation just started with the first post-fallback message.

Steps to reproduce

  • Long-running claude-cli session with Sonnet
  • Claude appears to do server-side compaction/summarization silently at times
  • Sometimes important context is lost after compaction
  • In the specific failure case below, Claude hit a usage/billing limit and OpenClaw fell back for that turn
  • The fallback model appeared to have no prior context at all
  • However:
    • the Claude local session file under ~/.claude/projects/*/*.jsonl still had the fuller history
    • later turns continued writing to that same Claude session file
    • /status still showed claude-cli/sonnet*

Relevant log

02:05:07+00:00 info agent/cli-backend {"subsystem":"agent/cli-backend"} cli exec: provider=claude-cli model=sonnet promptChars=1034 02:05:09+00:00 warn model-fallback/decision {"subsystem":"model-fallback/decision"} {"event":"model_fallback_decision","tags":["error_handling","model_fallback","candidate_failed"],"runId":"fc48945f-bf07-481d-bf19-c472d07c859c","decision":"candidate_failed","requestedProvider":"claude-cli","requestedModel":"claude-sonnet-4-6","candidateProvider":"claude-cli","candidateModel":"claude-sonnet-4-6","attempt":1,"total":10,"reason":"billing","status":402,"errorPreview":"You're out of extra usage · resets 11pm (America/New_York)","errorHash":"sha256:9f33328f03be","nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.4","isPrimary":true,"requestedModelMatched":true,"fallbackConfigured":true} model fallback decision

Session file observations

  • ~/.claude/projects/*/*.jsonl contains the fuller current Claude session history
  • ~/.openclaw/agents/*/sessions/ only shows the newer truncated current session plus older sessions
  • The fallback model behaved as if only the first post-fallback message existed

Expected behavior

When using claude-cli/claude-sonnet-4-6, a turn that falls back away from Claude can lose all prior context for the fallback model, even though the original Claude local session file still contains the fuller history and later Claude turns continue writing to that same file.

This makes the fallback turn behave as if the conversation just started with the first post-fallback message.

Actual behavior

The fallback turn appears to have no prior context, even though the fuller Claude-side session history still exists locally and the overall session later continues on Claude.

OpenClaw version

OpenClaw 2026.4.15 (041266a)

Operating system

macOS 26.3.1

Install method

npm global

Model

claude-cli/claude-sonnet-4-6

Provider / routing chain

openclaw -> claude-cli

Additional provider/model setup details

No response

Logs, screenshots, and evidence

02:05:07+00:00 info agent/cli-backend {"subsystem":"agent/cli-backend"} cli exec: provider=claude-cli model=sonnet promptChars=1034
02:05:09+00:00 warn model-fallback/decision {"subsystem":"model-fallback/decision"} {"event":"model_fallback_decision","tags":["error_handling","model_fallback","candidate_failed"],"runId":"fc48945f-bf07-481d-bf19-c472d07c859c","decision":"candidate_failed","requestedProvider":"claude-cli","requestedModel":"claude-sonnet-4-6","candidateProvider":"claude-cli","candidateModel":"claude-sonnet-4-6","attempt":1,"total":10,"reason":"billing","status":402,"errorPreview":"You're out of extra usage · resets 11pm (America/New_York)","errorHash":"sha256:9f33328f03be","nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.4","isPrimary":true,"requestedModelMatched":true,"fallbackConfigured":true} model fallback decision

### Session file observations
- `~/.claude/projects/*/*.jsonl` contains the fuller current Claude session history
- `~/.openclaw/agents/*/sessions/` only shows the newer truncated current session plus older sessions
- The fallback model behaved as if only the first post-fallback message existed

Impact and severity

No response

Additional information

This looks like a turn-level fallback continuity issue rather than the original Claude session being fully lost.

Additional observation

After the Claude usage window reset, subsequent turns again ran normally on claude-cli/sonnet with no fallback/session reset in logs. This suggests the original Claude session itself remained alive, and the context loss was specific to the fallback turn/handoff rather than the Claude session being destroyed.

Confirmed follow-up

After the Claude usage window reset, I asked the same Claude session for a summary and it returned the full expected context. This confirms the original Claude session/history was still intact. The context loss appears specific to the fallback turn/handoff, not to the Claude session being destroyed.

extent analysis

TL;DR

The fallback model loses prior context when falling back from Claude, despite the original Claude local session file containing the fuller history.

Guidance

  • Verify that the ~/.claude/projects/*/*.jsonl file contains the expected fuller session history after the fallback occurs.
  • Check the OpenClaw configuration to ensure that session continuity is properly set up for fallback scenarios.
  • Investigate the model fallback decision log to understand why the fallback model is not using the prior context.
  • Consider modifying the fallback logic to use the original Claude session file for context, if possible.

Example

No code example is provided as the issue seems to be related to the configuration and behavior of the OpenClaw and Claude systems.

Notes

The issue appears to be specific to the fallback turn/handoff and not related to the Claude session being destroyed. The original Claude session remains intact, and subsequent turns run normally after the usage window reset.

Recommendation

Apply a workaround to modify the fallback logic to use the original Claude session file for context, if possible, to ensure session continuity during fallback scenarios. This is recommended because the original Claude session history is still intact, and using it for fallback context would provide a more seamless experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

When using claude-cli/claude-sonnet-4-6, a turn that falls back away from Claude can lose all prior context for the fallback model, even though the original Claude local session file still contains the fuller history and later Claude turns continue writing to that same file.

This makes the fallback turn behave as if the conversation just started with the first post-fallback message.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: claude-cli fallback turn loses prior session context even though Claude session file still has full history [1 pull requests, 2 comments, 3 participants]