Skip to content

The agent that grows with you

fix(desktop): support zsh SSH probe watchdogs

KoNit-K1267d7fdd030
diff --git a/apps/desktop/electron/ssh-connection.test.ts b/apps/desktop/electron/ssh-connection.test.ts
index 5d9b223c87b..c8b9e92f977 100644
--- a/apps/desktop/electron/ssh-connection.test.ts
+++ b/apps/desktop/electron/ssh-connection.test.ts
@@ -1092,6 +1092,17 @@ test('withRemoteTimeout kills a hung probe remotely instead of orphaning it (#11
)
assert.ok(REMOTE_PROBE_TIMEOUT_SECS * 1000 < 20_000, 'remote watchdog fires before the local exec timeout')
+ // SSH runs the remote command through the account's login shell. In
+ // non-interactive zsh, a bare `set -m` is fatal, so the wrapper must still
+ // run a healthy probe rather than reporting the remote as unsupported.
+ const zsh = await execFileAsync('sh', ['-c', 'command -v zsh || true']).then(r => r.stdout.trim())
+
+ if (zsh) {
+ const { stdout: zshStdout } = await execFileAsync(zsh, ['-fc', withRemoteTimeout('echo zsh-ok', 5)])
+
+ assert.equal(zshStdout, 'zsh-ok\n')
+ }
+
// Behavior through a real POSIX shell: healthy output passes through …
const healthyStart = Date.now()
const { stdout } = await execFileAsync('sh', ['-c', withRemoteTimeout('echo hello', 5)])
diff --git a/apps/desktop/electron/ssh-connection.ts b/apps/desktop/electron/ssh-connection.ts
index 0af6437f825..09880e7bf18 100644
--- a/apps/desktop/electron/ssh-connection.ts
+++ b/apps/desktop/electron/ssh-connection.ts
@@ -350,10 +350,11 @@ function withRemoteTimeout(remoteCommand, timeoutSecs = REMOTE_PROBE_TIMEOUT_SEC
// Job control (`set -m`) puts the probe in its own process group so the
// watchdog can also reach a grandchild left behind by a launcher that runs
- // the CLI without exec. Shells that cannot enable it without a tty fall
- // back to killing the direct child.
+ // the CLI without exec. Non-interactive zsh exits when asked to enable
+ // monitor mode, so skip that setup there and fall back to killing the direct
+ // child. Other shells retain the process-group cleanup where supported.
return (
- `set -m 2>/dev/null; (${remoteCommand}) </dev/null & __htp=$!; set +m 2>/dev/null; ` +
+ `[ -n "\${ZSH_VERSION-}" ] || set -m 2>/dev/null; (${remoteCommand}) </dev/null & __htp=$!; set +m 2>/dev/null; ` +
`(sleep ${secs} </dev/null >/dev/null 2>&1; kill -9 -- -$__htp 2>/dev/null; kill -9 $__htp 2>/dev/null) & __htw=$!; ` +
`wait $__htp; __htrc=$?; ` +
`kill $__htw 2>/dev/null; wait $__htw 2>/dev/null; ` +