The best way to control Claude Code, Codex and more from any computer or phone
fix(ssh): failed launches report only their own output (#35717)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: MarMar Labs <271345736+MarMarLabs@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 14, 2026 at 18:29 UTC
033bb5a82ebdccf6414982483a3d30f303efcb92
3 files changed
+59
-1
docs/operations/observability.md
+2
-1
@@ -10,7 +10,8 @@ T3 Code has one server-side observability model:
10
11
The local trace file is the persisted source of truth for normal local launches. Those launches do not
12
write a separate server log file, but SSH-managed launches also persist the remote process's
13
-stdout/stderr at `~/.t3/ssh-launch/<state>/server.log`.
13
+stdout/stderr at `~/.t3/ssh-launch/<state>/server.log`. Each managed launch starts that file
14
+empty, so it holds only the latest launch's output.
15
16
## Where To Find Things
17
packages/ssh/src/tunnel.test.ts
+54
@@ -221,6 +221,60 @@ describe("ssh tunnel scripts", () => {
221
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
222
);
223
224
+ it.live("reports only the failed launch's own output, not an earlier launch's log", () =>
225
+ Effect.gen(function* () {
226
+ const fs = yield* FileSystem.FileSystem;
227
+ const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-ssh-launch-log-" });
228
+ const target = { alias: "devbox", hostname: "devbox", username: null, port: null };
229
+ const stateDir = NodePath.join(home, ".t3", "ssh-launch", yield* remoteStateKey(target));
230
+ const bin = NodePath.join(home, "bin");
231
+ yield* fs.makeDirectory(stateDir, { recursive: true });
232
+ yield* fs.makeDirectory(bin);
233
+ yield* fs.writeFileString(NodePath.join(stateDir, "server.log"), "EARLIER_LAUNCH\n");
234
+ // The new server exits without output. Readiness then fails after a process from the
235
+ // earlier launch writes through the log descriptor it still holds (fd 3).
236
+ yield* fs.writeFileString(
237
+ NodePath.join(bin, "node"),
238
+ '#!/bin/sh\n[ "$1" = - ] || exit 0\ncat >/dev/null\ncase "$2" in\n */port) echo 37731 ;;\n 37731) { printf "EARLIER_PROCESS\\n" >&3; } 2>/dev/null; exit 1 ;;\n *) exit 1 ;;\nesac\n',
239
+ { mode: 0o755 },
240
+ );
241
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
242
+ const remoteShell = ChildProcessSpawner.make((command) => {
243
+ if (command._tag !== "StandardCommand") return spawner.spawn(command);
244
+ return spawner.spawn(
245
+ ChildProcess.make(
246
+ "sh",
247
+ [
248
+ "-c",
249
+ 'exec 3>>"$1/server.log"; exec sh -s -- "$2"',
250
+ "sh",
251
+ stateDir,
252
+ launchStateKey(command) ?? "",
253
+ ],
254
+ {
255
+ ...command.options,
256
+ env: { HOME: home, PATH: `${bin}:${process.env.PATH ?? ""}` },
257
+ extendEnv: false,
258
+ },
259
+ ),
260
+ );
261
+ });
262
+ const result = yield* SshTunnel.launchOrReuseRemoteServer(target, undefined, {
263
+ nodeScriptPath: "/unused/server.ts",
264
+ }).pipe(
265
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, remoteShell),
266
+ Effect.result,
267
+ );
268
+ assert.isTrue(Result.isFailure(result));
269
+ if (!Result.isFailure(result)) return;
270
+ assert.isTrue(isSshCommandError(result.failure));
271
+ if (!isSshCommandError(result.failure)) return;
272
+ assert.include(result.failure.stderr, "It wrote nothing to");
273
+ assert.notInclude(result.failure.stderr, "EARLIER_LAUNCH");
274
+ assert.notInclude(result.failure.stderr, "EARLIER_PROCESS");
275
+ }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
276
+ );
277
+
278
it("rejects archive versions that are not a single exact version segment", () => {
279
for (const archiveVersion of [
280
"../other",
packages/ssh/src/tunnel.ts
+3
@@ -906,6 +906,9 @@ if [ -z "$REMOTE_PORT" ]; then
906
fi
907
exit 1
908
fi
909
+ # Start this launch's log empty. Unlink rather than truncate: a process from an
910
+ # earlier launch can still hold the old log open and keep writing to it.
911
+ rm -f "$LOG_FILE"
912
nohup env T3CODE_NO_BROWSER=1 "$RUNNER_FILE" serve --host 127.0.0.1 --port "$REMOTE_PORT" --base-dir "$DEFAULT_SERVER_HOME" >>"$LOG_FILE" 2>&1 < /dev/null &
913
REMOTE_PID="$!"
914
printf '%s\\n' "$REMOTE_PID" >"$PID_FILE"