diff --git a/src/agents/model-fallback.test.ts b/src/agents/model-fallback.test.ts index 160deb7e1..381da47ff 100644 --- a/src/agents/model-fallback.test.ts +++ b/src/agents/model-fallback.test.ts @@ -213,6 +213,34 @@ describe("runWithModelFallback", () => { expect(calls).toEqual([{ provider: "anthropic", model: "claude-opus-4-5" }]); }); + it("defaults provider/model when missing (regression #946)", async () => { + const cfg = makeCfg({ + agents: { + defaults: { + model: { + primary: "openai/gpt-4.1-mini", + fallbacks: [], + }, + }, + }, + }); + + const calls: Array<{ provider: string; model: string }> = []; + + const result = await runWithModelFallback({ + cfg, + provider: undefined as unknown as string, + model: undefined as unknown as string, + run: async (provider, model) => { + calls.push({ provider, model }); + return "ok"; + }, + }); + + expect(result.result).toBe("ok"); + expect(calls).toEqual([{ provider: "openai", model: "gpt-4.1-mini" }]); + }); + it("falls back on missing API key errors", async () => { const cfg = makeCfg(); const run = vi diff --git a/src/agents/model-fallback.ts b/src/agents/model-fallback.ts index f3d7e7d52..f407a4cbf 100644 --- a/src/agents/model-fallback.ts +++ b/src/agents/model-fallback.ts @@ -119,8 +119,8 @@ function resolveFallbackCandidates(params: { /** Optional explicit fallbacks list; when provided (even empty), replaces agents.defaults.model.fallbacks. */ fallbacksOverride?: string[]; }): ModelCandidate[] { - const provider = params.provider.trim() || DEFAULT_PROVIDER; - const model = params.model.trim() || DEFAULT_MODEL; + const provider = String(params.provider ?? "").trim() || DEFAULT_PROVIDER; + const model = String(params.model ?? "").trim() || DEFAULT_MODEL; const primary = params.cfg ? resolveConfiguredModelRef({ cfg: params.cfg,