Skip to content

Comments

fix: sort glob results for deterministic load order across all callers#14626

Open
kevinWangSheng wants to merge 2 commits intoanomalyco:devfrom
kevinWangSheng:fix/glob-deterministic-sort
Open

fix: sort glob results for deterministic load order across all callers#14626
kevinWangSheng wants to merge 2 commits intoanomalyco:devfrom
kevinWangSheng:fix/glob-deterministic-sort

Conversation

@kevinWangSheng
Copy link

Issue for this PR

Closes #14492

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Glob.scan and Glob.scanSync return results in filesystem readdir order, which varies across platforms and runs. This affects all callers — not just loadPlugin, but also loadAgent, loadMode, loadCommand (in config.ts), and custom tool loading (in tool/registry.ts).

This PR adds .sort() to both Glob.scan and Glob.scanSync in util/glob.ts, fixing the root cause at the utility level so all current and future callers get deterministic alphabetical order.

Also removes redundant .sort() calls in the existing glob tests — these were workarounds for the nondeterministic output and now serve as regression tests.

Note: This is an alternative to #14547, which only sorts in loadPlugin. This PR fixes the same issue at the source so all 5+ call sites benefit.

How did you verify your code works?

  • Reviewed all call sites of Glob.scan/Glob.scanSync to confirm none depend on filesystem ordering
  • Updated existing glob tests to assert sorted output directly (removed workaround .sort() in 6 test assertions)
  • Array.prototype.sort() is stable and deterministic for string arrays

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found Related PR:

PR #14547: fix(config): sort plugin paths for deterministic load order

Why it's related: This is the exact alternative approach mentioned in the PR description. PR #14626 fixes the root cause by adding .sort() to Glob.scan and Glob.scanSync at the utility level, while PR #14547 only sorts in loadPlugin. The description explicitly states this PR is "an alternative to #14547" — both address the same underlying issue (#14492) but at different levels. PR #14626's approach is more comprehensive since it fixes all 5+ call sites (loadPlugin, loadAgent, loadMode, loadCommand, and custom tool loading) rather than just the plugin loader.

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.

Plugin load order within a directory is nondeterministic

1 participant