Skip to content

Commit c5565d0

Browse files
committed
fix(catalog): custom model rows inherit provider reasoning metadata
1 parent cb8fcf3 commit c5565d0

2 files changed

Lines changed: 82 additions & 4 deletions

File tree

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@ async function gatherRoutedModelsUncached(
782782
// Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
783783
// custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
784784
const enrichedByName = new Map(activeProviders);
785+
// Provider-derived rows keyed by their Codex-facing slug: a custom override replaces the row
786+
// with the same slug below, so that row's provider capability metadata is the inheritance source.
787+
const replacedByRoutedSlug = new Map(all.map(model => [routedSlug(model.provider, model.id), model]));
785788
const customModels = (config.customModels ?? []).map(cm => {
786789
const rawProvider = config.providers[cm.provider];
787790
const supportsReasoningSummaries = configuredReasoningSummarySupport(rawProvider, cm.modelId);
@@ -794,19 +797,38 @@ async function gatherRoutedModelsUncached(
794797
...(cm.inputModalities ? { inputModalities: cm.inputModalities } : {}),
795798
...(typeof supportsReasoningSummaries === "boolean" ? { supportsReasoningSummaries } : {}),
796799
};
800+
// #962: the dedupe below drops the provider-derived row this custom row replaces. Inherit that
801+
// row's provider capability metadata (reasoning ladder, default effort, parallel tool calls,
802+
// context, ...) so the generated catalog keeps advertising what the router actually provides.
803+
// Explicit custom fields win by construction; this only fills gaps. Without it a
804+
// noReasoningModels model loses its empty ladder and the catalog synthesizes the generic one,
805+
// which Codex then rejects for spawn_agent with effort "none".
806+
const replaced = replacedByRoutedSlug.get(routedSlug(cm.provider, cm.modelId));
807+
const merged: CatalogModel = replaced ? {
808+
...base,
809+
...(base.contextWindow === undefined && replaced.contextWindow !== undefined ? { contextWindow: replaced.contextWindow } : {}),
810+
...(base.maxInputTokens === undefined && replaced.maxInputTokens !== undefined ? { maxInputTokens: replaced.maxInputTokens } : {}),
811+
...(base.inputModalities === undefined && replaced.inputModalities !== undefined ? { inputModalities: replaced.inputModalities } : {}),
812+
...(base.reasoningEfforts === undefined && replaced.reasoningEfforts !== undefined ? { reasoningEfforts: replaced.reasoningEfforts } : {}),
813+
...(base.defaultReasoningEffort === undefined && replaced.defaultReasoningEffort !== undefined ? { defaultReasoningEffort: replaced.defaultReasoningEffort } : {}),
814+
...(base.parallelToolCalls === undefined && replaced.parallelToolCalls !== undefined ? { parallelToolCalls: replaced.parallelToolCalls } : {}),
815+
...(base.supportsVerbosity === undefined && replaced.supportsVerbosity !== undefined ? { supportsVerbosity: replaced.supportsVerbosity } : {}),
816+
...(base.supportsReasoningSummaries === undefined && replaced.supportsReasoningSummaries !== undefined ? { supportsReasoningSummaries: replaced.supportsReasoningSummaries } : {}),
817+
...(base.capabilities === undefined && replaced.capabilities !== undefined ? { capabilities: replaced.capabilities } : {}),
818+
} : base;
797819
// Vision-sidecar coverage ONLY: if the custom model is in the enriched provider's
798820
// noVisionModels, advertise image input so the Codex app lets images reach the sidecar
799821
// (#349/#344). Deliberately NOT the full applyProviderConfigHints pass — custom rows are a
800822
// user override, so their explicit contextWindow / inputModalities / reasoning fields must be
801823
// preserved verbatim (the hint pass would cap context and overwrite modalities from registry).
802824
const enrichedProvider = enrichedByName.get(cm.provider) ?? rawProvider;
803-
if (enrichedProvider && modelInList(enrichedProvider.noVisionModels, base.id)) {
804-
const current = base.inputModalities ?? ["text"];
825+
if (enrichedProvider && modelInList(enrichedProvider.noVisionModels, merged.id)) {
826+
const current = merged.inputModalities ?? ["text"];
805827
if (!current.includes("image")) {
806-
return { ...base, inputModalities: [...current, "image"] };
828+
return { ...merged, inputModalities: [...current, "image"] };
807829
}
808830
}
809-
return base;
831+
return merged;
810832
});
811833
// Custom rows override discovered rows that encode to the same Codex-facing slug.
812834
const customKeys = new Set(customModels.map(c => routedSlug(c.provider, c.id)));

‎tests/codex-catalog.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,62 @@ describe("configured CatalogModel displayName -> catalog display_name", () => {
848848
});
849849
});
850850

851+
test("a custom row inherits provider reasoning metadata from the provider-derived row it replaces (#962)", async () => {
852+
clearModelCache("ollama");
853+
const originalFetch = globalThis.fetch;
854+
globalThis.fetch = (() => { throw new Error("fetch should not be called"); }) as typeof fetch;
855+
try {
856+
const models = await gatherRoutedModels({
857+
port: 10100,
858+
defaultProvider: "ollama",
859+
providers: {
860+
ollama: {
861+
baseUrl: "http://localhost:11434/v1",
862+
adapter: "openai-chat",
863+
authMode: "key",
864+
liveModels: false,
865+
models: ["qwen-coder-3b"],
866+
selectedModels: ["qwen-coder-3b"],
867+
noReasoningModels: ["qwen-coder-3b"],
868+
modelReasoningEfforts: { "qwen-coder-3b": [] },
869+
},
870+
},
871+
customModels: [
872+
{
873+
id: "cm-962",
874+
provider: "ollama",
875+
modelId: "qwen-coder-3b",
876+
displayName: "Qwen Coder 3B (local)",
877+
contextWindow: 32768,
878+
inputModalities: ["text"],
879+
addedAt: "2026-01-01T00:00:00.000Z",
880+
},
881+
],
882+
});
883+
884+
// Explicit custom fields stay verbatim; provider capability metadata is inherited from the
885+
// replaced provider-derived row (noReasoningModels -> empty reasoning ladder, openai-chat
886+
// adapter -> parallel tool calls).
887+
const custom = models.find(m => m.provider === "ollama" && m.id === "qwen-coder-3b");
888+
expect(custom?.displayName).toBe("Qwen Coder 3B (local)");
889+
expect(custom?.contextWindow).toBe(32768);
890+
expect(custom?.inputModalities).toEqual(["text"]);
891+
expect(custom?.reasoningEfforts).toEqual([]);
892+
expect(custom?.parallelToolCalls).toBe(true);
893+
894+
const entries = buildCatalogEntries(nativeTemplate(), [], models);
895+
const row = entries.find(e => e.slug === "ollama/qwen-coder-3b");
896+
expect(row?.display_name).toBe("Qwen Coder 3B (local)");
897+
// The catalog must expose no reasoning levels and no default reasoning level for this model;
898+
// the generic low..ultra ladder and the medium default must not be synthesized.
899+
expect(row?.supported_reasoning_levels).toEqual([]);
900+
expect(row?.default_reasoning_level).toBeUndefined();
901+
} finally {
902+
globalThis.fetch = originalFetch;
903+
clearModelCache("ollama");
904+
}
905+
});
906+
851907
function openAiApiCatalogConfig(overrides: Record<string, unknown> = {}): OcxConfig {
852908
return {
853909
port: 10100,

0 commit comments

Comments
 (0)