fix(amazonq): compaction nudge no longer reads "almost full (300%)" - #2876
Draft
laileni-aws wants to merge 1 commit into
Draft
laileni-aws wants to merge 1 commit into
laileni-aws wants to merge 1 commit into
Conversation
The compaction nudge body is built from currentRequestCount / maxOverallCharacters, where currentRequestCount is the current turn's input plus the entire serialized history. That ratio is not bounded by 1: a long agentic session with many serialized tool specs and accumulated tool_use / tool_result blocks can sit well above the budget, and users have reported values of 200-300%. COMPACTION_BODY interpolated that number into "The context window is almost full (N%)" unconditionally, so at 300% the nudge contradicted itself. Users reasonably read that as the percentage being miscalculated rather than as a genuinely over-budget session. Branch the wording at 100% and keep the real percentage visible, so an over-budget session stays diagnosable instead of being silently capped. Also rename the parameter from `threshold` to `percentUsed`; it is measured utilization, not a threshold, and the old name invited the misreading that the denominator was the compaction trigger point. No behaviour change below 100%. Adds regression tests covering the wording below, at, and above 100%.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
COMPACTION_BODYis rendered from measured utilization:characterCountiscurrentRequestCount= the current turn's input plus the entire serialized history (message content,tool_useandtool_resultblocks). That ratio is not bounded by 1. A long agentic session with many serialized tool specs can sit well above the budget, and users have reported readings of 200-300%.The copy interpolated that number unconditionally:
At 300% that is self-contradictory. In practice it misleads twice over: users read it as the percentage being miscalculated rather than as a genuinely over-budget session, and "exceeding it" is wrong tense once the budget is already exceeded.
This surfaced on a customer escalation where the over-100% readings were initially triaged as a display/denominator bug. They were not — the numbers were real. The message was what made them look wrong.
Change
Branch the wording at 100%, and keep the real percentage visible:
< 100%— unchanged: "The context window is almost full (79%) and exceeding it will clear your history.">= 100%— "The context window is full (300% of the limit) and continuing will clear your history."The percentage is deliberately not capped at 100. An over-budget session should stay diagnosable; capping it would have hidden the very signal that identified this case.
Also renames the parameter
threshold->percentUsed. It is measured utilization, not a threshold, and the old name actively invited the misreading that the denominator was the compaction trigger point.Scope
Deliberately narrow. No change to the budget model, the compaction trigger, or tool-spec serialization.
tokenLimitsCalculator.tsalready consolidated the previously-conflicting budget constants, so this is the remaining piece.Compatibility
agenticChatController.ts), positional,numberin /stringout - unaffected by the rename.Testing
Adds
constants.test.tscovering the wording below, at, and above 100%, that the real percentage is preserved rather than capped, and that the compaction offer is always present.I was not able to run
npm run test:unitin my environment (no command runner available in the sandbox), so please let CI validate this before review. Static checks that did pass: the pre-commitprettier/pretty-quickhook parsed and accepted both files, andcommitlintaccepted the commit. This is a copy + test change with no control-flow or type surface change.🤖 Drafted by DAE-ProdEng-Agent - AI-generated, please verify before merging. Opened as a draft with no reviewers; a human will publish and assign.