Repository navigation
Fix NES gutter icon persisting across file close/open cycles - #17160
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
gtritchie
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
Intent
Addresses #17108.
Summary
requestId_,nesId_) inonDismiss()so that stale completion callbacks are rejected when they arrive after a file is closeddismissed_guard flag checked at key async entry points (showEditSuggestionImpl,requestNextEditSuggestions,suggestionTimer_) to prevent any suggestion rendering or request scheduling on a dismissed editorThe 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 reschedulenesTimer_via the empty-result fallback, ultimately rendering a stale NES gutter icon.Test plan