Repository navigation
fix(agents): keep session forks on the parent's cached prompt prefix - #197074
Conversation
|
🦞👀 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 changes before merge. What this changesThis PR normalizes live fork tool-call IDs and preserves Anthropic tool choice when only client tools are present. Example: Advisor reviews a live Anthropic conversation containing tool call toolu_778d44bb.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 4 items remain Keep open: this maintainer-authored PR addresses a concrete cache-prefix defect, but introduces incorrect pending-tool context and leaves a diff-caused integration-test failure. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherAdvisor and session side questions reconstruct conversation context through the embedded runner, send an independent provider request, and return text and usage without executing local tools. flowchart TD
A[Advisor or side question] --> B[Session read authority]
B --> C[Live attempt context]
C --> D[Projection and ID normalization]
D --> E[Independent provider request]
E --> F[Tool denial or text response]
F --> G[Text and usage]
Technical reviewBest possible solution: Reuse the existing ID-normalization owner after preserving pending-call semantics, update the affected integration assertion, and document conditional Anthropic tool choice. Do we have a high-confidence way to reproduce the issue? Source confirms that foreground requests normalize IDs while current-main live fork projections do not; the PR also reports a before/after Gateway request comparison, but no target code was executed during this review. Is this the best way to solve the issue? Using existing projection and normalization owners is appropriately small, but invoking the full pairing-repair normalizer before fork pending-call handling violates an established ordering contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6a972bfaac53. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +12, Tests -2, Other +265. Total +275 across 4 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, 1:25 AM ET / 06:25 UTC. |
8552b2e to
ce345dd
Compare
Advisor reviews and /btw side questions fork the live session, but their Anthropic requests never reused the parent's cached messages: - the fork sent raw transcript tool-call IDs, while every foreground request sends them through the attempt's ID normalizer, so the prefix diverged at the first tool call; - the fork forced tool_choice none, and Anthropic invalidates every cached message block when tool_choice changes. Apply the attempt's own ID normalizer to live fork messages, and keep the parent's Anthropic tool_choice unless the request carries a hosted server tool, which runs before the fork can deny it. Client tool calls are still denied by the existing loop. scripts/perf/advisor-fork-prefix-gateway.ts records the main and fork request bodies from an isolated Gateway with a loopback Anthropic model. Co-authored-by: obviyus <[email protected]>
…iring The live fork reused the attempt's full replay normalizer, which also repairs tool-use pairing. On Anthropic that synthesized an "interrupted" error result for a tool still running in the parent, before the fork could add its non-error "still running" placeholder, so a reviewer saw a false failure. Expose an ID-only variant of the same normalizer for forks. Extend the live Anthropic fork integration case to a parent tool that is still running, keep the client-tool tool_choice assertion on the parent's value, and document the conditional Anthropic tool choice. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
ce345dd to
2d7bfc8
Compare
… prefix (#197074)" (#197175) This reverts commit 2706a18. Live provider measurements showed no cache gain. On Anthropic (haiku-5-5 and opus-5-5, thinking off and on, direct and custom routes), forks read the same parent prefix before and after: replaying one fork with the parent's tool_choice, with tool_choice none, and with mismatched tool IDs differed by 0-2 cached tokens. With thinking on, both tool IDs were already identical. The measured cause of fork cache misses is the fork's thinking config (it sends thinking disabled or a different effort and keeps or drops thinking blocks differently from the parent), and on OpenAI the deleted prompt_cache_key. Co-authored-by: obviyus <[email protected]>
…penclaw#197074) * fix(agents): keep session forks on the parent's cached prompt prefix Advisor reviews and /btw side questions fork the live session, but their Anthropic requests never reused the parent's cached messages: - the fork sent raw transcript tool-call IDs, while every foreground request sends them through the attempt's ID normalizer, so the prefix diverged at the first tool call; - the fork forced tool_choice none, and Anthropic invalidates every cached message block when tool_choice changes. Apply the attempt's own ID normalizer to live fork messages, and keep the parent's Anthropic tool_choice unless the request carries a hosted server tool, which runs before the fork can deny it. Client tool calls are still denied by the existing loop. scripts/perf/advisor-fork-prefix-gateway.ts records the main and fork request bodies from an isolated Gateway with a loopback Anthropic model. Co-authored-by: obviyus <[email protected]> * fix(agents): normalize only fork tool-call IDs before pending-call pairing The live fork reused the attempt's full replay normalizer, which also repairs tool-use pairing. On Anthropic that synthesized an "interrupted" error result for a tool still running in the parent, before the fork could add its non-error "still running" placeholder, so a reviewer saw a false failure. Expose an ID-only variant of the same normalizer for forks. Extend the live Anthropic fork integration case to a parent tool that is still running, keep the client-tool tool_choice assertion on the parent's value, and document the conditional Anthropic tool choice. Co-authored-by: obviyus <[email protected]> * test(agents): keep fork test lines within the ratchet Co-authored-by: obviyus <[email protected]> --------- Co-authored-by: obviyus <[email protected]>
… prefix (openclaw#197074)" (openclaw#197175) This reverts commit 9cae7fa. Live provider measurements showed no cache gain. On Anthropic (haiku-5-5 and opus-5-5, thinking off and on, direct and custom routes), forks read the same parent prefix before and after: replaying one fork with the parent's tool_choice, with tool_choice none, and with mismatched tool IDs differed by 0-2 cached tokens. With thinking on, both tool IDs were already identical. The measured cause of fork cache misses is the fork's thinking config (it sends thinking disabled or a different effort and keeps or drops thinking blocks differently from the parent), and on OpenAI the deleted prompt_cache_key. Co-authored-by: obviyus <[email protected]>
Summary
Advisor reviews and
/btwside questions fork the live session to reuse its prompt cache, but on Anthropic routes they reused only the system prompt and tools. On Peanutto (cliproxy/claude-opus-5-5), 49 Advisor reviews logged a flatcacheReadof 14,575 tokens against contexts of 136k–740k (median 357k), so each review wrote the whole transcript to cache again: about $3 per review instead of about $0.10–0.16.Two independent causes, each sufficient on its own:
normalizeToolCallIds(attempt-prompt-submit.ts). The live fork snapshot skipped it, so the fork senttoolu_778d44bbwhere the parent had senttoolu778d44bb, and the prefix diverged at the first tool call.tool_choice. The fork forced{ type: "none" }. Anthropic documents that atool_choicechange invalidates every cached message block (What invalidates the cache).Change
attempt-stream.ts/attempt-execution-phase.ts: the existingprojectSessionForkMessageshook now ends with an ID-only variant of the attempt's own replay normalizer, so fork IDs match every foreground request. It skips tool-use pairing repair, so a parent tool that is still running keeps the fork's non-error "still running" placeholder instead of a synthesized "interrupted" error result. No new contract field.session-fork.ts: on Anthropic Messages, keep the parent'stool_choiceunless the request carries a hosted server tool such asweb_search. A server tool runs before the fork could deny it, sononeis still required there. Client tool calls are still denied by the existing three-attempt loop. OpenAI routes are unchanged.Proof
scripts/perf/advisor-fork-prefix-gateway.tsstarts an isolated Gateway (no credentials, no inherited service environment) with a loopback Anthropic Messages model that records every request body. The main turn calls a tool three times with Advisor ateveryToolCalls: 1. The script then compares each fork request with the parent's preceding request.main(94a3775)tool_useID)tool_choicenonetools,system, other request keysThe first two forks still differ at message 1 on both branches. That's because the parent itself switches its runtime-context message from a block array to a string after its second request. It's a one-time foreground quirk early in each run and isn't fork-specific; I'll file it separately.
Tests: the live-fork integration case in
embedded-agent-runner.session-fork.test.tsnow covers Anthropic with a parent tool still running. With the full normalizer, it fails because the fork receives "Tool call interrupted before a result was recorded" (is_error: true). With the ID-only normalizer, it passes. The same case asserts that the client-tooltool_choiceis the parent's.session-fork.test.tscovers both Anthropic branches (hosted tool →none; client tools → parent's choice).attempt-stream-prepare,attempt-execution-phase, and Advisor suites pass.pnpm check:changedpasses, with the dead-export scan skipped.docs/plugins/sdk-runtime.mdnow describes the conditional Anthropic tool choice.Not covered
/btwon a session with no active run) still sends un-normalized IDs. Advisor only forks live runs. The rebuild path needs the attempt's tool allowlist, so it gets a follow-up.tool_choice: "none"and the deletedprompt_cache_keyremain on that path.