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): short, space-free ControlMaster socket path (macOS userData too long/spaced)

enes54ebc1c6d61f
diff --git a/src/main/remote-ssh/control-master.test.ts b/src/main/remote-ssh/control-master.test.ts
index 522b23841..533d95ff2 100644
--- a/src/main/remote-ssh/control-master.test.ts
+++ b/src/main/remote-ssh/control-master.test.ts
@@ -1,3 +1,4 @@
+import os from 'os'
import { describe, expect, it } from 'vitest'
import {
controlPathFor,
@@ -17,8 +18,19 @@ import {
const conn = { host: 'h.example.com', user: 'deploy', port: 2222, identityFile: '/k/id' }
describe('controlPathFor', () => {
- it('puts a per-project socket under <userData>/ssh-cm', () => {
- expect(controlPathFor('/ud', 'proj1')).toBe('/ud/ssh-cm/proj1.sock')
+ it('returns a SHORT, space-free socket path under ~/.nodeterm/ssh-cm (not the long/spaced userData)', () => {
+ // Regression: macOS userData is `~/Library/Application Support/<app>` — too long for a unix
+ // socket (sun_path 104, minus ssh's ~17-char bind suffix) AND has a space ssh's `-o` rejects.
+ const cp = controlPathFor('a-fairly-long-project-id-0123456789')
+ expect(cp.startsWith(`${os.homedir()}/.nodeterm/ssh-cm/`)).toBe(true)
+ expect(cp.endsWith('.sock')).toBe(true)
+ expect(cp).not.toContain(' ')
+ // Must stay well under 104 even after ssh appends its ~17-char temp suffix while binding.
+ expect(cp.length).toBeLessThan(87)
+ })
+ it('is deterministic and distinct per project id', () => {
+ expect(controlPathFor('proj1')).toBe(controlPathFor('proj1'))
+ expect(controlPathFor('proj1')).not.toBe(controlPathFor('proj2'))
})
})
diff --git a/src/main/remote-ssh/control-master.ts b/src/main/remote-ssh/control-master.ts
index 31780d577..216bba75b 100644
--- a/src/main/remote-ssh/control-master.ts
+++ b/src/main/remote-ssh/control-master.ts
@@ -1,13 +1,25 @@
// Pure ssh/tmux argv + remote-command builders for SSH projects. No electron/node-pty imports
// — unit-testable in isolation. The electron/spawn wiring lives in ssh-project.ts + pty-manager.
+import os from 'os'
+import path from 'path'
+import { createHash } from 'crypto'
import { quoteRemotePath, remoteTmuxCommand, type SshConnection } from '../../shared/ssh'
/** Dedicated remote tmux socket so an SSH project never collides with the user's own tmux. */
export const RMT_TMUX_SOCKET = 'nodeterm-rmt'
-/** Per-project ControlMaster socket path under <userData>/ssh-cm. */
-export function controlPathFor(userDataDir: string, projectId: string): string {
- return `${userDataDir}/ssh-cm/${projectId}.sock`
+/**
+ * Per-project ControlMaster socket path. Deliberately SHORT and space-free. The macOS userData dir
+ * (`~/Library/Application Support/<app>`) cannot host the socket: it both exceeds the unix-domain
+ * socket `sun_path` limit (104 bytes — and ssh appends a ~17-char temp suffix while binding the
+ * master, pushing a ~102-char path over) AND contains a space, which ssh's `-o ControlPath=` parser
+ * rejects ("extra arguments at end of line"). Either makes the master silently fail to bind. So we
+ * hash the project id to a fixed length under a short home dir (`~/.nodeterm/ssh-cm/`) — the master
+ * socket then always binds, regardless of project id or platform userData location.
+ */
+export function controlPathFor(projectId: string): string {
+ const id = createHash('sha256').update(projectId).digest('hex').slice(0, 16)
+ return path.join(os.homedir(), '.nodeterm', 'ssh-cm', `${id}.sock`)
}
function target(conn: SshConnection): string {
diff --git a/src/main/remote-ssh/ssh-project.test.ts b/src/main/remote-ssh/ssh-project.test.ts
index 8b051aab9..9c4b3d996 100644
--- a/src/main/remote-ssh/ssh-project.test.ts
+++ b/src/main/remote-ssh/ssh-project.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it, vi } from 'vitest'
import { SshProjectManager } from './ssh-project'
+import { controlPathFor } from './control-master'
const conn = { host: 'h', user: 'u' }
@@ -22,7 +23,7 @@ describe('SshProjectManager', () => {
it('connect emits connecting→connected and returns the control path', async () => {
const { mgr, statuses } = makeMgr()
const { controlPath } = await mgr.connect('p1', conn)
- expect(controlPath).toBe('/ud/ssh-cm/p1.sock')
+ expect(controlPath).toBe(controlPathFor('p1'))
expect(statuses).toEqual(['connecting', 'connected'])
})
@@ -44,7 +45,7 @@ describe('SshProjectManager', () => {
const { mgr } = makeMgr()
expect(mgr.refForProject('p1')).toBeUndefined()
await mgr.connect('p1', conn)
- expect(mgr.refForProject('p1')).toEqual({ conn, controlPath: '/ud/ssh-cm/p1.sock' })
+ expect(mgr.refForProject('p1')).toEqual({ conn, controlPath: controlPathFor('p1') })
expect(mgr.refForProject('nope')).toBeUndefined()
})
})
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index c6c8be631..c86f23c37 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -91,13 +91,13 @@ export class SshProjectManager {
existing.master.kill()
this.conns.delete(projectId)
}
- const controlPath = controlPathFor(this.r.userDataDir, projectId)
- // Best-effort: the socket dir lives under <userData> in production. If it can't be made,
- // the master/`-O check` loop below fails and we report an error status anyway.
+ const controlPath = controlPathFor(projectId)
+ // Best-effort: the socket dir is a short, space-free home dir (~/.nodeterm/ssh-cm). If it can't
+ // be made, the master/`-O check` loop below fails and we report an error status anyway.
try {
await fs.mkdir(path.dirname(controlPath), { recursive: true, mode: 0o700 })
} catch {
- // ignore — keeps the manager unit-testable with a synthetic userDataDir
+ // ignore — keeps the manager unit-testable
}
this.r.onStatus({ projectId, status: 'connecting' })
const master = this.r.spawnMaster(masterArgs(conn, controlPath))