fix: cap context window resolution (#6187) (thanks @iamEvanYT)

This commit is contained in:
Ayaan Zaidi
2026-02-01 19:49:35 +05:30
committed by Ayaan Zaidi
parent 5d3c898a94
commit 0992c5a809
7 changed files with 50 additions and 58 deletions

View File

@@ -77,7 +77,7 @@ describe("context-window-guard", () => {
cfg,
provider: "openrouter",
modelId: "tiny",
modelContextWindow: undefined,
modelContextWindow: 64_000,
defaultTokens: 200_000,
});
const guard = evaluateContextWindowGuard({ info });
@@ -85,7 +85,7 @@ describe("context-window-guard", () => {
expect(guard.shouldBlock).toBe(true);
});
it("falls back to agents.defaults.contextTokens", () => {
it("caps with agents.defaults.contextTokens", () => {
const cfg = {
agents: { defaults: { contextTokens: 20_000 } },
} satisfies OpenClawConfig;
@@ -93,7 +93,7 @@ describe("context-window-guard", () => {
cfg,
provider: "anthropic",
modelId: "whatever",
modelContextWindow: undefined,
modelContextWindow: 200_000,
defaultTokens: 200_000,
});
const guard = evaluateContextWindowGuard({ info });
@@ -102,6 +102,21 @@ describe("context-window-guard", () => {
expect(guard.shouldBlock).toBe(false);
});
it("does not override when cap exceeds base window", () => {
const cfg = {
agents: { defaults: { contextTokens: 128_000 } },
} satisfies OpenClawConfig;
const info = resolveContextWindowInfo({
cfg,
provider: "anthropic",
modelId: "whatever",
modelContextWindow: 64_000,
defaultTokens: 200_000,
});
expect(info.source).toBe("model");
expect(info.tokens).toBe(64_000);
});
it("uses default when nothing else is available", () => {
const info = resolveContextWindowInfo({
cfg: undefined,