Skip to content

fix(cli): detect dashboard PIDs when --profile precedes the subcommand#44048

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/dashboard-pid-detection-with-profile
Closed

fix(cli): detect dashboard PIDs when --profile precedes the subcommand#44048
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/dashboard-pid-detection-with-profile

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Problem

_find_stale_dashboard_pids() uses fixed substring patterns ("hermes dashboard", "hermes_cli.main dashboard", "hermes_cli/main.py dashboard") to detect running dashboard processes.

When --profile (or -p) appears between the entry point and the dashboard subcommand — e.g. python -m hermes_cli.main --profile prod dashboard --port 9119 — none of the patterns match, so:

  • hermes dashboard --status misses the process
  • hermes dashboard --stop can't kill it
  • hermes update skips the stale-dashboard cleanup, leaving the old backend running with a mismatched JS bundle

Closes #44035

Fix

Add a _cmd_is_dashboard_subcommand() helper that checks for:

  1. A known Hermes entry-point indicator (hermes, hermes_cli.main, hermes_cli/main.py) in the command
  2. dashboard appearing as a standalone whitespace-delimited token (" dashboard " or trailing " dashboard")

This catches the flag-in-between case while still rejecting unrelated processes that merely mention "dashboard" in arguments (e.g. hermes_cli.main chat -q 'rewrite my dashboard').

The existing exact-substring patterns are kept as _EXACT_DASHBOARD for the common no-flags case; the new helper runs as a fallback.

Files Changed

File Change
hermes_cli/main.py Added _cmd_is_dashboard_subcommand(), updated matching logic on both macOS/Linux and Windows paths
tests/hermes_cli/test_update_stale_dashboard.py Added test_profile_flag_before_subcommand and test_short_profile_flag_before_subcommand

Test Plan

  • All 22 existing tests pass (no regressions)
  • New test_profile_flag_before_subcommand--profile prod between entry point and dashboard
  • New test_short_profile_flag_before_subcommand-p dev short form
  • test_unrelated_process_containing_word_dashboard_not_matched — confirms no false positives on chat commands mentioning "dashboard"
Test output (24/24 passed)
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_no_matches_returns_empty PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_matches_running_dashboard PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_multiple_matches PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_self_pid_excluded PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_ps_not_found_returns_empty PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_ps_timeout_returns_empty PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_unrelated_process_containing_word_dashboard_not_matched PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_profile_flag_before_subcommand PASSED
tests/hermes_cli/test_update_stale_dashboard.py::TestFindStaleDashboardPids::test_short_profile_flag_before_subcommand PASSED
... 24 passed in 0.28s

NousResearch#44035)

The stale-dashboard PID scanner used fixed substrings like
'hermes_cli.main dashboard' to find running dashboard processes.
When --profile (or -p) sits between the entry point and the
subcommand (e.g. 'python -m hermes_cli.main --profile prod dashboard'),
none of the patterns matched and the process was missed.

Add a _cmd_is_dashboard_subcommand() helper that checks for a known
Hermes entry point plus 'dashboard' as a standalone whitespace-delimited
token, covering the flag-in-between case while still rejecting unrelated
processes that merely mention 'dashboard' in arguments.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 11, 2026
@AIalliAI

Copy link
Copy Markdown
Contributor

Thanks for jumping on this — I hit the same issue and want to flag one behavior of _cmd_is_dashboard_subcommand before it lands, because the scan feeds a SIGTERM/SIGKILL pass in hermes update.

The guard against quoted arguments doesn't hold against real ps output: the shell strips quotes before exec, so ps -A -o pid=,command= shows hermes -z "summarize my dashboard" as

hermes -z summarize my dashboard

which ends with dashboard → matches → the user's active oneshot/chat session gets killed mid-turn by hermes update. The existing test test_unrelated_process_containing_word_dashboard_not_matched only passes because the mocked cmdline keeps its literal quotes (-q 'rewrite my dashboard'), which ps never shows.

Two smaller variants of the same hole:

  • The entrypoint check is ep in cmd anywhere, so any path containing .hermes/ qualifies — e.g. python /Users/x/.hermes/scripts/report.py render dashboard weekly matches both conditions.
  • hermes chat -q "show dashboard" (word in final position) matches via the endswith branch.

I opened #44165 as an alternative that tokenizes the cmdline and only accepts known top-level flags (arity introspected from the real parser, same as hermes_cli.relaunch) between the entrypoint and dashboard, with negative tests for the shapes above. Happy to converge the two either way — e.g. keeping your PR with a token-walk instead of the substring checks would also close it.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough analysis @AIalliAI — you're right on all three points. The substring approach has real holes: ps output doesn't preserve shell quotes, ep in cmd matches paths containing .hermes/, and endswith(" dashboard") catches unrelated arguments. Your #44165 with the tokenized matcher and parser-introspected flag arity is the correct approach. Closing in favor of #44165.

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 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.

[Bug]: dashboard status/update miss running dashboards when --profile appears before the subcommand

3 participants