Skip to content

Fix Agent Mode context-window reporting#507

Open
BetaFold3 wants to merge 2 commits into
repoprompt:mainfrom
BetaFold3:fix/models-context-window-reporting
Open

Fix Agent Mode context-window reporting#507
BetaFold3 wants to merge 2 commits into
repoprompt:mainfrom
BetaFold3:fix/models-context-window-reporting

Conversation

@BetaFold3

Copy link
Copy Markdown
Contributor

Fixes #506

Why

The context indicator could use three different denominators during one session:

  • a static model maximum before provider activity,
  • the internal 200K fallback while waiting for usage,
  • and the provider-reported window after the first response.

Besides being confusing, this could produce incorrect percentages and silently discard valid usage readings above 200K.

This was especially visible with Codex GPT-5.5 and GPT-5.6: a fresh session could present the 200K internal fallback before runtime usage reported the actual window. GPT-5.5 was observed reporting approximately 258.4K after the first response. 353.4K in case of GPT 5.6.

What changed

  • Resolve Claude’s configured auto-compact window from the effective launch environment and supported Claude settings files.
  • Resolve Codex context configuration from user and project config.toml.
  • Keep canonical model capacity separate from the effective reporting denominator.
  • Show an unknown denominator as instead of exposing the internal 200K fallback as fact.
  • Carry configured Claude limits to the sidebar before the first usage event.
  • Preserve spawn-authoritative values across asynchronous provisional resolution, model changes, and workspace changes.
  • Retain valid large Claude usage readings while the canonical window is still unknown.

Bug found along the way

Claude result events may report usage for several models in the same session, including background Haiku work.

The translator previously selected the first positive modelUsage entry from an unordered dictionary. A background 200K model could therefore replace the main model’s 1M window, causing the sidebar to report 200K after the first response.

This change attributes usage to the tracked main model, handles normalized model variants deterministically, and resets attribution across live model switches and process respawns.

User-visible behavior

  • A 1M-capable Claude model configured to compact at 400K reports 400K consistently, with the 1M model maximum shown separately.
  • Codex GPT-5.5 and GPT-5.6 sessions show an unknown denominator before runtime usage, then switch to the provider-reported value when it arrives.
  • Percentages and warning colors are suppressed while the denominator is unknown.
  • Valid context readings above 200K are no longer dropped before the canonical window is known.

Validation

  • Focused Claude/Codex resolver and context-usage suites
  • make dev-provider-test FILTER=ClaudeSDKNDJSONTranslatorTests
  • make dev-test FILTER=AgentRuntimeSidebarViewModelTests
  • make dev-test FILTER=ClaudeContextUsageEstimatorTests
  • make dev-swift-build PRODUCT=RepoPrompt
  • make dev-lint
  • Authoritative root/provider test lists and test-ledger reconciliation
  • Manual CE debug-app checks for Claude 400K and Codex unknown-to-runtime-window transitions

Resolve configured Claude and Codex context limits while keeping the
canonical model maximum separate from the effective denominator.

Attribute Claude modelUsage to the active model, preserve valid large
usage readings, and avoid presenting unknown fallback windows as facts.

Add focused resolver, lifecycle, usage, translator, and sidebar coverage.
Upstream added the MCPAskOracleWorktreeTests git-diff-artifact row
independently after this branch had added it as a missing-row fix; the
rebase merge kept both copies and CI's strict-ledger duplicate gate
failed all app-test shards. Keep upstream's row, drop the duplicate.
@BetaFold3 BetaFold3 force-pushed the fix/models-context-window-reporting branch from c2a5aa2 to 3c4c9eb Compare July 11, 2026 23:32
@BetaFold3

Copy link
Copy Markdown
Contributor Author

This PR does not modify the failing test or Codemap implementation. Mind helping with the re-trigger? @baron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent Mode reports incorrect context windows for Claude and Codex sessions

1 participant