fix(dashboard): reload loopback tabs after stale session-token closes - #78313
Merged
kshitijk4poor merged 3 commits intoAug 4, 2026
Merged
Conversation
Loopback dashboard tabs now share one one-shot stale-token recovery path across REST 401s, the PTY socket, the structured event socket, and the shared JSON-RPC gateway wrapper. The shared client exposes only an optional close-event interception hook; the dashboard remains responsible for deciding that loopback 4401 means reload. Constraint: Current main delegates the web gateway to apps/shared JsonRpcGatewayClient, and NousResearch#54022 review requires a shared-client-compatible close-code hook plus direct ChatSidebar event-socket coverage. Rejected: Restore the dashboard's old direct WebSocket implementation | stale against the shared JSON-RPC client and would duplicate transport behavior. Confidence: high Scope-risk: moderate Directive: Keep stale-token policy dashboard-specific; the shared JSON-RPC client should expose close events without learning dashboard auth semantics. Tested: npm --workspace web test (21 files, 106 tests); focused stale-token tests (5 files, 14 tests); npm --workspace web run typecheck; npm --workspace @hermes/shared run lint; npm --workspace @hermes/shared run typecheck; focused web eslint; git diff --check. Not-tested: Manual browser smoke test across a real dashboard restart.
react-router v7 exports MemoryRouter from 'react-router', not 'react-router-dom'. The test was written when the repo still imported from 'react-router-dom' (4000+ commits ago).
Sibling site missed by PR NousResearch#54022 — /api/console WebSocket in HermesConsoleModal.tsx has the same buildWsUrl → stale-token → 4401 close path as the PTY and events WebSockets. Without this guard, opening the console after a dashboard restart shows 'Console closed (4401). auth: token_mismatch' with no recovery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dashboard chat tabs now auto-reload once when the PTY/events/gateway WebSocket closes with a 4401 (stale session token) after a
hermes dashboardrestart, instead of blanking and looping on every focus/visibility change.Root cause
Every dashboard restart mints a new
_SESSION_TOKENinweb_server.py. The browser tab still holds the old token inwindow.__HERMES_SESSION_TOKEN__. REST fetches already handled this (one-shot reload on 401), but WebSocket connections had no equivalent — the PTY reconnect logic firedreconnectPty()on everyvisibilitychange/focus/pageshow/onlineevent, each attempt rejected withtoken_mismatch, leaving the terminal blank until the user manually reloaded.Changes
web/src/lib/dashboard-auth-reload.ts(new): sharedmaybeReloadForLoopbackWsAuthFailure()— reloads the page once on a 4401 WS close in loopback mode (no-op in gated mode). Also extractsattemptDashboardTokenReloadOnce()+clearDashboardTokenReloadAttempt()so the REST 401 path inapi.tsuses the same logic.web/src/pages/ChatPage.tsx: callmaybeReloadForLoopbackWsAuthFailure(ev.code)before setting the "Auth failed" banner on 4401 PTY close.web/src/components/ChatSidebar.tsx: same guard on the/api/eventsWS close handler.web/src/lib/gatewayClient.ts: wireonSocketCloseinto the JSON-RPC gateway client so the/api/wssidecar also auto-reloads.apps/shared/src/json-rpc-gateway.ts: addonSocketCloseoption toGatewayClientOptionsso the close handler can intercept the default closed-state transition.web/src/lib/api.ts: refactor the inline 401 reload logic to use the shareddashboard-auth-reloadmodule.Test plan
tsc --noEmit)Closes #53972