Skip to content

Commit 26ec201

Browse files
committed
fix(agents): preserve provider catalog defaults
1 parent 4362256 commit 26ec201

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎src/agents/model-catalog.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,47 @@ describe("loadModelCatalog", () => {
344344
expect(augmentCatalogMock).not.toHaveBeenCalled();
345345
});
346346

347+
it("preserves provider context defaults for persisted read-only catalog rows", async () => {
348+
readFileMock.mockResolvedValueOnce(
349+
JSON.stringify({
350+
providers: {
351+
custom: {
352+
contextWindow: 262144,
353+
models: [
354+
{ id: "inherits-provider-context" },
355+
{ id: "overrides-context", contextWindow: 65536 },
356+
],
357+
},
358+
},
359+
}),
360+
);
361+
362+
const result = await loadModelCatalog({ config: {} as OpenClawConfig, readOnly: true });
363+
364+
expect(result).toEqual([
365+
{
366+
provider: "custom",
367+
id: "inherits-provider-context",
368+
name: "inherits-provider-context",
369+
reasoning: false,
370+
contextWindow: 262144,
371+
input: ["text"],
372+
compat: undefined,
373+
},
374+
{
375+
provider: "custom",
376+
id: "overrides-context",
377+
name: "overrides-context",
378+
reasoning: false,
379+
contextWindow: 65536,
380+
input: ["text"],
381+
compat: undefined,
382+
},
383+
]);
384+
expect(ensureOpenClawModelsJsonMock).not.toHaveBeenCalled();
385+
expect(augmentCatalogMock).not.toHaveBeenCalled();
386+
});
387+
347388
it("does not synthesize stale openai-codex/gpt-5.3-codex-spark entries from gpt-5.4", async () => {
348389
mockPiDiscoveryModels([
349390
{

‎src/agents/model-catalog.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ function sortModelCatalogEntries(entries: ModelCatalogEntry[]): ModelCatalogEntr
176176
function normalizePersistedModelCatalogEntry(
177177
providerRaw: string,
178178
entry: Record<string, unknown>,
179+
defaults?: {
180+
contextWindow?: number;
181+
},
179182
): ModelCatalogEntry | undefined {
180183
const id = normalizeOptionalString(entry.id) ?? "";
181184
if (!id) {
@@ -189,7 +192,9 @@ function normalizePersistedModelCatalogEntry(
189192
const contextWindow =
190193
typeof entry?.contextWindow === "number" && entry.contextWindow > 0
191194
? entry.contextWindow
192-
: PI_CUSTOM_MODEL_DEFAULT_CONTEXT_WINDOW;
195+
: defaults?.contextWindow !== undefined
196+
? defaults.contextWindow
197+
: PI_CUSTOM_MODEL_DEFAULT_CONTEXT_WINDOW;
193198
const reasoning = typeof entry?.reasoning === "boolean" ? entry.reasoning : false;
194199
const parsedInput = Array.isArray(entry?.input)
195200
? entry.input.filter((value): value is ModelInputType =>
@@ -222,8 +227,14 @@ async function loadReadOnlyPersistedModelCatalog(params?: {
222227
if (!Array.isArray(providerConfig?.models)) {
223228
continue;
224229
}
230+
const providerContextWindow =
231+
typeof providerConfig?.contextWindow === "number" && providerConfig.contextWindow > 0
232+
? providerConfig.contextWindow
233+
: undefined;
225234
for (const entry of providerConfig.models as Record<string, unknown>[]) {
226-
const normalized = normalizePersistedModelCatalogEntry(providerRaw, entry);
235+
const normalized = normalizePersistedModelCatalogEntry(providerRaw, entry, {
236+
contextWindow: providerContextWindow,
237+
});
227238
if (normalized && !shouldSuppressBuiltInModel(normalized)) {
228239
models.push(normalized);
229240
}

0 commit comments

Comments
 (0)