Skip to content

fix(ai): retain Anthropic cache checkpoints across tool loops - #1075

Open
codeg-dev wants to merge 4 commits into
code-yeongyu:mainfrom
codeg-dev:codex/iss-11187-cache-marker-regression
Open

fix(ai): retain Anthropic cache checkpoints across tool loops#1075
codeg-dev wants to merge 4 commits into
code-yeongyu:mainfrom
codeg-dev:codex/iss-11187-cache-marker-regression

Conversation

@codeg-dev

@codeg-dev codeg-dev commented Aug 22, 2026

Copy link
Copy Markdown

Summary

Fixes direct anthropic-messages prompt-cache replay during tool loops by retaining the prior dynamic cache checkpoint while marking the newest tool-result tail.

  • preserves a rolling pair of dynamic checkpoints for direct and OAuth Messages requests
  • keeps OAuth payloads within Anthropic’s four-breakpoint limit by omitting the redundant fixed Claude Code identity marker when a user system prompt is present
  • adds no-network regression coverage for three tool loops, both OAuth system-prompt variants, disabled cache retention, and unpaired tool results

Evidence

  • Stock RED: prior checkpoint was dropped after the next tool-result tail.
  • GREEN: ./node_modules/.bin/vitest --run packages/ai/test/anthropic-cache-checkpoint-stability.test.ts packages/ai/test/warm-prompt-cache.test.ts (8 passed)
  • ./node_modules/.bin/tsc --noEmit --pretty false passed.

Related: #1005 (goal-continuation cache prefix stability); this PR addresses the remaining serializer-level checkpoint movement.


Summary by cubic

Retains Anthropic prompt-cache checkpoints across tool loops to avoid prefix reprocessing. Previously we replaced the tail checkpoint each loop, dropping the prior boundary; now we keep the newest tool_result tail and the preceding cacheable user message while staying within Anthropic’s four-breakpoint limit.

  • Maintain two rolling checkpoints for direct and OAuth anthropic-messages.
  • In OAuth, omit the fixed Claude Code identity cache marker when a context system prompt exists to preserve the checkpoint budget.
  • Add regression tests (packages/ai/test/anthropic-cache-checkpoint-stability.test.ts) and docs updates (packages/ai/CHANGELOG.md, packages/ai/src/changes.md).

Review notes

  • Core changes in packages/ai/src/api/anthropic-messages.ts (convertMessages, buildParams) with new markUserMessageCacheCheckpoint helper.

Written for commit 5437b99. Summary will update on new commits.

Review in cubic

@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: 32ee10114a

ℹ️ 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 thread packages/ai/src/api/anthropic-messages.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant