fix: use context_window for [1m] model display instead of total_tokens#117
Merged
graykode merged 4 commits intoMay 13, 2026
Merged
Conversation
total_tokens() includes cache_read which inflates far beyond 200k on normal 200k-window sessions, causing false [1m] display. context_window is already correctly set by context_window_for_model() in the collector. Use it directly.
200.0k → 200k, 1.0M → 1M. Fractional values like 123.4k preserved.
> 200_000 is semantically correct (any window larger than 200k is extended) and handles future window sizes like 500k correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sessions were incorrectly displaying the
[1m]suffix on models that only have a 200k context window.Root cause:
sessions.rswas usingsession.total_tokens() > 200_000to detect 1M context, buttotal_tokens()accumulates all token usage across the entire session lifetime, includingcache_readtokens. Sincecache_readis reused on every turn, a long-running session on a standard 200k model can easily accumulate 200k+ total tokens and trigger a false[1m]display.Additionally,
fmt_tokensalways rendered one decimal place, producing awkward labels like200.0kinstead of200k.Fixes
1. Use
context_windowfor exact[1m]display (sessions.rs)The collector already computes
context_window. The UI should not infer a 1M label from cumulative token totals, and it should not treat every non-200k window as a literal 1M window. Codex can report windows such as 258.4k, which are larger than 200k but are not 1M.2. Drop unnecessary decimal in
fmt_tokens(mod.rs)Fractional values like
123.4kare preserved. Whole numbers get a clean display.3. Regression coverage
Added a sessions-panel regression test for a Codex session with
context_window: 258_400, verifying that the rendered model label does not include[1m].Affected files
src/ui/sessions.rs— use exact 1M detection for the[1m]model suffix and add regression coveragesrc/ui/mod.rs— drop unnecessary decimals infmt_tokens()Testing
cargo test— 137 passedcargo clippy -- -D warnings— passed