#15126: fix(status): avoid false 100% context usage when totals mirror context
stale
size: XS
Cluster:
Context Management Fixes
## Summary
Fixes #15114.
`/status` could report a misleading `100%` context usage when `contextUsageInput` and `totalInput` had the same numeric value, even if model/provider usage data indicated the real context window utilization should be much lower.
This patch makes context-percentage selection stricter:
- Prefer provider/model-reported `contextWindow` usage when available.
- Only fall back to `contextUsageInput / totalInput` when there is no stronger context-window denominator.
- Avoid the false `100%` path when totals merely mirror context counters.
## Changes
- `src/auto-reply/status.ts`
- tightened denominator/source selection for context usage percentage
- `src/auto-reply/status.test.ts`
- added/updated coverage for the false-100% scenario
## Validation
- ✅ `pnpm check`
- ✅ `pnpm vitest run src/auto-reply/status.test.ts`
## AI-assisted
- This PR is AI-assisted.
- Testing level: targeted local validation completed for impacted scope.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts `/status` context usage reporting to avoid a misleading “100%” when session `totalTokens` mirrors the context window. It adds a guard in `buildStatusMessage` to prefer other usage counters and introduces a regression test for the mirror case.
However, `SessionEntry.totalTokens` is stored as last-call context-window utilization, while `inputTokens`/`outputTokens` can be accumulated for cost. Replacing `totalTokens` with `inputTokens+outputTokens` risks inflating the context percentage in real runs where accumulated usage exceeds the context window.
<h3>Confidence Score: 2/5</h3>
- This PR is not safe to merge as-is due to a logic change that can misreport context usage in common real-world sessions.
- The new guard in `buildStatusMessage` can rewrite context-window `totalTokens` from accumulated `inputTokens`/`outputTokens`, contradicting how usage is persisted and causing definite over-reporting (>100%) when accumulated usage exceeds the context window.
- src/auto-reply/status.ts
<sub>Last reviewed commit: f68d16f</sub>
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22387: fix: session_status context tracking undercount for cached providers
by 1ucian · 2026-02-21
81.5%
#19412: fix(status): prefer configured contextTokens over session entry
by rafaelipuente · 2026-02-17
80.7%
#13895: fix(usage): exclude cache tokens from context-window accounting
by zerone0x · 2026-02-11
78.7%
#15726: fix(sessions): use model contextWindow instead of agent contextToke...
by lailoo · 2026-02-13
77.9%
#11109: fix(tui): prefer config contextTokens over persisted session value
by marezgui · 2026-02-07
77.6%
#18886: fix(status): prefer configured contextTokens over model metadata
by BinHPdev · 2026-02-17
77.4%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
76.7%
#4999: fix(memory-flush): use contextTokens instead of totalTokens for thr...
by Farfadium · 2026-01-30
76.6%
#14913: fix: update context pruning to notify session metadata after prunin...
by ScreenTechnicals · 2026-02-12
76.3%
#17253: fix: propagate lastTurnTotal through usage accumulator for accurate...
by robbyczgw-cla · 2026-02-15
75.9%