fix: prioritize Anthropic 1M limits over cached context limits

This commit is contained in:
YeonGyu-Kim
2026-03-11 20:38:44 +09:00
parent d40d686014
commit 4516b2e484
4 changed files with 84 additions and 11 deletions
@@ -90,4 +90,48 @@ describe("context-window-monitor modelContextLimitsCache", () => {
expect(output.output).toContain("[Context Status: 72.5% used (190,000/262,144 tokens), 27.5% remaining]")
expect(output.output).not.toContain("1,000,000")
})
describe("#given Anthropic provider with cached context limit and 1M mode enabled", () => {
describe("#when cached usage would exceed 200K but stay below 1M", () => {
it("#then should ignore the cached limit and skip the reminder", async () => {
// given
const modelContextLimitsCache = new Map<string, number>()
modelContextLimitsCache.set("anthropic/claude-sonnet-4-5", 200000)
const hook = createContextWindowMonitorHook({} as never, {
anthropicContext1MEnabled: true,
modelContextLimitsCache,
})
const sessionID = "ses_anthropic_1m_overrides_cached_limit"
await hook.event({
event: {
type: "message.updated",
properties: {
info: {
role: "assistant",
sessionID,
providerID: "anthropic",
modelID: "claude-sonnet-4-5",
finish: true,
tokens: {
input: 300000,
output: 0,
reasoning: 0,
cache: { read: 0, write: 0 },
},
},
},
},
})
// when
const output = createOutput()
await hook["tool.execute.after"]({ tool: "bash", sessionID, callID: "call_1" }, output)
// then
expect(output.output).toBe("original")
})
})
})
})