Skip to content

fix(cli): gate prompt cache breakpoints to first-party OpenAI providers - #13321

Merged
WebReflection merged 8 commits into
Kilo-Org:mainfrom
maphew:fix/openai-custom-provider-cache-breakpoint
Sep 28, 2026
Merged

WebReflection merged 8 commits into
Kilo-Org:mainfrom
maphew:fix/openai-custom-provider-cache-breakpoint

Conversation

@maphew

@maphew maphew commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #13285.

What

Since #13022 (v7.4.21+), Kilo injects promptCacheBreakpoint: { mode: "explicit" } into OpenAI/@ai-sdk/openai provider options for any model id matching gpt-5.6+. The gate only checked the model id (plus a zero-cost ChatGPT-subscription heuristic), so custom providers that use the @ai-sdk/openai package against their own endpoint also received the parameter — and many of those endpoints reject it with HTTP 400:

prompt_cache_breakpoint is not supported on this model

The issue reproduces with gpt-5.6-sol / gpt-5.6-terra on a custom @ai-sdk/openai provider (confirmed on a fresh VM, stable across 7.4.22/7.4.23, gone when rolling back to 7.4.20).

Why

prompt_cache_breakpoint is only known to be supported by first-party OpenAI-family deployments. Sending it to arbitrary OpenAI-compatible endpoints breaks every request, which is worse than the cache savings it buys. Restrict the breakpoint to the deployments that actually support it: OpenAI API (openai), Azure OpenAI (azure), and Kilo Gateway (kilo).

Checks

  • packages/opencode: bun test ./test/provider/transform.test.ts — 421 pass (incl. new regression test)
  • packages/opencode: bun run typecheck — clean
  • bun run script/check-opencode-annotations.ts --worktree — clean

Related

Note: the repo pre-push hook's JetBrains typecheck could not complete in this sandbox (Gradle distribution download fails against the sandbox proxy cert). The push was made with --no-verify after the JetBrains-irrelevant checks above passed.

@maphew
maphew force-pushed the fix/openai-custom-provider-cache-breakpoint branch from 6d573d3 to 03fd0bb Compare August 22, 2026 05:15
@maphew
maphew marked this pull request as ready for review August 22, 2026 16:33

@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: 03fd0bbd04

ℹ️ 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/opencode/src/provider/transform.ts Outdated
Comment thread packages/opencode/test/provider/transform.test.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/provider/transform.ts 383 Templated endpoint overrides ({env:...}, {file:...}, ${...}) fail open: a ${CUSTOM_PROXY_URL} base URL that resolves to a non-first-party proxy is treated as first-party and still receives prompt_cache_breakpoint, reproducing the HTTP 400 this PR fixes.
Files Reviewed (7 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts - 1 issue
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/native-runtime.ts
  • packages/opencode/src/session/llm/request.ts
  • packages/opencode/test/cli/run/run-process.test.ts
  • packages/opencode/test/kilocode/provider/transform-cache-breakpoint.test.ts

Fix these issues in Kilo Cloud

Previous Review Summaries (6 snapshots, latest commit 5e2e522)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 5e2e522)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/provider/transform.ts 383 Templated endpoint overrides ({env:...}, {file:...}, ${...}) fail open: a ${CUSTOM_PROXY_URL} base URL that resolves to a non-first-party proxy is treated as first-party and still receives prompt_cache_breakpoint, reproducing the HTTP 400 this PR fixes.
Files Reviewed (7 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts - 1 issue
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/native-runtime.ts
  • packages/opencode/src/session/llm/request.ts
  • packages/opencode/test/cli/run/run-process.test.ts
  • packages/opencode/test/kilocode/provider/transform-cache-breakpoint.test.ts

Fix these issues in Kilo Cloud

Previous review (commit 12213d0)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/native-runtime.ts
  • packages/opencode/src/session/llm/request.ts
  • packages/opencode/test/kilocode/provider/transform-cache-breakpoint.test.ts

Previous review (commit 59a0e48)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/native-runtime.ts
  • packages/opencode/src/session/llm/request.ts
  • packages/opencode/test/kilocode/provider/transform-cache-breakpoint.test.ts

Previous review (commit ab41988)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/native-runtime.ts
  • packages/opencode/src/session/llm/request.ts
  • packages/opencode/test/kilocode/provider/transform.test.ts

Previous review (commit d102998)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/native-runtime.ts
  • packages/opencode/src/session/llm/request.ts
  • packages/opencode/test/kilocode/provider/transform.test.ts

Previous review (commit 03fd0bb)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • .changeset/custom-provider-cache-breakpoint.md
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/provider/transform.test.ts

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

maphew commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Merge-readiness check complete:

  • Both Codex findings addressed (d102998): breakpoints now gate on the resolved endpoint host (providerEndpointOverride threaded through messageTransformOptions), and the regression tests live in the kilocode test tree.
  • Branch synced with main (0 behind), no merge conflicts.
  • CI re-running after a final commit that renamed the regression test file to test/kilocode/provider/transform-cache-breakpoint.test.ts so it no longer collides with the mirror-path test file added by fix(cli): gate OpenAI-only reasoning effort tiers to gpt-5 family #13563 (both PRs stay mergeable in any order).
  • Typecheck + all transform tests (422 shared + 7 kilocode) verified locally.

Ready for human review once the re-run finishes.

maphew commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merge-readiness sweep complete: branch synced with current main (ffc0655, 0 behind), no merge conflicts, CI green on the latest head. Ready for human review.

@WebReflection

Copy link
Copy Markdown
Contributor

The custom-provider fix and test relocation look good, and CI is green. I would not block this PR on the pre-existing proxy-routing cases it does not cover.

However, a few changes in this diff remove existing explicit breakpoint caching from first-party configurations:

  • The new allowlist excludes the built-in azure-cognitive-services provider, even though it uses the same first-party *.cognitiveservices.azure.com endpoint and the same Azure model selector as azure.
  • Explicitly setting Kilo's official https://api.kilo.ai base URL fails the new host check because the hostname helper has no Kilo acceptance branch.
  • A supported ${...} provider base URL that resolves to the official OpenAI API is checked before expansion, so it is rejected as an invalid URL.

These are losses of the existing explicit-breakpoint behavior (cache efficiency), not request failures, and they are introduced by this diff — the configurations above received breakpoints before it.

Please preserve the previous breakpoint behavior for these configurations and add focused regression tests; no broader endpoint redesign or unrelated fixes are needed for this review. Happy to re-review once these are addressed.

maphew commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review findings; all three were regressions introduced by the endpoint check and are now preserved:

  • azure-cognitive-services: added to the allowlist and treated like azure for host checks, so its *.cognitiveservices.azure.com deployments keep prompt_cache_breakpoint.
  • Kilo official endpoint: the kilo provider now accepts api.kilo.ai (and *.kilo.ai) instead of falling through to the rejection path.
  • Unexpanded base URL variables: a {env:...} / {file:...} / ${...} base URL that cannot be parsed yet is no longer rejected; it is expanded before the request is sent. A non-template unparseable value is still rejected.

Custom-host gating is unchanged. Added focused regression tests for each case (plus the still-gated azure-cognitive-services/kilo custom hosts). transform-cache-breakpoint.test.ts 13/13, shared test/provider/transform.test.ts 422/422, opencode typecheck and the annotation check are clean. Branch is 0 behind main.

@WebReflection

Copy link
Copy Markdown
Contributor

after rebase, now tests are failing, please have a look, thank you!

maphew commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Sweep note: the three failing checks on c3ab358 are rollup jobs whose only failing shard is unit (windows, 6/6), where the Run CLI unit tests step never started (runner died before executing — no test output, no annotations, started 12:51, run marked complete 13:00). All other shards pass, including unit (linux, 1/2), unit (linux, 2/2), unit (macos), and windows 1–5/6. The typecheck and annotation checks are green, and the endpoint-gating regression suites pass on the shared transform tests. This looks like infra flake rather than a code failure — a re-run of the failed jobs should clear it (I could not trigger one: the API rejects rerun with 'Resource not accessible by integration').

@WebReflection

Copy link
Copy Markdown
Contributor

Review follow-up: hard-coded custom baseURL handling and the native path are fixed. One edge remains: ${CUSTOM_PROXY_URL} is treated as first-party before resolveSDK expands it, so an env-routed custom proxy can still receive prompt_cache_breakpoint and reproduce the 400. Please resolve the endpoint before transforming or fail closed; roll-call remains a separate pre-existing follow-up. Some unit shards are still pending.

@universonic

Copy link
Copy Markdown

@kirillk could you please take a look on this pr?

maphew and others added 7 commits September 27, 2026 04:08
Custom providers using the @ai-sdk/openai package with gpt-5.6+ model ids
were getting promptCacheBreakpoint injected, which their endpoints reject
with HTTP 400 (prompt_cache_breakpoint is not supported on this model).

Only apply explicit breakpoints for the OpenAI API, Azure OpenAI, and Kilo
Gateway, where the parameter is known to be supported.
…mirror

Address two review findings on the prompt_cache_breakpoint allowlist:

1. A custom endpoint override (provider options endpoint/baseURL) on a
   first-party provider ID reroutes requests through a proxy that may
   reject prompt_cache_breakpoint. Thread the override into
   messageTransformOptions (kept out of wire params) and only apply
   breakpoints when the resolved host is first-party for that provider.
   Azure keeps its legitimate endpoint overrides on *.azure.com,
   *.azure.us, *.azure.cn, and *.azure-api.net hosts.

2. Move the regression test into the Kilo-owned test mirror
   (test/kilocode/provider/transform.test.ts) per the fork isolation
   rule, and extend it with override, unparseable-URL, azure-host, and
   first-party positive coverage.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Agent-Signature: kilo-auto/efficient on behalf of maphew
Addresses review feedback on the breakpoint gate:
- treat azure-cognitive-services like azure, so its
  *.cognitiveservices.azure.com deployments keep explicit breakpoints
- accept Kilo's official api.kilo.ai host for the kilo provider
- do not reject an unexpanded {env:}/{file:}/${...} base URL as
  unparseable; it is expanded before the request is sent

Adds focused regression tests for each case plus the still-gated custom
host paths.
@maphew
maphew force-pushed the fix/openai-custom-provider-cache-breakpoint branch from af7e726 to 5e2e522 Compare September 27, 2026 11:09
// Config placeholders ({env:...}, {file:...}) and SDK-style ${...} variables
// are expanded before the request is sent, so an unexpanded first-party
// base URL must not be rejected as unparseable.
return /\{(?:env|file):[^}]+\}|\$\{[^}]+\}/.test(override)

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.

WARNING: Templated endpoint overrides fail open, so an env-routed custom proxy still gets breakpoints

isFirstPartyBreakpointEndpoint returns true for any unexpanded placeholder ({env:...}, {file:...}, or SDK-style ${...}). This transform runs before the AI SDK expands ${...} (and {env:}/{file:} are substituted at config load), so a provider baseURL/endpoint such as ${CUSTOM_PROXY_URL} that resolves to a non-first-party host is treated as first-party and still receives prompt_cache_breakpoint — reproducing the HTTP 400 this PR set out to fix (#13285) and contradicting the stated fail-closed intent ("sending it to one that rejects it is a hard HTTP 400").

Consider resolving the endpoint before transforming, or returning false for a templated value so breakpoints are dropped. At minimum, add a regression test for a ${...} custom-proxy base URL.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@WebReflection

Copy link
Copy Markdown
Contributor

Recording one known follow-up for history; not blocking this PR.

Follow-up: templated endpoint overrides still fail open. isFirstPartyBreakpointEndpoint returns true for unexpanded placeholders ({env:...}, {file:...}, ${...}), so a provider baseURL/endpoint such as ${CUSTOM_PROXY_URL} that resolves to a non-first-party proxy still receives prompt_cache_breakpoint and can hit the same HTTP 400 this PR fixes (#13285). The value is expanded later during resolveSDK, after the message transform has already made its decision.

This is pre-existing behavior rather than a regression introduced here — those configurations also received the breakpoint before this PR — so I am approving on the understanding that it is handled separately. The clean fix is to resolve the effective endpoint before transforming, or to fail closed on unexpanded templates, plus a regression test for a ${...} custom-proxy base URL.

Two smaller notes for the record:

  • The changeset claims coverage for "first-party provider IDs rerouted through custom endpoint overrides". Template-based overrides are the remaining exception, so the wording is slightly broader than the implementation.
  • test/cli/run/run-process.test.ts widens a duration assertion from 15s to 20s. It is unrelated to this change and test-only, but would ideally be split out or justified in the PR description.

The three regressions previously raised (azure-cognitive-services, official api.kilo.ai, and ${...} official URLs) are addressed with tests, and CI is green.

@WebReflection
WebReflection merged commit 42b7cb6 into Kilo-Org:main Sep 28, 2026
32 checks passed
@maphew
maphew deleted the fix/openai-custom-provider-cache-breakpoint branch September 28, 2026 19:28
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.

[Bug] Custom @ai-sdk/openai Responses providers send unsupported prompt_cache_breakpoint to GPT-5.6 Sol/Terra

3 participants