-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(opencode-go): support Grok 4.6 Responses #3394
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
lidge-jun
merged 4 commits into
lidge-jun:dev
from
kremnyi:fix/opencode-go-grok46-responses
Sep 4, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| /** Hosted tools rejected by specific native model slugs. */ | ||
| const UNSUPPORTED_HOSTED_TOOLS: ReadonlyArray<{ match: (model: string) => boolean; tools: ReadonlySet<string> }> = [ | ||
| /** Hosted tools rejected by specific native model slugs or exact provider destinations. */ | ||
| const UNSUPPORTED_HOSTED_TOOLS: ReadonlyArray<{ | ||
| match: (model: string, baseUrl?: string) => boolean; | ||
| tools: ReadonlySet<string>; | ||
| }> = [ | ||
| { match: model => model.includes("codex-spark"), tools: new Set(["image_generation", "tool_search"]) }, | ||
| { | ||
| match: (model, baseUrl) => model === "grok-4.6" | ||
| && baseUrl?.replace(/\/+$/, "") === "https://opencode.ai/zen/go/v1", | ||
| tools: new Set(["web_search", "web_search_preview"]), | ||
| }, | ||
| ]; | ||
|
|
||
| /** True when forwarding this hosted tool to the model would be rejected upstream. */ | ||
| export function isHostedToolUnsupportedForModel(modelId: string, tool: string): boolean { | ||
| return UNSUPPORTED_HOSTED_TOOLS.some(entry => entry.match(modelId) && entry.tools.has(tool)); | ||
| export function isHostedToolUnsupportedForModel(modelId: string, tool: string, baseUrl?: string): boolean { | ||
| return UNSUPPORTED_HOSTED_TOOLS.some(entry => entry.match(modelId, baseUrl) && entry.tools.has(tool)); | ||
| } |
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,135 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { createResponsesPassthroughAdapter as createResponsesPassthroughAdapterProduction } from "../src/adapters/openai-responses"; | ||
| import { providerConfigSeed } from "../src/providers/derive"; | ||
| import { getProviderRegistryEntry } from "../src/providers/registry"; | ||
| import { resolveWireProtocolOverride } from "../src/server/adapter-resolve"; | ||
| import type { OcxProviderConfig } from "../src/types"; | ||
| import { withTestTranslatorBudget } from "./helpers/translator-budget"; | ||
|
|
||
| const createResponsesPassthroughAdapter = (...args: Parameters<typeof createResponsesPassthroughAdapterProduction>) => | ||
| withTestTranslatorBudget(createResponsesPassthroughAdapterProduction(...args)); | ||
|
|
||
| const registryEntry = getProviderRegistryEntry("opencode-go"); | ||
| if (!registryEntry) throw new Error("missing opencode-go registry fixture"); | ||
|
|
||
| function provider(baseUrl = "https://opencode.ai/zen/go/v1"): OcxProviderConfig { | ||
| return { | ||
| ...providerConfigSeed(registryEntry), | ||
| adapter: "openai-responses", | ||
| baseUrl, | ||
| apiKey: "test-key", | ||
| } as OcxProviderConfig; | ||
| } | ||
|
|
||
| function build( | ||
| modelId: string, | ||
| rawBody: Record<string, unknown>, | ||
| configuredProvider = provider(), | ||
| ): Record<string, unknown> { | ||
| const request = createResponsesPassthroughAdapter(configuredProvider).buildRequest({ | ||
| modelId, | ||
| context: { messages: [] }, | ||
| stream: true, | ||
| options: {}, | ||
| _rawBody: { model: modelId, input: "ping", ...rawBody }, | ||
| }, { headers: new Headers() }); | ||
| return JSON.parse(request.body) as Record<string, unknown>; | ||
| } | ||
|
|
||
| describe("OpenCode Go Grok 4.6 Responses compatibility", () => { | ||
| test("routes only the documented Grok model to Responses", () => { | ||
| const configured = providerConfigSeed(registryEntry); | ||
|
|
||
| expect(resolveWireProtocolOverride("opencode-go", "grok-4.6", configured).adapter) | ||
| .toBe("openai-responses"); | ||
| expect(resolveWireProtocolOverride("opencode-go", "grok-4.5", configured).adapter) | ||
| .toBe("openai-chat"); | ||
| }); | ||
|
|
||
| test("maps a stale Codex max request to Grok's highest supported effort", () => { | ||
| const body = build("grok-4.6", { reasoning: { effort: "max" } }); | ||
|
|
||
| expect(body.reasoning).toEqual({ effort: "xhigh" }); | ||
| expect(registryEntry.modelReasoningEfforts?.["grok-4.6"]) | ||
| .toEqual(["low", "medium", "high", "xhigh"]); | ||
| expect(registryEntry.modelDefaultReasoningEfforts?.["grok-4.6"]).toBe("high"); | ||
| }); | ||
|
|
||
| test("drops the hosted search tool that this exact destination rejects", () => { | ||
| const functionTool = { type: "function", name: "lookup", parameters: { type: "object" } }; | ||
| const body = build("grok-4.6", { | ||
| tools: [ | ||
| { type: "web_search", search_context_size: "medium" }, | ||
| { type: "web_search_preview" }, | ||
| functionTool, | ||
| ], | ||
| }); | ||
|
|
||
| expect(body.tools).toEqual([functionTool]); | ||
| }); | ||
|
|
||
| test("drops hosted search from an additional_tools-only request", () => { | ||
| const functionTool = { type: "function", name: "lookup", parameters: { type: "object" } }; | ||
| const body = build("grok-4.6", { | ||
| input: [{ | ||
| type: "additional_tools", | ||
| tools: [{ type: "web_search_preview" }, functionTool], | ||
| }], | ||
| }); | ||
|
|
||
| expect(body.input).toEqual([{ type: "additional_tools", tools: [functionTool] }]); | ||
| }); | ||
|
|
||
| test("disables an explicit choice for a removed hosted tool", () => { | ||
| const body = build("grok-4.6", { | ||
| tools: [{ type: "web_search" }], | ||
| tool_choice: { type: "web_search" }, | ||
| }); | ||
|
|
||
| expect(body.tools).toEqual([]); | ||
| expect(body.tool_choice).toBe("none"); | ||
| }); | ||
|
|
||
| test("narrows allowed_tools to declarations that remain", () => { | ||
| const functionTool = { type: "function", name: "lookup", parameters: { type: "object" } }; | ||
| const body = build("grok-4.6", { | ||
| tools: [{ type: "web_search_preview" }, functionTool], | ||
| tool_choice: { | ||
| type: "allowed_tools", | ||
| mode: "required", | ||
| tools: [{ type: "web_search_preview" }, { type: "function", name: "lookup" }], | ||
| }, | ||
| }); | ||
|
|
||
| expect(body.tools).toEqual([functionTool]); | ||
| expect(body.tool_choice).toEqual({ | ||
| type: "allowed_tools", | ||
| mode: "required", | ||
| tools: [{ type: "function", name: "lookup" }], | ||
| }); | ||
| }); | ||
|
|
||
| test("disables required mode when every declared tool is removed", () => { | ||
| const body = build("grok-4.6", { | ||
| tools: [{ type: "web_search" }], | ||
| tool_choice: "required", | ||
| }); | ||
|
|
||
| expect(body.tools).toEqual([]); | ||
| expect(body.tool_choice).toBe("none"); | ||
| }); | ||
|
|
||
| test("preserves hosted search for another model on OpenCode Go", () => { | ||
| const webSearch = { type: "web_search", search_context_size: "medium" }; | ||
| const body = build("gpt-5.6-luna", { tools: [webSearch] }); | ||
|
|
||
| expect(body.tools).toEqual([webSearch]); | ||
| }); | ||
|
|
||
| test("preserves hosted search for Grok 4.6 on another destination", () => { | ||
| const webSearch = { type: "web_search", search_context_size: "medium" }; | ||
| const body = build("grok-4.6", { tools: [webSearch] }, provider("https://api.x.ai/v1")); | ||
|
|
||
| expect(body.tools).toEqual([{ type: "web_search" }]); | ||
| }); | ||
| }); |
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.