Skip to content

fix(amazonq): compaction nudge no longer reads "almost full (300%)" - #2876

Draft
laileni-aws wants to merge 1 commit into
Amazon-Q-Developer:mainfrom
laileni-aws:fix/compaction-nudge-percent-over-100
Draft

laileni-aws wants to merge 1 commit into
Amazon-Q-Developer:mainfrom
laileni-aws:fix/compaction-nudge-percent-over-100

Conversation

@laileni-aws

Copy link
Copy Markdown
Collaborator

Problem

COMPACTION_BODY is rendered from measured utilization:

const body = COMPACTION_BODY(Math.round((characterCount / maxOverallCharacters) * 100))

characterCount is currentRequestCount = the current turn's input plus the entire serialized history (message content, tool_use and tool_result blocks). 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:

The context window is almost full (300%) and exceeding it will clear your history.

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.ts already consolidated the previously-conflicting budget constants, so this is the remaining piece.

Compatibility

  • No behaviour change below 100%.
  • One production call site (agenticChatController.ts), positional, number in / string out - unaffected by the rename.
  • No existing test or snapshot asserted the old copy.

Testing

Adds constants.test.ts covering 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:unit in my environment (no command runner available in the sandbox), so please let CI validate this before review. Static checks that did pass: the pre-commit prettier/pretty-quick hook parsed and accepted both files, and commitlint accepted 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.

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-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants