fix(dashboard): spawn fresh PTY on session switch from sidebar - #65313
Open
coding-linheng wants to merge 1 commit into
Open
fix(dashboard): spawn fresh PTY on session switch from sidebar#65313coding-linheng wants to merge 1 commit into
coding-linheng wants to merge 1 commit into
Conversation
When switching sessions via the dashboard Chat sidebar, the keep-alive PTY registry reused the existing terminal process because the `attach_token` (browser-localStorage identity) was unchanged. The old PTY was still running the previous conversation, so the user saw stale history and new messages went to the wrong session. Include the `resume` session id in the registry key so each unique (session, tab) pair gets its own PTY. Switching back to a previously visited session reattaches to its still-alive PTY (correct behavior). The idle reaper continues to clean up detached sessions after TTL. Fixes: session switch from sidebar shows wrong conversation history
Collaborator
teknium1
reviewed
Jul 16, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the registry choke point; current main confirms the reported stale-PTY reuse at hermes_cli/web_server.py:15870-15871 and hermes_cli/pty_session.py:151-153.
Problems
- The proposed key uses
resumeafterpty_ws()may replace an absent query value from the active-session file (hermes_cli/web_server.py:15818-15824). A default/chatconnection first keys asattach:; after the PTY writes its session ID, a refresh keys asattach:<id>, spawning a second PTY and defeating keep-alive. - The key omits
profile.ChatPagesends profile with the same attach token (web/src/pages/ChatPage.tsx:910-915), while the server uses it to set the childHERMES_HOME(hermes_cli/web_server.py:14941-14954), so profile changes can still reattach the wrong process. This matches the broader scope noted in the #60745 discussion. - No regression tests accompany the change; current
tests/test_pty_keepalive_ws.py:7-51only checks same-token reuse.
Suggested changes
- Capture raw query resume before the fallback, include profile in the identity, and add explicit-switch, default-refresh, profile-isolation, and canonical-parent-to-child coverage.
Automated hermes-sweeper review.
| # Registry key includes the resume target so that switching sessions | ||
| # in the dashboard sidebar spawns a fresh PTY instead of reattaching | ||
| # to the old one (which is still running the previous conversation). | ||
| _registry_key = f"{attach_token}:{resume or ''}" |
Contributor
There was a problem hiding this comment.
resume has already been rewritten by the active-session-file fallback before this point (web_server.py:15818-15824), so a default-chat refresh changes from attach: to attach:<session-id> and spawns a second PTY. Capture raw query resume before that fallback, include profile (which scopes the child HERMES_HOME), and add regressions for default refresh, profile isolation, and explicit resume switching.
This was referenced Jul 29, 2026
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.
Problem
When switching sessions via the dashboard Chat sidebar, the keep-alive PTY registry reuses the existing terminal process because the
attach_token(browser localStorage identity) is unchanged. The old PTY is still running the previous conversation, so the user sees stale history and new messages go to the wrong session.Root Cause
In
pty_ws()(web_server.py), the PTY registry key is the bareattach_token. When the user clicks a different session in the sidebar:?resume=<new_session_id>in the URLChatPagedetects the change and triggers a WebSocket reconnectPTY_REGISTRY.attach_or_spawn(attach_token, spawn=_spawn)The
_spawnclosure (which would create a new PTY with--resume <new_id>) is never called.Fix
Include the
resumesession id in the PTY registry key (attach_token:resume_id) so each unique (session, tab) pair gets its own PTY. Switching back to a previously visited session reattaches to its still-alive PTY (correct behavior). The idle reaper continues to clean up detached sessions after TTL.Testing