Skip to content

fix: preserve opt-in OpenAI prompt-cache boundaries - #12880

Open
ZenAlexa wants to merge 13 commits into
can1357:mainfrom
ZenAlexa:contrib/12780-agent-loop-never-enables-explicit-prompt-caching-for-g
Open

ZenAlexa wants to merge 13 commits into
can1357:mainfrom
ZenAlexa:contrib/12780-agent-loop-never-enables-explicit-prompt-caching-for-g

Conversation

@ZenAlexa

@ZenAlexa ZenAlexa commented Sep 22, 2026 •

Copy link
Copy Markdown

what

kept explicit prompt caching opt-in and fixed cache boundaries across tool loops. omitted policy and caller-supplied markers keep their existing behavior.

chat completions selects stable assistant and tool boundaries. responses keeps function-output markers aligned with the stored prefix across incremental requests and falls back to the existing full replay when history changes. the content union stays intact, the gateway rejects unsupported nested markers, and custom endpoint configuration accepts supportsPromptCacheBreakpoints.

why

related to #12780. explicit caching needs a stable prefix across tool calls and later dialogue. automatic cache enablement remains a separate policy decision.

current main

merged main@b91db66e9 into 7fcaeb3ce7. the cache policy remains opt-in, and both changelog entries stay under unreleased.

testing

on 7fcaeb3ce7, 455 tests passed across 19 files with bun 1.4.2 on macos arm64. these cover cache boundaries, incremental replay, gateway marker rejection, model configuration, session cleanup, provider pricing, and the stats and model-browser consumers.

BUN_INSTALL_AUTO=disable bun --no-install test --timeout 60000 \
  packages/coding-agent/test/model-browser.test.ts \
  packages/coding-agent/test/model-registry.test.ts \
  packages/catalog/test/time-based-pricing.test.ts \
  packages/catalog/test/nanogpt-model-limits.test.ts \
  packages/catalog/test/cursor-pricing.test.ts \
  packages/catalog/test/devin-discovery.test.ts \
  packages/catalog/test/cursor-discovery.test.ts \
  packages/catalog/test/kilo-discovery.test.ts \
  packages/catalog/test/gemini-argon-pricing.test.ts \
  packages/agent/test/agent.test.ts \
  packages/ai/test/openai-configuration-update.test.ts \
  packages/ai/test/auth-gateway-openai-prompt-cache.test.ts \
  packages/ai/test/openai-responses-cache-affinity.test.ts \
  packages/ai/test/google-gemini-cli-variant-routing.test.ts \
  packages/ai/test/provider-session-release.test.ts \
  packages/ai/test/openai-responses-delta-input.test.ts \
  packages/ai/test/openai-responses-stateful.test.ts \
  packages/ai/test/openai-completions-cache-affinity.test.ts \
  packages/stats/test/db-cost.test.ts

bun check passed, including lint, formatting, workspace typechecks and rust checks. a separate request-lifecycle scenario passed 19 checks for opt-in transitions, cache key changes, incremental replay and gateway rejection.

optional transformers inference, live billing and cache-hit rates remain outside this run. the rust check used the project's stub for apple foundation models because the optional sdk was unavailable.

  • bun check passes
  • tested locally
  • changelog updated with the required attribution

@ZenAlexa
ZenAlexa marked this pull request as ready for review September 22, 2026 18:33
Copilot AI lite review requested due to automatic review settings September 22, 2026 18:33
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@roboomp roboomp added agent Agent runtime planning and orchestration fix provider:openai Provider-specific issues for openai providers LLM provider-specific issues review:p1 triaged labels Sep 22, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P2 — this is a cost-bearing default behavior change; automatic enablement needs explicit maintainer sign-off.
Blocking: caller-silent agent requests now enable 1.25× cache writes. Should-fix: the exported Responses output type narrows valid callers, the gateway rejection misses nested output markers, and affected package changelogs are absent.
Focused verification passed: 231 tests across the four touched suites.
Thanks @ZenAlexa for the structured capability path and targeted coverage.

Comment thread packages/agent/src/agent-loop.ts Outdated
Comment thread packages/ai/src/providers/openai-responses-wire.ts Outdated
Comment thread packages/ai/src/providers/openai-responses.ts Outdated
Comment thread packages/coding-agent/src/config/models-config-schema-bundle.ts
@ZenAlexa
ZenAlexa force-pushed the contrib/12780-agent-loop-never-enables-explicit-prompt-caching-for-g branch from 296d139 to e667f42 Compare September 23, 2026 04:23
@ZenAlexa
ZenAlexa force-pushed the contrib/12780-agent-loop-never-enables-explicit-prompt-caching-for-g branch from e667f42 to eed2185 Compare September 23, 2026 04:26
@ZenAlexa

Copy link
Copy Markdown
Author

I addressed the type, gateway, and changelog findings in eed21859. The Responses wire preserves the existing content union, the auth gateway rejects explicit markers nested under function-call output arrays, and the behavior tests cover capable, caller-overridden, and markerless branches. The PR is rebased onto current main; bun run check and the focused suites pass. Automatic explicit-cache enablement remains capability-gated and awaits maintainer sign-off for its billed cache-write policy.

@ZenAlexa ZenAlexa changed the title feat: enable capability-driven explicit prompt caching fix: preserve opt-in OpenAI prompt-cache boundaries Sep 23, 2026
@ZenAlexa

Copy link
Copy Markdown
Author

Kept explicit prompt caching opt-in and fixed the cache markers so later tool calls can reuse the existing Responses prefix.

Keep the stateful test imports and align gateway requests with the
current authentication fixture.

Signed-off-by: ZenAlexa <zimingwang945@gmail.com>
Retain explicit-cache boundary handling alongside current auth-broker
usage flushing and terminal progress updates.

Signed-off-by: ZenAlexa <zimingwang945@gmail.com>
Retain opt-in cache boundaries with current account refresh, resumed
session affinity, catalog discovery, and interrupted tool-result handling.

Signed-off-by: ZenAlexa <zimingwang945@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Agent runtime planning and orchestration fix provider:openai Provider-specific issues for openai providers LLM provider-specific issues review:p1 triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants