Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(ssh): re-validate masters on wake instead of waiting out ServerAlive

enes063f242b763a
diff --git a/src/main/index.ts b/src/main/index.ts
index 73328d430..187609576 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -2,7 +2,7 @@ import { join, resolve, posix } from 'path'
import { readFile } from 'fs/promises'
import { homedir } from 'os'
import { randomUUID } from 'crypto'
-import { app, BrowserWindow, dialog, ipcMain, Notification, shell, systemPreferences } from 'electron'
+import { app, BrowserWindow, dialog, ipcMain, Notification, powerMonitor, shell, systemPreferences } from 'electron'
import { IPC } from '../shared/ipc'
import { registerFsHandlers } from '../core/fs-handlers'
import { PtyManager } from '../core/pty-manager'
@@ -1234,6 +1234,13 @@ app.whenReady().then(async () => {
if (adopted) sendToMain(IPC.workspaceExternalChange, adopted)
})
})
+ // Wake-from-sleep: re-validate every SSH master NOW instead of letting ServerAlive discover the
+ // dead TCP ~60s later — until it does, every remote terminal looks alive and is dead (no echo,
+ // no scroll). The small delay lets the network interface come back up first; connect() is
+ // idempotent so a master that survived the nap is a cheap `-O check` no-op.
+ powerMonitor.on('resume', () => {
+ setTimeout(() => void sshProjectManager?.revalidateAll(), 2000)
+ })
// While connected, poll each SSH project's server file: the mobile companion appends the
// sessions it starts to <remoteCwd>/.nodeterm/project.json, and this is how those nodes reach
// the live canvas without a reconnect. Read-only unless a mirror write is owed
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index 56a97ff25..6044a6edf 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -431,6 +431,26 @@ export class SshProjectManager {
return this.conns.get(projectId)?.remoteHome
}
+ /**
+ * Proactively re-validate every cached master (powerMonitor 'resume'). Sleep kills the TCP
+ * under the masters, but ServerAlive only notices ~60s AFTER wake — until then every terminal
+ * looks alive and is dead (keys echo nothing, scroll does nothing). `connect()` is idempotent:
+ * a live master returns immediately; a dead one is killed — which tears down its mux'd
+ * per-terminal ssh clients too, so their exit-255 drops fire the renderer's SshReconnector
+ * NOW instead of a minute later — and re-established, after which the reconnector's
+ * 'connected' flush respawns the dead nodes. Failures just leave the normal status-event
+ * error path in charge (connect reports it before throwing).
+ */
+ async revalidateAll(): Promise<void> {
+ for (const [projectId, e] of [...this.conns]) {
+ try {
+ await this.connect(projectId, e.conn, e.remoteCwd)
+ } catch {
+ // connect() already reported an error status for this project; keep checking the rest.
+ }
+ }
+ }
+
/** The connection's cached remote `--permission-mode auto` capability (undefined = not
* probed / not connected). Feeds the agent-status settings block the phone reads. */
remoteAutoPermFor(projectId: string): boolean | undefined {