Repository navigation
refactor: make context counters model-specific (1M-context models) + re-sync model catalog (#1521) - #1524
Conversation
…nc model catalog (#1521) Replace ~15 scattered hardcoded 200000 context-window denominators with one model→context-window catalog so the "% context used" gauge is correct for 1M-context models (Opus 4.8/4.7, Sonnet 5, Fable 5, Gemini = 1M; Codex = 272K). The runtime-reported modelUsage.contextWindow stays PRIMARY; the catalog is the FALLBACK only — bare Claude → 200K safe floor, [1m] → 1M, Gemini → 1M, Codex → 272K, unknown → 200K + logged warning. The bare-Claude floor is deliberate: the effective window is auth/plan-dependent, so a fixed 1M fallback would hide an imminent 200K compaction wall. - New pure-stdlib services/model_context.py, vendored byte-identically into the agent server (Invariant #5, parity-tested). - Unify 5 disagreeing agent-server resolvers (state.py, claude_code, gemini, codex, the ABC) via the catalog. Seed metadata.context_window at construction in the Claude + headless paths — the real Claude fallback, since get_context_window is dead code for Claude and the flat Pydantic default was the actual fallback. Fix state.py init-ordering so a [1m] agent reports 1M before its first turn. The non-abstract ABC default means a new runtime can't ship a silently-wrong 200K. - Backend downstream fallbacks use the shared DEFAULT_CONTEXT_WINDOW constant. - Re-sync ModelSelector presets (add Fable 5, Sonnet 5) + agent-server alias note. - No schema change (columns/DDL unchanged; only written values become correct). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…text-windows # Conflicts: # tests/registry.json
|
Review (direct). Consolidates scattered Strengths: total function (bounded output, never raises); the safe-floor invariant is the right call — bare Claude ids resolve to the guaranteed 200K floor (over-report usage = safe) rather than the 1M ceiling (which would hide a 200K compaction wall), with Notes (non-blocking):
Merge conflict in |
Summary
% context usedgauge assumed a flat 200K window, reading up to ~5× too high on 1M-context models (Opus 4.8/4.7, Sonnet 5, Fable 5 = 1M; Gemini = 1M; Codex = 272K). This consolidates ~15 scattered200000literals + the 5 disagreeing agent-server resolvers into one model→context-window catalog.modelUsage.contextWindowstays primary (only it knows the effective plan/auth/beta window); the catalog is the fallback — bare Claude → 200K safe floor,[1m]→ 1M, Gemini → 1M, Codex → 272K, unknown → 200K + logged warning.Changes
src/backend/services/model_context.py— pure-stdlib catalog (resolve_context_window+DEFAULT_CONTEXT_WINDOW), vendored byte-identically intodocker/base-image/agent_server/model_context.py(Invariant Setup improvements #5, parity-tested).ClaudeCodeRuntime.get_context_windowwas dead code — the real Claude fallback was the staticExecutionMetadata.context_window = 200000default. Now the catalog seedsmetadata.context_windowat construction in the Claude + headless paths (the stream value overrides it), guarded by a regression test.state.py,claude_code,gemini_runtime,codex_runtime, ABC-now-non-abstract); fixedstate.pyinit-ordering so a[1m]agent reports 1M pre-first-turn.or 200000→or DEFAULT_CONTEXT_WINDOW.ModelSelector.vuepresets (added Fable 5, Sonnet 5) + agent-server alias note.architecture.md(Context-window catalog note),model-selection.md,learnings.md.Test Plan
pytest tests/unit/test_model_context_catalog.py tests/unit/test_model_context_parity.py— 35 pass (resolution table incl.[1m]/unknown/None, byte-parity, Claude-metadata seed regression, AgentState init-ordering)fork_to_own/capacity_manager— pass in isolation, don't touch this code)/review→ 0 criticalFixes #1521
🤖 Generated with Claude Code