Skip to content

fix(agents): recover claude-cli context-overflow sessions and keep retry artifacts alive#98934

Merged
obviyus merged 2 commits into
mainfrom
codex/fix-cli-session-recovery
Jul 2, 2026
Merged

fix(agents): recover claude-cli context-overflow sessions and keep retry artifacts alive#98934
obviyus merged 2 commits into
mainfrom
codex/fix-cli-session-recovery

Conversation

@obviyus

@obviyus obviyus commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #98897

What Problem This Solves

Two claude-cli session-recovery defects found by a reliability audit:

  1. CLI context overflow permanently wedged the session. "Prompt is too long" failures classified to a context_overflow classification that mapped to failover reason unknown with no retry code, so the existing fresh-session reseed machinery never fired and nothing on the main auto-reply path cleared the stale binding. Every subsequent turn resumed the same overflowing session and failed identically until a manual /reset. Since claude-cli sets ownsNativeCompaction: true, OpenClaw pre-turn compaction is a no-op for it — this path had no recovery at all. Same failure class as FailoverError during cli-backend turn does not clear stale cliSessionIds from sessions.json, causing infinite retry loop #97887.
  2. Live-session recovery retries ran against deleted run artifacts. In non-capture mode (MCP loopback unavailable), artifact-cleanup ownership transferred into the live session; a retryable no-output timeout closed the session and deleted the temp mcp.json and skills-plugin dirs, then the fresh-session recovery retry re-ran on the same context whose argv still pointed at the deleted paths — the recovery spawn failed, defeating the retry.

Why This Change Was Made

  1. context_overflow is now a first-class failover reason across the closed reason unions (agent runtime, cron run-log, gateway protocol schema — additive enum extension, HTTP status 413, OpenAI-compat invalid_request_error). CLI context-overflow failures carry a cli_context_overflow retry code on both the live and one-shot paths, flow through shouldRetryFreshCliSessionAfterFailover, clear the stale binding, and take the existing fresh-session reseed retry so context is carried forward instead of dropped.
  2. Run artifacts stay owned by the run (as capture mode already did): the ownership transfer into the live session is deleted, so a session close never deletes artifacts a pending retry still needs, and cleanup happens exactly once at run scope. The only spawn site builds sessions from the current turn's context, so no path respawns against another run's artifacts.

User Impact

Long-running claude-cli sessions that hit a context overflow now recover automatically with a fresh reseeded session instead of failing every turn until a manual /reset. Recovery retries after no-output timeouts work in non-capture configurations instead of spawning against deleted config paths.

Evidence

  • New regression tests: context-overflow on a resumed turn clears the binding and retries with a reseed prompt (retry-budget and post-delivery guards still hold); non-capture live session + no-output timeout + fresh retry runs with existing artifact paths and cleans up exactly once.
  • Validation: node scripts/run-vitest.mjs across cli-runner reliability/spawn/session, failover-error, cron run-log, and protocol conformance tests (400 tests pass); full remote pnpm check:changed green on Blacksmith Testbox tbx_01kwgm9tmtgyw8rzwh48exqer7 (https://github.com/openclaw/openclaw/actions/runs/28567342178, exit 0); repo autoreview (branch mode) clean.

@obviyus
obviyus requested a review from a team as a code owner July 2, 2026 05:36
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(agents): recover claude-cli context-overflow sessions and keep retry artifacts alive This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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

Labels

agents Agent runtime and tooling app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-cli session recovery: context overflow wedges binding permanently; live-session retry reuses deleted run artifacts

1 participant