Skip to content

fix(registry): dedupe getAllCommands so aliased commands are not exported twice - #220

Merged
NianJiuZst merged 1 commit into
MiniMax-AI:mainfrom
shoemoney:fix/dedupe-getallcommands
Aug 4, 2026
Merged

fix(registry): dedupe getAllCommands so aliased commands are not exported twice#220
NianJiuZst merged 1 commit into
MiniMax-AI:mainfrom
shoemoney:fix/dedupe-getallcommands

Conversation

@shoemoney

@shoemoney shoemoney commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

config export-schema currently emits 19 tool schemas with only 17 distinct names:

$ mmx config export-schema | jq -r '.[].name' | sort | uniq -d
mmx_search_query
mmx_speech_synthesize

Duplicate function names are rejected by both the Anthropic and OpenAI tool APIs, so the exported schema cannot be handed to a model as-is without post-processing.

Cause. Two commands are registered under a second alias path:

'speech synthesize': speechSynthesize,
'speech generate':   speechSynthesize,   // same object
'search query':      searchQuery,
'search web':        searchQuery,        // same object

CommandRegistry.getAllCommands() walks the path trie and pushes node.command at every node that has one — so an aliased command is pushed once per path, not once per command. export-schema maps that list straight to generateToolSchema, and the duplicates land in the output.

Fix. Dedupe by object identity during the traversal. Callers of getAllCommands want the set of distinct commands, not the set of invocation paths.

Verified locally (bun run src/main.ts):

before   total entries: 19   unique names: 17   duplicates: {mmx_speech_synthesize: 2, mmx_search_query: 2}
after    total entries: 17   unique names: 17   duplicates: none

Alias routing is untouched — mmx speech generate --help and mmx search web --help both still resolve and exit 0. Only enumeration changes.

bun test: 385 pass / 8 fail, identical to the baseline on a clean checkout with this change stashed. Those 8 appear to be network-dependent (one logs Detecting region... failed) and are unrelated.

Happy to add a regression test asserting getAllCommands().length === new Set(getAllCommands()).size if you'd like one — I left it out because the repo's registry tests looked deliberately light, but say the word.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Aliases register the same Command object under more than one path
('speech generate' -> speechSynthesize, 'search web' -> searchQuery), so the
traversal in getAllCommands returned it once per path.

config export-schema maps that list straight to tool schemas, so it emitted 19
entries with only 17 distinct names — mmx_speech_synthesize and mmx_search_query
each appeared twice. Duplicate function names are rejected by both the Anthropic
and OpenAI tool APIs, so the exported schema could not be used as-is.

Dedupe by object identity: callers of getAllCommands want the set of distinct
commands, not the set of invocation paths. Alias routing is unaffected.
@NianJiuZst
NianJiuZst self-requested a review August 4, 2026 10:21
@NianJiuZst NianJiuZst self-assigned this Aug 4, 2026

@NianJiuZst NianJiuZst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution! I verified the current head (8f352b6) against main: config export-schema changes from 19 entries with 17 unique names to 17/17, while the speech generate and search web aliases continue to resolve correctly.

The identity-based deduplication is narrowly scoped and matches the current use of getAllCommands(). The exact-head CI is green, and local validation passed all 449 tests, typecheck, and the development build; lint has no errors (only one unrelated existing warning).

I found no blocking issues, and this looks ready to merge. A direct regression assertion that exported schema names remain unique would be a nice follow-up, but I do not consider it blocking.

Thanks again for the clear explanation and focused fix!

@NianJiuZst
NianJiuZst merged commit 2f829ae into MiniMax-AI:main Aug 4, 2026
4 checks passed
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