fix(shared): return GA 1M context limit for Anthropic 4.6/4.7 models without cached entry
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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -158,6 +158,76 @@ describe("resolveActualContextLimit", () => {
|
|||||||
expect(actualLimit).toBe(200_000)
|
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", () => {
|
it("returns null for non-Anthropic providers without a cached limit", () => {
|
||||||
// given
|
// given
|
||||||
delete process.env[ANTHROPIC_CONTEXT_ENV_KEY]
|
delete process.env[ANTHROPIC_CONTEXT_ENV_KEY]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import process from "node:process"
|
import process from "node:process"
|
||||||
|
|
||||||
const DEFAULT_ANTHROPIC_ACTUAL_LIMIT = 200_000
|
const DEFAULT_ANTHROPIC_ACTUAL_LIMIT = 200_000
|
||||||
|
const ANTHROPIC_GA_1M_LIMIT = 1_000_000
|
||||||
export type ContextLimitModelCacheState = {
|
export type ContextLimitModelCacheState = {
|
||||||
anthropicContext1MEnabled: boolean
|
anthropicContext1MEnabled: boolean
|
||||||
modelContextLimitsCache?: Map<string, number>
|
modelContextLimitsCache?: Map<string, number>
|
||||||
@@ -15,11 +16,11 @@ function getAnthropicActualLimit(modelCacheState?: ContextLimitModelCacheState):
|
|||||||
return (modelCacheState?.anthropicContext1MEnabled ?? false) ||
|
return (modelCacheState?.anthropicContext1MEnabled ?? false) ||
|
||||||
process.env.ANTHROPIC_1M_CONTEXT === "true" ||
|
process.env.ANTHROPIC_1M_CONTEXT === "true" ||
|
||||||
process.env.VERTEX_ANTHROPIC_1M_CONTEXT === "true"
|
process.env.VERTEX_ANTHROPIC_1M_CONTEXT === "true"
|
||||||
? 1_000_000
|
? ANTHROPIC_GA_1M_LIMIT
|
||||||
: DEFAULT_ANTHROPIC_ACTUAL_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)
|
return /^claude-(opus|sonnet)-4(?:-|\.)(?:6|7)(?:-high)?$/.test(modelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,10 +31,12 @@ export function resolveActualContextLimit(
|
|||||||
): number | null {
|
): number | null {
|
||||||
if (isAnthropicProvider(providerID)) {
|
if (isAnthropicProvider(providerID)) {
|
||||||
const explicit1M = getAnthropicActualLimit(modelCacheState)
|
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}`)
|
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
|
return DEFAULT_ANTHROPIC_ACTUAL_LIMIT
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user