Skip to content

Fix NES gutter icon persisting across file close/open cycles - #17160

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/nes-gutter-persists-across-files
Mar 3, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/nes-gutter-persists-across-files

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Addresses #17108.

Summary

  • Invalidate in-flight async RPC request IDs (requestId_, nesId_) in onDismiss() so that stale completion callbacks are rejected when they arrive after a file is closed
  • Add a dismissed_ guard flag checked at key async entry points (showEditSuggestionImpl, requestNextEditSuggestions, suggestionTimer_) to prevent any suggestion rendering or request scheduling on a dismissed editor

The root cause is a race condition specific to the Copilot NES fallback path: when a regular completion request is in-flight at the time a file is closed, the response callback can pass the staleness check (since onDismiss() did not previously invalidate the request IDs), then reschedule nesTimer_ via the empty-result fallback, ultimately rendering a stale NES gutter icon.

Test plan

  • Open a file, trigger an NES suggestion with Copilot, accept it, then close the file without saving
  • Open a new file and verify no stale NES gutter icon appears
  • Verify NES suggestions still work normally after the fix (accept, dismiss, auto-trigger)

@posit-snyk-bot

posit-snyk-bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kevinushey
kevinushey requested a review from gtritchie March 3, 2026 17:08
@kevinushey kevinushey added this to the Globemaster Allium milestone Mar 3, 2026

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

The fix is correct — the two-layer defense (request ID invalidation + dismissed_ guard) directly addresses the race condition. Two items worth considering:

1. Unguarded Timers.singleShot callback in onAssistantAcceptNextWord (~line 2022)

This deferred callback accesses editSuggestion_.startAnchor and display_, but onDismiss() nulls editSuggestion_ via resetSuggestion(). If a user rapidly accepts a word-by-word completion and immediately closes the tab, the deferred callback can NPE. Timers.singleShot uses Scheduler.get().scheduleDeferred() which isn't cancellable by onDismiss().

Timers.singleShot(() ->
{
   if (dismissed_ || editSuggestion_ == null)
      return;
   // ... rest unchanged
});

2. Consider moving ID increments earlier in onDismiss()

Currently requestId_ += 1 and nesId_ += 1 happen after timer cancellation, resetSuggestion(), and clearDiffState(). While safe in GWT's single-threaded model, placing the invalidation immediately after dismissed_ = true is clearer — the two mechanisms that reject stale callbacks get set together:

public void onDismiss()
{
   dismissed_ = true;
   requestId_ += 1;
   nesId_ += 1;
   // ... then cancel timers, reset, cleanup
}

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Some minor suggestions from CC review to consider.

- Add dismissed_/null check to the Timers.singleShot callback in
  onAssistantAcceptNextWord to prevent NPE if editor is dismissed
  while word-by-word acceptance is deferred
- Move request ID invalidation earlier in onDismiss(), right after
  setting the dismissed_ flag, to group the two stale-callback
  rejection mechanisms together
@kevinushey
kevinushey merged commit dbb8cec into main Mar 3, 2026
1 check failed
@kevinushey
kevinushey deleted the bugfix/nes-gutter-persists-across-files branch March 3, 2026 19:09
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.

3 participants