Skip to content

Commit ea43bc0

Browse files
committed
fix(subagents): keep a saved roster slot listed when its model is disabled
GET /api/subagent-models built `available` purely from currently-pickable models, so a featured model disabled elsewhere vanished from it. The dashboard filters `chosen` against `available` and then PUTs exactly the rows it holds, which turned a hide into a delete: the next Save wrote the truncated roster to config.json, and the user read it as "ocx service lost my subagent models". Retain a chosen id in `available` when it is not otherwise selectable, appended after the selectable set and deduplicated. Models that are disabled and NOT in the roster stay excluded, so the picker behavior is unchanged for every model the user has not deliberately featured. The combo test asserted the old truncating behavior; it now asserts retention while a roster slot is held, and full exclusion once the slot is released. Closes #2133
1 parent ceac592 commit ea43bc0

3 files changed

Lines changed: 104 additions & 4 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,15 +613,29 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
613613
stored === catalogModelSlug(m) || slugEquals(stored, m.provider, m.id)
614614
))
615615
.map(catalogModelSlug))];
616-
const available = [
616+
const chosen = config.subagentModels ?? [];
617+
const selectable = [
617618
...listCatalogNativeSlugs().filter(ns => !disabled.has(ns)),
618619
...visibleRouted,
619620
];
621+
// A saved roster slot must stay representable even after its model is disabled
622+
// elsewhere (Models page, provider allowlist, a provider row going away). The
623+
// dashboard treats `available` as the set of rows it can render, so a chosen id
624+
// missing from it disappears from the roster UI and the next Save — which PUTs
625+
// exactly what the UI holds — silently truncates the persisted list. Losing a
626+
// deliberate 5-model roster to an unrelated visibility toggle is data loss, not a
627+
// filter. Same reasoning as `fetchGrokCandidateModels`, which deliberately lists a
628+
// model the user already excluded so its switch remains reachable.
629+
const selectableSet = new Set(selectable);
630+
const available = [
631+
...selectable,
632+
...[...new Set(chosen)].filter(model => !selectableSet.has(model)),
633+
];
620634
// #857: let CLI/GUI show when a running Codex app-server keeps an older
621635
// in-memory catalog than the one on disk.
622636
const { collectCodexAppServerCatalogState } = await import("../../codex/app-server-processes");
623637
const catalogState = collectCodexAppServerCatalogState();
624-
return jsonResponse({ chosen: config.subagentModels ?? [], available, catalogState });
638+
return jsonResponse({ chosen, available, catalogState });
625639
}
626640
if (url.pathname === "/api/subagent-models" && req.method === "PUT") {
627641
let body: { models?: unknown };

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,22 @@ describe("combo management API", () => {
655655
expect(body.available.filter(model => model === "deepseek-v4-flash")).toHaveLength(1);
656656
expect(body.available).not.toContain("combo/free");
657657

658+
// Disabling an alias hides it from the pickable set, but NOT while it still holds a
659+
// saved roster slot: the dashboard PUTs exactly the rows it can render, so dropping a
660+
// chosen id here silently truncates the persisted roster on the next Save. Covered by
661+
// tests/subagent-roster-retention.test.ts.
658662
config.disabledModels = ["deepseek-v4-flash"];
659663
const disabledResponse = await comboApi(config, "GET", "/api/subagent-models");
660-
const disabledBody = await disabledResponse!.json() as { available: string[] };
661-
expect(disabledBody.available).not.toContain("deepseek-v4-flash");
664+
const disabledBody = await disabledResponse!.json() as { chosen: string[]; available: string[] };
665+
expect(disabledBody.chosen).toEqual(["deepseek-v4-flash"]);
666+
expect(disabledBody.available).toContain("deepseek-v4-flash");
667+
expect(disabledBody.available.filter(model => model === "deepseek-v4-flash")).toHaveLength(1);
668+
669+
// Once it no longer occupies a roster slot, the disable takes full effect.
670+
config.subagentModels = [];
671+
const unfeaturedResponse = await comboApi(config, "GET", "/api/subagent-models");
672+
const unfeaturedBody = await unfeaturedResponse!.json() as { available: string[] };
673+
expect(unfeaturedBody.available).not.toContain("deepseek-v4-flash");
662674
}, 15_000);
663675

664676
test("GET models round-trips a disabled combo alias for the Models GUI", async () => {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* A saved subagent roster must survive an unrelated model-visibility change.
3+
*
4+
* The dashboard renders the roster from the reported available list and PUTs exactly what it
5+
* holds, so a
6+
* chosen id that GET omits is not merely hidden: the next Save writes the truncated list
7+
* back to config.json. Disabling a model on the Models page, narrowing a provider
8+
* allowlist, or removing a provider therefore used to silently shrink a deliberate
9+
* 5-model roster.
10+
*/
11+
import { describe, expect, test } from "bun:test";
12+
import { handleManagementAPI } from "../src/server/management-api";
13+
import { ManagementRequest as Request } from "./helpers/management-auth";
14+
import type { OcxConfig } from "../src/types";
15+
16+
function makeConfig(overrides: Partial<OcxConfig> = {}): OcxConfig {
17+
return { port: 10100, providers: {}, defaultProvider: "openai", ...overrides } as OcxConfig;
18+
}
19+
20+
async function getRoster(config: OcxConfig): Promise<{ chosen: string[]; available: string[] }> {
21+
const res = await handleManagementAPI(
22+
new Request("http://localhost/api/subagent-models"),
23+
new URL("http://localhost/api/subagent-models"),
24+
config,
25+
);
26+
expect(res).not.toBeNull();
27+
return await res!.json() as { chosen: string[]; available: string[] };
28+
}
29+
30+
describe("/api/subagent-models roster retention", () => {
31+
test("a chosen model disabled elsewhere stays listed in available", async () => {
32+
const chosen = ["gpt-5.5", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.4-mini"];
33+
const config = makeConfig({
34+
subagentModels: [...chosen],
35+
disabledModels: ["gpt-5.5", "gpt-5.4-mini"],
36+
});
37+
38+
const roster = await getRoster(config);
39+
40+
// The saved list itself is untouched.
41+
expect(roster.chosen).toEqual(chosen);
42+
// And every slot the user saved can still be rendered, so a Save round-trip
43+
// cannot truncate the roster to the models that happen to be enabled today.
44+
for (const model of chosen) expect(roster.available).toContain(model);
45+
});
46+
47+
test("retained roster entries are appended once, after the selectable models", async () => {
48+
const config = makeConfig({
49+
subagentModels: ["gpt-5.5", "gpt-5.5", "gpt-5.6-terra"],
50+
disabledModels: ["gpt-5.5"],
51+
});
52+
53+
const { available } = await getRoster(config);
54+
55+
// A duplicate saved id must not produce a duplicate row.
56+
expect(available.filter(model => model === "gpt-5.5").length).toBe(1);
57+
// An enabled chosen model is already selectable and must not be re-appended.
58+
expect(available.filter(model => model === "gpt-5.6-terra").length).toBe(1);
59+
// Retained-but-disabled entries sort after everything still selectable.
60+
expect(available.indexOf("gpt-5.5")).toBeGreaterThan(available.indexOf("gpt-5.6-terra"));
61+
});
62+
63+
test("a disabled model that is NOT in the roster stays out of available", async () => {
64+
const config = makeConfig({
65+
subagentModels: ["gpt-5.6-terra"],
66+
disabledModels: ["gpt-5.6-sol"],
67+
});
68+
69+
const { available } = await getRoster(config);
70+
71+
expect(available).not.toContain("gpt-5.6-sol");
72+
expect(available).toContain("gpt-5.6-terra");
73+
});
74+
});

0 commit comments

Comments
 (0)