Repository navigation
fix(claude-cli): apply thinking and keep live sessions warm - #125528
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 7:49 AM ET / 11:49 UTC. ClawSweeper reviewWhat this changesThis PR forwards selected thinking levels to Claude CLI processes and reuses compatible Claude live processes across MCP-captured turns without retaining stale turn authority. Merge readinessKeep open: the PR is not on current main, and source review plus its exact-head hosted Gateway/Claude/MCP evidence support the proposed repair with no discrete correctness finding. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherThe CLI runner prepares each agent turn, launches or resumes a provider-owned Claude CLI child, and routes MCP tool delivery through the Gateway. The change carries prepared thinking policy into that child and rotates each turn’s Gateway authority while preserving an eligible warm process. flowchart LR
A[Agent turn] --> B[Prepared CLI execution]
B --> C[Thinking policy environment]
B --> D[MCP turn grant]
C --> E[Claude CLI child process]
D --> F[Live-process grant transfer]
F --> E
E --> G[Gateway MCP tool delivery]
G --> H[Turn cleanup or next resume]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +640, Tests +1113, Docs +7. Total +1760 across 72 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: Preserve the single prepared-runtime capability handoff and fingerprinted live-session path, then validate the clean merge result rather than adding a thinking-specific reuse exception or parallel grant path. Do we have a high-confidence way to reproduce the issue? Yes for the PR head: source and focused tests define the prior spawn-per-captured-turn behavior, and the PR body supplies exact-head hosted Gateway/Claude/MCP after-fix evidence; this reviewer did not execute it in the read-only checkout. Is this the best way to solve the issue? Yes: carrying prepared thinking facts to the provider backend and transferring each fresh admission onto the existing process bearer is cleaner than rediscovering policy at projection time or adding a thinking-only reuse gate. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c28c279afa37. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What 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 (26 earlier review cycles; latest 8 shown)
|
9be8039 to
1baba8c
Compare
MCP delivery capture no longer kills the warm Claude process after every turn. Capture-key admission is fenced by grant activate/deactivate so prompt-cache continuity can survive across messages. Co-authored-by: Cursor <[email protected]>
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
|
Related follow-up: #140566 (“preserve resumed CLI caches across Git changes”) is now merged. Keeping a compatible Claude process warm and preserving the request prefix when a process must resume are complementary improvements. The new fix targets the latter: it prevents Claude Code’s refreshed startup Git snapshot from rewriting the conversation prefix after workspace activity. It does not change MCP capture/grant lifetimes, process-reuse decisions, or thinking-level transitions. It should not be read as replacing the warm-session work tracked here. Existing merged/closed status is unchanged. Reference: #140566 |
Summary
High Level TLDR
Claude CLI now advertises and applies thinking levels end to end. Captured live sessions keep the same Claude process warm for compatible turns so prompt-cache reuse survives; a changed spawn-time thinking budget cleanly replaces that process.
What Problem This Solves
This combines the two related Claude CLI fixes from #125528 and #125972.
Logical
anthropic/<model>rows route toclaude-cli/<model>but prepared configured catalogs intentionally omit runtime-only rows. The former projection-time bridge searched for that absent sibling, so the live Gateway advertisedreasoning=false, defaulted tooff, and ignored configured thinking defaults. Separately, selecting a level changed only an informational system-prompt token and not Claude Code execution.Captured MCP-delivery turns also killed the live Claude child after every response because the capture key is spawn-time process/MCP-header state. That erased prompt-cache continuity and forced cold resume on every following turn.
Why This Change Was Made
models.listkeeps the public logical provider but uses the concrete runtime policy; Claude CLI Mythos therefore stays off-only.off=0,minimal=1024,low=2048,medium=8192,high/xhigh=16384,max=32768MAX_THINKING_TOKENS. Positive fixed budgets also setCLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1where needed.reasoning=false. Existing Fableoffselections normalize to low mandatory-adaptive execution; ordinary optional-thinking rows remain constrained to onlyoff.thinking=<level>remains informational prompt runtime info; Claude Code execution is controlled by launch environment.prepared-model-runtime-materializations.tsandchat-metadata-runtime.tsoverlay hunks.User Impact
Claude CLI model controls now show the levels the concrete runtime can execute, honor the configured default, and make a selected level affect the next run. Unchanged captured turns retain the warm child and its prompt cache. Switching thinking level cleanly respawns the child so the new budget actually takes effect.
Evidence
Thinking-level cache lane coverage (2026-08-19)
The existing
CLI_CACHE_PROBEfresh-process resume flow now configuresthinking: medium, switches the same session tohigh, and logs/asserts normalized usage forresume2,thinking-switch, andthinking-steady. The switch floor is 30%: Anthropic's tools -> system -> messages cache hierarchy says a thinking-parameter change invalidates messages only, so a hit proves the tools and system tiers survived. The next same-level turn retains the existing 90% floor.The same
CLI_RESUMEcontinuity flow now leaves bundled MCP enabled and requires the Claude live-session generation to survive the capture-enabled resume, proving delivery capture does not respawn the child.Contract source, maintainer deployed-Haiku measurement: steady state 99.8%; medium -> high switch 63.5% (messages tier invalidated only); next high turn 99.8%.
Live lane: not run locally because API-key mode requires
ANTHROPIC_API_KEYorANTHROPIC_API_KEY_OLD, and neither is present. Docker and Claude CLI are available; subscription auth and the operator Gateway were deliberately not substituted.Thinking evidence
Claude Code environment variables document
MAX_THINKING_TOKENS=0as disabling thinking and positive values as fixed budgets; adaptive models requireCLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1for positive fixed budgets.Standalone installed Claude Code 2.1.235 headless proof used the sanitized form below (no Gateway, OpenClaw state, credentials, or response content included):
Observed stream JSON: unset produced 0 thinking blocks;
1024produced 1 block / 62 thinking tokens;16384produced 1 block / 81 thinking tokens;0produced 0 blocks / 0 thinking tokens.The prepared-catalog boundary regression uses sparse logical Anthropic overrides with no
reasoning, routes them throughclaude-cli, and configuresparams.thinking=medium. It proves logical rows publish runtime reasoning, full levels, and the configured default without runtime siblings in the prepared catalog.Live-session evidence
#125972 is integrated from
565510b98bd553e18cb40a8a8455edabeed004ac. The reviewed execution chain isexecutePreparedCliRun→runSerializedClaudeTurn→createCliToolTracking→ MCP grant admission. Same-identity captured turns retain one process and one capture key; grant deactivation fences turns; undrained delivery closes the process withmcp-capture-rotation.The joint real execute/live-session regression proves:
2048starts the child, another2048turn reuses it, and16384cancels that child and spawns exactly one replacement. This retains #125972's prompt-cache benefit for unchanged levels while applying a level change on the next captured turn.Verification
pnpm check:test-types— passed.pnpm check:changed— passed../.agents/skills/autoreview/scripts/autoreview --mode uncommittedand--mode branch— clean; no accepted/actionable findings.The CI repair also adds the new prepared runtime fact to both worker fixtures and corrects the command-list expectation: authored
models.providers[].models[].inputremains authoritative even though provider normalization runs, so normalization must not add image capability the operator did not configure.Production vs test LOC
Relative to
origin/main, production is +260/−39 (net +221) and tests are +682/−132 (net +550). Production growth is the prepared-capability owner boundary and Claude Code launch contract; test growth covers preparation, capture lifetime, and cross-boundary regressions.What was not tested
The operator's live Gateway and
~/.openclawstate were not touched. No new live cache-token benchmark was run after combining the PRs; repeating one would require operator credentials/state. The owner-path tests are the closest safe proof.Deployed live proof (2026-08-19)
oc-update --skip-codexdeployed the current aggregate overlay build (base5976e74d1cc8022c82c644f9d2fffbd07473d7a5; included #125471 and #125528) and completed successfully. The restarted Gateway reportedRuntime: running,Connectivity probe: ok, andNRestarts=0.Sanitized migration pair, from the same live config key:
The updater doctor stage reported:
Migrated legacy external CLI auth.profiles metadata to OAuth.After restart,models.authStatuspublished one coherent credential-bearing provider:{"provider":"claude-cli","status":"ok","profiles":[{"profileId":"anthropic:claude-cli","type":"oauth","status":"expiring"}]}The prior observed contradiction,
{"provider":"anthropic","status":"missing","profiles":[]}beside the Claude CLI profile, is absent.expiringis the profile rotating access-token horizon; the provider itself isokand is not reported missing.Post-restart
models.listreports all configured Claude CLI routes as available and reasoning-capable. Fable:available:true, reasoning:true, [off,minimal,low,medium,adaptive,high,xhigh,max], default:high; Haiku:available:true, reasoning:true, [off,minimal,low,medium,high], default:medium; Opus and Sonnet:available:true, reasoning:true, [off,minimal,low,medium,adaptive,high,xhigh,max], default:medium. This is the deployed post-restart result, against the previously reportedreasoning:false/[off]state.Real Control UI proof was captured with read-only picker interaction only. Before capture, session/sidebar DOM was hidden locally and the image was cropped to the picker controls; no titles, identifiers, transcript, credential, or message content is present. I opened and visually inspected each capture: the first visibly shows the four selectable Claude CLI rows without a Sign in needed state, and the second visibly shows the unlocked Effort control.
Maintainer live Claude CLI cache proof (2026-08-19)
tbx_01m0eejgzgaqzghn9zst57gbsr.The Testbox wrapper completed the command successfully; the backing Actions job later shows cancelled because the externally managed lease was closed after proof, which is expected for this Testbox workflow.
Final repaired-head Claude CLI cache proof (2026-08-20)
902ed828292c951270055f48ddaf2fda24629855.tbx_01m0f0mv3vqsfny6jb3c72w0vq.Exact-head hosted Claude CLI cache E2E (2026-08-20)
18f3373b0816df8d9d27af303c25c0c81897419a.tools/callcompleted successfully.Compatibility coverage for the CLI-backend preparation additions is additive:
contextTokenBudget?andthinkingLevel?remain optional. Existing preparation fixtures that omit them continue to pass, whilesrc/agents/cli-runner/prepare.test.tsexplicitly verifies both values when supplied. The Anthropic plugin tests cover the thinking-to-launch mapping.Final exact-head LOC accounting: