Fix duplicate comment threads in diff editor#8739
Merged
Merged
Conversation
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix comment showing twice in diff editor
Fix duplicate comment threads in diff editor
May 12, 2026
alexr00
approved these changes
May 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a race condition in the PR diff editor comment controllers that could create duplicate vscode.CommentThread widgets for the same GitHub review thread after restart (cache-seeding vs. added event ordering).
Changes:
- Add “existing thread” guards in both comment controllers so
addedevents update an already-cached thread instead of creating a new one. - Fix control flow in
PullRequestCommentController.onDidChangeReviewThreadsso missing-editor casescontinuerather than aborting the entire event processing. - Add a
workingDirectory?: Urifield to proposed chat participant private typings.
Show a summary per file
| File | Description |
|---|---|
| src/view/reviewCommentController.ts | Adds an early match/update path when an added review thread already exists in controller thread maps. |
| src/view/pullRequestCommentController.ts | Adds an early cache check/update to avoid duplicate threads; adjusts return → continue in the added loop. |
| src/@types/vscode.proposed.chatParticipantPrivate.d.ts | Extends proposed LM tool invocation option types with a workingDirectory URI. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/view/reviewCommentController.ts:292
- There are unit tests for
ReviewCommentController, but none appear to cover the new "existing thread" path inonDidChangeReviewThreads(added event should update an already-created thread instead of creating a duplicate). Adding a regression test for this race/ordering case would help prevent reintroducing the duplicate-thread behavior.
// Defensive: if a comment thread for this review thread id already exists in any of the
// thread maps (e.g. because doInitializeCommentThreads already created it from the cache
// before this event was processed), update it in place instead of creating a duplicate
// VS Code comment thread.
const existingMatch = this._findMatchingThread(thread);
if (existingMatch.index > -1) {
const matchingThread = existingMatch.threadMap[thread.path][existingMatch.index];
updateThread(this._context, matchingThread, thread, githubRepositories);
continue;
}
- Files reviewed: 2/3 changed files
- Comments generated: 1
meganrogge
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug Fix
What was the bug?
Review threads were rendered twice in PR diff editors after VS Code restart on some machines: two
vscode.CommentThreadwidgets appeared for the same review thread on the same line.How did you fix it?
The
onDidChangeReviewThreadshandlers in both comment controllers create a new VS Code comment thread when anaddedevent arrives that doesn't match any pending thread. They never checked whether a thread with thatgitHubThreadIdwas already present in their cache, so any race betweenaddThreadsForEditors/doInitializeCommentThreads(which seeds threads frompullRequestModel.reviewThreadsCache) and a concurrentaddedevent for the same thread produced a duplicate widget.PullRequestCommentController.onDidChangeReviewThreads: before falling through to pending-match / editor-match creation, look up the cache bygitHubThreadId; if found, route throughupdateThreadandcontinue.ReviewCommentController.onDidChangeReviewThreads: same guard, reusing the existing_findMatchingThreadhelper that already searches the workspace / review-scheme / obsolete maps.return, aborting the rest of theaddedloop and the entirechanged/removedprocessing for that event. Changed tocontinue.