Skip to content

feat: SSH session persistence across app background/foreground#8

Open
ZacharyZcR wants to merge 1 commit intoTermix-SSH:dev-1.3.0from
ZacharyZcR:feat/session-persistence
Open

feat: SSH session persistence across app background/foreground#8
ZacharyZcR wants to merge 1 commit intoTermix-SSH:dev-1.3.0from
ZacharyZcR:feat/session-persistence

Conversation

@ZacharyZcR
Copy link
Member

Summary

  • Adapt mobile client to server-side session persistence protocol (depends on Termix PR #594): when the app goes to background and iOS/Android kills the WebSocket, the server keeps the SSH session alive (default 30 min). On foreground return, the client sends attachSession to reattach with buffered output replay instead of creating a new SSH connection.
  • Handle session lifecycle messages: sessionCreated, sessionAttached, sessionExpired (auto-fallback to fresh connect), and sessionTakenOver (multi-device graceful disconnect).
  • Send explicit disconnect on component destroy to clean up server-side sessions when the user intentionally closes a terminal tab.
  • Skip terminal clear and post-connection setup on reattach so the user sees continuous output without a jarring reset.

Files Changed

File Change
app/tabs/sessions/terminal/NativeWebSocketManager.ts Core session persistence logic — track serverSessionId, conditional attachSession vs connectToHost, new message handlers
app/tabs/sessions/terminal/Terminal.tsx Skip terminal reset and hasReceivedData clear on reattach

Test plan

  • Connect to a host → background the app for ~10s → return to foreground → verify session reattaches without terminal clear, previous output preserved
  • Connect to a host → background the app → wait for server timeout (default 30 min) → return → verify graceful fallback to fresh connection
  • Connect to a host → close the terminal tab → verify server-side session is destroyed (check server logs for session_destroyed)
  • Connect to same host from two devices → verify second device takes over, first shows disconnect
  • Connect to a host → toggle airplane mode → return → verify reconnection works (fresh connect since server lost the session)
  • Verify npx tsc --noEmit shows no new errors beyond pre-existing upstream issues

Note: This PR depends on the server-side session persistence feature from Termix PR #594. Without the server changes, the client will receive no sessionCreated messages and behave identically to the current version (always fresh connectToHost).

Fixes Termix-SSH/Support#364

Adapt the mobile client to the server-side session persistence protocol
(Termix PR #594). When the app goes to background and the WebSocket dies,
the server keeps the SSH session alive. On foreground return, the client
sends attachSession instead of connectToHost, reattaching to the existing
session with buffered output replay.

- Track server sessionId from sessionCreated messages
- Send attachSession on reconnect when a sessionId exists
- Handle sessionExpired with automatic fallback to fresh connectToHost
- Handle sessionTakenOver for multi-device scenarios
- Send explicit disconnect on destroy to clean up server sessions
- Skip terminal clear and post-connection setup on reattach
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.

1 participant