Repository navigation
fix(anthropic): preserve cache prefixes across runtime context - #157650
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 maintainer review before merge. Reviewed September 25, 2026, 2:00 AM ET / 06:00 UTC (Revision 7). ClawSweeper reviewWhat this changesThe branch backports Anthropic prompt-cache and runtime-context replay repairs to the extended-stable release line, adds a provider-selected carrier-retention fact, and extends tests, docs, and live release validation. Merge readiness✅ Ready for maintainer review Keep open. The main-branch repairs do not deliver this fix to the 2026.8.33 extended-stable line. The earlier release-gate and stored-session proof gaps are addressed, and the final Copilot change follows its existing thinking-stripping policy. Priority: P2 Review scores
Verification
How this fits togetherThe embedded agent runner turns user requests and runtime context into a session transcript. Provider replay policy and the Anthropic request builders then decide which parts of that transcript can anchor a reusable prompt-cache prefix. flowchart LR
A[User turn and runtime context] --> B[Provider replay policy]
B --> C[Session boundary]
C --> D[Anthropic request builder]
D --> E{Carrier retained?}
E -->|Yes| F[Cache through carrier]
E -->|No| G[Cache before carrier]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +74, Tests +523, Docs +12, Config +6, Other +1. Total +616 across 39 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain the provider-selected carrier fact at the session boundary and use the shared cache policy in both request builders when landing this backport. The frozen branch lacks those policy and emitted-position contracts, which accounts for the justified production growth. Do we have a high-confidence way to reproduce the issue? Yes for the release line: its base source marks all Anthropic carriers cacheable, and the reported frozen-candidate live validation failed. I did not establish a failing path on current main, which already contains the earlier cache repairs. Is this the best way to solve the issue? Yes. The branch carries the provider's retention decision through the session boundary and lets the existing cache policy place checkpoints in both request builders; Copilot explicitly keeps its different replay rule. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d5b9c6bf3a9d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Exact-head live cache qualification is green: workflow #36071835053, candidate The
The workflow concluded success and reported all live-cache regression floors satisfied. This clears ClawSweeper's sole remaining exact-candidate proof item. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…de models (#136990) * fix(agents): scope append-only runtime context to prefix-binding Claude models Append-only runtime-context replay (persisted carriers, retained inline inbound metadata, no consecutive-user merge on the Messages API) exists because Claude Fable 5.1 binds thinking to the exact request prefix. It was enabled for every Anthropic-family route, so Opus 5, Sonnet 5, Opus 4.8, Sonnet 4.6 and Haiku 4.5 sessions paid for persisted carriers on every later request (cache-read billing plus context) without any prefix to protect. - Add `bindsClaudeThinkingPrefix` to the llm-core Claude contracts (Fable 5.1 and Mythos 5.1 identities, including cloud ids and canonical deployment metadata) and derive `appendOnlyRuntimeContext` from it in the core fallback and the shared Anthropic replay helpers; GitHub Copilot stays transient. Non-binding Claude models return to transient carriers and normal user-turn merging. - Next-turn carriers now carry only the delimited context body. The shared instruction (runtime context for the user request it follows, not user-authored, keep internal details private, continue without waiting) moves once into the stable system prompt prefix for every provider, so it is cached instead of re-sent per turn. Runtime-event prefaces are unchanged; historical prefaced carriers are still stripped from user-visible surfaces. - Docs: anthropic provider page, transcript hygiene, system prompt. Live proof on a recording proxy with drop_block binding controls: an Opus 5 session merged consecutive user turns and kept its model-switch carrier transient; a Fable 5.1 session switched to Opus 5 and back, then ran three more turns with tool loops while the persisted compact carrier stayed in place, thinking blocks accumulated (1 -> 3) and every response reported input_transformations: []. * fix(agents): limit prefix-binding replay to Fable 5.1 and match compact carriers in e2e `bindsClaudeThinkingPrefix` now covers only the Fable 5.1 identity. Mythos 5.1 is not registered in the bundled Anthropic catalog and has no live replay proof, so it keeps transient carriers and normal user-turn merging like every other non-Fable model; extending the predicate requires live proof for the new model. Predicate, transcript-policy, replay-helper and provider plugin tests assert the narrowed set. The qa-lab gateway RPC chat e2e test still imported the removed next-turn carrier preface; its carrier filter now matches the delimiter-only shape. * test(agents): expect merged user turns for non-binding Claude replay (cherry picked from commit de7518b)
…#140621) Anthropic tool loops could repeatedly write growing conversation history to the prompt cache because a moving runtime-context carrier owned the checkpoint. Use the existing replay lifecycle contract to exclude transient carriers from both request builders while preserving retained anchors. Also omit empty beta headers that caused direct API requests with thinking disabled to fail. Add deterministic regression coverage and a packaged Docker test that verifies real cache reads and incremental writes across two tool continuations and a new user turn in both builders. Require that lane in stable/full release validation, with explicit API-key preflight, no request retries, and a declared runtime entry for dependency analysis. Validation includes focused package/model/session and workflow tests, build and package integrity checks, static checks, independent review, mock Docker, and eight successful live Anthropic Docker requests. Hosted CI run 34379052492 passed on the final PR head at attempt 2, after one unchanged browser-animation rerun. Closes #140607 Thanks to @LightningWareLLC for reporting the regression and contributing the lifecycle-aware cache repair. Co-authored-by: LightningWareLLC <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit faaf4b0)
a63bf0c to
bbd8e36
Compare
|
Exact-head repair evidence for
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Exact live cache qualification is now green: https://github.com/openclaw/openclaw/actions/runs/36086789596 This run exercised the frozen 2026.8.33 candidate through the carrier-aware Anthropic cache path after the strict native replay-policy repair. The focused local suites remain 84/84 green on exact head @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
3f0eec6 to
cd57d37
Compare
|
Final exact-head evidence for
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
cd57d37 to
9b99ac1
Compare
|
Final exact-head qualification for
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
9b99ac1 to
ca35df9
Compare
|
Final exact-head evidence for
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
ca35df9 to
7b39133
Compare
|
Final mechanical CI repair at
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
7b39133 to
152593a
Compare
|
Final repair head:
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Exact final-head live qualification is now green: run #36099416431, job @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Final exact-head CI repair pushed at The sole failed leaf in CI run https://github.com/openclaw/openclaw/actions/runs/36099399189 was Proof:
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
What Problem This Solves
Fixes an issue where the frozen 2026.8.33 candidate's Anthropic cache validation lost reusable runtime-context prefixes across tool loops and new turns, causing the live cache lane in Full Validation #36055733728 to fail.
Why This Change Was Made
This backports the merged runtime-context replay and cache-carrier ownership repairs from #136990 and #140621 onto
extended-stable/2026.8.33. The adapted backport records the provider-resolved retention decision on the LLM-boundary carrier, so model identity cannot override an owner plugin's replay policy.User Impact
Operators validating or running the 2026.8.33 extended-stable candidate retain Anthropic prompt-cache prefixes across supported tool-loop and turn boundaries without incorrectly caching transient provider-owned context.
Evidence
live-anthropic-cacheleaf in Full Validation #36055733728.node scripts/check-changed.mjs -- <36 touched paths>passed.live-anthropic-cachevalidation will be attached to this PR.Production growth is the backported replay-policy capability plus one retained-policy fact at the LLM boundary; tests and docs carry the remaining expansion.