Skip to content

fix(ai): allow disabling cache control on tools - #58793

Closed
TheBrain0110 wants to merge 1 commit into
anomalyco:v2from
TheBrain0110:anthropic-cache-compat
Closed

TheBrain0110 wants to merge 1 commit into
anomalyco:v2from
TheBrain0110:anthropic-cache-compat

Conversation

@TheBrain0110

Copy link
Copy Markdown

What

Add a model compatibility option, supportsToolCacheControl, that allows Anthropic-compatible endpoints to disable cache_control on tool definitions while retaining cache markers on supported system and message content.

Why

Some Anthropic-compatible endpoints accept prompt-cache markers on system and message content but reject tools[].cache_control with HTTP 400. The existing cache: "none" policy is too broad because it disables all automatic cache placement, including cache sites those endpoints support.

This was reproduced against an Anthropic-compatible governed proxy: ordinary prompts worked until OpenCode's automatic cache policy marked a tool definition. Suppressing only tool-definition markers restored both streaming and tool-call loops while preserving system/message caching.

How

  • Add optional supportsToolCacheControl model compatibility metadata; omitted defaults to the existing behavior (true).
  • Make automatic cache placement skip tool definitions when compatibility is explicitly false.
  • Make Anthropic Messages lowering omit manually supplied tool cache hints under the same compatibility setting.
  • Exclude unsupported tool hints from the four-breakpoint budget so system and message markers retain the available capacity.
  • Add tests covering automatic and manual tool cache hints while confirming system/message markers remain intact.

Verification

  • bun test test/cache-policy.test.ts from packages/ai: 18 passed, 0 failed
  • bun run --cwd packages/schema typecheck: passed
  • bun run --cwd packages/ai typecheck: passed
  • bun run --cwd packages/core typecheck: passed
  • git diff --check: passed
  • Built the Linux x64 CLI from the v2 branch.
  • Live Anthropic-compatible streaming test: ANTHROPIC_COMPAT_OK
  • Live tool loop reading proof.txt: tool-proof-73
  • Live OpenAI-provider regression test: OPENAI_REGRESSION_OK

Notes

The default remains unchanged for Anthropic and other providers. This is generic compatibility metadata rather than a check for any private provider ID.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@opencode-agent opencode-agent Bot closed this Oct 24, 2026
@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks for putting this together, @TheBrain0110!

The v2 branch was promoted to dev on 2026-10-10, and dev is now where v2 work happens. This pull request targets a branch that is no longer used, so it's being closed automatically.

Please open it again with dev as the base. Your same branch works fine: just open a new pull request from it into dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant