Files
oh-my-opencode/src/shared/context-limit-resolver.ts
T
YeonGyu-Kim b9a8ffec51 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>
2026-05-18 13:36:01 +09:00

46 lines
1.6 KiB
TypeScript

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<string, number>
}
function isAnthropicProvider(providerID: string): boolean {
const normalized = providerID.toLowerCase()
return normalized === "anthropic" || normalized === "google-vertex-anthropic" || normalized === "aws-bedrock-anthropic"
}
function getAnthropicActualLimit(modelCacheState?: ContextLimitModelCacheState): number {
return (modelCacheState?.anthropicContext1MEnabled ?? false) ||
process.env.ANTHROPIC_1M_CONTEXT === "true" ||
process.env.VERTEX_ANTHROPIC_1M_CONTEXT === "true"
? ANTHROPIC_GA_1M_LIMIT
: DEFAULT_ANTHROPIC_ACTUAL_LIMIT
}
function hasGA1MContext(modelID: string): boolean {
return /^claude-(opus|sonnet)-4(?:-|\.)(?:6|7)(?:-high)?$/.test(modelID)
}
export function resolveActualContextLimit(
providerID: string,
modelID: string,
modelCacheState?: ContextLimitModelCacheState,
): number | null {
if (isAnthropicProvider(providerID)) {
const explicit1M = getAnthropicActualLimit(modelCacheState)
if (explicit1M === ANTHROPIC_GA_1M_LIMIT) return explicit1M
const cachedLimit = modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`)
if (cachedLimit && hasGA1MContext(modelID)) return cachedLimit
if (hasGA1MContext(modelID)) return ANTHROPIC_GA_1M_LIMIT
return DEFAULT_ANTHROPIC_ACTUAL_LIMIT
}
return modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`) ?? null
}