Skip to content

Commit 5fd060f

Browse files
committed
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.
1 parent bd79ab5 commit 5fd060f

8 files changed

Lines changed: 263 additions & 18 deletions

File tree

185 KB
Loading

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ 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 }
7475
export interface SidecarData {
7576
webSearch: SidecarSetting;
7677
vision: SidecarSetting;
7778
/** Server-computed eligible describers. Optional: an older server omits it and
7879
* the client falls back to the legacy provider-name list rather than showing
7980
* an empty picker. */
8081
visionModels?: VisionModelOption[];
82+
/** Server-computed runnable web-search models (#2188). Same undefined-vs-[]
83+
* contract as visionModels: an older server omits the key and the client
84+
* falls back to the legacy list; a current server's [] means none. */
85+
webSearchModels?: WebSearchModelOption[];
8186
}
8287
export interface SidecarPatch {
8388
webSearch?: { backend?: SidecarBackend | null; model?: string; streamRoutedModelOutput?: boolean };
@@ -280,6 +285,31 @@ export function sidecarModelOptions(models: ModelInfo[]) {
280285
return out;
281286
}
282287

288+
/**
289+
* Server list when present, else the legacy openai+anthropic list — the same
290+
* undefined-vs-[] contract visionModelOptions documents. The persisted model is
291+
* grandfathered into the list so the picker can DISPLAY a now-illegal setting;
292+
* the server still rejects new writes of it.
293+
*/
294+
export function webSearchModelOptionsForPicker(
295+
serverOptions: WebSearchModelOption[] | undefined,
296+
models: ModelInfo[],
297+
current: string | undefined,
298+
): Array<{ value: string; label: string }> {
299+
if (serverOptions === undefined) {
300+
const legacy = sidecarModelOptions(models);
301+
if (current && !legacy.some(option => option.value === current)) {
302+
legacy.unshift({ value: current, label: current });
303+
}
304+
return legacy;
305+
}
306+
const out = serverOptions.map(option => ({ value: option.value, label: option.label }));
307+
if (current && !out.some(option => option.value === current)) {
308+
out.unshift({ value: current, label: current });
309+
}
310+
return out;
311+
}
312+
283313
/**
284314
* Server list when present, else the legacy openai+anthropic list.
285315
*

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

Lines changed: 7 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,9 @@ 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(sidecar?.webSearchModels, models, sidecar?.webSearch.model);
470+
}, [models, sidecar?.webSearchModels, sidecar?.webSearch]);
476471
const visionModels = useMemo(
477472
() => visionModelOptions(sidecar?.visionModels, models, sidecar?.vision?.model, sidecar?.vision?.backend),
478473
[sidecar?.visionModels, models, sidecar?.vision],
@@ -485,6 +480,7 @@ export function useDashboardData(apiBase: string) {
485480
webSearch: mergeSidecarSetting(sidecar.webSearch, patch.webSearch),
486481
vision: mergeSidecarSetting(sidecar.vision, patch.vision),
487482
...(sidecar.visionModels ? { visionModels: sidecar.visionModels } : {}),
483+
...(sidecar.webSearchModels ? { webSearchModels: sidecar.webSearchModels } : {}),
488484
};
489485
setSidecarSaving(true);
490486
setSidecar(next);
@@ -499,6 +495,7 @@ export function useDashboardData(apiBase: string) {
499495
webSearch: data.webSearch,
500496
vision: data.vision,
501497
...(data.visionModels ? { visionModels: data.visionModels } : {}),
498+
...(data.webSearchModels ? { webSearchModels: data.webSearchModels } : {}),
502499
});
503500
const prev = readSessionListCache<CachedControls>(controlsCacheKey(apiBase)) ?? {};
504501
writeSessionListCache(controlsCacheKey(apiBase), {
@@ -507,6 +504,7 @@ export function useDashboardData(apiBase: string) {
507504
webSearch: data.webSearch,
508505
vision: data.vision,
509506
...(data.visionModels ? { visionModels: data.visionModels } : {}),
507+
...(data.webSearchModels ? { webSearchModels: data.webSearchModels } : {}),
510508
},
511509
});
512510
} catch {

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

Lines changed: 18 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,17 @@ 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" && typeof section.model === "string" && section.model !== "") {
1098+
const requested = section.model;
1099+
const candidates = await webSearchCandidateRows(config);
1100+
if (webSearchModelIsRejected(requested, candidates)) {
1101+
return jsonResponse(webSearchModelRejection("webSearchSidecar.model", requested, candidates), 400);
1102+
}
1103+
}
10881104
}
10891105
const next = { ...(config.claudeCode ?? {}) };
10901106
for (const field of ["webSearchSidecar", "visionSidecar"] as const) {

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

Lines changed: 17 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

@@ -600,6 +610,13 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
600610
}
601611

602612
if (body.webSearch) {
613+
if (typeof body.webSearch.model === "string" && body.webSearch.model !== "") {
614+
const requested = body.webSearch.model;
615+
const candidates = await webSearchCandidateRows(config);
616+
if (webSearchModelIsRejected(requested, candidates)) {
617+
return jsonResponse(webSearchModelRejection("webSearch.model", requested, candidates), 400);
618+
}
619+
}
603620
config.webSearchSidecar = { ...config.webSearchSidecar };
604621
if (typeof body.webSearch.model === "string") {
605622
if (body.webSearch.model === "") delete config.webSearchSidecar.model;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* The one place that decides which models the management API offers as the
3+
* web-search sidecar, and which it refuses to persist (#2188).
4+
*
5+
* Two routes write `webSearchSidecar.model` — `PUT /api/sidecar-settings`
6+
* and the `webSearchSidecar` override in `PUT /api/claude-code`. They share
7+
* this module for the same reason the vision routes share
8+
* vision-sidecar-options.ts: a gate on one route and a stale copy on the
9+
* other is the same as no gate at all. `ocx config set` raw JSON writes
10+
* bypass management gates by design (operator escape hatch, same as vision).
11+
*
12+
* Unlike vision's provably-blind gate (reject only on positive proof), the
13+
* web-search gate is MEMBERSHIP: the executor set is closed and known, so an
14+
* id outside (candidates ∪ auth slots) can never run and is refused.
15+
*/
16+
import type { OcxConfig } from "../../types";
17+
import { resolveSidecarAuth } from "../../sidecar/auth";
18+
import { pickerVisibleSidecarCandidates, type SidecarCandidate } from "../../sidecar/candidates";
19+
import { isWebSearchAuthSlotModel, webSearchSidecarCandidates } from "../../web-search/backends";
20+
21+
export interface WebSearchModelOption {
22+
value: string;
23+
label: string;
24+
/** True when the row is an auth-slot entitlement rather than a picker row. */
25+
authSlot?: boolean;
26+
}
27+
28+
/** The candidate rows the web-search executors can actually run right now. */
29+
export async function webSearchCandidateRows(config: OcxConfig): Promise<SidecarCandidate[]> {
30+
const auth = resolveSidecarAuth(config);
31+
const all = await pickerVisibleSidecarCandidates(config, auth);
32+
return webSearchSidecarCandidates(config, auth, all);
33+
}
34+
35+
/**
36+
* The GUI/CLI option list. The persisted model is display-grandfathered so an
37+
* operator can SEE a now-illegal setting in the picker (parity with the vision
38+
* GET); new writes of such an id are still rejected by the gate below.
39+
*/
40+
export function webSearchModelOptionsFrom(
41+
config: Pick<OcxConfig, "webSearchSidecar">,
42+
candidates: readonly SidecarCandidate[],
43+
): WebSearchModelOption[] {
44+
const byValue = new Map<string, WebSearchModelOption>();
45+
for (const candidate of candidates) {
46+
if (byValue.has(candidate.id)) continue;
47+
byValue.set(candidate.id, {
48+
value: candidate.id,
49+
label: candidate.id,
50+
...(candidate.authSlot ? { authSlot: true } : {}),
51+
});
52+
}
53+
const persisted = config.webSearchSidecar?.model;
54+
if (persisted && !byValue.has(persisted)) {
55+
byValue.set(persisted, { value: persisted, label: persisted });
56+
}
57+
return [...byValue.values()].sort((a, b) => a.value.localeCompare(b.value));
58+
}
59+
60+
/**
61+
* Membership gate: reject when the id is neither a runnable candidate nor an
62+
* auth-slot model. Auth slots pass even when the matching login is currently
63+
* absent — the slot is a legal setting whose executor simply is not live yet,
64+
* and refusing it would make settings order-dependent on login state.
65+
*/
66+
export function webSearchModelIsRejected(
67+
requested: string,
68+
candidates: readonly SidecarCandidate[],
69+
): boolean {
70+
if (isWebSearchAuthSlotModel(requested)) return false;
71+
return !candidates.some(candidate => candidate.id === requested);
72+
}
73+
74+
/** Uniform 400 payload naming the filter, mirroring visionDescriberRejection's shape. */
75+
export function webSearchModelRejection(
76+
field: string,
77+
requested: string,
78+
candidates: readonly SidecarCandidate[],
79+
): { error: string; allowedModels: string[] } {
80+
return {
81+
error: `${field}: "${requested}" is not a web-search sidecar candidate — the model must be ` +
82+
"picker-visible and runnable by an active executor-backed backend (or an auth-slot model)",
83+
allowedModels: candidates.map(candidate => candidate.id).sort(),
84+
};
85+
}

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,23 +376,31 @@ test("Claude sidecar overrides round-trip, partially update, clear, and reject u
376376
});
377377
try {
378378
let response = await put({
379-
webSearchSidecar: { backend: "anthropic", model: "claude-search" },
379+
// The web-search override now passes the #2188 membership gate; the
380+
// Haiku auth slot is always a legal setting regardless of login state.
381+
webSearchSidecar: { backend: "anthropic", model: "claude-haiku-4-5" },
380382
visionSidecar: { backend: "openai", model: "gpt-vision" },
381383
});
382384
expect(response.status).toBe(200);
383385
expect(loadConfig().claudeCode).toMatchObject({
384-
webSearchSidecar: { backend: "anthropic", model: "claude-search" },
386+
webSearchSidecar: { backend: "anthropic", model: "claude-haiku-4-5" },
385387
visionSidecar: { backend: "openai", model: "gpt-vision" },
386388
});
387389

388390
let get = await fetch(new URL("/api/claude-code", server.url)).then(r => r.json()) as Record<string, unknown>;
389-
expect(get.webSearchSidecar).toEqual({ backend: "anthropic", model: "claude-search" });
391+
expect(get.webSearchSidecar).toEqual({ backend: "anthropic", model: "claude-haiku-4-5" });
390392
expect(get.visionSidecar).toEqual({ backend: "openai", model: "gpt-vision" });
391393

394+
// A model outside (runnable candidates ∪ auth slots) is refused with the
395+
// filter named — this route shares the gate with /api/sidecar-settings.
396+
response = await put({ webSearchSidecar: { model: "claude-search" } });
397+
expect(response.status).toBe(400);
398+
expect(((await response.json()) as { error: string }).error).toContain("web-search sidecar candidate");
399+
392400
// Nested partial updates preserve omitted fields and omitted sections.
393-
response = await put({ webSearchSidecar: { model: "claude-search-2" } });
401+
response = await put({ webSearchSidecar: { model: "gpt-5.6-luna" } });
394402
expect(response.status).toBe(200);
395-
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ backend: "anthropic", model: "claude-search-2" });
403+
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ backend: "anthropic", model: "gpt-5.6-luna" });
396404
expect(loadConfig().claudeCode?.visionSidecar).toEqual({ backend: "openai", model: "gpt-vision" });
397405

398406
// null backend is the explicit Auto/inherit transition; empty model deletes only model.
@@ -401,10 +409,10 @@ test("Claude sidecar overrides round-trip, partially update, clear, and reject u
401409
visionSidecar: { backend: null, model: "" },
402410
});
403411
expect(response.status).toBe(200);
404-
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ model: "claude-search-2" });
412+
expect(loadConfig().claudeCode?.webSearchSidecar).toEqual({ model: "gpt-5.6-luna" });
405413
expect(loadConfig().claudeCode?.visionSidecar).toBeUndefined();
406414
get = await fetch(new URL("/api/claude-code", server.url)).then(r => r.json()) as Record<string, unknown>;
407-
expect(get.webSearchSidecar).toEqual({ model: "claude-search-2" });
415+
expect(get.webSearchSidecar).toEqual({ model: "gpt-5.6-luna" });
408416
expect(get.visionSidecar).toBeUndefined();
409417

410418
// null and empty sections both clear the whole override.

0 commit comments

Comments
 (0)