Skip to content

fix(anthropic): enable Claude CLI session-expired history reseed#80934

Merged
steipete merged 2 commits into
openclaw:mainfrom
bitloi:fix/issue-80905-claude-cli-reseed
May 13, 2026
Merged

fix(anthropic): enable Claude CLI session-expired history reseed#80934
steipete merged 2 commits into
openclaw:mainfrom
bitloi:fix/issue-80905-claude-cli-reseed

Conversation

@bitloi
Copy link
Copy Markdown
Contributor

@bitloi bitloi commented May 12, 2026

Summary

  • Problem: Claude CLI session_expired recovery could retry fresh without OpenClaw transcript history.
  • Why it matters: users could see conversation amnesia after Claude CLI rotation even though OpenClaw transcript history was still available.
  • What changed: enabled the existing bounded raw transcript reseed opt-in for the bundled Claude CLI backend.
  • What did NOT change (scope boundary): native Claude resume, custom CLI backend defaults, and auth-boundary no-reseed protections.

Change Type

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof

  • Behavior or issue addressed: Claude CLI session_expired fresh-session recovery can now use bounded OpenClaw transcript reseed because the bundled Claude backend opts into the existing reseed contract.
  • Real environment tested: Local OpenClaw source checkout on Linux, branch fix/issue-80905-claude-cli-reseed, built from upstream/main abb4f96b81df4f91ab2b593d0aea2ebc9698e445.
  • Exact steps or command run after this patch:
    • node scripts/run-node.mjs --help
    • CI=true corepack pnpm test:extension anthropic
    • CI=true corepack pnpm test extensions/anthropic/cli-shared.test.ts
    • CI=true corepack pnpm test src/agents/cli-runner/session-history.test.ts src/agents/cli-runner/prepare.test.ts src/agents/cli-runner.reliability.test.ts extensions/anthropic/cli-shared.test.ts
    • CI=true corepack pnpm test extensions/anthropic
    • CI=true corepack pnpm check:changed
  • Evidence after fix (terminal capture):
$ node scripts/run-node.mjs --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
OpenClaw 2026.5.12-beta.1 (abb4f96) -- All your chats, one OpenClaw.
Usage: openclaw [options] [command]
Commands:
  agent                Run one agent turn via the Gateway
  gateway *            Run, inspect, and query the OpenClaw Gateway
  models *             List, scan, and set model providers
  sessions *           List stored conversation sessions

$ CI=true corepack pnpm test:extension anthropic
[test-extension] Running 6 test files for anthropic
Test Files  6 passed (6)
Tests       69 passed (69)

$ CI=true corepack pnpm test extensions/anthropic/cli-shared.test.ts
Test Files  1 passed (1)
Tests       17 passed (17)

$ CI=true corepack pnpm test src/agents/cli-runner/session-history.test.ts src/agents/cli-runner/prepare.test.ts src/agents/cli-runner.reliability.test.ts extensions/anthropic/cli-shared.test.ts
Test Files  3 passed (3)
Tests       50 passed (50)
Test Files  1 passed (1)
Tests       17 passed (17)

$ CI=true corepack pnpm test extensions/anthropic
Test Files  6 passed (6)
Tests       69 passed (69)

$ CI=true corepack pnpm check:changed
runtime-sidecar-loaders: local runtime sidecar loaders look OK.
Import cycle check: 0 runtime value cycle(s).
  • Observed result after fix: source-built OpenClaw starts locally, and the bundled Claude CLI backend now reports reseedFromRawTranscriptWhenUncompacted: true while preserving native resume args. The regression test failed before the fix with expected undefined to be true, then passed after the backend opt-in was added.
  • What was not tested: live authenticated Claude CLI rotation. This environment does not have a claude binary installed (command -v claude returned exit code 1), so live provider rotation proof needs a Claude-authenticated environment or maintainer proof: override.
  • Before evidence (optional but encouraged):
$ CI=true corepack pnpm test extensions/anthropic/cli-shared.test.ts
FAIL extensions/anthropic/cli-shared.test.ts > normalizeClaudeBackendConfig > opts bundled Claude CLI into bounded raw transcript reseed without disabling native resume
AssertionError: expected undefined to be true

Root Cause

  • Root cause: bundled Claude CLI had native resume configured but did not opt into the existing bounded raw transcript reseed contract, so session_expired fresh retries could be prepared without OpenClaw history.
  • Missing detection / guardrail: no extension-level regression test asserted that the bundled Claude backend enabled the reseed contract while preserving native resume.
  • Contributing context (if known): fix(cli-runner): add opt-in raw transcript reseed for invalidated CLI sessions #79764 added the generic opt-in reseed machinery, but left backend participation explicit and disabled by default.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/anthropic/cli-shared.test.ts
  • Scenario the test should lock in: bundled Claude CLI opts into bounded raw transcript reseed without disabling native resume.
  • Why this is the smallest reliable guardrail: the bug was a missing bundled-backend config opt-in; generic runner reseed behavior was already covered.
  • Existing test that already covers this (if any): src/agents/cli-runner/session-history.test.ts, src/agents/cli-runner/prepare.test.ts, and src/agents/cli-runner.reliability.test.ts cover the safe reseed, session_expired, and preserved auth-boundary behavior.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Claude CLI fresh-session recovery after safe invalidations can include bounded OpenClaw transcript history instead of retrying with only the current prompt.

Diagram

Before:
Claude resume -> session_expired -> fresh retry -> current prompt only

After:
Claude resume -> session_expired -> fresh retry -> bounded OpenClaw history + current prompt

Security Impact

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: N/A.

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: local source checkout
  • Model/provider: claude-cli backend config; no live Claude binary available in this environment
  • Integration/channel (if any): Anthropic bundled CLI backend
  • Relevant config (redacted): default bundled backend config

Steps

  1. Add an extension-level regression assertion that buildAnthropicCliBackend().config.reseedFromRawTranscriptWhenUncompacted is true and native resume args remain present.
  2. Run the regression before the fix and observe it fail with expected undefined to be true.
  3. Enable reseedFromRawTranscriptWhenUncompacted: true in the bundled Claude backend config.
  4. Run the targeted regression, issue acceptance tests, Anthropic extension tests, formatting check, and changed-file check.

Expected

  • Bundled Claude CLI opts into bounded raw transcript reseed.
  • Native Claude resume remains configured with sessionMode: "always" and --resume {sessionId}.
  • Existing raw-reseed safety behavior remains governed by generic CLI runner/session-history tests.

Actual

  • All targeted tests and checks passed after the one-field backend config fix.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification

What you personally verified (not just CI), and how:

  • Verified scenarios: new regression failed before and passed after; Anthropic extension lane passed; issue acceptance test slice passed; local OpenClaw CLI built and printed help from this checkout.
  • Edge cases checked: native resume args are preserved; generic tests cover safe invalidation reasons and auth-boundary no-reseed behavior.
  • What you did not verify: live authenticated Claude CLI rotation or an actual provider-side session_expired event in a Claude-authenticated runtime.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A.

Risks and Mitigations

  • Risk: live Claude rotation was not reproduced locally because the environment lacks the claude binary.
    • Mitigation: the patch uses existing bounded reseed machinery, adds a regression for the exact bundled-backend opt-in, and runs the issue's requested acceptance tests. Maintainers can either apply proof: override or rerun the same branch in a Claude-authenticated environment for live proof.
  • Risk: raw transcript reseed could be too broad.
    • Mitigation: this PR only opts the bundled Claude backend into the existing bounded contract; generic session-history tests preserve auth-profile and credential-epoch no-reseed protections.

@openclaw-barnacle openclaw-barnacle Bot added extensions: anthropic size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 12, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 12, 2026

Codex review: needs real behavior proof before merge.

Summary
The PR adds reseedFromRawTranscriptWhenUncompacted: true to the bundled Anthropic Claude CLI backend and adds a focused regression asserting native resume args remain configured.

Reproducibility: yes. from source: current main's Anthropic backend lacks the opt-in while prepareCliRunContext() only prepares raw transcript reseed for session-expired recovery when that boolean is true. I did not reproduce a live authenticated Claude CLI rotation.

Real behavior proof
Needs stronger real behavior proof before merge: The PR body includes terminal output for tests and CLI help, but not live or redacted runtime output showing Claude CLI session-expired recovery preserving history after the fix; the contributor should add logs/output/recording or get maintainer proof override, then update the PR body for re-review.

Next step before merge
The remaining blocker is contributor live proof or maintainer proof override, not a narrow code defect that ClawSweeper can repair automatically.

Security
Cleared: Cleared: the diff does not add dependencies, workflows, permissions, secret handling, or new execution machinery; it opts one bundled backend into an existing bounded same-session reseed contract with auth-boundary exclusions.

Review details

Best possible solution:

Land the narrow Anthropic backend opt-in after redacted live Claude CLI session-expired proof or maintainer proof override, while keeping the shared reseed safety boundaries unchanged.

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

Yes, from source: current main's Anthropic backend lacks the opt-in while prepareCliRunContext() only prepares raw transcript reseed for session-expired recovery when that boolean is true. I did not reproduce a live authenticated Claude CLI rotation.

Is this the best way to solve the issue?

Yes, the proposed path is the narrow maintainable fix: the owner plugin opts into an existing generic contract and adds a regression for that backend. A broader core default change would weaken the explicit opt-in boundary added by the earlier reseed work.

Acceptance criteria:

  • CI=true corepack pnpm test extensions/anthropic/cli-shared.test.ts
  • CI=true corepack pnpm test src/agents/cli-runner/session-history.test.ts src/agents/cli-runner/prepare.test.ts src/agents/cli-runner.reliability.test.ts extensions/anthropic/cli-shared.test.ts
  • CI=true corepack pnpm test:extension anthropic
  • CI=true corepack pnpm check:changed
  • Live or redacted Claude-authenticated session-expired recovery output showing bounded OpenClaw history is included on the fresh retry.

What I checked:

  • PR diff is narrowly scoped: The live PR diff adds one backend config boolean and one focused assertion that the bundled Claude CLI backend opts into raw transcript reseed while preserving sessionMode: "always" and --resume {sessionId}. (extensions/anthropic/cli-backend.ts:66, 62d8f4778774)
  • Current main lacks the Anthropic opt-in: On checkout HEAD, the bundled Anthropic backend has resumeArgs, sessionArg, and sessionMode: "always", but no reseedFromRawTranscriptWhenUncompacted field. (extensions/anthropic/cli-backend.ts:65, 7121791735fa)
  • Shared runner requires the opt-in: prepareCliRunContext() sets allowRawTranscriptReseed only when the backend config boolean is true, and treats reusable session retry prep as session-expired; without the boolean, session-expired recovery cannot prepare raw OpenClaw history. (src/agents/cli-runner/prepare.ts:414, 7121791735fa)
  • Existing reseed boundary remains bounded: loadCliSessionReseedMessages() only loads raw transcript tail when the opt-in is true and the invalidation reason is one of the allowed safe reasons; auth-profile and auth-epoch are not in the allowed set. (src/agents/cli-runner/session-history.ts:202, 7121791735fa)
  • Generic behavior already has focused coverage: Current tests cover opted-in session-expired raw-tail history preparation and auth-boundary no-reseed behavior, so the PR's added extension test is the missing owner-backend guardrail rather than a new core policy. (src/agents/cli-runner/prepare.test.ts:662, 7121791735fa)
  • Related issue remains the canonical user problem: The linked user report is still open and describes Claude CLI conversation amnesia after rotation; this PR uses closing syntax for that issue, so the right path is to review/land or reject this PR rather than close the report early.

Likely related people:

  • hclsys: The related merged PR and commit aeb7d0736446388055f4ac71f2f4713374acdfd6 added the opt-in raw transcript reseed contract, safety boundaries, docs, schema, and tests now used by this backend opt-in. (role: introduced generic reseed contract; confidence: high; commits: aeb7d0736446; files: src/agents/cli-runner/prepare.ts, src/agents/cli-runner/session-history.ts, src/config/types.agent-defaults.ts)
  • stainlu: GitHub path history for extensions/anthropic/cli-backend.ts shows recent Claude CLI backend work in commit 74ab62c6a297e2f92607c7f165a82598516f7fbb, making this a useful routing signal for the owner-plugin surface. (role: recent Anthropic backend contributor; confidence: medium; commits: 74ab62c6a297; files: extensions/anthropic/cli-backend.ts)
  • steipete: Recent path history for the CLI runner files shows multiple adjacent changes around prompt preparation and session history, including f28a987442374e53dc2dd17af7b4cabd8c045690 on prepare.ts and 15cf49222f92e7ff68ec9af049d0295b4a45e194 on session-history.ts. (role: recent adjacent area contributor; confidence: medium; commits: f28a98744237, 15cf49222f92; files: src/agents/cli-runner/prepare.ts, src/agents/cli-runner/session-history.ts)

Remaining risk / open question:

  • Live authenticated Claude CLI session-expired rotation has not been demonstrated after this patch; the current proof is test and CLI-startup output only.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7121791735fa.

Re-review progress:

@bitloi bitloi changed the title fix: reseed Claude CLI session context on rotation fix(anthropic): enable Claude CLI session-expired history reseed May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 12, 2026
@bitloi
Copy link
Copy Markdown
Contributor Author

bitloi commented May 12, 2026

@clawsweeper re-test

@kris-miller0705
Copy link
Copy Markdown

hi. @clawsweeper bitloi sometimes forked other's pr.

@kris-miller0705
Copy link
Copy Markdown

@clawsweeper i think it would be better to close this PR as soon as quickly. @bitloi has bad habit.

@bitloi
Copy link
Copy Markdown
Contributor Author

bitloi commented May 12, 2026

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 12, 2026

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@steipete steipete force-pushed the fix/issue-80905-claude-cli-reseed branch from bd464dc to 86e729b Compare May 13, 2026 11:49
@steipete
Copy link
Copy Markdown
Contributor

Maintainer proof before landing:

  • Rebased onto current main ce31fc91e15d3ec6bc48700f12400d728a8ca808.
  • Added maintainer changelog entry in CHANGELOG.md.
  • Targeted regression/runner slice passed locally:
    • pnpm test extensions/anthropic/cli-shared.test.ts src/agents/cli-runner/session-history.test.ts src/agents/cli-runner/prepare.test.ts src/agents/cli-runner.reliability.test.ts -- --reporter=verbose
    • 2 Vitest shards passed: agents 50 tests, extension-providers 17 tests.
  • Anthropic plugin lane passed locally:
    • pnpm test extensions/anthropic -- --reporter=verbose
    • 6 files, 69 tests passed.
  • Changed gate passed on Blacksmith Testbox:
  • Live Claude CLI proof run from PR worktree:
    • real Claude CLI 2.1.114 + first-party Claude.ai Max auth
    • forced stale Claude --resume <uuid> path, OpenClaw retried fresh with historyPrompt=present
    • result success: true, spawnedAttempts: 2, seeded marker RIVERGLASS-80934 returned by the model
    • caveat: synthetic backend id with bundled MCP/liveSession disabled to avoid preflight noise; it proves the Claude CLI session-expired reseed contract and retry path, not the full bundled MCP path.

GitHub CI note: pushed head 86e729b1d5cbb0be1806576d449a2e9c4b931b94 ran CI https://github.com/openclaw/openclaw/actions/runs/25797223575. The red lanes are unrelated to this PR surface and already fail on current main CI at ce31fc91e15d3ec6bc48700f12400d728a8ca808: https://github.com/openclaw/openclaw/actions/runs/25796317891 (check-dependencies, check-lint, checks-fast-contracts-plugins-c). This PR changes only CHANGELOG.md, extensions/anthropic/cli-backend.ts, and extensions/anthropic/cli-shared.test.ts.

Thanks @bitloi.

@steipete steipete merged commit c796b96 into openclaw:main May 13, 2026
98 of 105 checks passed
@steipete
Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

Thanks @bitloi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: anthropic proof: supplied External PR includes structured after-fix real behavior proof. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session context lost on Claude CLI rotation — conversation amnesia between messages

3 participants