Skip to content

chat: sort custom modes alphabetically by name in ChatModes - #332354

Open
sundeep8967 wants to merge 3 commits into
microsoft:mainfrom
sundeep8967:fix/custom-agents-sort-order
Open

chat: sort custom modes alphabetically by name in ChatModes#332354
sundeep8967 wants to merge 3 commits into
microsoft:mainfrom
sundeep8967:fix/custom-agents-sort-order

Conversation

@sundeep8967

Copy link
Copy Markdown

Problem

In multi-root workspaces and dynamic customization updates, custom chat modes retrieved via ChatModes.getCustomModes() can be enumerated in non-deterministic order or insertion order depending on dictionary/map iteration and asynchronous resolution timing.

Solution

Sort custom mode instances in ChatModes.getCustomModes() deterministically by name (using localeCompare) and tie-break by ID/URI.

Fixes #332339

Testing

  • Added unit test in src/vs/workbench/contrib/chat/test/common/chatModeService.test.ts verifying that custom modes are returned sorted alphabetically by name.
  • TypeScript compiler verification passed.

Copilot AI balanced review requested due to automatic review settings August 24, 2026 15:51

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

Sorts custom chat modes alphabetically for stable Agent dropdown ordering.

Changes:

  • Sorts by name, then URI-backed ID.
  • Adds unit coverage for unsorted input.

Reviewed changes

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

File Description
chatModes.ts Sorts custom modes deterministically.
chatModeService.test.ts Tests alphabetical ordering.
Suppressed comments (1)

src/vs/workbench/contrib/chat/test/common/chatModeService.test.ts:389

  • The test guidance asks tests to minimize fine-grained assertions and prefer one snapshot-style deep equality assertion. Mapping the names into one array also gives a clearer failure diff and removes the redundant length assertion.
		assert.strictEqual(modes.custom.length, 3);
		assert.strictEqual(modes.custom[0].name.get(), 'Alpha Mode');
		assert.strictEqual(modes.custom[1].name.get(), 'Beta Mode');
		assert.strictEqual(modes.custom[2].name.get(), 'Zeta Mode');

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +381 to +382
// Insert in unsorted order (Zeta, Alpha, Beta)
promptsService.setCustomModes([modeZ, modeA, modeM]);
@sundeep8967

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Custom agents in the Agent dropdown are not sorted by name after a change

3 participants