#19412: fix(status): prefer configured contextTokens over session entry
size: XS
Cluster:
Context Management Fixes
Fixes #18696
- Root cause: buildStatusMessage resolved contextTokens as
entry?.contextTokens ?? args.agent?.contextTokens ?? …,
causing the session-stored value to shadow an explicit
agents.defaults.contextTokens configuration.
- Fix: Swap precedence so args.agent?.contextTokens is evaluated
before entry?.contextTokens. Fallback behavior unchanged.
- Test: Added regression test asserting that when
agent.contextTokens = 1_000_000 and
sessionEntry.contextTokens = 200_000,
/status reflects the configured 1M value.
Made with [Cursor](https://cursor.com)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a context token precedence bug in `buildStatusMessage` where the session-stored `entry.contextTokens` was shadowing the explicitly configured `agent.contextTokens`. The fix is a minimal two-line swap in `src/auto-reply/status.ts` and is accompanied by a regression test.
- **Fix**: In `status.ts:344-348`, `args.agent?.contextTokens` is now evaluated before `entry?.contextTokens`, making the precedence consistent with how `resolveContextTokens` already works in `model-selection.ts` (`agentCfg?.contextTokens ?? lookupContextTokens(model) ?? DEFAULT_CONTEXT_TOKENS`).
- **Test**: The new test in `status.test.ts` correctly validates that when `agent.contextTokens = 1_000_000` and `sessionEntry.contextTokens = 200_000`, the `/status` output reflects the configured 1M value at the correct percentage (5%).
- **Note**: The same precedence pattern (`entry?.contextTokens` shadowing configured values) exists in `src/commands/status.summary.ts:130` and `src/tui/tui-session-actions.ts:205`, which are not addressed by this PR. These are pre-existing issues unrelated to this change.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — the change is minimal, correct, and well-tested.
- The fix is a two-line precedence swap that is directly supported by a regression test, consistent with the precedence logic already used in `resolveContextTokens` in the reply pipeline, and has no side effects on fallback behavior when neither value is set.
- No files require special attention.
<sub>Last reviewed commit: f5d4b65</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#18721: fix: prefer configured contextTokens over model catalog in status d...
by MisterGuy420 · 2026-02-17
87.4%
#18886: fix(status): prefer configured contextTokens over model metadata
by BinHPdev · 2026-02-17
85.4%
#11109: fix(tui): prefer config contextTokens over persisted session value
by marezgui · 2026-02-07
85.1%
#15726: fix(sessions): use model contextWindow instead of agent contextToke...
by lailoo · 2026-02-13
84.3%
#17414: fix(sessions): refresh contextTokens when model override changes
by michaelbship · 2026-02-15
80.9%
#15126: fix(status): avoid false 100% context usage when totals mirror context
by AlexAnys · 2026-02-13
80.7%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
80.0%
#10998: fix(agents): pass session thinking/reasoning levels to session_stat...
by wony2 · 2026-02-07
79.5%
#16609: fix: resolve session store race condition and contextTokens updates
by battman21 · 2026-02-14
79.5%
#22387: fix: session_status context tracking undercount for cached providers
by 1ucian · 2026-02-21
79.2%