Skip to content

Commit 2b988b3

Browse files
authored
fix(responses): capability-gate external_web_access in the canonical-only table (#2262)
The #2258 series unconditional strip collided with the #2238 capability contract: official OpenAI API-key traffic lost external_web_access (lidge full suite 1/14025 fail). The table row is now capabilityGated, active only when supportsOpenAiWebSearchToolFields === false; defer_loading stays unconditional. 387/0 across six suites.
1 parent 6c928aa commit 2b988b3

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,29 @@ function stripInvalidItemIds(body: unknown): unknown {
166166
* with its own traversal, and the traversals disagreed about which containers they covered; a new
167167
* one should be a row here instead. `toolTypes` omitted means the field is private on any tool.
168168
*/
169-
const CANONICAL_ONLY_TOOL_FIELDS: readonly { field: string; toolTypes?: ReadonlySet<string> }[] = [
169+
const CANONICAL_ONLY_TOOL_FIELDS: readonly { field: string; toolTypes?: ReadonlySet<string>; capabilityGated?: boolean }[] = [
170170
// ChatGPT's browsing policy bit. The public hosted tool is enabled by its presence alone.
171-
{ field: "external_web_access", toolTypes: new Set(["web_search", "web_search_preview"]) },
171+
// OWNERSHIP: official OpenAI API-key traffic and unclassified gateways ACCEPT this field, so
172+
// it is only stripped when the provider capability denies it (supportsOpenAiWebSearchToolFields
173+
// === false), matching stripOpenAiOnlyWebSearchFields; see
174+
// tests/responses-routed-web-search-fields.test.ts.
175+
{ field: "external_web_access", toolTypes: new Set(["web_search", "web_search_preview"]), capabilityGated: true },
172176
// Deferred-discovery marker. `activateDeferredTool` clears it only for tools a `tool_search_output`
173177
// already loaded, so a still-deferred declaration — including one promoted out of a namespace
174178
// group — otherwise reaches the wire carrying it.
175179
{ field: "defer_loading" },
176180
];
177181

178-
function stripCanonicalOnlyToolFields(body: unknown): unknown {
182+
function stripCanonicalOnlyToolFields(body: unknown, includeCapabilityGated: boolean): unknown {
179183
if (!isPlainObject(body)) return body;
180184

181185
const rewriteTools = (tools: unknown[]): unknown[] => {
182186
let changed = false;
183187
const rewritten = tools.map(tool => {
184188
if (!isPlainObject(tool)) return tool;
185189
let next = tool;
186-
for (const { field, toolTypes } of CANONICAL_ONLY_TOOL_FIELDS) {
190+
for (const { field, toolTypes, capabilityGated } of CANONICAL_ONLY_TOOL_FIELDS) {
191+
if (capabilityGated && !includeCapabilityGated) continue;
187192
if (!Object.hasOwn(next, field)) continue;
188193
if (toolTypes && (typeof next.type !== "string" || !toolTypes.has(next.type))) continue;
189194
const { [field]: _private, ...rest } = next;
@@ -1722,7 +1727,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
17221727
outBody = rewritten.body;
17231728
convertedRoutedNamespaceToolAliases = rewritten.aliases;
17241729
// Last, so promoted namespace children are also cleared of Codex-private fields.
1725-
outBody = stripCanonicalOnlyToolFields(outBody);
1730+
outBody = stripCanonicalOnlyToolFields(outBody, provider.supportsOpenAiWebSearchToolFields === false);
17261731
}
17271732
const threadServingIdentityChanged = parsed._stripReasoningEncryptedContent === true;
17281733
const sanitizedBody = normalizeToolSchemas(stripSparkCompatibility(stripUnsupportedReasoningParams(stripItemIdsWhenUnstored(stripInvalidItemIds(stripUnsupportedHostedTools(sanitizeReasoningInputContent(scrubOcxCompactionItems(

‎tests/openai-responses-passthrough.test.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -976,13 +976,16 @@ describe("OpenAI Responses passthrough sanitization", () => {
976976
expect(body.tools[0]).toMatchObject({ type: "image_generation" });
977977
});
978978

979-
test("drops ChatGPT's external_web_access hint but keeps routed web search", () => {
980-
const adapter = createResponsesPassthroughAdapter({
981-
adapter: "openai-responses",
982-
baseUrl: "https://api.x.ai/v1",
983-
authMode: "key" as const,
984-
apiKey: "xai-test",
985-
});
979+
test("drops ChatGPT's external_web_access hint but keeps routed web search", () => {
980+
const adapter = createResponsesPassthroughAdapter({
981+
adapter: "openai-responses",
982+
baseUrl: "https://api.x.ai/v1",
983+
authMode: "key" as const,
984+
apiKey: "xai-test",
985+
// The registry declares this denial for xAI; the strip is capability-driven, not
986+
// hostname-driven (official OpenAI API-key traffic keeps the fields).
987+
supportsOpenAiWebSearchToolFields: false,
988+
});
986989
const request = adapter.buildRequest({
987990
modelId: "grok-4.6",
988991
context: { messages: [] },
@@ -1033,13 +1036,14 @@ describe("OpenAI Responses passthrough sanitization", () => {
10331036
// `activateDeferredTool` clears `defer_loading` only for tools a `tool_search_output` already
10341037
// loaded, so the first turn of a deferred catalog — and any child promoted out of a namespace
10351038
// group — otherwise carries the private field to a gateway that rejects unknown arguments.
1036-
test("drops Codex-private tool fields from routed declarations", () => {
1037-
const adapter = createResponsesPassthroughAdapter({
1038-
adapter: "openai-responses",
1039-
baseUrl: "https://api.x.ai/v1",
1040-
authMode: "key" as const,
1041-
apiKey: "xai-test",
1042-
});
1039+
test("drops Codex-private tool fields from routed declarations", () => {
1040+
const adapter = createResponsesPassthroughAdapter({
1041+
adapter: "openai-responses",
1042+
baseUrl: "https://api.x.ai/v1",
1043+
authMode: "key" as const,
1044+
apiKey: "xai-test",
1045+
supportsOpenAiWebSearchToolFields: false,
1046+
});
10431047
const request = adapter.buildRequest({
10441048
modelId: "grok-4.6",
10451049
context: { messages: [] },

0 commit comments

Comments
 (0)