Skip to content

Commit 4666235

Browse files
author
Watcher Bot
committed
fix(catalog): preserve provider metadata on custom rows
1 parent 1d1c803 commit 4666235

3 files changed

Lines changed: 70 additions & 49 deletions

File tree

‎src/codex/catalog/provider-fetch.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -780,26 +780,26 @@ async function gatherRoutedModelsUncached(
780780
replaceLastComboCatalogOmissions(localOmissions);
781781
all.sort((a, b) => (a.provider === b.provider ? a.id.localeCompare(b.id) : a.provider.localeCompare(b.provider)));
782782
// Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
783-
// custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
783+
// custom rows get the same capability hints as discovered rows.
784784
const enrichedByName = new Map(activeProviders);
785785
const customModels = (config.customModels ?? []).map(cm => {
786786
const rawProvider = config.providers[cm.provider];
787-
const supportsReasoningSummaries = configuredReasoningSummarySupport(rawProvider, cm.modelId);
787+
const enrichedProvider = enrichedByName.get(cm.provider) ?? rawProvider;
788+
const providerCap = cm.contextWindow === undefined ? providerContextCap(config, cm.provider) : undefined;
789+
const hints = enrichedProvider
790+
? catalogHintsFromProviderConfig(cm.provider, enrichedProvider, cm.modelId, providerCap)
791+
: {};
788792
const base: CatalogModel = {
793+
...hints,
789794
id: cm.modelId,
790795
provider: cm.provider,
791796
// Display-only label: never feeds routing (customModels are keyed by routedSlug below).
792797
...(cm.displayName ? { displayName: cm.displayName } : {}),
793798
...(cm.contextWindow ? { contextWindow: cm.contextWindow } : {}),
794799
...(cm.inputModalities ? { inputModalities: cm.inputModalities } : {}),
795-
...(typeof supportsReasoningSummaries === "boolean" ? { supportsReasoningSummaries } : {}),
796800
};
797-
// Vision-sidecar coverage ONLY: if the custom model is in the enriched provider's
798-
// noVisionModels, advertise image input so the Codex app lets images reach the sidecar
799-
// (#349/#344). Deliberately NOT the full applyProviderConfigHints pass — custom rows are a
800-
// user override, so their explicit contextWindow / inputModalities / reasoning fields must be
801-
// preserved verbatim (the hint pass would cap context and overwrite modalities from registry).
802-
const enrichedProvider = enrichedByName.get(cm.provider) ?? rawProvider;
801+
// Explicit custom modalities win over hints, but noVisionModels still needs to append image
802+
// so the Codex app permits attachments to reach the proxy's vision sidecar.
803803
if (enrichedProvider && modelInList(enrichedProvider.noVisionModels, base.id)) {
804804
const current = base.inputModalities ?? ["text"];
805805
if (!current.includes("image")) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { expect, test } from "bun:test";
2+
import { buildCatalogEntries, gatherRoutedModels } from "../src/codex/catalog";
3+
4+
test("custom rows retain declared metadata while inheriting provider capability hints", async () => {
5+
const models = await gatherRoutedModels({
6+
port: 10100,
7+
defaultProvider: "ollama",
8+
providers: {
9+
ollama: {
10+
adapter: "openai-chat",
11+
baseUrl: "http://127.0.0.1:11434/v1",
12+
liveModels: false,
13+
models: ["qwen-coder-3b"],
14+
modelContextWindows: { "qwen-coder-3b": 32_768 },
15+
modelInputModalities: { "qwen-coder-3b": ["text", "image"] },
16+
modelReasoningEfforts: { "qwen-coder-3b": [] },
17+
},
18+
},
19+
customModels: [{
20+
id: "qwen-coder-3b-custom",
21+
provider: "ollama",
22+
modelId: "qwen-coder-3b",
23+
displayName: "Qwen Coder 3B",
24+
contextWindow: 65_536,
25+
inputModalities: ["text"],
26+
addedAt: "2026-08-03T00:00:00.000Z",
27+
}],
28+
});
29+
30+
const custom = models.filter(model => model.provider === "ollama" && model.id === "qwen-coder-3b");
31+
expect(custom).toHaveLength(1);
32+
expect(custom[0]).toMatchObject({
33+
displayName: "Qwen Coder 3B",
34+
contextWindow: 65_536,
35+
inputModalities: ["text"],
36+
reasoningEfforts: [],
37+
});
38+
39+
const entry = buildCatalogEntries(null, [], models).find(candidate => candidate.slug === "ollama/qwen-coder-3b");
40+
expect(entry?.supported_reasoning_levels).toEqual([]);
41+
expect(entry).not.toHaveProperty("default_reasoning_level");
42+
});

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

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ describe("vision-sidecar custom-model override (#349/#344)", () => {
5656
// vision sidecar could run. The image augmentation must come from the REGISTRY-enriched clone,
5757
// so we deliberately do NOT set noVisionModels on the persisted provider — opencode-go's
5858
// registry entry classifies glm-5.2 as text-only, and enrichment must supply it.
59-
const originalFetch = globalThis.fetch;
60-
globalThis.fetch = (() => { throw new Error("fetch should not be called"); }) as typeof fetch;
61-
try {
62-
const models = await gatherRoutedModels({
59+
const models = await gatherRoutedModels({
6360
port: 10100,
6461
defaultProvider: "opencode-go",
6562
providers: {
@@ -74,20 +71,14 @@ describe("vision-sidecar custom-model override (#349/#344)", () => {
7471
customModels: [
7572
{ id: "cm-1", provider: "opencode-go", modelId: "glm-5.2", displayName: "GLM 5.2", addedAt: "2026-01-01T00:00:00.000Z" },
7673
],
77-
});
78-
const custom = models.find(m => m.provider === "opencode-go" && m.id === "glm-5.2");
79-
expect(custom).toBeDefined();
80-
expect(custom?.inputModalities).toEqual(["text", "image"]);
81-
} finally {
82-
globalThis.fetch = originalFetch;
83-
}
74+
});
75+
const custom = models.find(m => m.provider === "opencode-go" && m.id === "glm-5.2");
76+
expect(custom).toBeDefined();
77+
expect(custom?.inputModalities).toEqual(["text", "image"]);
8478
});
8579

8680
test("a custom row NOT in noVisionModels keeps its declared modalities untouched", async () => {
87-
const originalFetch = globalThis.fetch;
88-
globalThis.fetch = (() => { throw new Error("fetch should not be called"); }) as typeof fetch;
89-
try {
90-
const models = await gatherRoutedModels({
81+
const models = await gatherRoutedModels({
9182
port: 10100,
9283
defaultProvider: "opencode-go",
9384
providers: {
@@ -103,22 +94,13 @@ describe("vision-sidecar custom-model override (#349/#344)", () => {
10394
customModels: [
10495
{ id: "cm-2", provider: "opencode-go", modelId: "kimi-text", inputModalities: ["text"], addedAt: "2026-01-01T00:00:00.000Z" },
10596
],
106-
});
107-
const custom = models.find(m => m.provider === "opencode-go" && m.id === "kimi-text");
108-
expect(custom?.inputModalities).toEqual(["text"]);
109-
} finally {
110-
globalThis.fetch = originalFetch;
111-
}
97+
});
98+
const custom = models.find(m => m.provider === "opencode-go" && m.id === "kimi-text");
99+
expect(custom?.inputModalities).toEqual(["text"]);
112100
});
113101

114-
test("the image augmentation does NOT overwrite a custom row's explicit context/modalities/reasoning", async () => {
115-
// The augmentation must be narrow: for a noVisionModels custom row we only ADD image; every
116-
// other explicitly configured custom field (contextWindow, extra modalities) stays verbatim,
117-
// and no registry reasoning metadata leaks onto the user override.
118-
const originalFetch = globalThis.fetch;
119-
globalThis.fetch = (() => { throw new Error("fetch should not be called"); }) as typeof fetch;
120-
try {
121-
const models = await gatherRoutedModels({
102+
test("the image augmentation preserves explicit custom fields and canonical provider reasoning", async () => {
103+
const models = await gatherRoutedModels({
122104
port: 10100,
123105
defaultProvider: "opencode-go",
124106
providers: {
@@ -133,17 +115,14 @@ describe("vision-sidecar custom-model override (#349/#344)", () => {
133115
customModels: [
134116
{ id: "cm-3", provider: "opencode-go", modelId: "glm-5.2", contextWindow: 2_000_000, inputModalities: ["text", "video"], addedAt: "2026-01-01T00:00:00.000Z" },
135117
],
136-
});
137-
const custom = models.find(m => m.provider === "opencode-go" && m.id === "glm-5.2");
138-
// image is appended to the user's declared modalities (not replaced), context is preserved,
139-
// and no registry reasoning fields were injected onto the custom override.
140-
expect(custom?.inputModalities).toEqual(["text", "video", "image"]);
141-
expect(custom?.contextWindow).toBe(2_000_000);
142-
expect(custom?.reasoningEfforts).toBeUndefined();
143-
expect(custom?.defaultReasoningEffort).toBeUndefined();
144-
} finally {
145-
globalThis.fetch = originalFetch;
146-
}
118+
});
119+
const custom = models.find(m => m.provider === "opencode-go" && m.id === "glm-5.2");
120+
// image is appended to the user's declared modalities (not replaced), custom context is
121+
// preserved, and the registry-enriched provider supplies its canonical reasoning metadata.
122+
expect(custom?.inputModalities).toEqual(["text", "video", "image"]);
123+
expect(custom?.contextWindow).toBe(2_000_000);
124+
expect(custom?.reasoningEfforts).toEqual(["low", "medium", "high", "xhigh", "max"]);
125+
expect(custom?.defaultReasoningEffort).toBeUndefined();
147126
});
148127
});
149128

0 commit comments

Comments
 (0)