Skip to content

Commit 7881319

Browse files
authored
Merge pull request #2283 from lidge-jun/codex/backfill-xai-web-search-capability
fix(router): backfill the xAI web-search capability into routed provider config
2 parents e3b2136 + d5ea14a commit 7881319

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎src/router.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,17 @@ export function routedProviderConfig(providerName: string, provider: OcxProvider
355355
...(provider.supportsServiceTier === undefined && registryEntry.supportsServiceTier !== undefined
356356
? { supportsServiceTier: registryEntry.supportsServiceTier }
357357
: {}),
358+
// Registry-only web-search capability: without this backfill a saved provider row reaches
359+
// the Responses adapter with the flag `undefined`, so the capability gate added in #2262
360+
// reads "unclassified" and forwards Codex's OpenAI-only `web_search` config fields. xAI
361+
// rejects the whole request before inference ("Argument not supported:
362+
// external_web_access"), which killed every routed Grok turn on the Responses lane.
363+
// enrichProviderFromRegistry() already fills this, but the request path resolves through
364+
// routedProviderConfig() and never called it.
365+
...(provider.supportsOpenAiWebSearchToolFields === undefined
366+
&& registryEntry.supportsOpenAiWebSearchToolFields !== undefined
367+
? { supportsOpenAiWebSearchToolFields: registryEntry.supportsOpenAiWebSearchToolFields }
368+
: {}),
358369
...(provider.preserveResponsesReasoningContent === undefined && registryEntry.preserveResponsesReasoningContent !== undefined
359370
? { preserveResponsesReasoningContent: registryEntry.preserveResponsesReasoningContent }
360371
: {}),

‎tests/responses-routed-web-search-fields.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
22
import { createResponsesPassthroughAdapter as createResponsesPassthroughAdapterProduction, stripOpenAiOnlyWebSearchFields } from "../src/adapters/openai-responses";
33
import { enrichProviderFromRegistry, providerConfigSeed } from "../src/providers/derive";
44
import { getProviderRegistryEntry } from "../src/providers/registry";
5+
import { routedProviderConfig } from "../src/router";
56
import type { OcxProviderConfig } from "../src/types";
67
import { withTestTranslatorBudget } from "./helpers/translator-budget";
78

@@ -81,3 +82,52 @@ describe("Responses buildRequest web_search capability", () => {
8182
}]);
8283
});
8384
});
85+
86+
// The request path resolves a saved provider row through routedProviderConfig(), NOT through
87+
// enrichProviderFromRegistry(). Until this backfill existed, a saved xai row reached the
88+
// Responses adapter with supportsOpenAiWebSearchToolFields === undefined, so the #2262
89+
// capability gate read "unclassified" and forwarded the fields; live xAI answered
90+
// `400 Argument not supported: external_web_access` and every routed Grok turn on the
91+
// Responses lane died before inference (verified against cli-chat-proxy.grok.com 2026-08-21).
92+
// Asserting on the adapter with a hand-built provider cannot catch this — the gap is upstream
93+
// of the adapter, in what the router hands it.
94+
describe("routedProviderConfig web_search capability backfill", () => {
95+
test("a saved xai row without the flag is classified by the registry", () => {
96+
const saved: OcxProviderConfig = {
97+
adapter: "openai-chat",
98+
baseUrl: "https://api.x.ai/v1",
99+
authMode: "oauth",
100+
// The GUI Responses opt-in writes only modelAdapters; it never writes the capability.
101+
modelAdapters: { "grok-4.6": "openai-responses" },
102+
};
103+
expect(saved.supportsOpenAiWebSearchToolFields).toBeUndefined();
104+
105+
const routed = routedProviderConfig("xai", saved);
106+
expect(routed.supportsOpenAiWebSearchToolFields).toBe(false);
107+
});
108+
109+
test("the routed row actually strips the fatal fields at the adapter", () => {
110+
const routed = routedProviderConfig("xai", {
111+
adapter: "openai-chat",
112+
baseUrl: "https://api.x.ai/v1",
113+
authMode: "oauth",
114+
modelAdapters: { "grok-4.6": "openai-responses" },
115+
});
116+
117+
const body = buildWebSearchBody({ ...routed, adapter: "openai-responses" });
118+
expect(body.tools).toEqual([{
119+
type: "web_search",
120+
user_location: { type: "approximate" },
121+
}]);
122+
});
123+
124+
test("an explicit saved value still overrides the registry default", () => {
125+
const routed = routedProviderConfig("xai", {
126+
adapter: "openai-responses",
127+
baseUrl: "https://api.x.ai/v1",
128+
authMode: "oauth",
129+
supportsOpenAiWebSearchToolFields: true,
130+
});
131+
expect(routed.supportsOpenAiWebSearchToolFields).toBe(true);
132+
});
133+
});

0 commit comments

Comments
 (0)