From b9a8ffec51a426831e90fae9a68cb8b459b03605 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 18 May 2026 13:36:01 +0900 Subject: [PATCH 1/2] fix(shared): return GA 1M context limit for Anthropic 4.6/4.7 models without cached entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Anthropic made the 1M context window GA for Opus 4.6, Sonnet 4.6, and 4.7 models on March 13, 2026 — no beta header required. The resolver was still falling back to 200K when no modelContextLimitsCache entry existed, causing premature compaction and over-truncation. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/shared/context-limit-resolver.test.ts | 70 +++++++++++++++++++++++ src/shared/context-limit-resolver.ts | 11 ++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/shared/context-limit-resolver.test.ts b/src/shared/context-limit-resolver.test.ts index d924d8a99..10ded16e5 100644 --- a/src/shared/context-limit-resolver.test.ts +++ b/src/shared/context-limit-resolver.test.ts @@ -158,6 +158,76 @@ describe("resolveActualContextLimit", () => { expect(actualLimit).toBe(200_000) }) + it("returns GA 1M for claude-sonnet-4-6 without cached limit (GA context window)", () => { + // given + delete process.env[ANTHROPIC_CONTEXT_ENV_KEY] + delete process.env[VERTEX_CONTEXT_ENV_KEY] + + // when + const actualLimit = resolveActualContextLimit("anthropic", "claude-sonnet-4-6", { + anthropicContext1MEnabled: false, + }) + + // then + expect(actualLimit).toBe(1_000_000) + }) + + it("returns GA 1M for claude-opus-4-6 without cached limit (GA context window)", () => { + // given + delete process.env[ANTHROPIC_CONTEXT_ENV_KEY] + delete process.env[VERTEX_CONTEXT_ENV_KEY] + + // when + const actualLimit = resolveActualContextLimit("anthropic", "claude-opus-4-6", { + anthropicContext1MEnabled: false, + }) + + // then + expect(actualLimit).toBe(1_000_000) + }) + + it("returns GA 1M for claude-opus-4-7 without cached limit (GA context window)", () => { + // given + delete process.env[ANTHROPIC_CONTEXT_ENV_KEY] + delete process.env[VERTEX_CONTEXT_ENV_KEY] + + // when + const actualLimit = resolveActualContextLimit("anthropic", "claude-opus-4-7", { + anthropicContext1MEnabled: false, + }) + + // then + expect(actualLimit).toBe(1_000_000) + }) + + it("returns GA 1M for claude-sonnet-4-6-high without cached limit (GA context window)", () => { + // given + delete process.env[ANTHROPIC_CONTEXT_ENV_KEY] + delete process.env[VERTEX_CONTEXT_ENV_KEY] + + // when + const actualLimit = resolveActualContextLimit("anthropic", "claude-sonnet-4-6-high", { + anthropicContext1MEnabled: false, + }) + + // then + expect(actualLimit).toBe(1_000_000) + }) + + it("returns GA 1M for GA models on google-vertex-anthropic without cached limit", () => { + // given + delete process.env[ANTHROPIC_CONTEXT_ENV_KEY] + delete process.env[VERTEX_CONTEXT_ENV_KEY] + + // when + const actualLimit = resolveActualContextLimit("google-vertex-anthropic", "claude-sonnet-4-6", { + anthropicContext1MEnabled: false, + }) + + // then + expect(actualLimit).toBe(1_000_000) + }) + it("returns null for non-Anthropic providers without a cached limit", () => { // given delete process.env[ANTHROPIC_CONTEXT_ENV_KEY] diff --git a/src/shared/context-limit-resolver.ts b/src/shared/context-limit-resolver.ts index 2d440658b..ee7e23a18 100644 --- a/src/shared/context-limit-resolver.ts +++ b/src/shared/context-limit-resolver.ts @@ -1,6 +1,7 @@ import process from "node:process" const DEFAULT_ANTHROPIC_ACTUAL_LIMIT = 200_000 +const ANTHROPIC_GA_1M_LIMIT = 1_000_000 export type ContextLimitModelCacheState = { anthropicContext1MEnabled: boolean modelContextLimitsCache?: Map @@ -15,11 +16,11 @@ function getAnthropicActualLimit(modelCacheState?: ContextLimitModelCacheState): return (modelCacheState?.anthropicContext1MEnabled ?? false) || process.env.ANTHROPIC_1M_CONTEXT === "true" || process.env.VERTEX_ANTHROPIC_1M_CONTEXT === "true" - ? 1_000_000 + ? ANTHROPIC_GA_1M_LIMIT : DEFAULT_ANTHROPIC_ACTUAL_LIMIT } -function supportsCachedAnthropicLimit(modelID: string): boolean { +function hasGA1MContext(modelID: string): boolean { return /^claude-(opus|sonnet)-4(?:-|\.)(?:6|7)(?:-high)?$/.test(modelID) } @@ -30,10 +31,12 @@ export function resolveActualContextLimit( ): number | null { if (isAnthropicProvider(providerID)) { const explicit1M = getAnthropicActualLimit(modelCacheState) - if (explicit1M === 1_000_000) return explicit1M + if (explicit1M === ANTHROPIC_GA_1M_LIMIT) return explicit1M const cachedLimit = modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`) - if (cachedLimit && supportsCachedAnthropicLimit(modelID)) return cachedLimit + if (cachedLimit && hasGA1MContext(modelID)) return cachedLimit + + if (hasGA1MContext(modelID)) return ANTHROPIC_GA_1M_LIMIT return DEFAULT_ANTHROPIC_ACTUAL_LIMIT } From 35df9119197c8d96548d7ab76b19b6b9d98af5a0 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 18 May 2026 13:36:17 +0900 Subject: [PATCH 2/2] test(hooks): update preemptive-compaction token thresholds for GA 1M context Raise test token counts from 170K/180K to 800K/810K so compaction triggers at 78% of 1M instead of 78% of 200K, matching the actual GA context limit for 4.6 models. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../preemptive-compaction.aws-bedrock.test.ts | 2 +- src/hooks/preemptive-compaction.test.ts | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hooks/preemptive-compaction.aws-bedrock.test.ts b/src/hooks/preemptive-compaction.aws-bedrock.test.ts index 9ce47ac8c..ce4174a29 100644 --- a/src/hooks/preemptive-compaction.aws-bedrock.test.ts +++ b/src/hooks/preemptive-compaction.aws-bedrock.test.ts @@ -42,7 +42,7 @@ describe("preemptive-compaction aws-bedrock-anthropic", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 1000, reasoning: 0, cache: { read: 10000, write: 0 }, diff --git a/src/hooks/preemptive-compaction.test.ts b/src/hooks/preemptive-compaction.test.ts index ebf90c208..f7b7344c6 100644 --- a/src/hooks/preemptive-compaction.test.ts +++ b/src/hooks/preemptive-compaction.test.ts @@ -142,7 +142,7 @@ describe("preemptive-compaction", () => { const hook = createPreemptiveCompactionHook(ctx as never, {} as never) const sessionID = "ses_high" - // 170K input + 10K cache = 180K → 90% of 200K + // 800K input + 10K cache = 810K → 81% of 1M (GA limit for 4.6 models) await hook.event({ event: { type: "message.updated", @@ -154,7 +154,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 1000, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -190,7 +190,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 1000, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -267,7 +267,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -313,7 +313,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -357,7 +357,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -386,7 +386,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -504,7 +504,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -544,7 +544,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -576,7 +576,7 @@ describe("preemptive-compaction", () => { const hook = createPreemptiveCompactionHook(ctx as never, {} as never) const sessionID = "ses_recompact" - // given - first compaction cycle + // given - first compaction cycle (810K > 78% of 1M GA limit) await hook.event({ event: { type: "message.updated", @@ -588,7 +588,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -619,7 +619,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 }, @@ -657,7 +657,7 @@ describe("preemptive-compaction", () => { modelID: "claude-sonnet-4-6", finish: true, tokens: { - input: 170000, + input: 800000, output: 0, reasoning: 0, cache: { read: 10000, write: 0 },