You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(amazonq): prevent race condition in inline completion provider (aws#8163)
## 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:
1. Automatic trigger (t=0ms) - sends LSP request, receives valid
suggestions after ~380ms
2. Invoke trigger (t=2ms) - sends duplicate LSP request, receives empty
response after ~6ms (language server skips concurrent requests)
3. VS Code uses the most recent provider response, which is the empty
result from the second call, causing the first call's valid suggestions
to be ignored.
Evidence from logs:
```
[info] Sending inline completion request (474)
[info] Sending inline completion request (476)
[info] Received response (476): { sessionId: '', items: [] } ← Used by VS Code
[info] Received response (474): { items: [{ itemId: '...', insertText: '...' }] } ← Ignored
```
## Solution
I am not able to have a working fix to prevent either automatic or
invoke trigger, which is 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:
* Added pendingRequest field to track in-flight requests
* Wrapped provideInlineCompletionItems to check for and reuse pending
requests
* Added per-call cancellation check when reusing requests
* Ensured pendingRequest is cleared after completion for fresh
subsequent requests
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:
```
[info] _provideInlineCompletionItems called (Automatic)
[info] _provideInlineCompletionItems called (Invoke)
[info] Reusing pending inline completion request to avoid race condition
[info] Received response: { sessionId: '...', itemCount: 2, items: [...] }
```
---
- Treat all work as PUBLIC. Private `feature/x` branches will not be
squash-merged at release time.
- Your code changes must meet the guidelines in
[CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines).
- License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.
0 commit comments