Skip to content

feat(amazonq): add auto compaction feature#2623

Draft
laileni-aws wants to merge 1 commit intoaws:feature/auto-compactionfrom
laileni-aws:feature/auto-compaction
Draft

feat(amazonq): add auto compaction feature#2623
laileni-aws wants to merge 1 commit intoaws:feature/auto-compactionfrom
laileni-aws:feature/auto-compaction

Conversation

@laileni-aws
Copy link
Contributor

Problem

When the context window is exceeded during agentic chat, users see an "Improperly formed request" or "Input is too long" error and must manually run /compact then re-ask their question.

Solution

Automatically detect context window overflow errors and run compaction + retry transparently, using a single boolean flag (didAutoCompactOnOverflow) to allow one automatic compaction per user turn (preventing infinite loops).

Auto-compaction is handled at two levels:

  1. Mid-loop (inside #runAgentLoop): When getChatResponse() throws a context overflow error, the agent loop compacts conversation history and continues from the current iteration — preserving in-progress state and tool execution context.

  2. Outer catch (in onChatPrompt): Catches overflow errors from request preparation, compaction itself, or result handling. Compacts and retries the full onChatPrompt call.

The flag is reset at the start of each new user message, so:

  • First overflow → auto-compact + retry (flag: falsetrue)
  • Second overflow in same turn → shows error to user (already true)
  • New user message → flag reset to false

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@laileni-aws laileni-aws requested a review from a team as a code owner February 19, 2026 03:19
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 27.77778% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.39%. Comparing base (f56d56e) to head (5484278).

Files with missing lines Patch % Lines
...nguage-server/agenticChat/agenticChatController.ts 17.30% 86 Missing ⚠️
...hisperer/src/language-server/agenticChat/errors.ts 76.19% 5 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                     @@
##           feature/auto-compaction    #2623      +/-   ##
===========================================================
- Coverage                    60.52%   60.39%   -0.14%     
===========================================================
  Files                          279      279              
  Lines                        65790    65915     +125     
  Branches                      4180     4179       -1     
===========================================================
- Hits                         39821    39807      -14     
- Misses                       25887    26025     +138     
- Partials                        82       83       +1     
Flag Coverage Δ
unittests 60.39% <27.77%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@laileni-aws laileni-aws marked this pull request as draft March 17, 2026 00:37
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