Repository navigation
fix(agents): Anthropic session forks miss the parent's prompt cache when thinking comes from the agent default - #197203
Conversation
Co-authored-by: obviyus <[email protected]>
…hen thinking comes from the agent default OpenClaw-Publication: 261c0cd5-0c5f-4a34-93fe-b7f52875d4da
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesAnthropic session forks now resolve configured thinking defaults through the existing thinking-selection owner. Example: Advisor forks an Anthropic session configured with thinkingDefault: high and no session override.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep open: this collaborator-authored PR fixes a current Anthropic fork cache mismatch with a focused change, relevant live measurements, and no identified introduced defect. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherPlugins request read-only session forks through the Gateway; the embedded runtime reconstructs parent context, shapes a provider request, and returns text and usage. flowchart TD
A[Plugin fork request] --> B[Gateway session access]
B --> C[Parent context reconstruction]
C --> D[Existing thinking selection]
D --> E[Anthropic request builder]
E --> F[Provider response]
F --> G[Text and usage]
Technical reviewBest possible solution: Use the existing thinking-selection owner for Anthropic forks while retaining current context reconstruction and tool denial. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the missing-default path, and the author reports before/after live Gateway measurements plus a regression failing on main; no target code was executed during this review. Is this the best way to solve the issue? This is a small root-cause repair using the existing resolver; it avoids the earlier reverted tool-choice changes and adds no competing owner or persistence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3275ef4d21c3. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +15, Tests 0. Total +15 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 11, 2026, 7:05 AM ET / 12:05 UTC. |
…hen thinking comes from the agent default (openclaw#197203) * fix(agents): run Anthropic session forks at the parent's thinking level Co-authored-by: obviyus <[email protected]> * fix(agents): Anthropic session forks miss the parent's prompt cache when thinking comes from the agent default OpenClaw-Publication: 261c0cd5-0c5f-4a34-93fe-b7f52875d4da --------- Co-authored-by: obviyus <[email protected]>
…hen thinking comes from the agent default (#197203) * fix(agents): run Anthropic session forks at the parent's thinking level Co-authored-by: obviyus <[email protected]> * fix(agents): Anthropic session forks miss the parent's prompt cache when thinking comes from the agent default OpenClaw-Publication: 261c0cd5-0c5f-4a34-93fe-b7f52875d4da --------- Co-authored-by: obviyus <[email protected]> (cherry picked from commit 7743284) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes: on Anthropic models with thinking on, Advisor reviews and other plugin session forks miss the parent's prompt cache, so each review pays to write almost the whole conversation again. This happens when the agent's thinking comes from its configured default rather than a per-session override.
User Impact
User impact: with thinking on, Anthropic session forks now read the parent's cached prompt instead of re-writing it. A fork's cost and latency drop to roughly the uncached tail after the parent's last cached point. OpenAI and other APIs keep their current behavior.
Why This Change Was Made
A plugin fork took its thinking level only from the session's
thinkingLeveloverride. When the agent ran onthinkingDefault(or a per-model default), the fork sent a different thinking config from the parent's. On opus that waseffort: lowinstead ofhigh; on haiku thinking wasdisabledinstead of adaptive. Anthropic invalidates the cached message prefix when thinking parameters change, so the fork could only reuse the tools and system portion.The fork's request shaping in
btw-stream.tsnow resolves the level the same way the parent's turn does: the session override first, then the agent and model defaults (resolveThinkingSelection), clamped for the model. This applies only onanthropic-messages. Other APIs keep sending the session override until their own cache behavior has been measured live.The thinking-block projection does not change. In an earlier offline replay, stripping prior thinking blocks looked necessary. That replay sent no beta headers, though. On the real route, a level-only build hit the parent's latest prefix with thinking blocks kept. Stripping the blocks instead made later forks reuse the previous fork's cache rather than the parent's.
Evidence
Live measurements through the real route: an isolated test Gateway,
cliproxywithanthropic-messages,thinkingDefault: high, AdvisoreveryToolCalls: 1, and one parent turn with three sequentialsession_statuscalls. Provider usage was read from the captured response streams.output_config/thinking2598631ab4616c01*b4616c01has the same production code as the PR head. The head only changes the test's mock-server callback to satisfy lint.src/gateway/server-plugin-subagent-runtime.fork-transport.test.tsnow runs the gatewayforkSessionintegration over a loopback Anthropic Messages provider withthinkingDefault: "high". It fails on main (thinking: {type: "disabled"}) and passes here. Converting the existing test keeps the test-lines ratchet at net −1.btw*,session-forkandextensions/advisortests pass (82 tests).pnpm tsgo:coreandOPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 pnpm check:changedare clean.Gaps and accepted edge cases:
/btwuses its own system prompt and keeps thinking off on purpose, so it shares no cached prefix with the parent. It is not affected.