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.

fix(ssh): only set tmuxConfPath when the remote conf write succeeds (no -f to a missing conf)

enes84ee8e77ff9e
diff --git a/src/main/remote-ssh/ssh-project.test.ts b/src/main/remote-ssh/ssh-project.test.ts
index 18d33ddae..c45168b31 100644
--- a/src/main/remote-ssh/ssh-project.test.ts
+++ b/src/main/remote-ssh/ssh-project.test.ts
@@ -132,6 +132,30 @@ describe('SshProjectManager', () => {
expect(calls.some((c) => c.args.join(' ').includes(`source-file '/home/u/.nodeterm/tmux.conf'`))).toBe(true)
})
+ it('connect leaves tmuxConfPath undefined when the remote conf write fails (no -f to a missing conf)', async () => {
+ // The runner resolves (does not throw) on a non-zero remote exit. Fail the `cat >`/mkdir write
+ // with code 1 while letting the $HOME probe succeed so remoteHome resolves — this isolates the
+ // write-failure path. tmuxConfPath must stay undefined (so no `-f <missing-conf>`), yet connect
+ // still succeeds and returns the control path.
+ const run = vi.fn(async (args: string[]) => {
+ const cmd = args.join(' ')
+ if (cmd.includes('printf %s')) return { code: 0, stdout: '/home/u' }
+ if (cmd.includes('cat > ') || cmd.includes('mkdir -p')) return { code: 1, stdout: '' }
+ return { code: 0, stdout: '' }
+ })
+ const mgr = new SshProjectManager({
+ userDataDir: '/ud',
+ spawnMaster: vi.fn(() => ({ kill: vi.fn(), on: vi.fn() })),
+ run,
+ runScp: vi.fn(async () => ({ code: 0 })),
+ getHook: () => ({ port: 1, token: 't', version: '1' }),
+ onStatus: vi.fn()
+ })
+ const { controlPath, tmuxConfPath } = await mgr.connect('p1', conn)
+ expect(tmuxConfPath).toBeUndefined()
+ expect(controlPath).toBe(controlPathFor('p1'))
+ })
+
it('uploadFile fails open (null) when not connected', async () => {
const { mgr } = makeMgr()
expect(await mgr.uploadFile('nope', '/x', 'x')).toBeNull()
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index aadaf84a8..8d0189d25 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -174,12 +174,19 @@ export class SshProjectManager {
const confPath = `${remoteHome}/.nodeterm/tmux.conf`
try {
const dir = `${remoteHome}/.nodeterm`
- await this.r.run(
+ // The runner RESOLVES (doesn't throw) on a non-zero remote exit, so the catch below
+ // only guards a thrown error. Gate `tmuxConfPath` on the WRITE's exit code: a failed
+ // write (mkdir perms, disk full, …) must leave it undefined so `remoteTmuxCommand`
+ // never passes `-f <missing-conf>` (which makes tmux refuse to start → terminal dies).
+ const w = await this.r.run(
childArgs(conn, controlPath, `mkdir -p ${posixQuote(dir)} && cat > ${posixQuote(confPath)}`),
remoteTmuxConf(50000)
)
- await this.r.run(childArgs(conn, controlPath, `tmux -L ${RMT_TMUX_SOCKET} source-file ${posixQuote(confPath)}`))
- tmuxConfPath = confPath
+ if (w.code === 0) {
+ // source-file is best-effort (pushes options into a warm server); ignore its result.
+ await this.r.run(childArgs(conn, controlPath, `tmux -L ${RMT_TMUX_SOCKET} source-file ${posixQuote(confPath)}`))
+ tmuxConfPath = confPath
+ }
} catch {
/* fail-open: no conf → remote tmux uses host defaults */
}