Skip to content

Modify the idGenerator - #333905

Draft
SteVen Batten (sbatten) wants to merge 1 commit into
sbatten/calm-silkwormfrom
sbatten/random-bunny
Draft

Modify the idGenerator#333905
SteVen Batten (sbatten) wants to merge 1 commit into
sbatten/calm-silkwormfrom
sbatten/random-bunny

Conversation

@sbatten

Copy link
Copy Markdown
Member

No description provided.

@sbatten SteVen Batten (sbatten) changed the title Add code review skill and user-specific instructions Modify the idGenerator Sep 1, 2026
@sbatten
SteVen Batten (sbatten) requested a balanced review from Copilot September 1, 2026 23:37

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 review overview

🟡 Changes recommended

Counter wrapping introduces duplicate IDs that can overwrite active resources.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity src/​vs/​base/​common/​idGenerator.ts — The modulo makes IDs repeat after 1,000 calls, violating the generator's uniqueness contract. This…
What changed in this PR

Changes the shared ID generator to cycle numeric suffixes every 1,000 IDs.

Changes:

  • Adds modulo-based counter wrapping.
File Description
src/​vs/​base/​common/​idGenerator.ts Wraps generated IDs at 1,000.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +17 to +18
this._lastId = (this._lastId + 1) % 1000;
return this._prefix + this._lastId;

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 review overview

🔵 Needs a closer look

Wrapping introduces duplicate IDs for consumers that require uniqueness.

Review tier: Balanced
Findings: 1 High severity

Pre-existing issues (1)
Severity Finding
High severity src/​vs/​base/​common/​idGenerator.ts — The modulo makes IDs repeat after 1,000 calls, violating the generator's uniqueness contract. This… View comment
Suppressed comments (1)

src/vs/base/common/idGenerator.ts:18

  • The modulo makes IDs repeat every 1,000 calls (and changes the 1,000th ID to prefix0). This generator is used where IDs must remain unique—for example, OneReference.id is the tree identity and TextEditorDecorationType keys may remain registered—so a large reference result or a long-running extension host can collide with a live object and overwrite/misidentify it. Keep the counter monotonic rather than wrapping it.
		this._lastId = (this._lastId + 1) % 1000;
		return this._prefix + this._lastId;

<!-- Thank you for submitting a Pull Request. Please:
* Read our Pull Request guidelines:
  https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests
* Associate an issue with the Pull Request.
* Ensure that the code is up-to-date with the `main` branch.
* Include a description of the proposed changes and how to test them.
-->

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 review overview

🔵 Needs a closer look

Wrapping generates duplicate IDs and breaks callers that require uniqueness.

Review tier: Balanced
Findings: 1 High severity

Pre-existing issues (1)
Severity Finding
High severity src/​vs/​base/​common/​idGenerator.ts — The modulo makes IDs repeat after 1,000 calls, violating the generator's uniqueness contract. This… View comment
Suppressed comments (1)

src/vs/base/common/idGenerator.ts:18

  • This makes a process-wide ID generator repeat values after 1,000 calls, violating the uniqueness its callers rely on. For example, TextEditorDecorationType uses a static generator for registration keys; the 1,001st decoration will reuse the first key, and disposing either instance can unregister the other. Keep the counter monotonic rather than wrapping it.
		this._lastId = (this._lastId + 1) % 1000;
		return this._prefix + this._lastId;

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.

2 participants