Skip to content

fix(cli,gateway): guard quick_commands non-dict entries before .get()#20654

Open
haosenwang1018 wants to merge 1 commit into
NousResearch:mainfrom
haosenwang1018:fix/18816-quick-commands-non-dict-guard
Open

fix(cli,gateway): guard quick_commands non-dict entries before .get()#20654
haosenwang1018 wants to merge 1 commit into
NousResearch:mainfrom
haosenwang1018:fix/18816-quick-commands-non-dict-guard

Conversation

@haosenwang1018

Copy link
Copy Markdown

Issue

Closes #18816

Root cause

A quick_commands entry that is not a dict (e.g. foo: '' in config.yaml) crashed slash-command dispatch with AttributeError: 'str' object has no attribute 'get'. Worse, since quick_commands dispatch runs before plugin/skill commands, a single malformed entry poisoned every command sharing that key — a valid /mygif skill could not load if quick_commands.mygif was a string.

The same crash pattern existed in three places — the bug report flagged one, but I found two more in gateway/run.py while writing the regression test:

  1. cli.py:6580 — the interactive CLI's main slash-command dispatcher
  2. gateway/run.py:5247 — the gateway's early alias resolution block (runs before built-in dispatch so aliases like /model openai/... reach the /model handler)
  3. gateway/run.py:5446 — the gateway's main quick_commands dispatch

Fix

All three sites now guard isinstance(qcmd, dict) before calling .get(). When a malformed entry is encountered, we log a warning and fall through to the next dispatch tier (plugin commands → skill commands → built-in commands). Behavior for valid dict entries is unchanged.

The cli.py change also defensively re-validates that quick_commands itself is a dict (matching the pattern already used in gateway/run.py:5214).

Tests

Added three regression tests in tests/cli/test_quick_commands.py:

  • test_string_value_does_not_crashquick_commands={'foo': ''}, /foo no longer raises AttributeError; warning is logged.
  • test_string_value_does_not_block_skill_command_with_same_name — confirms the skill-poisoning scenario from the bug report: a string quick_commands.mygif no longer blocks a same-named skill command from loading.
  • test_string_value_does_not_crash_gateway — gateway equivalent; would have failed twice without both gateway fixes.

All 19 tests in tests/cli/test_quick_commands.py pass:

$ pytest tests/cli/test_quick_commands.py
19 passed in 1.06s

Closes NousResearch#18816

A quick_commands entry that is not a dict (e.g. ``foo: ''`` in
config.yaml) crashed slash-command dispatch with
``AttributeError: 'str' object has no attribute 'get'``. Worse, since
quick_commands dispatch runs before plugin/skill commands, a single
malformed entry poisoned every command sharing that key — a valid
``/mygif`` skill could not load if ``quick_commands.mygif`` was a string.

Three places had the same crash pattern:

- ``cli.py``: the main slash-command dispatcher
- ``gateway/run.py``: the gateway's main quick_commands dispatch
- ``gateway/run.py``: the early alias-resolution block that runs
  before built-in dispatch

All three now guard ``isinstance(qcmd, dict)`` and log a warning before
falling through to plugin/skill dispatch. Behavior for valid dict
entries is unchanged.

Tests cover:

- a string entry no longer crashes
- a string entry with the same name as a skill command does not block
  skill dispatch
- the gateway path also no longer crashes on string entries

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels May 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #18850 and #18937 are open PRs also fixing #18816 (non-dict quick_commands crash). This PR is the most comprehensive — covers all three crash sites (cli.py, gateway/run.py alias resolution, gateway/run.py main dispatch) with regression tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quick_commands with non-dict values crashes slash command dispatch

2 participants