Skip to content

fix(models): preserve provider prompt cache boundaries#89460

Merged
steipete merged 1 commit into
mainfrom
fix/89386-provider-cache-boundary
Jun 2, 2026
Merged

fix(models): preserve provider prompt cache boundaries#89460
steipete merged 1 commit into
mainfrom
fix/89386-provider-cache-boundary

Conversation

@steipete

@steipete steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #89386.

  • Split Anthropic system prompts at the internal cache boundary so only the stable prefix gets cache_control; the dynamic suffix stays uncached.
  • Strip the internal cache boundary when Anthropic cache control is disabled, so the marker is never sent to providers as prompt text.
  • Strip the marker for normal OpenAI-compatible completions requests, while preserving and splitting it for OpenAI-compatible Anthropic cache-control routes such as OpenRouter Anthropic models.

Verification

  • node scripts/run-vitest.mjs src/llm/providers/anthropic.test.ts src/llm/providers/openai-completions.test.ts (28 passed)
  • node ./node_modules/.bin/oxfmt --check src/llm/providers/anthropic.ts src/llm/providers/openai-completions.ts src/llm/providers/anthropic.test.ts src/llm/providers/openai-completions.test.ts
  • node scripts/run-oxlint.mjs src/llm/providers/anthropic.ts src/llm/providers/openai-completions.ts src/llm/providers/anthropic.test.ts src/llm/providers/openai-completions.test.ts
  • git diff --check
  • pnpm tsgo:prod && pnpm check:test-types
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main (clean after fixing the OpenRouter Anthropic cache-control edge it identified)

Notes

The OpenAI-compatible prompt_cache_key regression mentioned in #89386 was already repaired on current main by #88976. This PR fixes the remaining cache-boundary split/strip behavior in the refactored provider path.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jun 2, 2026
@clawsweeper

clawsweeper Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(models): preserve provider prompt cache boundaries This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39bb4b585e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +881 to +882
if (split.dynamicSuffix) {
parts.push({ type: "text", text: split.dynamicSuffix });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep OpenRouter wrapper from re-caching the suffix

For OpenRouter Anthropic models reached through the normal extra-params path, createOpenRouterSystemCacheWrapper is still applied afterward (src/agents/embedded-agent-runner/extra-params.ts:819), and its payload patch tags the last system content part with cache_control (src/agents/anthropic-payload-policy.ts:250-256). After this split, that last part is the dynamic suffix, so the wrapped OpenRouter route still caches the per-turn suffix that this change is trying to leave uncached; either skip the outer marker when the provider already handled Anthropic cache control or make that wrapper boundary-aware too.

Useful? React with 👍 / 👎.

@steipete

steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer proof for exact head 39bb4b585e890ea72062adab52243d59d588abce:

  • Fixed the remaining Bug: 5.28 transport refactor regressed prompt caching for Anthropic and OpenAI-compatible providers #89386 provider-cache-boundary regression on current main. The OpenAI-compatible prompt_cache_key half was already fixed by fix(mistral): enable prompt cache key compat #88976; this PR fixes Anthropic split/strip and OpenAI-compatible marker stripping, including OpenRouter Anthropic-style cache-control routing.
  • Ran node scripts/run-vitest.mjs src/llm/providers/anthropic.test.ts src/llm/providers/openai-completions.test.ts (28 passed).
  • Ran node ./node_modules/.bin/oxfmt --check src/llm/providers/anthropic.ts src/llm/providers/openai-completions.ts src/llm/providers/anthropic.test.ts src/llm/providers/openai-completions.test.ts.
  • Ran node scripts/run-oxlint.mjs src/llm/providers/anthropic.ts src/llm/providers/openai-completions.ts src/llm/providers/anthropic.test.ts src/llm/providers/openai-completions.test.ts and git diff --check.
  • Ran pnpm tsgo:prod && pnpm check:test-types.
  • Ran .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main; first pass surfaced the OpenRouter Anthropic cache-control split edge, which is now fixed and covered; final pass clean, no accepted/actionable findings.
  • Exact-head CI is merge-clean: 136 passed, 41 skipped. The PR rollup still displays the first canceled auto-response and Real behavior proof attempts, but both exact rerun attempts succeeded: Auto response run 26822133300 attempt 2, Real behavior proof run 26822133292 attempt 2.

Land-ready.

@steipete steipete merged commit eef24d4 into main Jun 2, 2026
181 of 183 checks passed
@steipete steipete deleted the fix/89386-provider-cache-boundary branch June 2, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: 5.28 transport refactor regressed prompt caching for Anthropic and OpenAI-compatible providers

1 participant