Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: retain model catalog prefix on overflow (#889)
Gustavo Yec03330523588
diff --git a/src/daemon/agent-driver/src/adapters/antigravity/catalog.test.ts b/src/daemon/agent-driver/src/adapters/antigravity/catalog.test.tsindex 4cddc23e1..d46608036 100644--- a/src/daemon/agent-driver/src/adapters/antigravity/catalog.test.ts+++ b/src/daemon/agent-driver/src/adapters/antigravity/catalog.test.ts@@ -3,11 +3,22 @@ import { describe, expect, it } from "vitest";import { antigravityModelForEffort, antigravityReasoningCatalog, parseAntigravityCatalog } from "./catalog.js";describe("Antigravity native model variants", () => {- it.each([1024, 1025])("keeps the complete catalog or rejects overflow (%s models)", (count) => {+ it.each([1024, 1025])("keeps the complete catalog or truncates overflow (%s models)", (count) => {const models = Array.from({ length: count }, (_, index) => `model-${index}`);- const catalog = parseAntigravityCatalog({ models: { availableModels: models.map((modelId) => ({ modelId })) } });- if (count > RUNTIME_MODEL_CATALOG_MAX) expect(catalog).toBeUndefined();- else expect(catalog?.models.map((model) => model.id)).toEqual(models);+ const catalog = parseAntigravityCatalog({ models: { availableModels: [null, { modelId: models[0] }, ...models.map((modelId) => ({ modelId }))] } });+ expect(catalog?.models.map((model) => model.id)).toEqual(models.slice(0, RUNTIME_MODEL_CATALOG_MAX));+ });++ it("truncates grouped choices after validation and deduplication", () => {+ const models = Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 }, (_, index) => `model-${index}`);+ const catalog = parseAntigravityCatalog({ configOptions: [{+ id: "model", type: "select", currentValue: models[0], options: [+ { options: [null, { value: "invalid model" }, { value: models[0] }] },+ { options: models.map((value) => ({ value })) },+ ],+ }] });+ expect(catalog?.models.map((model) => model.id)).toEqual(models.slice(0, RUNTIME_MODEL_CATALOG_MAX));+ expect(catalog?.currentModelId).toBe(models[0]);});it("preserves returned choices and maps effort only to offered siblings", () => {@@ -28,7 +39,7 @@ describe("Antigravity native model variants", () => {id: "native-model", category: "model", type: "select", currentValue: "actual",options: [{ group: "g", options: [{ value: "actual", name: "Actual" }, { value: "actual" }, { value: "invalid model" }] }],}] })).toEqual({ configId: "native-model", currentModelId: "actual", models: [{ id: "actual", displayName: "Actual" }] });- expect(parseAntigravityCatalog({ models: { availableModels: Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 }, (_, i) => ({ modelId: `model-${i}` })) } })).toBeUndefined();+ expect(parseAntigravityCatalog({ models: { availableModels: Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 }, (_, i) => ({ modelId: `model-${i}` })) } })?.models).toHaveLength(RUNTIME_MODEL_CATALOG_MAX);expect(parseAntigravityCatalog(null)).toBeUndefined();});});diff --git a/src/daemon/agent-driver/src/adapters/antigravity/catalog.ts b/src/daemon/agent-driver/src/adapters/antigravity/catalog.tsindex f79e3c247..be00807ad 100644--- a/src/daemon/agent-driver/src/adapters/antigravity/catalog.ts+++ b/src/daemon/agent-driver/src/adapters/antigravity/catalog.ts@@ -6,22 +6,24 @@ export type AntigravityModel = { id: string; displayName?: string };export type AntigravityCatalog = { models: AntigravityModel[]; currentModelId?: string; configId?: string };function choices(value: unknown): AntigravityModel[] {- if (!Array.isArray(value) || value.length > RUNTIME_MODEL_CATALOG_MAX) return [];+ if (!Array.isArray(value)) return [];const rows: AntigravityModel[] = [];+ const seen = new Set<string>();for (const item of value) {const row = asRecord(item);if (!row) continue;const nested = Array.isArray(row.options) ? row.options : [row];- if (nested.length + rows.length > RUNTIME_MODEL_CATALOG_MAX) return [];for (const child of nested) {const option = asRecord(child);const id = normalizeRuntimeModelId(option?.value ?? option?.modelId);- if (!id) continue;+ if (!id || seen.has(id)) continue;+ seen.add(id);const name = option?.name;rows.push({ id, ...(typeof name === "string" && name.length <= 256 ? { displayName: name } : {}) });+ if (rows.length >= RUNTIME_MODEL_CATALOG_MAX) return rows;}}- return rows.filter((row, index) => rows.findIndex((other) => other.id === row.id) === index);+ return rows;}export function parseAntigravityCatalog(value: unknown): AntigravityCatalog | undefined {diff --git a/src/daemon/agent-driver/src/adapters/codex/index.test.ts b/src/daemon/agent-driver/src/adapters/codex/index.test.tsindex 95c862c96..344fbeeed 100644--- a/src/daemon/agent-driver/src/adapters/codex/index.test.ts+++ b/src/daemon/agent-driver/src/adapters/codex/index.test.ts@@ -279,12 +279,12 @@ describe("CodexDriver reasoning catalog probe", () => {const result = await new CodexDriver().probe();expect(result.status).toBe("healthy");- if (hasNext) expect(result.reasoning).toBeUndefined();- else expect(result.reasoning?.models.map((model) => model.id)).toEqual(models.map((model) => model.id));+ expect(result.reasoning?.models.map((model) => model.id)).toEqual(models.map((model) => model.id));+ expect(proc.kill).toHaveBeenCalledTimes(1);expect(cursors).toEqual([undefined, ...Array.from({ length: 10 }, (_, index) => String(index + 1))]);});- it("returns no catalog for 1025 unique models across distinct pages", async () => {+ it("retains the first1024 models across distinct pages", async () => {const models = Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 }, (_, index) => ({id: `gpt-model-${index}`,supportedReasoningEfforts: [],@@ -298,19 +298,21 @@ describe("CodexDriver reasoning catalog probe", () => {} };});runtimeMocks.spawnAgentProcess.mockReturnValueOnce(proc as never);- await expect(new CodexDriver().probe()).resolves.toMatchObject({ reasoning: undefined });+ const result = await new CodexDriver().probe();+ expect(result.reasoning?.models.map((model) => model.id)).toEqual(models.slice(0, RUNTIME_MODEL_CATALOG_MAX).map((model) => model.id));});- it("returns no catalog when a producer ignores the page limit and sends 1025 unique models", async () => {+ it("truncates an oversized native page to the first1024 models", async () => {const models = Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 }, (_, index) => ({id: `gpt-model-${index}`,supportedReasoningEfforts: [],}));const proc = probingProcess((request) => request.method === "initialize"? { jsonrpc: "2.0", id: request.id, result: {} }- : { jsonrpc: "2.0", id: request.id, result: { data: models, nextCursor: null } });+ : { jsonrpc: "2.0", id: request.id, result: { data: [null, { id: "invalid model" }, models[0], ...models], nextCursor: null } });runtimeMocks.spawnAgentProcess.mockReturnValueOnce(proc as never);- await expect(new CodexDriver().probe()).resolves.toMatchObject({ reasoning: undefined });+ const result = await new CodexDriver().probe();+ expect(result.reasoning?.models.map((model) => model.id)).toEqual(models.slice(0, RUNTIME_MODEL_CATALOG_MAX).map((model) => model.id));});it("returns no catalog when app-server output exceeds the byte bound", async () => {diff --git a/src/daemon/agent-driver/src/adapters/codex/index.ts b/src/daemon/agent-driver/src/adapters/codex/index.tsindex 8973634f5..a4529d2d3 100644--- a/src/daemon/agent-driver/src/adapters/codex/index.ts+++ b/src/daemon/agent-driver/src/adapters/codex/index.ts@@ -167,7 +167,6 @@ export class CodexDriver implements BackendAdapter {let listId = 0;const models: RuntimeReasoningCatalog["models"][number][] = [];const seenModels = new Set<string>();- let overflow = false;let defaultModelId: string | undefined;const finish = (catalog?: RuntimeReasoningCatalog) => {if (settled) return;@@ -191,10 +190,6 @@ export class CodexDriver implements BackendAdapter {const model = value as Record<string, unknown>;const id = normalizeRuntimeModelId(model.id);if (!id || seenModels.has(id)) return;- if (models.length >= MODEL_LIST_MAX) {- overflow = true;- return;- }const rawOptions = Array.isArray(model.supportedReasoningEfforts)? model.supportedReasoningEfforts: [];@@ -240,11 +235,12 @@ export class CodexDriver implements BackendAdapter {if (message.id !== listId) return;if (message.error || !message.result || typeof message.result !== "object") return finish();const result = message.result as Record<string, unknown>;- for (const model of Array.isArray(result.data) ? result.data : []) consumeModel(model);- if (overflow) return finish();+ for (const model of Array.isArray(result.data) ? result.data : []) {+ consumeModel(model);+ if (models.length >= MODEL_LIST_MAX) break;+ }const cursor = typeof result.nextCursor === "string" ? result.nextCursor : undefined;- if (cursor && models.length >= MODEL_LIST_MAX) return finish();- if (cursor) return requestModelPage(cursor);+ if (cursor && models.length < MODEL_LIST_MAX) return requestModelPage(cursor);if (models.length === 0) return finish();finish({updateMode: "live_next_turn",diff --git a/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.test.ts b/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.test.tsindex 925c80bfe..2edde5df9 100644--- a/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.test.ts+++ b/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.test.ts@@ -45,11 +45,10 @@ function respond(process: FakeProcess, request: Record<string, unknown>, result:}describe("Cursor ACP model catalog", () => {- it.each([1024, 1025])("keeps the complete catalog or rejects overflow (%s models)", (count) => {+ it.each([1024, 1025])("keeps the complete catalog or truncates overflow (%s models)", (count) => {const models = Array.from({ length: count }, (_, index) => `model-${index}`);- const catalog = parseCursorAcpModelCatalog({ configOptions: [{ id: "model", options: models.map((id) => ({ value: id })) }] });- if (count > RUNTIME_MODEL_CATALOG_MAX) expect(catalog).toBeUndefined();- else expect(catalog?.models.map((model) => model.id)).toEqual(models);+ const catalog = parseCursorAcpModelCatalog({ configOptions: [{ id: "model", options: [null, { value: "default[]" }, { value: models[0] }, ...models.map((id) => ({ value: id }))] }] });+ expect(catalog?.models.map((model) => model.id)).toEqual(models.slice(0, RUNTIME_MODEL_CATALOG_MAX));});it("normalizes nested exact values, preserves duplicate labels, and omits ACP Auto", () => {@@ -93,7 +92,7 @@ describe("Cursor ACP model catalog", () => {});});- it("drops malformed labels without dropping exact values and fails closed on overflow", () => {+ it("drops malformed labels without dropping exact values and truncates overflow", () => {expect(parseCursorAcpModelCatalog({configOptions: [{id: "model",@@ -108,7 +107,7 @@ describe("Cursor ACP model catalog", () => {id: "model",options: Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 }, (_, index) => ({ value: `model-${index}` })),}],- })).toBeUndefined();+ })?.models).toHaveLength(RUNTIME_MODEL_CATALOG_MAX);});it("uses only initialize/auth/session-new, returns exact ACP values, and cleans once", async () => {diff --git a/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.ts b/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.tsindex 126392b44..c17d4cf36 100644--- a/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.ts+++ b/src/daemon/agent-driver/src/adapters/cursor/catalog-probe.ts@@ -77,7 +77,7 @@ export function parseCursorAcpModelCatalog(session: unknown): RuntimeReasoningCaconst models: RuntimeReasoningCatalog["models"][number][] = [];for (const option of flattenCursorAcpSelectOptions(modelConfig.options)) {if (option.value === "default[]" || seen.has(option.value)) continue;- if (models.length >= RUNTIME_MODEL_CATALOG_MAX) return undefined;+ if (models.length >= RUNTIME_MODEL_CATALOG_MAX) break;seen.add(option.value);models.push({id: option.value,diff --git a/src/daemon/agent-driver/src/adapters/grok/catalog-probe.ts b/src/daemon/agent-driver/src/adapters/grok/catalog-probe.tsindex 43ba52119..cf27020db 100644--- a/src/daemon/agent-driver/src/adapters/grok/catalog-probe.ts+++ b/src/daemon/agent-driver/src/adapters/grok/catalog-probe.ts@@ -98,7 +98,7 @@ export function parseGrokModelCatalog(value: unknown): RuntimeReasoningCatalog |const model = asRecord(item);const id = normalizeRuntimeModelId(model?.modelId);if (!model || !id || seen.has(id)) continue;- if (models.length >= RUNTIME_MODEL_CATALOG_MAX) return undefined;+ if (models.length >= RUNTIME_MODEL_CATALOG_MAX) break;seen.add(id);const displayName = boundedText(model.name, MODEL_DISPLAY_NAME_MAX);models.push({ id, ...(displayName ? { displayName } : {}), ...reasoningCatalog(model) });diff --git a/src/daemon/agent-driver/src/adapters/grok/index.test.ts b/src/daemon/agent-driver/src/adapters/grok/index.test.tsindex 37245bade..75fd44f6a 100644--- a/src/daemon/agent-driver/src/adapters/grok/index.test.ts+++ b/src/daemon/agent-driver/src/adapters/grok/index.test.ts@@ -69,11 +69,10 @@ const modelState = {};describe("Grok ACP model catalog", () => {- it.each([1024, 1025])("keeps the complete catalog or rejects overflow (%s models)", (count) => {+ it.each([1024, 1025])("keeps the complete catalog or truncates overflow (%s models)", (count) => {const models = Array.from({ length: count }, (_, index) => `model-${index}`);- const catalog = parseGrokModelCatalog({ availableModels: models.map((modelId) => ({ modelId })) });- if (count > RUNTIME_MODEL_CATALOG_MAX) expect(catalog).toBeUndefined();- else expect(catalog?.models.map((model) => model.id)).toEqual(models);+ const catalog = parseGrokModelCatalog({ availableModels: [null, { modelId: models[0] }, ...models.map((modelId) => ({ modelId }))] });+ expect(catalog?.models.map((model) => model.id)).toEqual(models.slice(0, RUNTIME_MODEL_CATALOG_MAX));});it("preserves provider ids and dynamic reasoning values", () => {diff --git a/src/daemon/agent-driver/src/internal/modelCatalog.test.ts b/src/daemon/agent-driver/src/internal/modelCatalog.test.tsindex 604fc40f5..500cab5d0 100644--- a/src/daemon/agent-driver/src/internal/modelCatalog.test.ts+++ b/src/daemon/agent-driver/src/internal/modelCatalog.test.ts@@ -46,7 +46,7 @@ describe("runtime startup model catalog parsers", () => {expect(ids(parsePiModelCatalog(models.map((id) => ({ provider: "provider", id: id.slice(9) }))))).toEqual(models);});- it("returns no catalog instead of truncating when unique IDs overflow the bound", () => {+ it("retains the first valid unique IDs when producer catalogs overflow", () => {const opencode = Array.from({ length: RUNTIME_MODEL_CATALOG_MAX + 1 },(_, index) => `provider/model-${index}`,@@ -56,7 +56,8 @@ describe("runtime startup model catalog parsers", () => {(_, index) => ({ provider: "provider", id: `model-${index}` }),);- expect(parseOpenCodeModelCatalog(opencode)).toBeUndefined();- expect(parsePiModelCatalog(pi)).toBeUndefined();+ const expected = Array.from({ length: RUNTIME_MODEL_CATALOG_MAX }, (_, index) => `provider/model-${index}`);+ expect(ids(parseOpenCodeModelCatalog(`invalid row\nprovider/model-0\n${opencode}`))).toEqual(expected);+ expect(ids(parsePiModelCatalog([null, pi[0], ...pi]))).toEqual(expected);});});diff --git a/src/daemon/agent-driver/src/internal/modelCatalog.ts b/src/daemon/agent-driver/src/internal/modelCatalog.tsindex 2c05f0418..1599acc95 100644--- a/src/daemon/agent-driver/src/internal/modelCatalog.ts+++ b/src/daemon/agent-driver/src/internal/modelCatalog.ts@@ -16,7 +16,7 @@ function catalogFromIds(ids: Iterable<string>): RuntimeReasoningCatalog | undefifor (const rawId of ids) {const id = normalizeRuntimeModelId(rawId);if (!id || seen.has(id)) continue;- if (models.length >= RUNTIME_MODEL_CATALOG_MAX) return undefined;+ if (models.length >= RUNTIME_MODEL_CATALOG_MAX) break;seen.add(id);models.push({ id, supportedReasoningEfforts: [] });}diff --git a/src/shared/src/schemas.test.ts b/src/shared/src/schemas.test.tsindex 562c6e204..b514592aa 100644--- a/src/shared/src/schemas.test.ts+++ b/src/shared/src/schemas.test.ts@@ -32,11 +32,14 @@ describe("large runtime model catalogs", () => {expect(runtime.reasoning).toEqual(reasoning)})- it("accepts the full bound and rejects overflow without returning a partial catalog", () => {+ it("accepts the full bound and truncates overflow through the machine wire schema", () => {expect(RuntimeReasoningCatalogSchema.parse(catalog(COMMUNITY_REASONING_MODELS_MAX))).toEqual(catalog(COMMUNITY_REASONING_MODELS_MAX))- expect(RuntimeReasoningCatalogSchema.safeParse(catalog(COMMUNITY_REASONING_MODELS_MAX + 1)).success)- .toBe(false)+ const overflow = catalog(COMMUNITY_REASONING_MODELS_MAX + 1)+ const reasoning = { ...overflow, defaultModelId: overflow.models.at(-1)!.id,+ models: [null, overflow.models[0], ...overflow.models] }+ expect(CommunityMachineRuntimeSchema.parse({ id: "opencode", reasoning }).reasoning)+ .toEqual({ ...catalog(COMMUNITY_REASONING_MODELS_MAX), defaultModelId: reasoning.defaultModelId })})})diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.tsindex eed16a669..43f8c462b 100644--- a/src/shared/src/schemas.ts+++ b/src/shared/src/schemas.ts@@ -883,17 +883,19 @@ export const RuntimeReasoningCatalogSchema = z.object({defaultModelId: z.string().min(1).max(100).optional().catch(undefined),models: z.array(z.unknown())- .max(COMMUNITY_REASONING_MODELS_MAX).transform((models) => {const seen = new Set<string>();- return models.flatMap((candidate) => {+ const retained: z.infer<typeof RuntimeReasoningModelSchema>[] = [];+ for (const candidate of models) {const parsed = RuntimeReasoningModelSchema.safeParse(candidate);- if (!parsed.success) return [];+ if (!parsed.success) continue;const model = parsed.data;- if (seen.has(model.id)) return [];+ if (seen.has(model.id)) continue;seen.add(model.id);- return [model];- });+ retained.push(model);+ if (retained.length >= COMMUNITY_REASONING_MODELS_MAX) break;+ }+ return retained;}),});diff --git a/src/shared/test/schemas/community-runtime.test.ts b/src/shared/test/schemas/community-runtime.test.tsindex 3832b2369..9574625a0 100644--- a/src/shared/test/schemas/community-runtime.test.ts+++ b/src/shared/test/schemas/community-runtime.test.ts@@ -183,7 +183,7 @@ describe("CommunityMachineRuntimeSchema", () => {})).toEqual({ id: "codex", status: "healthy" });});- it("accepts the full 512-model startup snapshot", () => {+ it("accepts the full bounded model startup snapshot", () => {const models = Array.from({ length: COMMUNITY_REASONING_MODELS_MAX }, (_, index) => ({id: `provider/model-${index}`,supportedReasoningEfforts: [],@@ -194,15 +194,19 @@ describe("CommunityMachineRuntimeSchema", () => {}).reasoning?.models).toHaveLength(COMMUNITY_REASONING_MODELS_MAX);});- it("drops only an overflowing optional catalog and keeps the runtime", () => {+ it("retains the first valid unique models from an overflowing catalog", () => {const models = Array.from({ length: COMMUNITY_REASONING_MODELS_MAX + 1 }, (_, index) => ({id: `provider/model-${index}`,supportedReasoningEfforts: [],}));expect(CommunityMachineRuntimeSchema.parse({id: "opencode",- reasoning: { updateMode: "unsupported", models },- })).toEqual({ id: "opencode", status: "healthy" });+ reasoning: { updateMode: "unsupported", models: [null, { id: "" }, models[0], ...models] },+ })).toEqual({+ id: "opencode",+ status: "healthy",+ reasoning: { updateMode: "unsupported", models: models.slice(0, COMMUNITY_REASONING_MODELS_MAX) },+ });});});