fix: prevent nested subparser commands from falling through to chat REPL - #18469
Closed
gruuna-bannert wants to merge 1 commit into
Closed
fix: prevent nested subparser commands from falling through to chat REPL#18469gruuna-bannert wants to merge 1 commit into
gruuna-bannert wants to merge 1 commit into
Conversation
When using nested subparsers (e.g. `hermes mcp add`), Python 3.11's argparse may leave args.func set to the parent parser's default (cmd_chat) instead of propagating the child subparser's func. This caused MCP, cron, and gateway subcommands to incorrectly enter the chat REPL. Fix: check for subcommand-specific attributes (mcp_action, cron_command, gateway_command) when args.func == cmd_chat, and dispatch to the correct handler if one is found. Closes NousResearch#4184
Collaborator
1 similar comment
Collaborator
Author
|
@alt-glitch But #4189 is extremely bloated and includes many unrelated changes. |
Contributor
|
This appears to be implemented on current Evidence:
Thanks for the focused PR and for the follow-up discussion about #4189 being broader than necessary; the narrower behavior this PR targeted is now covered on main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4184 —
hermes mcp add(and other nested subparser commands) incorrectly falling through to the chat REPL instead of executing the intended subcommand.Root Cause
On Python 3.11, argparse's nested subparser handling may leave
args.funcset to the parent parser's default (cmd_chat) instead of propagating the child subparser'sset_defaults(func=...). The existing dispatch logic checkedargs.funcbut didn't distinguish between a genuine bare invocation and a nested-subparser bug.Fix
When
args.func == cmd_chat, check for subcommand-specific attributes (mcp_action,cron_command,gateway_command) that indicate a real subcommand was parsed. If found, dispatch to the correct handler instead of falling through to chat.Additionally, when
args.funcpoints to a real subcommand handler (notcmd_chat), dispatch it immediately without further checks.