← Back to PRs

#19412: fix(status): prefer configured contextTokens over session entry

by rafaelipuente open 2026-02-17 19:34 View on GitHub →
size: XS
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