Repository navigation
fix(cli): gate prompt cache breakpoints to first-party OpenAI providers #13321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WebReflection
merged 8 commits into
Kilo-Org:main
from
maphew:fix/openai-custom-provider-cache-breakpoint
Sep 28, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad173c7
fix(cli): gate prompt cache breakpoints to first-party OpenAI providers
maphew 5ff1660
review: gate breakpoints on resolved endpoint; move test to kilocode …
maphew 9fac226
chore(cli): annotate applyCaching signature with kilocode_change marker
maphew d5e94e0
ci: re-trigger pipeline (flaky httpapi-pty test on loaded shard)
maphew a576100
test(cli): rename cache-breakpoint test to avoid mirror path collision
maphew 112adb2
fix(cli): preserve cache breakpoints for first-party endpoints
maphew 5e2e522
test(cli): widen unknown-model duration check for loaded CI runners
maphew ff08791
test(cli): annotate duration check change with kilocode_change marker
maphew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@kilocode/cli": patch | ||
| --- | ||
|
|
||
| Stop sending prompt_cache_breakpoint to custom OpenAI-compatible providers, and to first-party provider IDs rerouted through custom endpoint overrides; both reject the parameter with HTTP 400. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
226 changes: 226 additions & 0 deletions
226
packages/opencode/test/kilocode/provider/transform-cache-breakpoint.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import { ProviderTransform } from "@/provider/transform" | ||
|
|
||
| describe("ProviderTransform.message - prompt cache breakpoint endpoint gating", () => { | ||
| const createModel = (overrides: Partial<any> = {}) => | ||
| ({ | ||
| id: "gpt-5.6", | ||
| providerID: "openai", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "https://api.openai.com/v1", | ||
| npm: "@ai-sdk/openai", | ||
| }, | ||
| name: "GPT 5.6", | ||
| capabilities: { | ||
| temperature: true, | ||
| reasoning: true, | ||
| attachment: true, | ||
| toolcall: true, | ||
| input: { text: true, audio: false, image: true, video: false, pdf: true }, | ||
| output: { text: true, audio: false, image: false, video: false, pdf: false }, | ||
| interleaved: false, | ||
| }, | ||
| cost: { input: 0.00125, output: 0.01, cache: { read: 0.000125, write: 0 } }, | ||
| limit: { context: 400_000, output: 128_000 }, | ||
| status: "active", | ||
| options: {}, | ||
| headers: {}, | ||
| ...overrides, | ||
| }) as any | ||
|
|
||
| const msgs = () => | ||
| [ | ||
| { role: "system", content: "You are a helpful assistant" }, | ||
| { role: "user", content: "Hello" }, | ||
| ] as any[] | ||
|
|
||
| test("custom @ai-sdk/openai provider does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "custom", | ||
| api: { | ||
| id: "gpt-5.6-sol", | ||
| url: "https://redacted/v1", | ||
| npm: "@ai-sdk/openai", | ||
| }, | ||
| id: "gpt-5.6-sol", | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, {}) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("openai provider with a custom endpoint override does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel() | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://proxy.example.com/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("openai provider with a model-level baseURL override does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel() | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| baseURL: "https://gateway.internal:8443/openai/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("openai provider with an unparseable override does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel() | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "not a url", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("first-party openai without overrides still applies promptCacheBreakpoint", () => { | ||
| const model = createModel() | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, {}) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| }) | ||
|
|
||
| test("azure endpoint override on an azure host still applies promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "azure", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "", | ||
| npm: "@ai-sdk/azure", | ||
| }, | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://myresource.cognitiveservices.azure.com/openai/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.azure?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| expect(result[1].providerOptions?.azure?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| }) | ||
|
|
||
| test("azure endpoint override on a non-azure host does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "azure", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "", | ||
| npm: "@ai-sdk/azure", | ||
| }, | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://proxy.example.com/azure/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.azure?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.azure?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("azure-cognitive-services endpoint still applies promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "azure-cognitive-services", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "", | ||
| npm: "@ai-sdk/azure", | ||
| }, | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://myresource.cognitiveservices.azure.com/openai/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.azure?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| expect(result[1].providerOptions?.azure?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| }) | ||
|
|
||
| test("azure-cognitive-services endpoint on a non-azure host does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "azure-cognitive-services", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "", | ||
| npm: "@ai-sdk/azure", | ||
| }, | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://proxy.example.com/azure/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.azure?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.azure?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("kilo provider with the official api.kilo.ai base URL still applies promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "kilo", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "https://api.kilo.ai", | ||
| npm: "@ai-sdk/openai", | ||
| }, | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://api.kilo.ai", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| }) | ||
|
|
||
| test("kilo provider with a custom base URL does not apply promptCacheBreakpoint", () => { | ||
| const model = createModel({ | ||
| providerID: "kilo", | ||
| api: { | ||
| id: "gpt-5.6", | ||
| url: "", | ||
| npm: "@ai-sdk/openai", | ||
| }, | ||
| }) | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "https://proxy.example.com/kilo/v1", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined() | ||
| }) | ||
|
|
||
| test("openai provider with an unexpanded {env:} base URL still applies promptCacheBreakpoint", () => { | ||
| const model = createModel() | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "{env:OPENAI_BASE_URL}", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| }) | ||
|
|
||
| test("openai provider with an unexpanded ${} base URL still applies promptCacheBreakpoint", () => { | ||
| const model = createModel() | ||
|
|
||
| const result = ProviderTransform.message(msgs(), model, { | ||
| providerEndpointOverride: "${OPENAI_BASE_URL}", | ||
| }) as any[] | ||
|
|
||
| expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toEqual({ mode: "explicit" }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
isFirstPartyBreakpointEndpointreturnstruefor 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 providerbaseURL/endpointsuch as${CUSTOM_PROXY_URL}that resolves to a non-first-party host is treated as first-party and still receivesprompt_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
falsefor a templated value so breakpoints are dropped. At minimum, add a regression test for a${...}custom-proxy base URL.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.