The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 03:00 UTC
fix(server): device-host SSH tunnels exit when the server dies (#17448)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Killian Cazin committed
Oct 19, 2026 at 13:44 UTC
4130507748ac10fd84d3016bb19410e7c39b7df8
2 files changed
+19
-3
apps/server/src/device/SshDeviceHost.test.ts
+11
-1
@@ -21,6 +21,7 @@ it.effect("preserves installed status after probes and cleans failed agent activ
21
const modes: string[] = [];
22
const owners: string[] = [];
23
const tunnelArgs: string[][] = [];
24
+ const tunnelStdins: unknown[] = [];
25
const commandArgs: string[][] = [];
26
let forwards = 0;
27
let failForward = true;
@@ -28,8 +29,9 @@ it.effect("preserves installed status after probes and cleans failed agent activ
29
const spawner = ChildProcessSpawner.make((command) =>
30
Effect.gen(function* () {
31
if (command._tag !== "StandardCommand") return yield* Effect.die("Unexpected command");
31
- const forwarding = command.args.includes("-N");
32
+ const forwarding = command.args.includes("-L");
33
(forwarding ? tunnelArgs : commandArgs).push([...command.args]);
34
+ if (forwarding) tunnelStdins.push(command.options.stdin);
35
let output = "";
36
if (forwarding) {
37
if (failForward) {
@@ -143,7 +145,15 @@ it.effect("preserves installed status after probes and cleans failed agent activ
145
expect(index).toBeGreaterThan(0);
146
expect(args[index - 1]).toBe("-o");
147
}
148
+ // The tunnel lives only as long as the server holds the write end of its stdin.
149
+ expect(args).not.toContain("-N");
150
+ expect(args.slice(args.indexOf("test.example") + 1)).toEqual([
151
+ "sh",
152
+ "-c",
153
+ "'exec cat >/dev/null'",
154
+ ]);
155
}
156
+ expect(tunnelStdins).toEqual(tunnelArgs.map(() => "pipe"));
157
expect(commandArgs.length).toBeGreaterThan(0);
158
for (const args of commandArgs) {
159
for (const option of multiplexingOff) expect(args).not.toContain(option);
apps/server/src/device/SshDeviceHost.ts
+8
-2
@@ -254,15 +254,21 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
254
"ServerAliveInterval=10",
255
"-o",
256
"ServerAliveCountMax=3",
257
- "-N",
257
+ "-T",
258
"-L",
259
`127.0.0.1:${hubPort}:127.0.0.1:${remote.hubPort}`,
260
...(remote.daemonPort === undefined
261
? []
262
: ["-L", `127.0.0.1:${daemonPort}:127.0.0.1:${remote.daemonPort}`]),
263
config.target,
264
+ // The server holds the only write end of this stdin, so when it exits for any
265
+ // reason the remote `cat` sees EOF and ssh exits once its forwarded connections
266
+ // close, instead of being orphaned.
267
+ "sh",
268
+ "-c",
269
+ quoteRemoteArg("exec cat >/dev/null"),
270
],
265
- { stdin: "ignore", stdout: "ignore", stderr: "pipe" },
271
+ { stdin: "pipe", stdout: "ignore", stderr: "pipe" },
272
),
273
)
274
.pipe(