fix: clamp overflowing context usage display#777
fix: clamp overflowing context usage display#777jeffscottward merged 2 commits intoRunMaestro:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes an overflow display bug in Confidence Score: 5/5Safe to merge — minimal, targeted fix with no regressions. The change is a one-branch addition in a pure utility function. All findings are P2 or lower; the logic is correct, the test is accurate, and the fix is consistent with the existing ContextDisplayResult interface documentation. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/renderer/utils/contextUsage.ts | Adds an else branch to clamp tokens to contextWindow when raw values overflow and no fallback percentage is available; logic is correct and the ContextDisplayResult jsdoc already documents this capping behavior. |
| src/tests/renderer/utils/contextUsage.test.ts | Test title and assertion updated to match the new clamped behavior (result.tokens now expected to be 200000 rather than the raw 1008000); accurately covers the no-fallback overflow branch. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[calculateContextDisplay called] --> B{contextWindow <= 0?}
B -->|yes| C[Return zeros]
B -->|no| D[raw = calculateContextTokens]
D --> E{raw > contextWindow?}
E -->|no| F[tokens = raw]
E -->|yes| G{fallbackPercentage != null\nAND >= 0?}
G -->|yes| H["tokens = round(fallbackPercentage/100 × contextWindow)\n(multi-tool turn: use preserved %)"]
G -->|no| I["tokens = contextWindow\n(NEW: clamp to window — no trustworthy fallback)"]
F --> J["percentage = min(100, round(tokens/contextWindow × 100))"]
H --> J
I --> J
J --> K[Return tokens, percentage, contextWindow]
Reviews (1): Last reviewed commit: "fix: clamp overflowing context usage dis..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/renderer/utils/contextUsage.ts`:
- Around line 171-173: In the branch inside src/renderer/utils/contextUsage.ts
where you compute tokens from fallbackPercentage (the block checking
fallbackPercentage != null && fallbackPercentage >= 0), clamp fallbackPercentage
to a maximum of 100 before deriving tokens so you never compute tokens >
contextWindow; e.g., compute an effectivePercent = Math.min(fallbackPercentage,
100) and then set tokens = Math.round((effectivePercent / 100) * contextWindow)
(or wrap the final tokens with Math.min(tokens, contextWindow)) to guarantee
tokens never exceed contextWindow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7dbcbbfe-79d1-4991-82b4-d31e91d6bb81
📒 Files selected for processing (2)
src/__tests__/renderer/utils/contextUsage.test.tssrc/renderer/utils/contextUsage.ts
|
Review pass completed on April 9, 2026. No blocking issues found in the changed surface I exercised. Validated:
Screenshot: |
|
Addressed the unresolved CodeRabbit review point from review Change pushed:
What changed:
Updated verification screenshot for the over-100 fallback case: |


Summary by CodeRabbit
Bug Fixes
Tests