Skip to content

Fix duplicate comment threads in diff editor#8739

Merged
alexr00 merged 5 commits into
mainfrom
copilot/fix-comment-duplicate-issues
May 12, 2026
Merged

Fix duplicate comment threads in diff editor#8739
alexr00 merged 5 commits into
mainfrom
copilot/fix-comment-duplicate-issues

Conversation

Copilot AI commented May 12, 2026

Copy link
Copy Markdown
Contributor

Bug Fix

What was the bug?

Review threads were rendered twice in PR diff editors after VS Code restart on some machines: two vscode.CommentThread widgets appeared for the same review thread on the same line.

How did you fix it?

The onDidChangeReviewThreads handlers in both comment controllers create a new VS Code comment thread when an added event arrives that doesn't match any pending thread. They never checked whether a thread with that gitHubThreadId was already present in their cache, so any race between addThreadsForEditors / doInitializeCommentThreads (which seeds threads from pullRequestModel.reviewThreadsCache) and a concurrent added event for the same thread produced a duplicate widget.

  • PullRequestCommentController.onDidChangeReviewThreads: before falling through to pending-match / editor-match creation, look up the cache by gitHubThreadId; if found, route through updateThread and continue.
  • ReviewCommentController.onDidChangeReviewThreads: same guard, reusing the existing _findMatchingThread helper that already searches the workspace / review-scheme / obsolete maps.
  • Drive-by: the early-exit when no matching open editor was found used return, aborting the rest of the added loop and the entire changed / removed processing for that event. Changed to continue.
// PullRequestCommentController.onDidChangeReviewThreads
for (const thread of e.added) {
    const key = this.getCommentThreadCacheKey(thread.path, thread.diffSide === DiffSide.LEFT);

    const existing = this._commentThreadCache[key]?.find(t => t.gitHubThreadId === thread.id);
    if (existing) {
        updateThread(this._context, existing, thread, this._githubRepositories);
        continue;
    }
    // ...pending-match / create-from-editor as before
}

Copilot AI linked an issue May 12, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits May 12, 2026 10:05
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
Copilot AI requested a review from alexr00 May 12, 2026 10:10
@alexr00 alexr00 marked this pull request as ready for review May 12, 2026 13:10
Copilot AI review requested due to automatic review settings May 12, 2026 13:10
@alexr00 alexr00 enabled auto-merge (squash) May 12, 2026 13:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 added events update an already-cached thread instead of creating a new one.
  • Fix control flow in PullRequestCommentController.onDidChangeReviewThreads so missing-editor cases continue rather than aborting the entire event processing.
  • Add a workingDirectory?: Uri field 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 returncontinue 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 in onDidChangeReviewThreads (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

Comment thread src/view/reviewCommentController.ts
@alexr00 alexr00 disabled auto-merge May 12, 2026 13:21
@alexr00 alexr00 enabled auto-merge (squash) May 12, 2026 13:38
Copilot AI review requested due to automatic review settings May 12, 2026 13:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 3/4 changed files
  • Comments generated: 2

Comment thread src/view/pullRequestCommentController.ts
Comment thread src/view/reviewCommentController.ts
@alexr00 alexr00 merged commit 3c3b66c into main May 12, 2026
10 checks passed
@alexr00 alexr00 deleted the copilot/fix-comment-duplicate-issues branch May 12, 2026 14:06
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.

Comment shows twice in diff editor

4 participants