Skip to content

fix: go back to the tab's tmux session after its session ends - #88

Merged
LukeGus merged 1 commit into
Termix-SSH:dev-1.4.1from
Li-Lee:fix/tmux-reattach-after-expiry
Nov 16, 2026
Merged

LukeGus merged 1 commit into
Termix-SSH:dev-1.4.1from
Li-Lee:fix/tmux-reattach-after-expiry

Conversation

@Li-Lee

@Li-Lee Li-Lee commented Nov 16, 2026

Copy link
Copy Markdown

Problem

With Auto tmux on, a terminal tab whose session on the server has ended logs in again like a brand new tab. On a host with more than one tmux session that means the "TMUX SESSIONS" picker, although the tab knew which session it was showing. The usual way to get there: the computer sleeps for longer than the session timeout (30 minutes by default), the server ends the detached sessions, and on wake every tab asks which session to open. The tmux sessions themselves are fine the whole time.

Cause

After sessionExpired (or a dropped SSH connection) the tab sends a fresh connectToHost that carries only the tab's tmuxAttachSession prop, which is empty for an ordinary tab. The tab keeps the name of its tmux session in tmuxSessionNameRef but never sends it, so the backend runs planTmuxAttach as for a new tab.

Fix

The tab remembers its tmux session and sends it as tmuxReattach with a fresh connectToHost. The Auto tmux path attaches it again when the host still has it. When the session is gone, nothing changes: create one, attach the only one, or show the picker.

tmux sessions get renamed, by hand or by tools that name a session after what runs in it, so the name alone is not enough. The backend now reports tmux's creation time (created, already in the session list) with tmux_session_created and tmux_session_attached, and the match uses that time first. The name only breaks a tie between sessions created in the same second, or is used alone when the time is unknown. A session that got the old name but has a different creation time is not taken.

  • tmux-attach-plan.ts: findTmuxSession (pure) and readTmuxSessionRef (checks the value from the client).
  • terminal-socket.ts: connectToHost accepts tmuxReattach, and the Auto tmux path tries it before planTmuxAttach. The picker's tmux_attach accepts the created the list showed. sessionAttached now carries tmuxSession on both reattach paths, so a tab restored after an app restart learns its session from the live server session.
  • session-manager.ts: tmuxSessionCreated next to tmuxSessionName.
  • Terminal.tsx with tmux-reattach.ts: the tab keeps { name, created }, forgets it on Detach tmux and when the picker is cancelled, and sends it with a fresh login. Reattaching to a live session is unchanged.
  • One line in the docs under "Sessions that survive", and a CHANGELOG entry under 1.4.1.

Not covered: a tab opened for a named session (tmuxAttachSession, for example from Tmux Monitor) still asks for that name. A tab restored after the app was closed for longer than the session timeout still asks once, because the remembered session lives in the tab's memory.

Testing

  • New tests: findTmuxSession and readTmuxSessionRef cases; a socket test (a renamed session found by its creation time, a gone session showing the picker as before, a malformed value ignored, created sent on create, tmuxSession sent on reattach, the picker's created kept); frontend tests for what the tab remembers and sends. reconnect-mouse.test.ts gets the new ref in its context.
  • Full suite 737/737 (after scripts/patch-ssh2-agent.cjs and a build), typecheck, Prettier, and validate pass. The new socket test fails without the change.
  • Ran the same change as a patch on a Termix 26.11.0 server (SSH Terminal 1.3.0), with the macOS desktop app linked and connections starting on the server. With the session timeout set to 1 minute, I put the Mac to sleep four times, for 7 to 16 minutes each. On wake, three tabs on two hosts went back to their own sessions without the picker, including sessions renamed after the tab had attached them.

🤖 Generated with Claude Code

When a tab's server session ends (the 30 minute timeout after the
computer slept, or a dropped SSH connection), the tab logs in again and
Auto tmux treats it like a new tab: with several sessions on the host it
shows the session picker, although the tab knew which session it was
showing.

The tab now remembers its tmux session and sends it with the new login.
Auto tmux attaches it again when the host still has it, and otherwise
does what it did before. tmux sessions get renamed (by hand or by a
hook), so the backend reports tmux's creation time with each attach and
create, and the match uses that time, with the name only as a tie
breaker or when the time is unknown. A reattach to a live session also
tells the tab its tmux session, so a tab restored after an app restart
knows it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@termix-triage-bot

Copy link
Copy Markdown

AI review | Looks safe to merge

Adds logic to remember a tab's tmux session and reattach to it after a connection drop or session expiry, using creation time to survive session renames. Input validation, state management, and tests are correct.

Reviewed 50afb27. AI can be wrong, a maintainer still decides. Comment /termix review to run it again.

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@LukeGus
LukeGus merged commit 8deab06 into Termix-SSH:dev-1.4.1 Nov 16, 2026
4 checks passed
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