Skip to content

Revert "Fix element already registered (#281000)"#281278

Merged
alexr00 merged 2 commits intomainfrom
alexr00/distinguished-parrotfish
Dec 4, 2025
Merged

Revert "Fix element already registered (#281000)"#281278
alexr00 merged 2 commits intomainfrom
alexr00/distinguished-parrotfish

Conversation

@alexr00
Copy link
Member

@alexr00 alexr00 commented Dec 4, 2025

This reverts commit ca3f221.

Copilot AI review requested due to automatic review settings December 4, 2025 17:00
@alexr00 alexr00 enabled auto-merge (squash) December 4, 2025 17:00
@alexr00 alexr00 self-assigned this Dec 4, 2025
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Dec 4, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reverts commit ca3f221, which attempted to fix a duplicate element registration issue in tree views. The revert removes sophisticated duplicate-handling logic and replaces it with a simpler check that has a race condition vulnerability.

Key changes:

  • Removes complex duplicate element detection and re-registration logic from _createAndRegisterTreeNode
  • Simplifies to a basic duplicate check that occurs after node creation but before cache addition
  • Skips the test that validated the fix for concurrent tree element registrations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/api/common/extHostTreeViews.ts Reverts _createAndRegisterTreeNode from handling duplicate elements gracefully to throwing an error, but introduces a race condition where concurrent registrations could both pass the duplicate check
extensions/vscode-api-tests/src/singlefolder-tests/tree.test.ts Skips the test validating concurrent reveal() calls don't throw duplicate element errors, indicating this behavior is no longer supported

Comment on lines 866 to +869
const node = this._createTreeNode(element, extTreeItem, parentNode);
if (extTreeItem.id && this._elements.has(node.item.handle)) {
throw new Error(localize('treeView.duplicateElement', 'Element with id {0} is already registered', extTreeItem.id));
}
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

This duplicate check has a race condition. The check happens after the node is created (line 866) but before it's added to the cache (line 870). If two concurrent calls to _createAndRegisterTreeNode with the same element ID occur (e.g., two simultaneous reveal() calls as tested in tree.test.ts), both could pass this check before either adds the element to _elements, resulting in duplicate registrations.

The original code (that was reverted) handled this scenario by checking for duplicates before creating the node and had logic to handle re-registering the same element object. Consider either:

  1. Re-applying the reverted logic that properly handles concurrent registrations
  2. Adding synchronization to prevent concurrent registrations of the same element
  3. Checking for duplicates before creating the node to avoid the race window
Suggested change
const node = this._createTreeNode(element, extTreeItem, parentNode);
if (extTreeItem.id && this._elements.has(node.item.handle)) {
throw new Error(localize('treeView.duplicateElement', 'Element with id {0} is already registered', extTreeItem.id));
}
if (extTreeItem.id && this._elements.has(extTreeItem.id)) {
throw new Error(localize('treeView.duplicateElement', 'Element with id {0} is already registered', extTreeItem.id));
}
const node = this._createTreeNode(element, extTreeItem, parentNode);

Copilot uses AI. Check for mistakes.
});

test('TreeView - element already registered', async function () {
test.skip('TreeView - element already registered', async function () {
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

Skipping this test instead of removing it suggests the tested behavior is still desired but currently broken. This test validates that concurrent reveal() calls for the same tree element don't throw duplicate element errors.

Since the main code change reintroduces the race condition this test was meant to verify is fixed, consider either:

  1. Removing this test entirely if the behavior is no longer supported
  2. Keeping it unskipped if the duplicate element handling will be fixed differently
  3. Adding a comment explaining why it's skipped and tracking the issue

Copilot uses AI. Check for mistakes.
@alexr00 alexr00 merged commit 653d30a into main Dec 4, 2025
33 of 34 checks passed
@alexr00 alexr00 deleted the alexr00/distinguished-parrotfish branch December 4, 2025 17:43
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jan 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants