fix(agents): warn clearly on unresolved model ids (#39215, thanks @ademczuk)

Co-authored-by: ademczuk <andrew.demczuk@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-07 22:50:27 +00:00
parent 3a761fbcf8
commit e83094e63f
7 changed files with 105 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import os from "node:os";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
import type { AuthProfileStore } from "./auth-profiles.js";
import { saveAuthProfileStore } from "./auth-profiles.js";
import { AUTH_STORE_VERSION } from "./auth-profiles/constants.js";
@@ -489,6 +490,34 @@ describe("runWithModelFallback", () => {
expect(run.mock.calls[1]?.[1]).toBe("claude-haiku-3-5");
});
it("warns when falling back due to model_not_found", async () => {
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
try {
const cfg = makeCfg();
const run = vi
.fn()
.mockRejectedValueOnce(new Error("Model not found: openai/gpt-6"))
.mockResolvedValueOnce("ok");
const result = await runWithModelFallback({
cfg,
provider: "openai",
model: "gpt-6",
run,
});
expect(result.result).toBe("ok");
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining('Model "openai/gpt-6" not found'),
);
} finally {
warnSpy.mockRestore();
setLoggerOverride(null);
resetLogger();
}
});
it("skips providers when all profiles are in cooldown", async () => {
await expectSkippedUnavailableProvider({
providerPrefix: "cooldown-test",