Repository navigation
fix(agents): preserve valid CLI session bindings - #128732
vincentkoc merged 5 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 10:01 PM ET / August 25, 2026, 02:01 UTC. ClawSweeper reviewWhat this changesAdds a documented CLI-backend recovery policy so Anthropic sessions survive non-expiration failures while existing backends keep their default fresh-session retry behavior. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open: current main still clears every failed CLI binding, while this PR makes recovery backend-owned and preserves Anthropic bindings only when invalidation is proven. The previous review findings are addressed and supplied real-process proof is sufficient; it awaits normal maintainer merge review and exact-head CI. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherCLI backends execute provider processes for agent turns and store resumable session bindings. Recovery either preserves that binding for the next turn or clears it before a fresh retry. flowchart LR
A[Agent turn] --> B[CLI backend]
B --> C[Persisted session binding]
B --> D[Failure classification]
D --> E[Backend recovery policy]
E --> F[Preserve or clear binding]
F --> G[Next resumed or fresh turn]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +39, Tests +239, Docs +15. Total +293 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the documented backend-owned policy only after exact-head checks confirm both the default fresh-retry path and Anthropic retained-binding path. Do we have a high-confidence way to reproduce the issue? Yes, source establishes it with high confidence: current main clears a binding after any FailoverError, while the added two-turn persisted-store coverage exercises the format-failure path. Is this the best way to solve the issue? Yes. The recovery choice belongs to the backend contract, and the default preserves existing behavior instead of adding a Claude-specific core branch. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4ded341a28b7. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
e95d791 to
20a54e9
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head session-state proof for
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head CI follow-up for
|
|
Exact-head proof for
The recovery regression now proves a retained Representative real Anthropic Agent SDK 0.3.232 transport trace on this head: {"sdkVersion":"0.3.232","firstResult":"error_during_execution","firstSessionId":"11111111-1111-4111-8111-111111111111","secondResumeArg":"--resume=11111111-1111-4111-8111-111111111111","secondResult":"success","secondSessionId":"11111111-1111-4111-8111-111111111111","bindingRetained":true}No live Anthropic credential was available in the sanitized Testbox; this is representative proof through the real SDK process transport and result/session parser, not a live API claim. |
|
Exact-head recovery proof for
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head session-state proof for
No pending maintainer or risk decision remains. |
shouldClearFailedCliSessionBinding cleared the stored CLI session binding for every FailoverError, including format-class failures (output limit exceeded, parser error, unsupported image input). A format-class failover means the stream could not be read, not that the CLI session on disk is invalid — clearing the binding silently lost the conversation context on the next turn. Narrow the condition to only session-invalidating failover reasons (session_expired, auth, auth_permanent) using a whitelist so new reasons default to preserving the binding. Fixes openclaw#128698
d0e5dc2 to
c6a6599
Compare
|
Maintainer compatibility-risk acceptance for exact head
|
|
Merged via squash.
|
* fix(agents): preserve CLI session binding on format-class failover shouldClearFailedCliSessionBinding cleared the stored CLI session binding for every FailoverError, including format-class failures (output limit exceeded, parser error, unsupported image input). A format-class failover means the stream could not be read, not that the CLI session on disk is invalid — clearing the binding silently lost the conversation context on the next turn. Narrow the condition to only session-invalidating failover reasons (session_expired, auth, auth_permanent) using a whitelist so new reasons default to preserving the binding. Fixes openclaw#128698 * fix(agents): preserve valid CLI session bindings * fix(agents): retain CLI binding across format recovery * fix(agents): scope fresh CLI recovery by backend * docs(plugins): document CLI recovery policy --------- Co-authored-by: Vincent Koc <[email protected]>
Fixes #128698
What Problem This Solves
OpenClaw could discard a valid persisted CLI/Agent SDK conversation binding after a failure that did not prove the provider-side session was gone. The next turn then started without the prior conversation.
Root Cause and Fix
FailoverError(reason === "session_expired")proves a provider conversation binding is invalid.CliBackendConfig.freshSessionRecoverynow owns fresh-recovery policy. Undefined orreplace-bindingpreserves existing Gemini/external clear-and-reseed behavior; Anthropic opts intoinvalidated-only.src/agents/cli-runner/cli-run-recovery.ts.AbortError Audit
AbortErrorcleanup remains unchanged. It represents terminal local process cleanup, not aFailoverErroridentity decision. Existing reuse, fork-marker, and detached-media coverage still passes.Release Note
Fixed Claude Agent SDK-backed conversations losing their persisted resume binding after format, authentication, rate-limit, TLS, and other non-session-expiration failures, while preserving Gemini and external CLI backends' existing fresh-session recovery behavior.
Evidence
Exact head:
c6a6599fff8ee1103f7af9e566fbd5e0a28dffe9run_253be58aff3csucceeded on clean implementation head48cccd4667309355cb01482aed9b6fa1150ebbd4: 40/40 session invalidation tests, 90/90 recovery tests, 121/121 persisted command-path tests, 51/51 Anthropic descriptor tests, and 27/27 Google descriptor tests. Git status was clean before and after.@anthropic-ai/claude-agent-sdk0.3.232and@google/genai2.17.1.git diff --check, plugin SDK surface, full core-test type graph, and build/runtime postbuild.48cccd4667309355cb01482aed9b6fa1150ebbd4completed hosted CI: https://github.com/openclaw/openclaw/actions/runs/32790806640d0e5dc2eceb81c9bfcb22170f5be5fef65eb2b10completed hosted CI: https://github.com/openclaw/openclaw/actions/runs/32797209366freshSessionRecoveryvalues and legacy default. Remote proof passed targeted formatting, MDX validation (779 files), internal-link audit (6,555 links, zero broken),git diff --check, and the docs-only changed gate.b840a3c84e2ce43708ca8810caec0a1896c167c1with zero touched-file overlap. Remote Testbox proof passed 40/40 session, 90/90 recovery, 121/121 persisted command-path, and 51/51 Anthropic descriptor tests; plugin SDK surface, formatting, boundaries, dead-export scan, and core production typecheck also passed. The core-test type shard reached only the known shared-install baseline: missingpakodeclarations inui/vite.config.ts.tls_certificate; onlysession_expiredclears the persisted binding.formatfailure performs one attempt, retains the binding on disk, and the next normal turn resumes it. Claudesession_expiredclears and starts fresh. Geminiformat/timeout retains its two-attempt clear-and-reseed contract. Concurrent rebind replacement is refused.Direct
@anthropic-ai/claude-agent-sdk0.3.232 source/types confirmOptions.resumesupplies the session to resume and result messages carrysession_id. The real SDK subprocess transport was exercised on implementation head48cccd4667309355cb01482aed9b6fa1150ebbd4with a deterministic representative Claude executable; the rebased exact head reran the focused recovery matrix above:{"sdkVersion":"0.3.232","exactHead":"48cccd4667309355cb01482aed9b6fa1150ebbd4","firstResult":"error_during_execution","firstSessionId":"11111111-1111-4111-8111-111111111111","secondResumeArg":"--resume=11111111-1111-4111-8111-111111111111","secondResult":"success","secondSessionId":"11111111-1111-4111-8111-111111111111","bindingRetained":true}No live Anthropic credential was available in the sanitized proof environment. This is exact-head proof through the real SDK process transport and result/session contract, not a live API claim.
The shipped Codex app-server path is unaffected: it owns
thread/resumeincodex-rs/app-server-protocolandcodex-rs/app-server, outside the genericCliBackendConfigflow.Size
Production: +41/-2 (net +39). Tests: +268/-29 (net +239). Total: +309/-31 (net +278) across nine files.
The positive production delta is the additive plugin ownership boundary and canonical recovery-policy contract.
AI Assistance
Co-authored-by: SunnyShu [email protected]
Co-authored-by: Vincent Koc [email protected]