Skip to content

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

Merged
LukeGus merged 18 commits intoTermix-SSH:dev-1.3.1from
ZacharyZcR:feat/session-persistence
Mar 3, 2026
Merged

feat: SSH session persistence across app background/foreground#8
LukeGus merged 18 commits intoTermix-SSH:dev-1.3.1from
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

LukeGus and others added 17 commits February 11, 2026 23:59
* feat: add iPadOS build workflow without EAS dependency (Termix-SSH#4)

* fix: handle physical keyboard special keys in terminal

Tab, Escape, and arrow keys from physical keyboards were filtered out
by the key.length === 1 check. Add explicit handling like Enter/Backspace.

* feat: add iOS native Shift+Tab support via UIKeyCommand

Add Expo native module that uses UIKeyCommand + method swizzling
to intercept Shift+Tab on iOS hardware keyboards and forward
the backtab escape sequence (\x1b[Z]) to the active terminal.

---------

Co-authored-by: swing <bestswngs@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
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
@LukeGus LukeGus changed the base branch from dev-1.3.0 to dev-1.3.1 March 3, 2026 05:58
@LukeGus LukeGus merged commit 66d7720 into Termix-SSH:dev-1.3.1 Mar 3, 2026
LukeGus added a commit that referenced this pull request Mar 9, 2026
* feat: SSH session persistence across app background/foreground (#8)

* fix: ipad keyboard issue + paste key not wokring and disabled auto correct

* fix: ipad keyboard issues

* fix: ipad styling issues, emoji/voice dictation support, android keyboard issues

* fix: ipad styling issues

* feat: add debuging to fix ipad keyboard margins

* fix: handle physical keyboard special keys in terminal (#6)

* feat: add iPadOS build workflow without EAS dependency (#4)

* fix: handle physical keyboard special keys in terminal

Tab, Escape, and arrow keys from physical keyboards were filtered out
by the key.length === 1 check. Add explicit handling like Enter/Backspace.

* feat: add iOS native Shift+Tab support via UIKeyCommand

Add Expo native module that uses UIKeyCommand + method swizzling
to intercept Shift+Tab on iOS hardware keyboards and forward
the backtab escape sequence (\x1b[Z]) to the active terminal.

---------

Co-authored-by: swing <bestswngs@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>

* feat: improve ipad ui logic and improve external keyboard handling

* feat: fix arrow keys and modifier keys on hardware keybords

* fix: fix arrow keys and modifier keys on hardware keybords

* feat: add voice over support and improved terminal background conneciton

* feat: add missing files

* feat: add host key verification support

* fix: dictation issues + android IME multi character input issues on android

* fix: none auth hosts

* chore: clean

* chore: update readme

* feat: add SSH session persistence for background/foreground transitions

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

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>
Co-authored-by: swing <bestswngs@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>

* fix: clear terminal after reconnecting and fix letter duplcation

* chore: increment ver

---------

Co-authored-by: ZacharyZcR <PayasoNorahC@protonmail.com>
Co-authored-by: swing <bestswngs@gmail.com>
LukeGus added a commit that referenced this pull request Mar 15, 2026
* feat: SSH session persistence across app background/foreground (#8)

* fix: ipad keyboard issue + paste key not wokring and disabled auto correct

* fix: ipad keyboard issues

* fix: ipad styling issues, emoji/voice dictation support, android keyboard issues

* fix: ipad styling issues

* feat: add debuging to fix ipad keyboard margins

* fix: handle physical keyboard special keys in terminal (#6)

* feat: add iPadOS build workflow without EAS dependency (#4)

* fix: handle physical keyboard special keys in terminal

Tab, Escape, and arrow keys from physical keyboards were filtered out
by the key.length === 1 check. Add explicit handling like Enter/Backspace.

* feat: add iOS native Shift+Tab support via UIKeyCommand

Add Expo native module that uses UIKeyCommand + method swizzling
to intercept Shift+Tab on iOS hardware keyboards and forward
the backtab escape sequence (\x1b[Z]) to the active terminal.

---------

Co-authored-by: swing <bestswngs@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>

* feat: improve ipad ui logic and improve external keyboard handling

* feat: fix arrow keys and modifier keys on hardware keybords

* fix: fix arrow keys and modifier keys on hardware keybords

* feat: add voice over support and improved terminal background conneciton

* feat: add missing files

* feat: add host key verification support

* fix: dictation issues + android IME multi character input issues on android

* fix: none auth hosts

* chore: clean

* chore: update readme

* feat: add SSH session persistence for background/foreground transitions

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

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>
Co-authored-by: swing <bestswngs@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>

* fix: clear terminal after reconnecting and fix letter duplcation

* chore: increment ver

* fix: use new 2.0.0 api routes and filter non ssh hosts

* chore: increment ver

---------

Co-authored-by: ZacharyZcR <PayasoNorahC@protonmail.com>
Co-authored-by: swing <bestswngs@gmail.com>
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.

2 participants