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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(ssh): a streaming child killed before its open fails never writes to its ended pipes
enes61b20dbbb94a
diff --git a/src/core/remote-ssh/native/native-invoke.test.ts b/src/core/remote-ssh/native/native-invoke.test.tsindex 5e32a3ba5..ab04ed29a 100644--- a/src/core/remote-ssh/native/native-invoke.test.ts+++ b/src/core/remote-ssh/native/native-invoke.test.ts@@ -172,6 +172,28 @@ describe('native-invoke', () => {expect(code).toBe(255)})+ it('a streaming child killed before its open FAILS never writes to its ended pipes', async () => {+ // CI caught this as an uncaught ERR_STREAM_WRITE_AFTER_END: kill() closed the child, then the+ // connection failed and the error path wrote to the ended stderr.+ const failing = new NativeMux({+ defaultAgent: () => undefined,+ resolveHost: () => new Promise((_r, reject) => setTimeout(() => reject(new Error('late failure')), 30))+ })+ muxes.push(failing)+ const uncaught: unknown[] = []+ const onErr = (e: unknown): void => void uncaught.push(e)+ process.on('uncaughtException', onErr)+ try {+ const child = spawnSshArgvStream(failing, childArgs(conn(), path.join(dir, 'late.sock'), 'x'))+ child.kill('SIGKILL')+ expect(await new Promise<number>((r) => child.on('close', r))).toBe(255)+ await new Promise((r) => setTimeout(r, 80)) // past the late failure+ expect(uncaught).toEqual([])+ } finally {+ process.off('uncaughtException', onErr)+ }+ })+it('an argv the parser refuses is a named exit 255, not a guess', async () => {const r = await runSshArgv(mux(), ['-L', '1:h:2', '[email protected]'])expect(r.code).toBe(255)diff --git a/src/core/remote-ssh/native/native-invoke.ts b/src/core/remote-ssh/native/native-invoke.tsindex 6e427954e..6f4ad0147 100644--- a/src/core/remote-ssh/native/native-invoke.ts+++ b/src/core/remote-ssh/native/native-invoke.ts@@ -216,6 +216,7 @@ export function spawnSshArgvStream(mux: NativeMux, argv: string[]): NativeStreamif (p.kind !== 'exec') throw new Error('native ssh transport: not a command argv')} catch (e) {queueMicrotask(() => {+ if (done) returnchild.stderr.write(`${(e as Error).message}\n`)finish(255)})@@ -236,6 +237,9 @@ export function spawnSshArgvStream(mux: NativeMux, argv: string[]): NativeStreamch.end()},(e: Error) => {+ // Killed before the open failed: the child already closed and its pipes are ended. A write+ // here would throw ERR_STREAM_WRITE_AFTER_END as an uncaught exception in main.+ if (done) returnchild.stderr.write(`${e.message}\n`)finish(255)}