Skip to content

fix(anthropic): bind cache carriers to replay policy - #157662

Merged
RomneyDa merged 1 commit into
mainfrom
fix/anthropic-cache-carrier-policy
Sep 25, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/anthropic-cache-carrier-policy

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where Anthropic cache-carrier retention could be recomputed from a model ID after a provider plugin had already selected a different replay policy. A provider-owned transient carrier could therefore be cached, or a retained carrier could lose its cache boundary.

Why This Change Was Made

The LLM session boundary now records the provider-resolved carrier-retention decision on the user message, media projection preserves that fact, and the Anthropic transport consumes it directly. This keeps policy ownership at the replay boundary instead of re-deriving it from model naming.

User Impact

Provider plugins that customize Anthropic replay behavior now get cache markers consistent with their selected policy across tool loops, turns, and image hydration.

Evidence

  • The 2026.8.33 backport review reproduced the policy disagreement with the GitHub Copilot provider's model fixture.
  • node scripts/run-vitest.mjs packages/ai/src/anthropic-cache-carrier-parity.test.ts src/agents/embedded-agent-runner/run/attempt-session-boundary.test.ts — 36/36 passed after rebasing onto current main.
    • cache-carrier parity: 6/6 in 3.57s
    • attempt-session boundary: 30/30 in 48.70s
  • The boundary suite is retained because it exercises the canonical session lifecycle where provider replay policy becomes model-visible carrier state; a transport-only test would not prove that producer-to-consumer handoff.
  • node scripts/check-changed.mjs -- <six touched paths> — passed.
  • Fresh P0-P2 autoreview — scoped clean.
  • Exact-head CI is currently blocked only by the two untouched main Madge cycles reproduced locally with pnpm check:madge-import-cycles; no PR-owned failure is known.

Production delta is +21/-5 (net +16) across four source files: one closed retention fact at the LLM boundary, propagation through image hydration, and removal of transport-side model inference. Tests are +76/-5 (net +71) across two files.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@RomneyDa
RomneyDa marked this pull request as ready for review September 24, 2026 22:59
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 1:48 AM ET / 05:48 UTC (Revision 7).

ClawSweeper review

What this changes

The branch records the provider's runtime-context retention decision on messages and uses it to place Anthropic prompt-cache markers, including after image hydration.

Merge readiness

✅ Ready for maintainer review

Current main still chooses Anthropic cache eligibility from the model ID even when a provider plugin chose a different replay policy. This PR addresses that gap, preserves the existing behavior for unannotated direct callers, and has no actionable finding in the introduced diff.

Priority: P2
Reviewed head: ba0c3015e5ec4083cf24dcec1ba3688c1261d003

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused patch has relevant boundary and request-parity coverage, with no concrete correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is exempt from the external-contributor real-setup proof gate. The reported focused tests exercise session message conversion and both Anthropic request builders, but were not rerun in this read-only review. The added field is request-time metadata, with no stored-data contract change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor real-setup proof gate. The reported focused tests exercise session message conversion and both Anthropic request builders, but were not rerun in this read-only review. The added field is request-time metadata, with no stored-data contract change.
Evidence reviewed 9 items Current-main gap: At fetched main, Anthropic message conversion uses a model-derived retention decision for cache eligibility, without a message-level replay-policy decision.
Policy owner: The provider runtime hook supplies replay policy; the GitHub Copilot plugin explicitly chooses strict Anthropic replay independent of the Claude model name.
Provider example: The GitHub Copilot plugin's replay policy drops thinking blocks for Anthropic Messages routes, establishing a concrete policy that can differ from model-name inference.
Findings None None.
Security None None.

How this fits together

The agent session turns user input and runtime context into messages for a model request. Provider replay policy determines whether context remains in later turns; the Anthropic transport then decides where cache markers belong.

flowchart LR
A[User turn and runtime context] --> B[Provider replay policy]
B --> C[Agent message boundary]
C --> D[Media projection]
D --> E[Anthropic request builder]
E --> F[Cache markers and model request]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +16, Tests +71. Total +87 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 21 5 +16
Tests 2 76 5 +71
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 97 10 +87

Review metrics

Metric Value Why it matters
Production and test delta production +16 net, tests +71 net The PR body explains the production growth and why the session-boundary coverage is retained.
Focused test cost 3.57s and 48.70s reported per file The session-boundary file exceeds the normal test-cost target, and its boundary-coverage rationale is recorded in the PR body.

Technical review

Best possible solution:

Keep provider replay policy as the retention authority at the agent boundary while preserving model-derived cache behavior for direct callers that provide no explicit decision.

Do we have a high-confidence way to reproduce the issue?

Yes. Current-main source supplies a high-confidence path: a provider can choose transient Anthropic replay for a Claude model while the transport still treats its carrier as cache-eligible. This read-only review did not run that path.

Is this the best way to solve the issue?

Yes. Recording the provider's decision at the existing LLM boundary and consuming it in the shared Anthropic transport is a narrow repair; the absent-metadata fallback protects direct callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 155ff367ba98.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded provider cache-correctness fix with limited user-facing blast radius.
  • merge-risk: 🚨 compatibility: Cache-marker placement changes for provider policies that differ from model inference; explicit fallback and parity cases cover existing unannotated callers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is exempt from the external-contributor real-setup proof gate. The reported focused tests exercise session message conversion and both Anthropic request builders, but were not rerun in this read-only review. The added field is request-time metadata, with no stored-data contract change.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • LightningWare LLC: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-24T23:08:30.741Z sha 3681131 :: blocked before merge. :: [P1] Preserve cache anchors for existing direct callers | [P3] Record the new test's measured cost
  • reviewed 2026-09-24T23:50:40.295Z sha 148e62b :: needs changes before merge. :: [P2] Exercise replay policies that disagree with the model | [P3] Record each changed test file's measured cost
  • reviewed 2026-09-25T02:05:57.732Z sha 80ecf2550a8672c3abaf0e19721aa604d8ca9b7c :: needs changes before merge. :: none
  • reviewed 2026-09-25T03:13:31.317Z sha 8cc756db7d7d95c8aa163b99e4678f6cf163c6dc :: needs changes before merge. :: none
  • reviewed 2026-09-25T03:22:35.766Z sha 41fcbbf :: blocked before merge. :: none
  • reviewed 2026-09-25T03:30:01.765Z sha 41fcbbf :: needs maintainer review before merge. :: none

@RomneyDa
RomneyDa force-pushed the fix/anthropic-cache-carrier-policy branch 2 times, most recently from dcd707b to 148e62b Compare September 24, 2026 23:36
@RomneyDa

Copy link
Copy Markdown
Member Author

Addressed the accepted compatibility finding at exact head 148e62bf32357a847b00f12b5447975bac8226b5:

  • the agent boundary now records an explicit true or false replay-policy decision on every runtime-context carrier;
  • both Anthropic string and block request paths use that explicit decision when present, while absent metadata preserves the published model-derived fallback for existing direct @openclaw/ai callers;
  • media projection preserves both boolean values rather than dropping explicit false;
  • request-parity coverage now proves explicit transient, explicit retained, and unannotated direct-caller behavior across both content shapes.

Validation:

  • focused suite: 36/36 passed;
  • measured one-worker wall time: 70.05 s on the final rebased source;
  • changed gate: all type, graph, boundary, dead-code, and formatting checks passed; the one lint finding (no-map-spread) was repaired and the exact changed-file lint rerun passed;
  • fresh P0–P2 autoreview: scoped clean.

Exact-head CI is running; I will attach its measured changed-test duration when terminal.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 24, 2026
@RomneyDa
RomneyDa force-pushed the fix/anthropic-cache-carrier-policy branch from 148e62b to 80ecf25 Compare September 25, 2026 01:59
@RomneyDa

Copy link
Copy Markdown
Member Author

Exact-head repair evidence for 80ecf2550a8672c3abaf0e19721aa604d8ca9b7c:

  • Anthropic carrier parity: 6/6 passed in 2.27s.
  • Embedded session boundary: 30/30 passed in 76.18s.
  • Combined focused proof: 36/36 passed.
  • Changed gate passed before the mechanical rebase; post-rebase focused proof is green.
  • Fresh P0-P2 autoreview: scoped clean.
  • Rebased onto current main; branch is conflict-free and non-draft.

The accepted review finding is fixed: explicit provider retention now disagrees with the model-derived default in both directions, so the parity suite fails if the carrier override is ignored.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@RomneyDa
RomneyDa force-pushed the fix/anthropic-cache-carrier-policy branch 2 times, most recently from 8cc756d to 41fcbbf Compare September 25, 2026 03:16
@RomneyDa

Copy link
Copy Markdown
Member Author

Exact-head rebase status:

  • rebased cleanly onto main at 6b5fb4b23509eef35aead816d03052efe60684e5
  • exact head: 41fcbbf6890860e21239932d4e94cd07e8cffcf9
  • focused owner proof: carrier parity 6/6 + attempt-session boundary 30/30 passed
  • GitHub reports non-draft and mergeable; ClawSweeper remains platinum hermit
  • exact-head CI fails only check-additional-runtime-topology-architecture

The failing architecture leaf reproduces locally after the clean rebase with pnpm check:madge-import-cycles: the two cycles are entirely in untouched current-main state/gateway files. This PR changes only the Anthropic cache-carrier owner boundary and its tests. Per the release-validation closeout instruction, this is held solely on unrelated red-main CI; no PR-owned failure remains.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 25, 2026
@RomneyDa
RomneyDa force-pushed the fix/anthropic-cache-carrier-policy branch from 41fcbbf to ba0c301 Compare September 25, 2026 05:41
@RomneyDa

RomneyDa commented Sep 25, 2026 •

Copy link
Copy Markdown
Member Author

Rebased conflict-free onto current main at bd3ac5c, including the merged host-broker CI repair. Exact head: ba0c301.\n\nFresh focused proof: 36/36 passed. Fresh mandatory P0–P2 autoreview: scoped-clean, no accepted/actionable findings. Exact-head CI is fully green: https://github.com/openclaw/openclaw/actions/runs/36099602380\n\nLive closeout: non-draft, MERGEABLE/CLEAN, ClawSweeper platinum hermit, ready for maintainer look.

@RomneyDa
RomneyDa merged commit d29ac12 into main Sep 25, 2026
193 checks passed
@RomneyDa
RomneyDa deleted the fix/anthropic-cache-carrier-policy branch September 25, 2026 07:24
roboclaw-bot added a commit that referenced this pull request Sep 25, 2026
Preserve authored selections, native thinking display and replay-bound cache
carriers. Raise the OAuth identity floor and retain required fallback betas
after custom headers and payload hooks without changing excluded transports.

Backport #156093: 5e5f9c2
Backport #156062: 2f10ac3
Backport #157662: d29ac12
Backport #158300: 169da00
The initial #155966 support is already inherited from the stable cut.

Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Serg <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant