fix(amazonq): prevent race condition in inline completion provider #8162
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
When pressing Enter to trigger inline suggestions, ghost text fails to appear in the editor despite the language server returning valid suggestions.
Root Cause: VS Code triggers two provideInlineCompletionItems calls simultaneously when Enter is pressed:
Evidence from logs:
Solution
I am not able to prevent either automatic or invoke trigger, it is likely controlled in toolkit. So I implement request deduplication on Q side by tracking pending requests in the inline completion provider:
Shared Request Pattern: When a request is in progress, subsequent concurrent calls reuse the same pending promise instead of creating new LSP requests
Independent Cancellation: Each call checks its own CancellationToken after the shared request completes, allowing independent cancellation semantics
Key Changes:
Tests:
Tested on the same scenarios, both concurrent calls now return the same valid suggestions, ghost text appears reliably when pressing Enter
Logs after fix:
feature/xbranches will not be squash-merged at release time.