Skip to content

Commit 60f60b6

Browse files
authored
feat(management): web-search sidecar write gates and filtered gui lists (#2188 L4) (#2209)
* feat(management): web-search sidecar write gate and filtered option lists (#2188) web-search-sidecar-options.ts is the one policy module both writing routes share: PUT /api/sidecar-settings and the claude-code webSearch override now refuse a model outside (runnable candidates ∪ auth slots), naming the filter and attaching the allowed list. GET always carries webSearchModels — [] means none; omission is reserved for older servers so the dashboard's legacy fallback stays correct. The persisted model is display-grandfathered like vision. The dashboard picker consumes the server list instead of expanding the full openai+anthropic union. * fix(management): echo webSearchModels on PUT and prove the HTTP contract The dashboard rebuilds sidecar state from the PUT body; an omitted key reads as old-server and falls back to the full union — exactly the regression the gate exists to prevent. PUT now echoes the same helper as GET. allowedModels lists the always-legal auth slots. The claude-management known-good snapshot uses a slot id so its later assertions run against real persisted state. HTTP tests cover GET-always-present, PUT reject/accept/echo, and empty-string clear. * test(sidecar): repin test 14 to the new web-search membership gate * test(vision): use an auth-slot web-search id so the round-trip survives the gate * 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 bd79ab5 commit 60f60b6

12 files changed

Lines changed: 520 additions & 30 deletions
185 KB
Loading

‎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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,30 @@ export interface SidecarSetting {
7171
timeoutMs?: number;
7272
}
7373
export interface VisionModelOption { value: string; label: string; backend: SidecarBackend; baseline?: 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+
}
7487
export interface SidecarData {
7588
webSearch: SidecarSetting;
7689
vision: SidecarSetting;
7790
/** Server-computed eligible describers. Optional: an older server omits it and
7891
* the client falls back to the legacy provider-name list rather than showing
7992
* an empty picker. */
8093
visionModels?: VisionModelOption[];
94+
/** Server-computed runnable web-search models (#2188). Same undefined-vs-[]
95+
* contract as visionModels: an older server omits the key and the client
96+
* falls back to the legacy list; a current server's [] means none. */
97+
webSearchModels?: WebSearchModelOption[];
8198
}
8299
export interface SidecarPatch {
83100
webSearch?: { backend?: SidecarBackend | null; model?: string; streamRoutedModelOutput?: boolean };
@@ -280,6 +297,47 @@ export function sidecarModelOptions(models: ModelInfo[]) {
280297
return out;
281298
}
282299

300+
/**
301+
* Server list when present, else the legacy openai+anthropic list — the same
302+
* undefined-vs-[] contract visionModelOptions documents. The persisted model is
303+
* grandfathered into the list so the picker can DISPLAY a now-illegal setting;
304+
* the server still rejects new writes of it.
305+
*/
306+
export function webSearchModelOptionsForPicker(
307+
serverOptions: WebSearchModelOption[] | undefined,
308+
models: ModelInfo[],
309+
current: string | undefined,
310+
currentBackend?: SidecarBackend,
311+
): WebSearchPickerOption[] {
312+
if (serverOptions === undefined) {
313+
const legacy: WebSearchPickerOption[] = sidecarModelOptions(models);
314+
if (current && !legacy.some(option => option.value === current)) {
315+
legacy.unshift({
316+
value: current,
317+
label: current,
318+
...(currentBackend ? { backend: currentBackend } : {}),
319+
model: current,
320+
});
321+
}
322+
return legacy;
323+
}
324+
const out: WebSearchPickerOption[] = serverOptions.map(option => ({
325+
value: option.value,
326+
label: option.label,
327+
backend: option.backend,
328+
model: option.model,
329+
}));
330+
if (current && !out.some(option => option.value === current)) {
331+
out.unshift({
332+
value: current,
333+
label: current,
334+
...(currentBackend ? { backend: currentBackend } : {}),
335+
model: current,
336+
});
337+
}
338+
return out;
339+
}
340+
283341
/**
284342
* Server list when present, else the legacy openai+anthropic list.
285343
*
@@ -321,6 +379,19 @@ export function sidecarBackendForModel(models: ModelInfo[], modelId: string): Si
321379
return models.find(model => model.id === modelId)?.provider === "anthropic" ? "anthropic" : "openai";
322380
}
323381

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+
324395
/** Server eligibility is authoritative; catalog inference only supports legacy picker entries. */
325396
export function visionSidecarBackendForModel(
326397
models: ModelInfo[],

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
mergeSidecarSetting,
4747
readDashboardSectionFromHash,
4848
requireJson,
49-
sidecarModelOptions,
49+
webSearchModelOptionsForPicker,
5050
visionModelOptions,
5151
useModalDialog,
5252
} from "./dashboard-shared";
@@ -465,14 +465,14 @@ export function useDashboardData(apiBase: string) {
465465
return out;
466466
}, [grouped, modelQuery]);
467467
const sidecarModels = useMemo(() => {
468-
const opts = sidecarModelOptions(models);
469-
for (const id of [sidecar?.webSearch.model, sidecar?.vision.model]) {
470-
if (id && !opts.some(option => option.value === id)) {
471-
opts.unshift({ value: id, label: id });
472-
}
473-
}
474-
return opts;
475-
}, [models, sidecar]);
468+
// Server-computed runnable set when present (#2188); legacy union otherwise.
469+
return webSearchModelOptionsForPicker(
470+
sidecar?.webSearchModels,
471+
models,
472+
sidecar?.webSearch.model,
473+
sidecar?.webSearch.backend,
474+
);
475+
}, [models, sidecar?.webSearchModels, sidecar?.webSearch]);
476476
const visionModels = useMemo(
477477
() => visionModelOptions(sidecar?.visionModels, models, sidecar?.vision?.model, sidecar?.vision?.backend),
478478
[sidecar?.visionModels, models, sidecar?.vision],
@@ -485,6 +485,7 @@ export function useDashboardData(apiBase: string) {
485485
webSearch: mergeSidecarSetting(sidecar.webSearch, patch.webSearch),
486486
vision: mergeSidecarSetting(sidecar.vision, patch.vision),
487487
...(sidecar.visionModels ? { visionModels: sidecar.visionModels } : {}),
488+
...(sidecar.webSearchModels ? { webSearchModels: sidecar.webSearchModels } : {}),
488489
};
489490
setSidecarSaving(true);
490491
setSidecar(next);
@@ -499,6 +500,7 @@ export function useDashboardData(apiBase: string) {
499500
webSearch: data.webSearch,
500501
vision: data.vision,
501502
...(data.visionModels ? { visionModels: data.visionModels } : {}),
503+
...(data.webSearchModels ? { webSearchModels: data.webSearchModels } : {}),
502504
});
503505
const prev = readSessionListCache<CachedControls>(controlsCacheKey(apiBase)) ?? {};
504506
writeSessionListCache(controlsCacheKey(apiBase), {
@@ -507,6 +509,7 @@ export function useDashboardData(apiBase: string) {
507509
webSearch: data.webSearch,
508510
vision: data.vision,
509511
...(data.visionModels ? { visionModels: data.visionModels } : {}),
512+
...(data.webSearchModels ? { webSearchModels: data.webSearchModels } : {}),
510513
},
511514
});
512515
} catch {

‎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: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ import {
5656
visionDescriberIsProvablyBlind,
5757
visionDescriberRejection,
5858
} from "./vision-sidecar-options";
59+
import {
60+
webSearchCandidateRows,
61+
webSearchModelIsRejected,
62+
webSearchModelRejection,
63+
} from "./web-search-sidecar-options";
5964
import { drainAndShutdown } from "../lifecycle";
6065
import { filterRequestLogs, getRequestLogEntries, type RequestLogEntry } from "../request-log";
6166
import { estimateComboCost, estimateRequestCost, normalizeCostTokens, tokensPerSecond } from "../../usage/cost";
@@ -1073,8 +1078,8 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
10731078
return jsonResponse({ error: `${field}.model must be a string` }, 400);
10741079
}
10751080
// Vision override only: reject a model we can prove is blind. Unknown ids stay
1076-
// allowed; webSearchSidecar has no vision requirement and is left alone. Shares
1077-
// one policy module with /api/sidecar-settings so the two gates cannot drift.
1081+
// allowed. Shares one policy module with /api/sidecar-settings so the two
1082+
// gates cannot drift.
10781083
if (field === "visionSidecar" && typeof section.model === "string" && section.model !== "") {
10791084
const requested = section.model;
10801085
const candidates = await visionCandidateRows(config);
@@ -1085,6 +1090,35 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
10851090
return jsonResponse(visionDescriberRejection("visionSidecar.model", requested, config, candidates), 400);
10861091
}
10871092
}
1093+
// Web-search override: membership gate (#2188). The executor set is closed,
1094+
// so an id outside (runnable candidates ∪ auth slots) can never run. Same
1095+
// module as /api/sidecar-settings — a gate on one route and a stale copy on
1096+
// the other is no gate at all.
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;
1112+
const candidates = await webSearchCandidateRows(config);
1113+
if (effectiveModel && webSearchModelIsRejected(effectiveBackend, effectiveModel, candidates)) {
1114+
return jsonResponse(webSearchModelRejection(
1115+
"webSearchSidecar.model",
1116+
effectiveBackend,
1117+
effectiveModel,
1118+
candidates,
1119+
), 400);
1120+
}
1121+
}
10881122
}
10891123
const next = { ...(config.claudeCode ?? {}) };
10901124
for (const field of ["webSearchSidecar", "visionSidecar"] as const) {

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ import {
7070
visionDescriberRejection,
7171
visionModelOptionsFor,
7272
} from "./vision-sidecar-options";
73+
import {
74+
webSearchCandidateRows,
75+
webSearchModelIsRejected,
76+
webSearchModelOptionsFrom,
77+
webSearchModelRejection,
78+
} from "./web-search-sidecar-options";
7379
import { getDebugLogEntries } from "../../lib/debug-log-buffer";
7480
import { getInjectionDebugLogEntries } from "../../lib/injection-debug-log";
7581
import {
@@ -511,6 +517,7 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
511517
if (url.pathname === "/api/sidecar-settings" && req.method === "GET") {
512518
const ws = config.webSearchSidecar ?? {};
513519
const vision = await sidecarVisionResponseSettings(config);
520+
const webSearchCandidates = await webSearchCandidateRows(config);
514521
return jsonResponse({
515522
webSearch: {
516523
model: ws.model ?? "gpt-5.6-luna",
@@ -519,6 +526,9 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
519526
},
520527
vision: publicVisionSidecarSettings(config, vision),
521528
visionModels: vision.models,
529+
// ALWAYS present: the dashboard treats an omitted list as "no filter" and
530+
// falls back to the full model union, so empty must be [] (review B3).
531+
webSearchModels: webSearchModelOptionsFrom(config, webSearchCandidates),
522532
});
523533
}
524534

@@ -545,6 +555,9 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
545555
&& body.webSearch.backend !== "openai" && body.webSearch.backend !== "anthropic") {
546556
return jsonResponse({ error: "webSearch.backend must be openai, anthropic, or null" }, 400);
547557
}
558+
if (body.webSearch?.model !== undefined && typeof body.webSearch.model !== "string") {
559+
return jsonResponse({ error: "webSearch.model must be a string" }, 400);
560+
}
548561
if (body.webSearch && body.webSearch.streamRoutedModelOutput !== undefined
549562
&& typeof body.webSearch.streamRoutedModelOutput !== "boolean") {
550563
return jsonResponse({ error: "webSearch.streamRoutedModelOutput must be a boolean" }, 400);
@@ -600,6 +613,21 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
600613
}
601614

602615
if (body.webSearch) {
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) {
626+
const candidates = await webSearchCandidateRows(config);
627+
if (webSearchModelIsRejected(effectiveBackend, effectiveModel, candidates)) {
628+
return jsonResponse(webSearchModelRejection("webSearch.model", effectiveBackend, effectiveModel, candidates), 400);
629+
}
630+
}
603631
config.webSearchSidecar = { ...config.webSearchSidecar };
604632
if (typeof body.webSearch.model === "string") {
605633
if (body.webSearch.model === "") delete config.webSearchSidecar.model;
@@ -645,6 +673,7 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
645673
saveConfigPreservingClaudeCode(config);
646674
const ws = config.webSearchSidecar ?? {};
647675
const vision = await sidecarVisionResponseSettings(config);
676+
const savedWebSearchCandidates = await webSearchCandidateRows(config);
648677
return jsonResponse({
649678
ok: true,
650679
webSearch: {
@@ -654,6 +683,10 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
654683
},
655684
vision: publicVisionSidecarSettings(config, vision),
656685
visionModels: vision.models,
686+
// Echoed for the same reason GET always carries it: the dashboard rebuilds
687+
// its sidecar state from this body, and an omitted key reads as "old
688+
// server" and falls back to the full union (review F1).
689+
webSearchModels: webSearchModelOptionsFrom(config, savedWebSearchCandidates),
657690
});
658691
}
659692

0 commit comments

Comments
 (0)