-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Open
maphew
wants to merge
8
commits into
Kilo-Org:main
Choose a base branch
from
maphew:fix/openai-custom-provider-cache-breakpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−7
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
03fd0bb
fix(cli): gate prompt cache breakpoints to first-party OpenAI providers
maphew d102998
review: gate breakpoints on resolved endpoint; move test to kilocode …
maphew 81bad8a
Merge branch 'main' into fix/openai-custom-provider-cache-breakpoint
maphew a90aa77
chore(cli): annotate applyCaching signature with kilocode_change marker
maphew 91d9733
chore: merge upstream main into fix/openai-custom-provider-cache-brea…
maphew ab41988
ci: re-trigger pipeline (flaky httpapi-pty test on loaded shard)
maphew fe61262
Merge remote-tracking branch 'upstream/main' into fix/openai-custom-p…
maphew 59a0e48
test(cli): rename cache-breakpoint test to avoid mirror path collision
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
132 changes: 132 additions & 0 deletions
132
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,132 @@ | ||
| 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() | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.