Repository navigation
feat(core): add prompt cache rules - #53927
hiroshi1000 wants to merge 5 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
I ran the new tests in packages/ai, packages/schema and packages/core (all pass) and type-checked those packages. I did not exercise this end to end against real providers. The rule-selection and body-lowering code looks careful, but a few issues should be addressed first:
- A typo in
cachedrops the entire config file. I checked withConfigNormalize.normalize: a misspelled condition (subAgent) makes the whole document rejected. The user's permissions, agents and providers silently disappear, with only a log warning. Other malformed keys are skipped individually. - Config mistakes crash requests. Ambiguous or unsupported rules are found only at request time and become defects (a plain
throwandEffect.orDie) on every request, including title generation and compaction. These should be validated and reported when the config loads. - Route and model gating is narrow and hard-coded.
cache_controlis accepted only on three routes. Bedrock Converse, Anthropic-compatible providers and OpenRouter (for Anthropic models) already honour TTL through the existing cache policy. The OpenAI checks guess support from model IDs with regexes, which goes against the forward-compatibility guidance inpackages/ai/AGENTS.md. - Design. The config exposes each provider's raw field names (
cache_control,prompt_cache_retention) and then translates Anthropic's back into the existingcache: { ttlSeconds }policy. It would be good to get a maintainer's view on this shape in #51109 before going further. - Tests. The new session test in
session-model-request-hooks.test.tsloops over every request kind × 5 scenarios × 2 providers in one large test, and the GPT body test loops over 6 model IDs × 4 option sets. Please cut these down to a few clear cases: one per behaviour (most specific rule wins, subagent vs fork, an OpenAI option reaching the body, reload).
|
Follow-up to the review summary, after 556825f:
The three inline findings have individual replies with the corresponding changes. Validation: 290 Core tests, 572 AI tests, and the repository-wide |
Use the current HTTP API module and enforce strict cache-rule decoding so unknown conditions are rejected during config normalization. Co-authored-by: Copilot <[email protected]>
71db803 to
477f8ee
Compare
Resolve the PR conflicts while preserving the existing branch history. Co-authored-by: Copilot <[email protected]>
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Refs #51109 and the configuration proposal.
Type of change
What does this PR do?
Add a top-level
cachemap keyed by configured provider ID. Rules match the actual agent, model, and subagent context; the most specific containing rule wins independently of order. Ambiguous and duplicate rules are diagnosed at configuration load; only the affected provider’s array is disabled, preserving unrelated configuration and preventing lower-priority rules from reappearing. Higher-priority config files replace each provider's whole rule array.Apply native Anthropic
cache_controland OpenAIprompt_cache_retention/prompt_cache_optionssettings, including subagents, title generation, and compaction. Unmatched requests and empty options keep existing behavior. Route-dependent unsupported settings return typed request errors. Cache controls reuse existing route policies, including Anthropic-compatible endpoints, Anthropic through OpenRouter, and supported Bedrock Converse models; unsupported Bedrock TTLs are rejected rather than shortened. Examples and limits are documented inspecs/v2/prompt-cache.md.GPT-5.6 and later accept native
prompt_cache_options(ttl: "30m",mode: "implicit" | "explicit"), including compaction. Model and account compatibility are left to the API rather than inferred from model-ID regular expressions. The deprecated24hretention may coexist with the new policy; it is not translated into a TTL. These rules do not insert explicit OpenAI breakpoints.This is an independent implementation on
v2, not a branch of #51110.How did you verify your code works?
bun run check(repository lint and typechecks).bun run generate; a second generation produced identical output.Screenshots / recordings
Not applicable; no UI changes.
Checklist