Skip to content

Conversation

@ashishrp-aws
Copy link
Contributor

Copy of #2234 for main branch

Problem

Current chat request strategy is insufficient and we need to be in parity with Q CLI's unified approach.

Solution

Implements a simplified AWS retry strategy for agentic chat operations that matches AWS CLI behavior with exponential backoff and proper error handling.

Changes Made

  • New AwsRetryStrategy class with AWS SDK-compatible retry logic
  • 3-attempt retry pattern with exponential backoff (1s, 2s, 4s base delays)
  • Jitter implementation (50-100%) to prevent thundering herd
  • 10-second maximum delay cap to match AWS SDK adaptive strategy
  • Comprehensive error classification for retry vs non-retry scenarios

Key Features

  • Smart error handling: Distinguishes between retryable (throttling, high load) and non-retryable errors (usage limits, input too long)
  • Monthly limit detection: Prevents unnecessary retries on quota exhaustion
  • Model unavailability handling: Provides appropriate messaging for capacity issues
  • Abort signal support: Respects cancellation requests
  • Delay notifications: Informs users about retry delays > 2 seconds
  • Request ID preservation: Maintains AWS request IDs for debugging

Error Types Handled

  • Usage limit errors (monthly quotas)
  • Throttling exceptions (429, service overload)
  • Model capacity issues (insufficient capacity)
  • Input validation errors (too long)
  • Abort/cancellation requests

Testing

  • Follows AWS SDK adaptive retry patterns
  • Matches existing CLI behavior
  • Preserves error context and request IDs

License

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

…2234)

* feat(amazonq): adding classification based retry strategy for chat requests

* fix(amazonq): added abortController back

* fix: fix to add aws retry strategy

* revert: revert package-lock.json changes from commit 22358a3

* fix: remove completed TODO for chat result stream integration

The delay notification integration with chat result stream is already
implemented via the setDelayNotificationCallback mechanism in the
AgenticChatController. Removed the TODO comment as the functionality
is complete.

* refactor: extract retry attempts to constant

Replace hardcoded retry attempts value (3) with DEFAULT_RETRY_ATTEMPTS
constant to improve maintainability and follow best practices.

* fix: refatcor hardcoded values for retry

* fix: fix to add custom AWS retry startegy wrapper

* fix: fix for unit test failures

* fix: fix to move sanitizeLogInput to utils

* fix(amazonq): fix to move to adaptiveRetryStrategy

* fix: fix for compilation errors

* revert: revert for package-lock

* fix(amazonq): fix for retry classification

* fix: fix for test failures

* fix: fix to cover more non-retryable exceptions

* fix: fix for nits to use constants

---------

Co-authored-by: Laxman Reddy <[email protected]>
@ashishrp-aws ashishrp-aws requested a review from a team as a code owner October 8, 2025 19:37
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2025

Codecov Report

❌ Patch coverage is 90.31414% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.25%. Comparing base (a908195) to head (067e293).

Files with missing lines Patch % Lines
...uage-server/agenticChat/agenticChatResultStream.ts 9.09% 20 Missing ⚠️
...guage-server/agenticChat/retry/errorTransformer.ts 93.21% 14 Missing and 1 partial ⚠️
...nguage-server/agenticChat/retry/retryClassifier.ts 93.37% 9 Missing and 2 partials ⚠️
...isperer/src/language-server/chat/chatController.ts 0.00% 6 Missing ⚠️
...-server/workspaceContext/workspaceFolderManager.ts 0.00% 6 Missing ⚠️
...nguage-server/agenticChat/agenticChatController.ts 50.00% 4 Missing ⚠️
...rer/src/language-server/agenticChat/retry/index.ts 0.00% 3 Missing ⚠️
...codewhisperer/src/shared/streamingClientService.ts 93.87% 3 Missing ⚠️
server/aws-lsp-codewhisperer/src/shared/utils.ts 83.33% 2 Missing and 1 partial ⚠️
...anguage-server/agenticChat/retry/qRetryStrategy.ts 98.87% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2409      +/-   ##
==========================================
+ Coverage   61.87%   62.25%   +0.38%     
==========================================
  Files         261      266       +5     
  Lines       58505    59090     +585     
  Branches     3672     3786     +114     
==========================================
+ Hits        36199    36788     +589     
+ Misses      22235    22227       -8     
- Partials       71       75       +4     
Flag Coverage Δ
unittests 62.25% <90.31%> (+0.38%) ⬆️

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.

@ashishrp-aws ashishrp-aws merged commit 15d1b1f into main Oct 8, 2025
17 checks passed
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.

7 participants