Skip to content

Commit 98eaba6

Browse files
committed
fix(sidecar): bind web-search options to runnable backend pairs
Carry backend/model provenance on every server option and preserve it through the dashboard picker, including auth-slot rows absent from the ordinary model catalog. Validate the effective explicit pair on both sidecar-settings and Claude override PUT paths, including partial updates, while retaining empty clears, grandfathered display rows, and PUT option echo. Evidence: 50-pass four-suite management/sidecar gate; 9-pass GUI option regression; root tsc, GUI lint, and GUI production build green.
1 parent 864bc90 commit 98eaba6

9 files changed

Lines changed: 215 additions & 42 deletions

‎gui/src/pages/dashboard-overview-sections.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
requireJson,
1616
type SidecarPatch,
1717
shadowCallModelOptions,
18-
sidecarBackendForModel,
18+
webSearchSidecarSelectionForModel,
1919
updateJobLabel,
2020
visionEnabledPatch,
2121
visionMaxDescriptionsPatch,
@@ -515,7 +515,9 @@ export function DashboardSidecarPanels({ d }: { d: Dash }) {
515515
<Select
516516
value={sidecar?.webSearch.model ?? "gpt-5.6-luna"}
517517
options={sidecarModels}
518-
onChange={model => { void saveSidecar({ webSearch: { model, backend: sidecarBackendForModel(models, model) } }); }}
518+
onChange={model => {
519+
void saveSidecar({ webSearch: webSearchSidecarSelectionForModel(models, sidecarModels, model) });
520+
}}
519521
disabled={!sidecar || sidecarSaving}
520522
label={t("dash.sidecarModel")}
521523
align="right"

‎gui/src/pages/dashboard-shared.ts‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,19 @@ export interface SidecarSetting {
7171
timeoutMs?: number;
7272
}
7373
export interface VisionModelOption { value: string; label: string; backend: SidecarBackend; baseline?: boolean }
74-
export interface WebSearchModelOption { value: string; label: string; authSlot?: boolean }
74+
export interface WebSearchModelOption {
75+
value: string;
76+
label: string;
77+
backend: SidecarBackend;
78+
model: string;
79+
authSlot?: boolean;
80+
}
81+
export interface WebSearchPickerOption {
82+
value: string;
83+
label: string;
84+
backend?: SidecarBackend;
85+
model?: string;
86+
}
7587
export interface SidecarData {
7688
webSearch: SidecarSetting;
7789
vision: SidecarSetting;
@@ -295,17 +307,33 @@ export function webSearchModelOptionsForPicker(
295307
serverOptions: WebSearchModelOption[] | undefined,
296308
models: ModelInfo[],
297309
current: string | undefined,
298-
): Array<{ value: string; label: string }> {
310+
currentBackend?: SidecarBackend,
311+
): WebSearchPickerOption[] {
299312
if (serverOptions === undefined) {
300-
const legacy = sidecarModelOptions(models);
313+
const legacy: WebSearchPickerOption[] = sidecarModelOptions(models);
301314
if (current && !legacy.some(option => option.value === current)) {
302-
legacy.unshift({ value: current, label: current });
315+
legacy.unshift({
316+
value: current,
317+
label: current,
318+
...(currentBackend ? { backend: currentBackend } : {}),
319+
model: current,
320+
});
303321
}
304322
return legacy;
305323
}
306-
const out = serverOptions.map(option => ({ value: option.value, label: option.label }));
324+
const out: WebSearchPickerOption[] = serverOptions.map(option => ({
325+
value: option.value,
326+
label: option.label,
327+
backend: option.backend,
328+
model: option.model,
329+
}));
307330
if (current && !out.some(option => option.value === current)) {
308-
out.unshift({ value: current, label: current });
331+
out.unshift({
332+
value: current,
333+
label: current,
334+
...(currentBackend ? { backend: currentBackend } : {}),
335+
model: current,
336+
});
309337
}
310338
return out;
311339
}
@@ -351,6 +379,19 @@ export function sidecarBackendForModel(models: ModelInfo[], modelId: string): Si
351379
return models.find(model => model.id === modelId)?.provider === "anthropic" ? "anthropic" : "openai";
352380
}
353381

382+
/** Server provenance wins; catalog inference supports only legacy option rows. */
383+
export function webSearchSidecarSelectionForModel(
384+
models: ModelInfo[],
385+
options: WebSearchPickerOption[],
386+
modelId: string,
387+
): { backend: SidecarBackend; model: string } {
388+
const option = options.find(entry => entry.value === modelId);
389+
return {
390+
backend: option?.backend ?? sidecarBackendForModel(models, modelId),
391+
model: option?.model ?? modelId,
392+
};
393+
}
394+
354395
/** Server eligibility is authoritative; catalog inference only supports legacy picker entries. */
355396
export function visionSidecarBackendForModel(
356397
models: ModelInfo[],

‎gui/src/pages/use-dashboard-data.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ export function useDashboardData(apiBase: string) {
466466
}, [grouped, modelQuery]);
467467
const sidecarModels = useMemo(() => {
468468
// Server-computed runnable set when present (#2188); legacy union otherwise.
469-
return webSearchModelOptionsForPicker(sidecar?.webSearchModels, models, sidecar?.webSearch.model);
469+
return webSearchModelOptionsForPicker(
470+
sidecar?.webSearchModels,
471+
models,
472+
sidecar?.webSearch.model,
473+
sidecar?.webSearch.backend,
474+
);
470475
}, [models, sidecar?.webSearchModels, sidecar?.webSearch]);
471476
const visionModels = useMemo(
472477
() => visionModelOptions(sidecar?.visionModels, models, sidecar?.vision?.model, sidecar?.vision?.backend),

‎gui/tests/vision-model-options.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { expect, test } from "bun:test";
22
import {
33
sidecarBackendForModel,
4+
webSearchModelOptionsForPicker,
5+
webSearchSidecarSelectionForModel,
46
visionModelOptions,
57
visionSidecarBackendForModel,
68
type ModelInfo,
@@ -95,3 +97,15 @@ test("an authoritative empty list still keeps the configured model and its backe
9597
expect(options.map(option => option.value)).toEqual([model]);
9698
expect(visionSidecarBackendForModel([], options, model)).toBe("anthropic");
9799
});
100+
101+
test("a server web-search auth-slot option keeps its backend without a catalog row", () => {
102+
const model = "claude-haiku-4-5";
103+
const options = webSearchModelOptionsForPicker([
104+
{ value: model, label: model, backend: "anthropic", model, authSlot: true },
105+
], [], undefined);
106+
107+
expect(webSearchSidecarSelectionForModel([], options, model)).toEqual({
108+
backend: "anthropic",
109+
model,
110+
});
111+
});

‎src/server/management/agent-settings-routes.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,11 +1094,29 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
10941094
// so an id outside (runnable candidates ∪ auth slots) can never run. Same
10951095
// module as /api/sidecar-settings — a gate on one route and a stale copy on
10961096
// the other is no gate at all.
1097-
if (field === "webSearchSidecar" && typeof section.model === "string" && section.model !== "") {
1098-
const requested = section.model;
1097+
if (field === "webSearchSidecar"
1098+
&& (section.model !== undefined || section.backend !== undefined)) {
1099+
const stored = config.claudeCode?.webSearchSidecar;
1100+
const effectiveBackend = section.backend === "anthropic"
1101+
? "anthropic"
1102+
: section.backend === "openai"
1103+
? "openai"
1104+
: section.backend === null
1105+
? config.webSearchSidecar?.backend ?? "openai"
1106+
: stored?.backend ?? config.webSearchSidecar?.backend ?? "openai";
1107+
const effectiveModel = section.model === ""
1108+
? config.webSearchSidecar?.model
1109+
: typeof section.model === "string"
1110+
? section.model
1111+
: stored?.model ?? config.webSearchSidecar?.model;
10991112
const candidates = await webSearchCandidateRows(config);
1100-
if (webSearchModelIsRejected(requested, candidates)) {
1101-
return jsonResponse(webSearchModelRejection("webSearchSidecar.model", requested, candidates), 400);
1113+
if (effectiveModel && webSearchModelIsRejected(effectiveBackend, effectiveModel, candidates)) {
1114+
return jsonResponse(webSearchModelRejection(
1115+
"webSearchSidecar.model",
1116+
effectiveBackend,
1117+
effectiveModel,
1118+
candidates,
1119+
), 400);
11021120
}
11031121
}
11041122
}

‎src/server/management/config-routes.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
555555
&& body.webSearch.backend !== "openai" && body.webSearch.backend !== "anthropic") {
556556
return jsonResponse({ error: "webSearch.backend must be openai, anthropic, or null" }, 400);
557557
}
558+
if (body.webSearch?.model !== undefined && typeof body.webSearch.model !== "string") {
559+
return jsonResponse({ error: "webSearch.model must be a string" }, 400);
560+
}
558561
if (body.webSearch && body.webSearch.streamRoutedModelOutput !== undefined
559562
&& typeof body.webSearch.streamRoutedModelOutput !== "boolean") {
560563
return jsonResponse({ error: "webSearch.streamRoutedModelOutput must be a boolean" }, 400);
@@ -610,11 +613,19 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
610613
}
611614

612615
if (body.webSearch) {
613-
if (typeof body.webSearch.model === "string" && body.webSearch.model !== "") {
614-
const requested = body.webSearch.model;
616+
const pairTouched = body.webSearch.model !== undefined || body.webSearch.backend !== undefined;
617+
const effectiveBackend = body.webSearch.backend === "anthropic"
618+
? "anthropic"
619+
: body.webSearch.backend === "openai" || body.webSearch.backend === null
620+
? "openai"
621+
: config.webSearchSidecar?.backend ?? "openai";
622+
const effectiveModel = typeof body.webSearch.model === "string"
623+
? body.webSearch.model || undefined
624+
: config.webSearchSidecar?.model;
625+
if (pairTouched && effectiveModel) {
615626
const candidates = await webSearchCandidateRows(config);
616-
if (webSearchModelIsRejected(requested, candidates)) {
617-
return jsonResponse(webSearchModelRejection("webSearch.model", requested, candidates), 400);
627+
if (webSearchModelIsRejected(effectiveBackend, effectiveModel, candidates)) {
628+
return jsonResponse(webSearchModelRejection("webSearch.model", effectiveBackend, effectiveModel, candidates), 400);
618629
}
619630
}
620631
config.webSearchSidecar = { ...config.webSearchSidecar };

‎src/server/management/web-search-sidecar-options.ts‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,34 @@
1616
import type { OcxConfig } from "../../types";
1717
import { AUTH_SLOT_MODELS, resolveSidecarAuth } from "../../sidecar/auth";
1818
import { pickerVisibleSidecarCandidates, type SidecarCandidate } from "../../sidecar/candidates";
19-
import { isWebSearchAuthSlotModel, webSearchSidecarCandidates } from "../../web-search/backends";
19+
import { WEB_SEARCH_BACKENDS, webSearchSidecarCandidates } from "../../web-search/backends";
20+
21+
export type WebSearchBackend = "openai" | "anthropic";
22+
23+
export interface WebSearchCandidateRow extends SidecarCandidate {
24+
/** Executor backend that admitted this exact candidate row. */
25+
backend: WebSearchBackend;
26+
}
2027

2128
export interface WebSearchModelOption {
2229
value: string;
2330
label: string;
31+
/** Exact runnable pair represented by this picker row. */
32+
backend: WebSearchBackend;
33+
model: string;
2434
/** True when the row is an auth-slot entitlement rather than a picker row. */
2535
authSlot?: boolean;
2636
}
2737

2838
/** The candidate rows the web-search executors can actually run right now. */
29-
export async function webSearchCandidateRows(config: OcxConfig): Promise<SidecarCandidate[]> {
39+
export async function webSearchCandidateRows(config: OcxConfig): Promise<WebSearchCandidateRow[]> {
3040
const auth = resolveSidecarAuth(config);
3141
const all = await pickerVisibleSidecarCandidates(config, auth);
32-
return webSearchSidecarCandidates(config, auth, all);
42+
return webSearchSidecarCandidates(config, auth, all).flatMap(candidate => {
43+
const descriptor = WEB_SEARCH_BACKENDS.find(entry =>
44+
entry.isActive(auth) && entry.eligibleModel(candidate, auth));
45+
return descriptor ? [{ ...candidate, backend: descriptor.backend }] : [];
46+
});
3347
}
3448

3549
/**
@@ -39,20 +53,27 @@ export async function webSearchCandidateRows(config: OcxConfig): Promise<Sidecar
3953
*/
4054
export function webSearchModelOptionsFrom(
4155
config: Pick<OcxConfig, "webSearchSidecar">,
42-
candidates: readonly SidecarCandidate[],
56+
candidates: readonly WebSearchCandidateRow[],
4357
): WebSearchModelOption[] {
4458
const byValue = new Map<string, WebSearchModelOption>();
4559
for (const candidate of candidates) {
4660
if (byValue.has(candidate.id)) continue;
4761
byValue.set(candidate.id, {
4862
value: candidate.id,
4963
label: candidate.id,
64+
backend: candidate.backend,
65+
model: candidate.id,
5066
...(candidate.authSlot ? { authSlot: true } : {}),
5167
});
5268
}
5369
const persisted = config.webSearchSidecar?.model;
5470
if (persisted && !byValue.has(persisted)) {
55-
byValue.set(persisted, { value: persisted, label: persisted });
71+
byValue.set(persisted, {
72+
value: persisted,
73+
label: persisted,
74+
backend: config.webSearchSidecar?.backend ?? "openai",
75+
model: persisted,
76+
});
5677
}
5778
return [...byValue.values()].sort((a, b) => a.value.localeCompare(b.value));
5879
}
@@ -64,26 +85,32 @@ export function webSearchModelOptionsFrom(
6485
* and refusing it would make settings order-dependent on login state.
6586
*/
6687
export function webSearchModelIsRejected(
88+
backend: WebSearchBackend,
6789
requested: string,
68-
candidates: readonly SidecarCandidate[],
90+
candidates: readonly WebSearchCandidateRow[],
6991
): boolean {
70-
if (isWebSearchAuthSlotModel(requested)) return false;
71-
return !candidates.some(candidate => candidate.id === requested);
92+
if (requested === AUTH_SLOT_MODELS.codex) return backend !== "openai";
93+
if (requested === AUTH_SLOT_MODELS.anthropic) return backend !== "anthropic";
94+
return !candidates.some(candidate => candidate.backend === backend && candidate.id === requested);
7295
}
7396

7497
/** Uniform 400 payload naming the filter, mirroring visionDescriberRejection's shape. */
7598
export function webSearchModelRejection(
7699
field: string,
100+
backend: WebSearchBackend,
77101
requested: string,
78-
candidates: readonly SidecarCandidate[],
102+
candidates: readonly WebSearchCandidateRow[],
79103
): { error: string; allowedModels: string[] } {
80-
const allowed = new Set(candidates.map(candidate => candidate.id));
81-
// The gate accepts auth slots unconditionally, so the legal set must list them.
104+
const allowed = new Set(candidates
105+
.filter(candidate => candidate.backend === backend)
106+
.map(candidate => candidate.id));
107+
// Preserve the response contract: allowedModels lists both always-configurable
108+
// auth-slot ids even though the pair gate below binds each to its own backend.
82109
allowed.add(AUTH_SLOT_MODELS.codex);
83110
allowed.add(AUTH_SLOT_MODELS.anthropic);
84111
return {
85-
error: `${field}: "${requested}" is not a web-search sidecar candidate — the model must be ` +
86-
"picker-visible and runnable by an active executor-backed backend (or an auth-slot model)",
112+
error: `${field}: backend/model pair "${backend}/${requested}" is not a web-search sidecar candidate — ` +
113+
"the model must be picker-visible and runnable by that executor-backed backend (or its auth-slot model)",
87114
allowedModels: [...allowed].sort(),
88115
};
89116
}

‎tests/claude-management-api.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,17 @@ test("Claude sidecar overrides round-trip, partially update, clear, and reject u
397397
expect(response.status).toBe(400);
398398
expect(((await response.json()) as { error: string }).error).toContain("web-search sidecar candidate");
399399

400-
// Nested partial updates preserve omitted fields and omitted sections.
400+
// A partial model update is validated against the effective preserved backend.
401401
response = await put({ webSearchSidecar: { model: "gpt-5.6-luna" } });
402+
expect(response.status).toBe(400);
403+
expect(((await response.json()) as { error: string }).error).toContain("backend/model pair");
404+
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ backend: "anthropic", model: "claude-haiku-4-5" });
405+
expect(loadConfig().claudeCode?.visionSidecar).toEqual({ backend: "openai", model: "gpt-vision" });
406+
407+
// Updating both fields to a runnable pair succeeds and preserves omitted sections.
408+
response = await put({ webSearchSidecar: { backend: "openai", model: "gpt-5.6-luna" } });
402409
expect(response.status).toBe(200);
403-
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ backend: "anthropic", model: "gpt-5.6-luna" });
410+
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ backend: "openai", model: "gpt-5.6-luna" });
404411
expect(loadConfig().claudeCode?.visionSidecar).toEqual({ backend: "openai", model: "gpt-vision" });
405412

406413
// null backend is the explicit Auto/inherit transition; empty model deletes only model.

0 commit comments

Comments
 (0)