fix(env): preserve desktop session token despite pinned .env value - #38586
fix(env): preserve desktop session token despite pinned .env value#38586liuhao1024 wants to merge 1 commit into
Conversation
When the Desktop app spawns the backend in local mode, it injects an auto-generated HERMES_DASHBOARD_SESSION_TOKEN via the process environment (main.cjs line 3362). load_hermes_dotenv() then runs with override=True, which clobbers the desktop token with the pinned value from ~/.hermes/.env. The token mismatch causes an infinite SIGTERM boot loop: the local backend enforces the pinned token while the renderer presents the auto-generated one. Fix: in load_hermes_dotenv(), detect the desktop's presence via HERMES_DASHBOARD_TUI=1 (set by main.cjs) and preserve the process-level HERMES_DASHBOARD_SESSION_TOKEN before override=True runs, then restore it afterward if dotenv overwrote it. Fixes NousResearch#38575
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Changes
In load_hermes_dotenv(), before the .env override pass clobbers process-level values, the desktop-generated HERMES_DASHBOARD_SESSION_TOKEN is preserved (when HERMES_DASHBOARD_TUI=1). After loading, the desktop token is restored if it was overwritten.
Reasoning
Fixes issue #38575 boot loop caused by a pinned .env token overriding the Desktop app's auto-generated one. The fix correctly distinguishes the two contexts:
- Desktop (
HERMES_DASHBOARD_TUI=1): desktop token wins (session is local, pinned token is for remote mode only) - Remote mode: pinned
.envtoken applies normally
Testing
Two tests cover both code paths cleanly.
Reviewed by Hermes Agent
|
Superseded by #39652. This PR gates preservation on |
|
Superseded by #39652 by @1RB, which takes a more fundamental approach:
#39652's migration approach is cleaner — it removes the stale config once rather than working around it on every boot. Closing in favor of #39652. |
What does this PR do?
Preserves the Desktop-spawned process-level
HERMES_DASHBOARD_SESSION_TOKENwhen~/.hermes/.envalso pins a value for the same variable. Without this fix, a pinned token in.envcauses the local-mode Desktop app to enter an infinite SIGTERM boot loop because the backend enforces the pinned token while the renderer presents the auto-generated one.Related Issue
Fixes #38575
Type of Change
Changes Made
hermes_cli/env_loader.py: Inload_hermes_dotenv(), detect the Desktop app's presence viaHERMES_DASHBOARD_TUI=1(set bymain.cjsline 3363) and save the process-levelHERMES_DASHBOARD_SESSION_TOKENbeforeoverride=Trueruns, then restore it afterward if dotenv overwrote it with the pinned.envvalue.tests/hermes_cli/test_env_loader.py: Added two tests —test_desktop_token_preserved_despite_pinned_dotenv(desktop token survives.envoverride) andtest_pinned_token_applied_when_not_desktop_mode(pinned token still applies in remote-backend use case).How to Test
HERMES_DASHBOARD_SESSION_TOKEN=pinned-valuein~/.hermes/.env~/.hermes/logs/desktop.log(SIGTERM + restart cycle)hermes dashboard(without Desktop) should still honor the pinned token from.envChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/hermes_cli/test_env_loader.py -vand all tests pass (8/8)Documentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
hermes_cli/env_loader.py:load_hermes_dotenv()— called fromhermes_cli/main.py,gateway/run.py,cron/scheduler.py,hermes_cli/doctor.py,hermes_cli/dump.py(6 call sites)HERMES_DASHBOARD_TUI=1(Desktop mode); all non-Desktop code paths are unaffectedmain.cjsline 3362 setsHERMES_DASHBOARD_SESSION_TOKENin the spawn env; line 3363 setsHERMES_DASHBOARD_TUI=1;web_server.pyline 135 reads the token at import time