Skip to content

Commit 9eb7f0b

Browse files
committed
fix(registry): fill per-model modality defaults beneath user overrides
Addresses review feedback on the xAI vision fix. enrichProviderFromRegistry filled modelInputModalities all-or-nothing, so a single customized model in a persisted config suppressed the registry map entirely. A user who narrowed one grok model would leave grok-4.5 with no declared modalities, which put the combo aggregator back on its ["text"] default and re-hid image support. Routing already merges these maps per key (mergeRecordFill in src/router.ts). Catalog enrichment now matches, so registry defaults fill in beneath the user's entries instead of being skipped wholesale. Explicit user values still win per model. Also broaden the registry assertion to cover all four vision-capable grok ids and both text-only exclusions, so a regression in any single entry fails.
1 parent 9441ed3 commit 9eb7f0b

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

‎src/providers/derive.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ function cloneRecordOfArrays(input: Record<string, string[]>): Record<string, st
7878
return Object.fromEntries(Object.entries(input).map(([key, value]) => [key, [...value]]));
7979
}
8080

81+
/**
82+
* Fill registry defaults BENEATH the user's per-model entries.
83+
*
84+
* Capability maps are keyed per model, so an all-or-nothing fill lets a single
85+
* customized model hide the registry's knowledge about every other model. That
86+
* is how a partially customized `modelInputModalities` could leave a
87+
* vision-capable model advertising no image support, which in turn collapses any
88+
* combo containing it to text-only. Routing already merges these maps per key
89+
* (`mergeRecordFill` in src/router.ts); catalog enrichment now matches.
90+
*/
91+
function fillRecordOfArrays(
92+
seed: Record<string, string[]>,
93+
user: Record<string, string[]> | undefined,
94+
): Record<string, string[]> {
95+
return { ...cloneRecordOfArrays(seed), ...(user ? cloneRecordOfArrays(user) : {}) };
96+
}
97+
8198
function cloneNestedRecord(input: Record<string, Record<string, string>>): Record<string, Record<string, string>> {
8299
return Object.fromEntries(Object.entries(input).map(([key, value]) => [key, { ...value }]));
83100
}
@@ -211,7 +228,7 @@ export function enrichProviderFromRegistry(name: string, prov: OcxProviderConfig
211228
if (prov.liveModels === undefined && seed.liveModels !== undefined) prov.liveModels = seed.liveModels;
212229
if (prov.contextWindow === undefined && seed.contextWindow !== undefined) prov.contextWindow = seed.contextWindow;
213230
if (!prov.modelContextWindows && seed.modelContextWindows) prov.modelContextWindows = { ...seed.modelContextWindows };
214-
if (!prov.modelInputModalities && seed.modelInputModalities) prov.modelInputModalities = cloneRecordOfArrays(seed.modelInputModalities);
231+
if (seed.modelInputModalities) prov.modelInputModalities = fillRecordOfArrays(seed.modelInputModalities, prov.modelInputModalities);
215232
if (prov.defaultMaxOutputTokens === undefined && seed.defaultMaxOutputTokens !== undefined) prov.defaultMaxOutputTokens = seed.defaultMaxOutputTokens;
216233
if (!prov.modelMaxOutputTokens && seed.modelMaxOutputTokens) prov.modelMaxOutputTokens = { ...seed.modelMaxOutputTokens };
217234
if (!prov.reasoningEfforts && seed.reasoningEfforts) prov.reasoningEfforts = [...seed.reasoningEfforts];

‎tests/catalog-vision-sidecar-modalities.test.ts‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { clearModelCache } from "../src/codex/model-cache";
44
import type { OcxProviderConfig } from "../src/types";
55
import { deriveComboCatalogModel } from "../src/codex/catalog";
66
import { PROVIDER_REGISTRY } from "../src/providers/registry";
7+
import { enrichProviderFromRegistry } from "../src/providers/derive";
78
import type { CatalogModel } from "../src/types";
89

910
const base: OcxProviderConfig = {
@@ -154,10 +155,19 @@ describe("vision-capable provider models feed combo modalities", () => {
154155
// attachments client-side before any request was made.
155156
test("xAI grok chat models declare image input in the registry", () => {
156157
const xai = PROVIDER_REGISTRY.find(entry => entry.id === "xai");
157-
expect(xai?.modelInputModalities?.["grok-4.5"]).toEqual(["text", "image"]);
158+
for (const model of [
159+
"grok-4.5",
160+
"grok-4.3",
161+
"grok-4.20-0309-reasoning",
162+
"grok-4.20-0309-non-reasoning",
163+
]) {
164+
expect(xai?.modelInputModalities?.[model]).toEqual(["text", "image"]);
165+
}
158166
// Text-only members stay out of the vision map (they are already in noVisionModels).
159-
expect(xai?.modelInputModalities?.["grok-build-0.1"]).toBeUndefined();
160-
expect(xai?.noVisionModels).toContain("grok-build-0.1");
167+
for (const model of ["grok-build-0.1", "grok-composer-2.5-fast"]) {
168+
expect(xai?.modelInputModalities?.[model]).toBeUndefined();
169+
expect(xai?.noVisionModels).toContain(model);
170+
}
161171
});
162172

163173
test("a combo of two vision-capable members still advertises image", () => {
@@ -200,4 +210,23 @@ describe("vision-capable provider models feed combo modalities", () => {
200210
);
201211
expect(derived?.inputModalities).toEqual(["text"]);
202212
});
213+
214+
test("a partial user modality map does not hide registry vision defaults", () => {
215+
// Regression: enrichProviderFromRegistry filled modelInputModalities all-or-nothing, so a
216+
// single customized model suppressed the registry's knowledge about every other model and
217+
// left vision-capable ids advertising no image support (collapsing combos to text-only).
218+
// Routing already merged these maps per key; catalog enrichment must match.
219+
const prov = {
220+
adapter: "openai-chat",
221+
baseUrl: "https://api.x.ai/v1",
222+
modelInputModalities: { "grok-4.3": ["text"] },
223+
} as OcxProviderConfig;
224+
enrichProviderFromRegistry("xai", prov);
225+
// The user's explicit narrowing still wins.
226+
expect(prov.modelInputModalities?.["grok-4.3"]).toEqual(["text"]);
227+
// Registry defaults fill in beneath it instead of being skipped wholesale.
228+
expect(prov.modelInputModalities?.["grok-4.5"]).toEqual(["text", "image"]);
229+
const hinted = applyProviderConfigHints("xai", prov, { provider: "xai", id: "grok-4.5" });
230+
expect(hinted.inputModalities).toEqual(["text", "image"]);
231+
});
203232
});

0 commit comments

Comments
 (0)