Skip to content

fix(terminal): clear sessionId on PTY close/exit (#80) - #155

Merged
outsourc-e merged 1 commit into
mainfrom
fix/terminal-session-desync-80
Apr 25, 2026
Merged

fix(terminal): clear sessionId on PTY close/exit (#80)#155
outsourc-e merged 1 commit into
mainfrom
fix/terminal-session-desync-80

Conversation

@outsourc-e

Copy link
Copy Markdown
Owner

Closes #80.

When a backend PTY exits, the SSE stream emits exit then close. Frontend was ignoring both, so the tab kept its dead sessionId. Subsequent terminal-input and terminal-resize calls 404 in a tight loop until reload.

Fix: handle exit and close in the SSE consumer; print a dim '[session ended]' line and clear the tab's sessionId. The existing handleSendInput and resize effect already short-circuit on undefined sessionId, so the spam stops immediately.

Reporter @joaompfp's diagnosis was correct; this is exactly the patch they described.

Auto-reconnect intentionally NOT implemented; if we want a restart button later we wire it on the same handler.

TypeScript clean.

… 404ing (#80)

When a backend PTY exits (user typed exit, command crashed, server
recycled), the SSE stream emits 'event: exit' followed by 'event: close'.
The frontend was ignoring both events, so the tab kept its now-dead
sessionId. Subsequent /api/terminal-input and /api/terminal-resize
calls then 404'd in a tight loop and the user saw a hung terminal until
they reloaded.

Fix: handle 'exit' and 'close' events in the SSE consumer:
- Print a dim '[session ended (exit code N)]' line into xterm so the
  user knows what happened.
- Clear the tab's sessionId in zustand state. handleSendInput and the
  resize effect both already short-circuit when sessionId is undefined,
  so the 404 spam stops immediately.
- Print a hint that '+' opens a new tab.

Auto-reconnect is intentionally not implemented here \u2014 the upstream
issue was just the spurious 404s and frozen UI. If we want a 'restart
session' button later, we wire it on the same handler.
@outsourc-e
outsourc-e merged commit d274636 into main Apr 25, 2026
2 checks passed
@outsourc-e
outsourc-e deleted the fix/terminal-session-desync-80 branch April 25, 2026 05:01
outsourc-e added a commit that referenced this pull request May 1, 2026
… 404ing (#80) (#155)

When a backend PTY exits (user typed exit, command crashed, server
recycled), the SSE stream emits 'event: exit' followed by 'event: close'.
The frontend was ignoring both events, so the tab kept its now-dead
sessionId. Subsequent /api/terminal-input and /api/terminal-resize
calls then 404'd in a tight loop and the user saw a hung terminal until
they reloaded.

Fix: handle 'exit' and 'close' events in the SSE consumer:
- Print a dim '[session ended (exit code N)]' line into xterm so the
  user knows what happened.
- Clear the tab's sessionId in zustand state. handleSendInput and the
  resize effect both already short-circuit when sessionId is undefined,
  so the 404 spam stops immediately.
- Print a hint that '+' opens a new tab.

Auto-reconnect is intentionally not implemented here \u2014 the upstream
issue was just the spurious 404s and frozen UI. If we want a 'restart
session' button later, we wire it on the same handler.

Co-authored-by: Eric <eric@outsourc-e.com>
(cherry picked from commit d274636)
JohnGuidry pushed a commit to JohnGuidry/hermes-workspace that referenced this pull request May 26, 2026
… 404ing (outsourc-e#80) (outsourc-e#155)

When a backend PTY exits (user typed exit, command crashed, server
recycled), the SSE stream emits 'event: exit' followed by 'event: close'.
The frontend was ignoring both events, so the tab kept its now-dead
sessionId. Subsequent /api/terminal-input and /api/terminal-resize
calls then 404'd in a tight loop and the user saw a hung terminal until
they reloaded.

Fix: handle 'exit' and 'close' events in the SSE consumer:
- Print a dim '[session ended (exit code N)]' line into xterm so the
  user knows what happened.
- Clear the tab's sessionId in zustand state. handleSendInput and the
  resize effect both already short-circuit when sessionId is undefined,
  so the 404 spam stops immediately.
- Print a hint that '+' opens a new tab.

Auto-reconnect is intentionally not implemented here \u2014 the upstream
issue was just the spurious 404s and frozen UI. If we want a 'restart
session' button later, we wire it on the same handler.

Co-authored-by: Eric <eric@outsourc-e.com>
(cherry picked from commit d274636)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal: sessionId desync → resize/input endpoints return 404, terminal appears hung

1 participant