fix: suppress low context window warning for explicitly configured models

When a model's contextWindow is explicitly set in modelsConfig (openclaw.json),
don't warn about it being below 32k. The user deliberately chose that value.

The warning still fires for auto-detected (model metadata) and default sources.
shouldBlock is unaffected — hard minimum still enforced regardless of source.

Closes #13933
This commit is contained in:
Tarun Sukhani
2026-02-11 15:28:53 +08:00
parent 0149f39e72
commit 8086915187
2 changed files with 38 additions and 1 deletions

View File

@@ -142,6 +142,43 @@ describe("context-window-guard", () => {
expect(guard.shouldBlock).toBe(false);
});
it("does not warn when context window is explicitly configured via modelsConfig", () => {
const cfg = {
models: {
providers: {
ollama: {
baseUrl: "http://localhost:11434/v1",
apiKey: "x",
models: [
{
id: "qwen2.5:7b-2k",
name: "Qwen 2.5 7B 2k",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 2_048,
maxTokens: 2_048,
},
],
},
},
},
} satisfies OpenClawConfig;
const info = resolveContextWindowInfo({
cfg,
provider: "ollama",
modelId: "qwen2.5:7b-2k",
modelContextWindow: undefined,
defaultTokens: 200_000,
});
const guard = evaluateContextWindowGuard({ info });
expect(info.source).toBe("modelsConfig");
expect(guard.tokens).toBe(2_048);
expect(guard.shouldWarn).toBe(false);
expect(guard.shouldBlock).toBe(true);
});
it("exports thresholds as expected", () => {
expect(CONTEXT_WINDOW_HARD_MIN_TOKENS).toBe(1_024);
expect(CONTEXT_WINDOW_WARN_BELOW_TOKENS).toBe(32_000);

View File

@@ -68,7 +68,7 @@ export function evaluateContextWindowGuard(params: {
return {
...params.info,
tokens,
shouldWarn: tokens > 0 && tokens < warnBelow,
shouldWarn: tokens > 0 && tokens < warnBelow && params.info.source !== "modelsConfig",
shouldBlock: tokens > 0 && tokens < hardMin,
};
}