fix(desktop): preserve HERMES_DASHBOARD_SESSION_TOKEN from parent process - #38931
fix(desktop): preserve HERMES_DASHBOARD_SESSION_TOKEN from parent process#389311RB wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR prevents python-dotenv loads from overwriting a session token injected into the environment (avoiding a 401 “boot loop” when ~/.hermes/.env contains a stale token).
Changes:
- Capture
HERMES_DASHBOARD_SESSION_TOKENbefore loading dotenv files. - Restore the token after loading the user and project
.envfiles.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2dc87bf to
3e28ca0
Compare
…cess The Desktop app generates a fresh random token per boot and injects it into the child backend process. A stale pinned token in .env from previous remote-mode use causes a 401 auth mismatch and infinite SIGTERM boot loop. Capture the parent-injected token unconditionally before any dotenv loading and restore it after all loading (including external secret sources) completes. This is safe because: - Desktop local mode: parent injects random token -> captured -> .env loads -> token restored -> handshake succeeds - hermes dashboard CLI / remote mode: no parent injection -> None captured -> .env token applies normally Fixes NousResearch#38575.
3e28ca0 to
b7ea277
Compare
|
Closing in favor of a proper config migration (version 27 → strip legacy HERMES_DASHBOARD_SESSION_TOKEN from .env) which follows the existing ANTHROPIC_TOKEN cleanup pattern. |
|
Superseded by #39652. The runtime preservation approach in this PR was a workaround; the root fix is a config migration that strips the stale |
Context
The previous docs recommended pinning
HERMES_DASHBOARD_SESSION_TOKENin~/.hermes/.envfor remote mode. The current docs switched to username/password auth (HERMES_DASHBOARD_BASIC_AUTH_*). Users who set up remote mode under the old docs still have a stale pinned token in.env.The bug (legacy migration edge case)
When those users run
hermes desktop(local mode), the Desktop app generates a fresh randomHERMES_DASHBOARD_SESSION_TOKENper boot and injects it into the child backend. Thenpython-dotenvloads~/.hermes/.envwithoverride=True, clobbering the valid parent-injected token with the stale pinned one. Auth mismatch → 401 on every API call → Desktop can't start until the stale token is manually removed.New users following current docs won't hit this because they won't have a pinned session token in
.env.Why #38586 does not fix this in practice
PR #38586 gates the fix on
os.environ.get("HERMES_DASHBOARD_TUI") == "1", but the Desktop app never setsHERMES_DASHBOARD_TUI. I grepped the entire codebase (apps/desktop/,hermes_cli/, all TS/JS/CJS) — the variable only exists in #38586's own test (monkeypatched) and patch. In real usage the condition is always false, so the 401 boot loop still happens for users with a stale pinned token.This fix (workaround)
This PR captures the parent-injected token unconditionally before any dotenv or external-secret loading, and restores it at the end. It works, but it's a workaround — the real fix should be a config migration that strips the stale
HERMES_DASHBOARD_SESSION_TOKENfrom.envduring update, following the exact pattern used forANTHROPIC_TOKEN(version 8 → 9 migration inhermes_cli/config.py).Why this isn't the ideal fix:
.envwithoverride=Trueis designed to win over stale shell exports. The deeper issue is that.envis being used for both user configuration AND legacy runtime session state._config_versionto 27 and add a migration blockif current_ver < 27:that detectsHERMES_DASHBOARD_SESSION_TOKENin.envand removes it, since remote mode now uses username/password auth and local mode auto-generates tokens per boot. This follows the established migration pattern (ANTHROPIC_TOKENcleanup inmigrate_config).Copilot review addressed
_apply_external_secret_sources). No duplication, linear sequence.Recommendation
Close this PR in favor of a proper config migration (version 27 → strip
HERMES_DASHBOARD_SESSION_TOKENfrom.envif present, with a console message explaining the auth model changed). The migration approach matches the existingANTHROPIC_TOKENcleanup pattern and removes the root cause without adding permanent complexity toenv_loader.py.Fixes #38575.