Skip to content

Commit e631f87

Browse files
committed
fix(responses): bridge routed tool_search through the Responses passthrough
Passthrough forwarded Codex's private {type:"tool_search"} unchanged to third-party /v1/responses gateways, which only understand public function tools. The model never saw a callable tool_search and emitted zero tool_search_call items, so deferred tool discovery silently did nothing on every routed provider. Lower the private tool to a public function on noncanonical forward targets, rewrite tool_choice and replayed history to match, then restore the private tool_search_call lifecycle on the way back so Codex sees what it can execute. Canonical ChatGPT forward is untouched. Carries @Ingwannu's #2040 implementation and tests, with two corrections for findings that were still open on it: History-only replay. A turn may replay tool_search history without re-declaring the tool. The history was lowered either way, but restoration was armed only when a declaration was present, so the client got back a public function_call for what it had issued as a private search call. SSE overflow was not atomic. Both overflow branches cleared routedItemIds along with the pending buffer, so an item already restored to tool_search_call started emitting function_call_arguments frames again and the client saw a mixed private/public lifecycle for one call. Overflow now stops buffering unknown frames without forgetting what was already classified. Closes #1950
1 parent cd8f9b8 commit e631f87

14 files changed

Lines changed: 1218 additions & 22 deletions

File tree

‎docs-site/src/content/docs/ja/reference/adapters.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ interface ProviderAdapter {
4343

4444
## `openai-responses`
4545

46-
**対象:** OpenAI **Responses API**。**`passthrough: true`** — 元のリクエスト本文をそのまま渡し、レスポンスを **変換せずに** ストリーミングします。
47-
**認証:** `forward`(呼び出し元ヘッダー中継)または `key`。
46+
**対象:** OpenAI **Responses API**。**`passthrough: true`** — 通常は元のリクエストとレスポンスをそのまま渡し、ルーティング先ゲートウェイに必要な限定的な互換変換だけを適用します。
47+
**認証:** canonical OpenAI `forward` は安全な呼び出し元ヘッダー許可リストだけを中継します。非 canonical な `forward` は呼び出し元の authorization を中継せず、設定済みの静的ヘッダーだけを使用します。`key` は設定済み provider key を使用します。
48+
49+
非 canonical な Responses ゲートウェイには、Codex のクライアント実行型 `tool_search`
50+
宣言を既存の公開 function tool と衝突しない名前で送り、対応するリクエスト履歴と JSON/SSE
51+
function call をクライアント向けの非公開 `tool_search` ライフサイクルに復元します。
52+
canonical OpenAI forward はネイティブな非公開型を維持します。
4853

4954
`key` 認証では、[`retryOn429`](/ja/reference/configuration/) もここに適用されます: プリストリームの
5055
429 は、翻訳された `openai-chat` / Anthropic リクエスト経路と同様に、他の処理やフェイルオーバーに

‎docs-site/src/content/docs/ko/reference/adapters.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ interface ProviderAdapter {
4949

5050
## `openai-responses`
5151

52-
**대상:** OpenAI **Responses API**. **`passthrough: true`** — 원본 요청 본문을 전달하고 응답을
53-
**변환하지 않은 채** 스트리밍합니다.
54-
**인증:** `forward`(호출자 헤더 중계) 또는 `key`.
52+
**대상:** OpenAI **Responses API**. **`passthrough: true`** — 일반적으로 원본 요청과 응답을
53+
그대로 전달하되, 라우팅된 게이트웨이에 필요한 좁은 호환성 변환만 적용합니다.
54+
**인증:** 정규 OpenAI `forward`는 안전한 호출자 헤더 허용 목록만 중계합니다. 비정규
55+
`forward`는 호출자 authorization을 중계하지 않고 설정된 정적 헤더만 사용하며, `key`는
56+
설정된 provider 키를 사용합니다.
57+
58+
비정규 Responses 게이트웨이에는 Codex의 클라이언트 실행형 `tool_search` 선언을 공개 function
59+
도구와 충돌하지 않는 이름으로 전달합니다. 일치하는 요청 기록과 JSON/SSE function call은
60+
클라이언트용 비공개 `tool_search` 수명 주기로 복원합니다. 정규 OpenAI forward 경로는
61+
네이티브 비공개 타입을 그대로 유지합니다.
5562

5663
`key` 인증에서는 [`retryOn429`](/ko/reference/configuration/)도 여기에 적용됩니다: 사전 스트림
5764
429는 번역된 `openai-chat`/Anthropic 요청 경로와 동일하게 다른 처리나 페일오버보다 먼저

‎docs-site/src/content/docs/reference/adapters.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ provider — xAI, Kimi, DeepSeek, GLM, Groq, OpenRouter, Ollama (local & cloud),
4949

5050
## `openai-responses`
5151

52-
**Targets:** the OpenAI **Responses API**. **`passthrough: true`** — forwards the raw request body and
53-
streams the response back **untranslated**.
54-
**Auth:** `forward` (relay the caller's headers) or `key`.
52+
**Targets:** the OpenAI **Responses API**. **`passthrough: true`** — normally forwards the raw request
53+
body and response, with narrow compatibility rewrites for routed gateways.
54+
**Auth:** canonical OpenAI `forward` relays only the safe caller-header allowlist; noncanonical
55+
`forward` uses configured static headers without relaying caller authorization; `key` uses the
56+
configured provider key.
57+
58+
Noncanonical Responses gateways receive Codex's client-executed `tool_search` declaration as a
59+
collision-safe public function tool. Matching request history and JSON/SSE function calls are
60+
translated back to the private `tool_search` lifecycle for the client. Canonical OpenAI forward
61+
keeps the native private type unchanged.
5562

5663
For `key` auth, [`retryOn429`](/reference/configuration/) applies here too: a pre-stream 429
5764
waits and replays the identical request on the same key before any other handling, exactly like

‎docs-site/src/content/docs/zh-cn/reference/adapters.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ interface ProviderAdapter {
4545

4646
## `openai-responses`
4747

48-
**目标:** OpenAI **Responses API**。**`passthrough: true`** —— 转发原始请求 body,并把响应
49-
**不经转换**地流式传回。
50-
**认证:** `forward`(转发调用方 header)或 `key`。
48+
**目标:** OpenAI **Responses API**。**`passthrough: true`** —— 通常原样转发请求与响应,仅对
49+
路由网关应用范围有限的兼容性转换。
50+
**认证:** 规范 OpenAI `forward` 只转发安全的调用方 header allowlist;非规范 `forward` 不会
51+
转发调用方 authorization,只使用已配置的静态 header;`key` 使用已配置的 provider key。
52+
53+
对于非规范 Responses 网关,Codex 的客户端执行型 `tool_search` 声明会作为公共 function tool
54+
以不与现有 function 名称冲突的方式发送;匹配的请求历史和 JSON/SSE function call 会恢复为
55+
客户端私有的 `tool_search` 生命周期。规范 OpenAI forward 路径仍保持原生私有类型不变。
5156

5257
使用 `key` 认证时,[`retryOn429`](/zh-cn/reference/configuration/) 同样适用:流开始前的 429
5358
会等待并先于其他处理或故障转移,在相同 key 上重放完全相同请求,与翻译后的

‎src/adapters/base.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export interface AdapterRequest {
7070
body: string;
7171
/** Custom-tool names actually lowered to upstream function calls while building this request. */
7272
convertedRoutedCustomToolNames?: ReadonlySet<string>;
73+
/** Client tool-search names actually lowered to upstream function calls for this request. */
74+
convertedRoutedToolSearchNames?: ReadonlySet<string>;
7375
/** Releases observation of a serialized request body after its final fetch attempt settles. */
7476
releaseBodyObservation?: () => void;
7577
/** Exact reasoning parameter emitted by the adapter, for request-log diagnostics only. */

‎src/adapters/openai-responses.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { OCX_REASONING_PREFIX } from "../responses/reasoning-envelope";
1111
import { modelRecordValue } from "../reasoning-effort";
1212
import type { TranslatorBudget } from "../lib/translator-budget";
1313
import { rewriteRoutedCustomToolsForUpstream } from "../responses/custom-tool-compat";
14+
import { rewriteRoutedToolSearchForUpstream } from "../responses/tool-search-compat";
1415
import { openaiResponsesUrl } from "./openai-responses-url";
1516
import {
1617
createAdapterTierMetadata,
@@ -1468,6 +1469,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
14681469

14691470
const forward = provider.authMode === "forward";
14701471
let convertedRoutedCustomToolNames: Set<string> | undefined;
1472+
let convertedRoutedToolSearchNames: Set<string> | undefined;
14711473
const unexpandedMiss = !!parsed.previousResponseId && parsed._previousResponseInputExpanded !== true;
14721474
let outBody = stripPreviousResponseId(
14731475
parsed._rawBody,
@@ -1522,6 +1524,13 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
15221524
outBody = rewritten.body;
15231525
convertedRoutedCustomToolNames = rewritten.names;
15241526
}
1527+
if (!isCanonicalOpenAiForwardProvider(provider)) {
1528+
// Run after custom-tool lowering so the search compatibility layer can choose a
1529+
// collision-free public function name against the final routed function catalog.
1530+
const rewritten = rewriteRoutedToolSearchForUpstream(outBody);
1531+
outBody = rewritten.body;
1532+
convertedRoutedToolSearchNames = rewritten.names;
1533+
}
15251534
const sanitizedBody = normalizeToolSchemas(stripSparkCompatibility(stripUnsupportedReasoningParams(stripItemIdsWhenUnstored(stripInvalidItemIds(stripUnsupportedHostedTools(sanitizeReasoningInputContent(scrubOcxCompactionItems(outBody), { preserveRawReasoningContent: provider.preserveResponsesReasoningContent === true })))))));
15261535
const finalBody = stripDisabledReasoningSummaries(
15271536
normalizeConfiguredReasoningSummaryDelivery(sanitizedBody, provider, parsed.modelId),
@@ -1549,6 +1558,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
15491558
body,
15501559
releaseBodyObservation,
15511560
...(convertedRoutedCustomToolNames ? { convertedRoutedCustomToolNames } : {}),
1561+
...(convertedRoutedToolSearchNames ? { convertedRoutedToolSearchNames } : {}),
15521562
...(tierLog ? { tierLog } : {}),
15531563
};
15541564
},

‎src/responses/parser.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { previousResponseReplayPrefixLength } from "./state";
2020
import { decodeReasoningEnvelope } from "./reasoning-envelope";
2121
import { extractHostedWebSearch, WEB_SEARCH_TOOL_NAME } from "../web-search/synthetic-tool";
2222
import { extractHostedImageGeneration, IMAGE_GEN_TOOL_NAME } from "../images/synthetic-tool";
23+
import { toolSearchDescription, toolSearchParameters } from "./tool-search-compat";
2324

2425
function isObj(v: unknown): v is Record<string, unknown> {
2526
return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -214,15 +215,8 @@ function buildTools(tools: unknown[] | undefined): OcxTool[] | undefined {
214215
// Expose as a function so chat models can call it; the bridge relays it as a tool_search_call.
215216
out.push({
216217
name: "tool_search",
217-
description: (t.description as string) ?? "Search for additional tools to load for the next turn.",
218-
parameters: (isObj(t.parameters) ? t.parameters : {
219-
type: "object",
220-
properties: {
221-
query: { type: "string", description: "Search query for tools to load." },
222-
limit: { type: "number", description: "Maximum number of tools to return." },
223-
},
224-
required: ["query"],
225-
}) as Record<string, unknown>,
218+
description: toolSearchDescription(t),
219+
parameters: normalizeParameters(toolSearchParameters(t)),
226220
toolSearch: true,
227221
});
228222
}

0 commit comments

Comments
 (0)