Skip to content

fix(cli): resolve deferred platform plugin for its top-level CLI command (salvage #54717) - #73498

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-2daea8e4
Jul 28, 2026
Merged

fix(cli): resolve deferred platform plugin for its top-level CLI command (salvage #54717)#73498
teknium1 merged 2 commits into
mainfrom
hermes/hermes-2daea8e4

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

hermes photon (and any future platform plugin's top-level CLI command) works again — the deferred platform lazy-loader now fires for the one platform whose name matches the invoked command, so its register_cli_command() side effect runs before argparse builds the subparser table.

Root cause: PR #54448 made bundled kind: platform plugins lazy-load (deferred registry loaders) to cut startup time. Photon is the only platform that registers a top-level hermes <name> CLI command inside its plugin register(), so deferral silently unregistered hermes photon — argparse rejects it with invalid choice (issue #54678, reported again by TheSameCat on X, July 28). The docs were correct; the command had vanished.

Salvages PR #54717 by @Bartok9 (earliest fix, June 29) onto current main with authorship preserved.

Changes

  • hermes_cli/main.py: new _resolve_deferred_platform_cli_command() — on the unknown-top-level-command slow path, after discover_plugins(), resolve the deferred platform matching the first positional argv token via platform_registry.get() so its loader imports the module and registers the CLI command. Only the matched platform loads; errors are logged-and-swallowed.
  • tests/hermes_cli/test_startup_plugin_gating.py: 4 regression tests, including a hermetic full-chain test (real PlatformRegistry + real PluginManager + fake deferred loader → CLI command visible in argparse choices) — no Photon SDK import.

Validation

Before After
hermes photon --help invalid choice: 'photon' full subcommand help
hermes photon status (temp HERMES_HOME) unreachable correct status table, exit 0
hermes version fast path ~0.2s ~0.2s (unchanged — resolution only runs on the unknown-command slow path)
test_startup_plugin_gating.py 41/41
test_plugin_cli_registration.py + tests/plugins/platforms/photon/ 119/119

Fixes #54678.

Infographic

hermes photon command restored

Bartok9 added 2 commits July 28, 2026 10:09
Closes #54678

`hermes photon ...` could fail with argparse `invalid choice: 'photon'`
even when the bundled Photon platform plugin is present. Photon registers
its top-level CLI command from the platform adapter module via
`ctx.register_cli_command(name="photon", ...)`, but bundled platform
plugins are cheap-registered as *deferred* entries to avoid importing every
gateway SDK during normal startup.

On the unknown-top-level-command slow path, `discover_plugins()` records the
deferred loader but never imports the matching platform module, so the CLI
registration side effect doesn't run and `photon` stays absent from
`_cli_commands` — argparse then rejects it.

Fix: after `discover_plugins()` on that slow path, resolve only the deferred
platform whose name matches the first positional token (via
`platform_registry.get(name)`) before reading `_cli_commands`. This imports
exactly the targeted platform, leaving normal startup cheap (a bare `hermes`
or flags-only invocation has no positional token and touches nothing). The
resolution is best-effort: registry/import failures are logged at debug and
never crash startup.

Added 3 tests in tests/hermes_cli/test_startup_plugin_gating.py: resolves the
matching platform, ignores empty/None command, and swallows registry errors.
Fails without the fix (symbol absent).
Responds to hermes-sweeper review on #54717: existing tests only mocked
platform_registry.get(). Add a hermetic fake deferred-loader test that
runs real PlatformRegistry resolution → PluginContext.register_cli_command
→ argparse subparser/choices visibility, without Photon SDK imports.
@github-actions

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on be31d2f

all good!

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.

Photon CLI command is hidden when platform plugin is deferred

2 participants