Skip to content

fix(web): force PTY re-spawn on session resume to respect new resume target - #63731

Closed
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-63701-pty-session-resume
Closed

fix(web): force PTY re-spawn on session resume to respect new resume target#63731
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-63701-pty-session-resume

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Fixes #63701

Problem

When the web dashboard resumes a different session from Sessions → History, both ?resume=SESSION_ID and ?attach=TOKEN are sent to /api/pty. The keep-alive PtySessionRegistry.attach_or_spawn() found the existing PTY (spawned for the previous session) and returned it without calling the _spawn closure. The new argv/env with the correct HERMES_TUI_RESUME was silently discarded, so every resume-after-the-first landed back on the original session's PTY.

Only the first click after a dashboard restart worked — because no PTY existed yet, so _spawn was called.

Fix

When a resume query parameter is present alongside attach, discard any existing keep-alive PTY via a new close_if_exists method on PtySessionRegistry before calling attach_or_spawn. This forces a fresh spawn with the correct resume arguments.

A future enhancement could skip the teardown when the resume target matches the existing PTY's session (by tracking the resolved session id), but the restart is fast (Node.js TUI spawn) and only happens on explicit user navigation, so the simpler unconditional teardown is sufficient.

Changes

  • pty_session.py: Add PtySessionRegistry.close_if_exists(key) — safely closes and removes a session if present, returns True if one was removed.
  • web_server.py: In pty_ws(), call close_if_exists(attach_token) when resume is set, so the registry creates a fresh PTY with the correct resume target.

…target

When the web dashboard resumes a different session, both ?resume=SESSION_ID
and ?attach=TOKEN are sent to /api/pty. The keep-alive registry returned the
existing PTY (spawned for the previous session) without calling the spawn
function, so the new argv/env with the correct HERMES_TUI_RESUME was silently
discarded.

This made every resume-after-the-first land back on the original session's
PTY regardless of which session was clicked. The first click after a dashboard
restart worked because no PTY existed yet, so spawn was called.

The fix discards any existing keep-alive PTY when a resume target is provided,
forcing a fresh spawn with the correct resume arguments. A new close_if_exists
method on PtySessionRegistry handles the safe teardown.

Fixes NousResearch#63701
@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 comp/dashboard Web dashboard / control panel UI (dashboard/, landing) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: this is the backend teardown mechanism in the wrong-session dashboard-chat PTY-reattach cluster (regression from keep-alive PTY #60515). Competing/complementary with #60745 (backend attach-token scoping), #62058 (frontend token rotation), and #61313 (frontend force-fresh) — same goal, different layers/mechanisms. A maintainer should pick the canonical approach across these.

@toshiowang

Copy link
Copy Markdown

This PR resolves #63701. I have verified the fix in hermes_cli/web_server.py and hermes_cli/pty_session.py, and required checks have passed.

@kyssta-exe

Copy link
Copy Markdown
Contributor Author

Stale — oldest open PR, no merge activity for weeks.

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 comp/dashboard Web dashboard / control panel UI (dashboard/, landing) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

**Web dashboard: clicking a previous session opens a blank new session (/api/pty ?attach= reattach discards the ?resume= spawn env)**

3 participants