Skip to content

Commit 4e79b56

Browse files
committed
fix(web-search): bind the passthrough bridge search model to its backend
sidecarSettingsForBridge read the model out of the global config.webSearchSidecar block without checking which backend that block was configured for, and src/server/responses/core.ts hands the block over whole. A global {backend: "openai", model: "gpt-5.6-luna"} therefore reached runAnthropicWebSearch whenever a provider set webSearchBridge.backend to "anthropic", and Anthropic rejects the model, so the bridge search failed. Same shape for xai and gemini. The global model now applies only when resolveSidecarBackend(sidecar.backend) equals the bridge backend; otherwise the bridge runs that backend's own default. An unset global backend still resolves to "openai", so an unset-backend model reaches an openai bridge and no other. Only the model is gated: reasoning is a generic effort level, and xSearch is xai-only with no per-backend default and no webSearchBridge equivalent, so gating it would make an openai sidecar plus an xai bridge plus x_search inexpressible. No credential crosses a backend, before or after this change. resolvePassthroughWebSearchBridgeAuth switches on the bridge backend and consults only that backend's credential locator. This is a model and settings defect. resolveSidecarBackend and WebSearchBackendId move from src/web-search/index.ts to src/web-search/sidecar-providers.ts, which exists precisely so the bridge can resolve a backend without value-importing the barrel; index.ts re-exports both, so every existing consumer is unchanged.
1 parent a84e6e8 commit 4e79b56

6 files changed

Lines changed: 156 additions & 27 deletions

File tree

‎docs-site/src/content/docs/reference/configuration/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Providers can expose a built-in shorthand, such as `agy` for `google-antigravity
201201
| `terminalContinuationGuard?` | `boolean` | Opt in an `openai-chat` provider to one bounded internal re-ask when an actionable turn announces work, then cleanly stops without a tool call. Defaults to `false`; explicit `false` behaves like omission. Combo attempts and routed compaction turns are excluded, and non-`openai-chat` adapters ignore this option. |
202202
| `responsesItemIdRepair?` | `{ message?: string[]; reasoning?: string[]; repairMissingTerminalIds?: boolean; repairInvalidIds?: boolean }` | Disabled-by-default downstream SSE repair for exact placeholder ids, missing terminal ids, and (with `repairInvalidIds`) message/reasoning ids missing the canonical `msg_`/`rs_` prefix. Function-call ids are never rewritten. Built-in DeepSeek enables the last two by default. |
203203
| `responsesSnapshotRepair?` | `boolean` | Disabled-by-default client-facing repair for sparse Responses lifecycle snapshots in SSE and JSON. Fills missing canonical status, output, and tool metadata while raw inspection and persistence remain unchanged. |
204-
| `webSearchBridge?` | `{ enabled?: boolean; backend?: "ollama" \| "openai" \| "anthropic" \| "xai" \| "gemini" \| "exa"; maxSearches?: number; timeoutMs?: number; endpoint?: string }` | Key-auth `openai-responses` passthrough providers only. Off by default. Codex always declares the hosted `web_search` tool, and the passthrough relays it on the assumption the destination executes it. A gateway that does not run hosted search answers with a `function_call` named `web_search` that nothing runs, and the undeclared-tool guard ends the turn. With `enabled: true` and an explicit `backend` OpenCodex intercepts that call, runs the search itself, feeds the result back to the same upstream, and shows Codex a hosted `web_search_call` cell. Never armed for `authMode: "forward"` (ChatGPT already searches) or for a provider that executes hosted search upstream. `backend` is required; there is no implicit default and a missing credential for the named backend leaves the bridge disarmed rather than falling through to another paid search. `ollama` reuses this provider's own API key on `POST <origin>/api/web_search`, so the origin must be `https://ollama.com` unless the operator names `endpoint` explicitly. `openai` / `anthropic` / `xai` / `gemini` / `exa` reuse the matching sidecar executor and that executor's own credential (`webSearchSidecar.exaApiKey` for Exa). Streaming turns only. A turn that mixes `web_search` with another client tool call still fails closed rather than dropping the client's call. Assistant text such as XML-like `<web_search>` prose is not executed. Defaults: `maxSearches: 3` (1..10), `timeoutMs: 60000` (1000..600000). |
204+
| `webSearchBridge?` | `{ enabled?: boolean; backend?: "ollama" \| "openai" \| "anthropic" \| "xai" \| "gemini" \| "exa"; maxSearches?: number; timeoutMs?: number; endpoint?: string }` | Key-auth `openai-responses` passthrough providers only. Off by default. Codex always declares the hosted `web_search` tool, and the passthrough relays it on the assumption the destination executes it. A gateway that does not run hosted search answers with a `function_call` named `web_search` that nothing runs, and the undeclared-tool guard ends the turn. With `enabled: true` and an explicit `backend` OpenCodex intercepts that call, runs the search itself, feeds the result back to the same upstream, and shows Codex a hosted `web_search_call` cell. Never armed for `authMode: "forward"` (ChatGPT already searches) or for a provider that executes hosted search upstream. `backend` is required; there is no implicit default and a missing credential for the named backend leaves the bridge disarmed rather than falling through to another paid search. `ollama` reuses this provider's own API key on `POST <origin>/api/web_search`, so the origin must be `https://ollama.com` unless the operator names `endpoint` explicitly. `openai` / `anthropic` / `xai` / `gemini` / `exa` reuse the matching sidecar executor and that executor's own credential (`webSearchSidecar.exaApiKey` for Exa). The search model comes from `webSearchSidecar.model` only when `webSearchSidecar.backend` resolves to the same backend this bridge names; otherwise the bridge runs that backend's own default, because a model chosen for one vendor is rejected by another. An unset `webSearchSidecar.backend` resolves to `openai`, so an unset-backend model reaches an `openai` bridge and no other. There is no per-provider bridge model override. Streaming turns only. A turn that mixes `web_search` with another client tool call still fails closed rather than dropping the client's call. Assistant text such as XML-like `<web_search>` prose is not executed. Defaults: `maxSearches: 3` (1..10), `timeoutMs: 60000` (1000..600000). |
205205
| `retryOn429?` | `{ enabled?: boolean; attempts?: number; intervalMs?: number; maxIntervalMs?: number; respectRetryAfter?: boolean }` | API-key providers only (`authMode: "key"`). Opt-in same-target 429 retry: when `retryOn429` is absent the feature is off; object presence enables it unless `enabled: false`. On 429 the proxy waits (upstream `Retry-After` or the fixed interval) and replays the identical request on the same key before any key failover — across the main text-turn recovery loop, the Responses passthrough wire, the image/video bridge, the web-search sidecar, and terminal continuations. Only pre-stream HTTP 429 responses are eligible for replay; custom `runTurn` transports are outside the HTTP retry loop. `attempts` counts same-key replays after the first 429 (total sends = `attempts` + 1) and is one request-wide budget shared by the main recovery loop, the terminal-guard continuation, and bridge retries. Exhausting `attempts` only stops further same-key replays: normal key failover or final-error handling then applies per the available targets — on the key-auth passthrough wire there is no failover, so the exhausted 429 surfaces as-is. Codex itself never retries 429, so this is the only defense for single-key providers. Defaults: `enabled: true`, `attempts: 3`, `intervalMs: 5000`, `maxIntervalMs: 60000` (any single wait is capped at `maxIntervalMs`, itself capped at 600000), `respectRetryAfter: true`. |
206206
| `transientRetryOn5xx?` | `{ enabled?: boolean; attempts?: number }` | Key-auth `openai-chat` providers only. Opt-in retry for pre-stream transient upstream statuses (500, 502, 503, 504, 520, 521, 522): absent means off, object presence enables it unless `enabled: false`. Covers the initial Responses request, the terminal-guard continuation, and native `/v1/chat/completions`. `attempts` is the TOTAL number of upstream sends allowed for one request including the first (1..10, default 3) — it is one budget shared with connection-reset recovery, so `3` means at most three real requests reach the provider. Waits use a fixed 400 ms exponential backoff capped at 5 s and honor `Retry-After`. Separate from `retryOn429`, which handles rate limiting; mid-stream failures are never replayed. |
207207
| `autoToolChoiceOnlyModels?` | `string[]` | Models whose `tool_choice` accepts only `auto` or `none`; forced choices are downgraded. |

‎src/web-search/index.ts‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import {
1515
findAnthropicSidecarProvider,
1616
findGeminiSidecarProvider,
1717
findXaiSidecarProvider,
18+
resolveSidecarBackend,
1819
xaiSearchOptionsFromConfig,
1920
type AnthropicSidecarProvider,
21+
type WebSearchBackendId,
2022
} from "./sidecar-providers";
2123

2224
export { runWithWebSearch } from "./loop";
@@ -29,8 +31,10 @@ export {
2931
findAnthropicSidecarProvider,
3032
findGeminiSidecarProvider,
3133
findXaiSidecarProvider,
34+
resolveSidecarBackend,
3235
xaiSearchOptionsFromConfig,
3336
type AnthropicSidecarProvider,
37+
type WebSearchBackendId,
3438
};
3539

3640
const DEFAULT_SIDECAR_MODEL = "gpt-5.6-luna";
@@ -98,24 +102,6 @@ export function webSearchStallTimeoutSec(
98102
return Math.min(Number.MAX_VALUE, Math.ceil(largestUnitSec) + STALL_MARGIN_SEC);
99103
}
100104

101-
/** Every backend id the config union admits. New ids are explicit-only and inert until their executor ships. */
102-
export type WebSearchBackendId = "openai" | "anthropic" | "xai" | "gemini" | "exa";
103-
104-
/**
105-
* Precedence: explicit config wins; unset defaults to "openai" (ChatGPT forward path). The
106-
* anthropic backend (web_search_20250305) is only used when explicitly configured — auto-selecting
107-
* it from credential availability caused the sidecar to send incompatible models (e.g. gpt-5.6-luna)
108-
* to the Anthropic API.
109-
* The 2188 follow-up ids (xai/gemini/exa) resolve to themselves the same explicit-only way; their
110-
* planWebSearch arms stay fail-closed until each executor layer lands.
111-
*/
112-
export function resolveSidecarBackend(
113-
explicit: WebSearchBackendId | undefined,
114-
): WebSearchBackendId {
115-
if (explicit === "anthropic" || explicit === "xai" || explicit === "gemini" || explicit === "exa") return explicit;
116-
return "openai";
117-
}
118-
119105
export interface SidecarPlan {
120106
/** Which executor runs the search. Anthropic does not require a forward provider. */
121107
backend: WebSearchBackendId;

‎src/web-search/passthrough-bridge.ts‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
findAnthropicSidecarProvider,
6262
findGeminiSidecarProvider,
6363
findXaiSidecarProvider,
64+
resolveSidecarBackend,
6465
xaiSearchOptionsFromConfig,
6566
} from "./sidecar-providers";
6667

@@ -677,7 +678,7 @@ export interface PassthroughWebSearchBridgeExecutorContext {
677678
auth?: PassthroughWebSearchBridgeAuth;
678679
hostedTool?: Record<string, unknown>;
679680
describeImages?: boolean;
680-
sidecar?: Pick<OcxWebSearchSidecarConfig, "model" | "reasoning" | "xSearch">;
681+
sidecar?: Pick<OcxWebSearchSidecarConfig, "backend" | "model" | "reasoning" | "xSearch">;
681682
}
682683

683684
const DEFAULT_OPENAI_BRIDGE_MODEL = "gpt-5.6-luna";
@@ -686,18 +687,52 @@ const DEFAULT_XAI_BRIDGE_MODEL = "grok-4.6";
686687
const DEFAULT_GEMINI_BRIDGE_MODEL = "gemini-3.8-flash";
687688
const DEFAULT_BRIDGE_REASONING = "low";
688689

689-
function sidecarSettingsForBridge(
690+
/**
691+
* Search model each bridge backend runs when the global sidecar block was configured for a
692+
* DIFFERENT backend (see modelForBridgeBackend). Exhaustive over the backend union on purpose:
693+
* a seventh backend must decide its own default here rather than fall through to a ChatGPT model.
694+
* The `ollama` and `exa` rows are inert — runOllamaWebSearch takes no model argument and
695+
* runExaWebSearch reads only settings.timeoutMs — and must stay that way.
696+
*/
697+
const DEFAULT_BRIDGE_MODELS: Record<ProviderWebSearchBridgeBackend, string> = {
698+
ollama: DEFAULT_OPENAI_BRIDGE_MODEL,
699+
openai: DEFAULT_OPENAI_BRIDGE_MODEL,
700+
anthropic: DEFAULT_ANTHROPIC_BRIDGE_MODEL,
701+
xai: DEFAULT_XAI_BRIDGE_MODEL,
702+
gemini: DEFAULT_GEMINI_BRIDGE_MODEL,
703+
exa: DEFAULT_OPENAI_BRIDGE_MODEL,
704+
};
705+
706+
/**
707+
* `sidecar` is the GLOBAL `config.webSearchSidecar` block, which carries the model chosen for
708+
* ITS backend. The bridge backend is the per-provider `webSearchBridge.backend` and the two are
709+
* configured independently, so the operator's model only means anything here when they agree:
710+
* a global {backend:"openai", model:"gpt-5.6-luna"} otherwise reaches runAnthropicWebSearch and
711+
* Anthropic rejects the model. On a mismatch the bridge falls back to the backend's own default.
712+
* The same reasoning already pins the backend first in planWebSearch.
713+
*
714+
* Only the model is gated. `reasoning` is a generic effort level, and `xSearch` is xai-only with
715+
* no per-backend default and no `webSearchBridge.xSearch` equivalent, so gating it would make an
716+
* openai sidecar plus an xai bridge plus x_search impossible to express at all.
717+
*/
718+
function modelForBridgeBackend(
719+
backend: ProviderWebSearchBridgeBackend,
720+
sidecar: Pick<OcxWebSearchSidecarConfig, "backend" | "model">,
721+
): string {
722+
const backendDefault = DEFAULT_BRIDGE_MODELS[backend];
723+
if (resolveSidecarBackend(sidecar.backend) !== backend) return backendDefault;
724+
return sidecar.model ?? backendDefault;
725+
}
726+
727+
/** The settings a bridge executor will run with. Exported for tests; the executor closes over it. */
728+
export function sidecarSettingsForBridge(
690729
backend: ProviderWebSearchBridgeBackend,
691730
plan: PassthroughWebSearchBridgePlan,
692731
context: PassthroughWebSearchBridgeExecutorContext,
693732
): SidecarSettings {
694733
const sidecar = context.sidecar ?? {};
695-
const model = backend === "anthropic" ? sidecar.model ?? DEFAULT_ANTHROPIC_BRIDGE_MODEL
696-
: backend === "xai" ? sidecar.model ?? DEFAULT_XAI_BRIDGE_MODEL
697-
: backend === "gemini" ? sidecar.model ?? DEFAULT_GEMINI_BRIDGE_MODEL
698-
: sidecar.model ?? DEFAULT_OPENAI_BRIDGE_MODEL;
699734
return {
700-
model,
735+
model: modelForBridgeBackend(backend, sidecar),
701736
reasoning: sidecar.reasoning ?? DEFAULT_BRIDGE_REASONING,
702737
timeoutMs: plan.timeoutMs,
703738
describeImages: context.describeImages === true,

‎src/web-search/sidecar-providers.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ import { resolveSidecarAuth } from "../sidecar/auth";
99
import { getAccountSet } from "../oauth/store";
1010
import type { XaiSearchOptions } from "./xai-executor";
1111

12+
/** Every backend id the config union admits. New ids are explicit-only and inert until their executor ships. */
13+
export type WebSearchBackendId = "openai" | "anthropic" | "xai" | "gemini" | "exa";
14+
15+
/**
16+
* Precedence: explicit config wins; unset defaults to "openai" (ChatGPT forward path). The
17+
* anthropic backend (web_search_20250305) is only used when explicitly configured — auto-selecting
18+
* it from credential availability caused the sidecar to send incompatible models (e.g. gpt-5.6-luna)
19+
* to the Anthropic API.
20+
* The 2188 follow-up ids (xai/gemini/exa) resolve to themselves the same explicit-only way; their
21+
* planWebSearch arms stay fail-closed until each executor layer lands.
22+
*
23+
* Lives here rather than in `index.ts` for the reason at the top of this file: the passthrough
24+
* bridge has to answer "which backend was this global sidecar block configured for?" without
25+
* value-importing the barrel.
26+
*/
27+
export function resolveSidecarBackend(
28+
explicit: WebSearchBackendId | undefined,
29+
): WebSearchBackendId {
30+
if (explicit === "anthropic" || explicit === "xai" || explicit === "gemini" || explicit === "exa") return explicit;
31+
return "openai";
32+
}
33+
1234
/** A configured anthropic-adapter OAuth provider whose ACTIVE stored account is usable (not needs-reauth). */
1335
export interface AnthropicSidecarProvider {
1436
providerName: string;

‎structure/runtime.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ disarmed rather than falling through to another paid search. A leg that mixes an
246246
`web_search` call with another client-executed tool still fails closed. Assistant text is not
247247
treated as a search instruction.
248248

249+
The bridge backend and the global `webSearchSidecar` block are configured independently, so the
250+
sidecar's `model` applies to a bridge search only when `resolveSidecarBackend(webSearchSidecar.backend)`
251+
equals that bridge backend; otherwise the bridge runs the backend's own default. An unset global
252+
backend resolves to `openai`, so an unset-backend model reaches an `openai` bridge and no other.
253+
There is no per-provider `webSearchBridge.model`, so a mismatched backend gets the default rather
254+
than a vendor-specific override. This is a model and settings rule, not a credential one:
255+
`resolvePassthroughWebSearchBridgeAuth` switches on the bridge backend and consults only that
256+
backend's credential locator, so no key crosses backends. `reasoning` and `xSearch` are not gated —
257+
`reasoning` is a generic effort level and `xSearch` is xai-only with no per-backend default and no
258+
`webSearchBridge` equivalent. `resolveSidecarBackend` lives in `src/web-search/sidecar-providers.ts`
259+
rather than the `src/web-search/index.ts` barrel so the bridge can answer this question without a
260+
value import of the barrel; the barrel re-exports it.
261+
`tests/web-search/web-search-passthrough-bridge.test.ts` covers the mismatch and matching cases for
262+
anthropic, xai, and gemini, plus the unset-backend default.
263+
249264
## Remote Hub hardening ownership
250265

251266
`src/remote/protocol.ts` owns pure interval/feature negotiation. `src/remote/hub-state.ts` owns the `GET|HEAD /v1/hub-state` contract, its caps, and the parser both sides share. `src/client/hub-client.ts` owns bounded, schema-validated remote catalog consumption, hub-state reads, and key-id probes; `src/client/hub-state.ts` owns the resolution and the owner-stamped 0600 cache, and a failed read reports "unavailable" rather than degrading to the client's own local provider and login state. `src/client/hub-relay.ts` is a fixed-authority management relay with URL, header, body, redirect, and stream bounds. The public data listener remains the direct client→hub path; the loopback management ingress never serves data-plane routes.

0 commit comments

Comments
 (0)