-
Notifications
You must be signed in to change notification settings - Fork 1.8k
NES: Debounce and language context fetch do not honor cancellation token #4383
Description
Problem
When Visual Studio cancels a Next Edit Suggestions (NES) request (e.g. because the user moved the cursor or a new request superseded the old one), the cancellation was effectively a no-op for two critical phases of the request pipeline in \XtabProvider:
- Debounce phase — \debounce()\ used \�wait timeout(debounceTime)\ unconditionally. Cancelling the request had no effect; the debounce timer ran to completion before the cancellation check fired.
- Language context fetch phase — \getLanguageContext()\ used \�wait raceTimeout(getContextPromise(), debounceTime)\ without passing the cancellation token. The fetch would block the full debounce window even when the outer request was already cancelled.
Impact on request queuing
Because cancelled requests would not yield until the debounce (and optionally the language context timeout) fully elapsed, subsequent NES requests accumulated behind them. Each queued request inherited an artificially inflated wait time, causing a visible multi-hundred-millisecond delay before later requests could start their own debounce or LLM fetch. In scenarios where VS fires rapid NES requests (e.g. caret moves after Tab acceptance) this manifested as a stall: the cancelled request's debounce blocked the pipeline, making healthy follow-on requests appear delayed or entirely unresponsive.
Expected behavior
When a NES request is cancelled, the debounce timer and language context fetch should abort immediately, freeing the pipeline for the next request without delay.