The best way to control Claude Code, Codex and more from any computer or phone
fix(ssh): retain actionable errors from failed device commands (#19972)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Luís Miguel committed
Oct 20, 2026 at 05:15 UTC
7a286c97442728d0f1db538be2539f2a5ccae603
4 files changed
+74
-6
apps/server/src/device/SshDeviceHost.test.ts
+17
-1
@@ -33,6 +33,7 @@ it.effect("preserves installed status after probes and cleans failed agent activ
33
(forwarding ? tunnelArgs : commandArgs).push([...command.args]);
34
if (forwarding) tunnelStdins.push(command.options.stdin);
35
let output = "";
36
+ let exitCode = 0;
37
if (forwarding) {
38
if (failForward) {
39
failForward = false;
@@ -77,13 +78,19 @@ it.effect("preserves installed status after probes and cleans failed agent activ
78
? { daemonPort: 1235, token: "fixture", entryPath: "/agent.mjs" }
79
: {}),
80
});
81
+ if (mode === "") {
82
+ output = `${"verbose-prefix ".repeat(400)}PANIC: emulator SDK is broken\n`;
83
+ exitCode = 1;
84
+ }
85
}
86
return ChildProcessSpawner.makeHandle({
87
pid: ChildProcessSpawner.ProcessId(123),
88
stdout: Stream.make(new TextEncoder().encode(output)),
89
stderr: Stream.empty,
90
all: Stream.empty,
86
- exitCode: forwarding ? Effect.never : Effect.succeed(ChildProcessSpawner.ExitCode(0)),
91
+ exitCode: forwarding
92
+ ? Effect.never
93
+ : Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
94
isRunning: Effect.succeed(forwarding),
95
kill: () => Effect.void,
96
stdin: Sink.drain,
@@ -124,6 +131,15 @@ it.effect("preserves installed status after probes and cleans failed agent activ
131
expect(owners[0]).toMatch(/^[a-f0-9]{24}$/);
132
expect(forwards).toBe(1);
133
expect(modes.filter((mode) => mode === "start")).toHaveLength(2);
134
+ const ready = yield* host.current;
135
+ expect(ready).not.toBeNull();
136
+ if (ready) {
137
+ const failed = yield* ready.run("emulator", ["-list-avds"]);
138
+ expect(failed.code).toBe(1);
139
+ expect(failed.stdout).toMatch(/^\[truncated\]/);
140
+ expect(failed.stderr).toBe(failed.stdout.trim());
141
+ expect(failed.stderr).toMatch(/PANIC: emulator SDK is broken$/);
142
+ }
143
yield* host.platformAvailability("ios");
144
expect((yield* host.summary).hubInstalled).toBe(true);
145
const failed = yield* host.ensureAgentReady(() => Effect.void).pipe(Effect.result);
apps/server/src/device/SshDeviceHost.ts
+1
@@ -176,6 +176,7 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
176
remoteCommandArgs: commandArgs(
177
`cd "$HOME/.t3/device/hosts/${owner}" && exec ${[command, ...args].map(quoteRemoteArg).join(" ")}`,
178
),
179
+ keepErrorOutputTail: true,
180
...(options?.stdin === undefined ? {} : { stdin: options.stdin }),
181
...(options?.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
182
}),
packages/ssh/src/command.test.ts
+48
@@ -187,6 +187,54 @@ describe("ssh command", () => {
187
}).pipe(Effect.provide(layerProcess));
188
});
189
190
+ it.live.each([
191
+ { name: "default head", keepErrorOutputTail: undefined, exitCode: 1, stderr: "" },
192
+ {
193
+ name: "opt-in tail",
194
+ keepErrorOutputTail: true,
195
+ exitCode: 1,
196
+ stderr: "stderr failure ".repeat(400),
197
+ },
198
+ { name: "successful output", keepErrorOutputTail: true, exitCode: 0, stderr: "" },
199
+ ])("preserves process output: $name", ({ keepErrorOutputTail, exitCode, stderr }) =>
200
+ Effect.gen(function* () {
201
+ const prefix = `HEAD\n${"verbose-prefix ".repeat(400)}`;
202
+ const secret = "synthetic-secret".repeat(400);
203
+ const diagnostic = "\nPANIC: emulator SDK is broken\n";
204
+ const stdout = `${prefix}{"credential":"${secret}"}${diagnostic}`;
205
+ const nativeSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
206
+ // Replace only the SSH endpoint with a real, deterministic process.
207
+ const spawner = ChildProcessSpawner.make(() =>
208
+ nativeSpawner.spawn(
209
+ ChildProcess.make(process.execPath, [
210
+ "-e",
211
+ `process.stdout.write(${JSON.stringify(stdout)}); process.stderr.write(${JSON.stringify(stderr)}); process.exitCode = ${exitCode};`,
212
+ ]),
213
+ ),
214
+ );
215
+ const command = runSshCommand(
216
+ { alias: "synthetic-fixture", hostname: "synthetic-fixture", username: null, port: null },
217
+ keepErrorOutputTail === undefined ? {} : { keepErrorOutputTail },
218
+ ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
219
+ if (exitCode === 0) {
220
+ assert.deepEqual(yield* command, { stdout, stderr });
221
+ return;
222
+ }
223
+ const failure = yield* Effect.flip(command);
224
+ assert.instanceOf(failure, SshCommandError);
225
+ assert.equal(failure.exitCode, 1);
226
+ assert.equal(failure.stderr, stderr);
227
+ assert.equal(failure.message, stderr.trim() || failure.stdout?.trim());
228
+ const redacted = `${prefix}{"credential":"[redacted]"}${diagnostic}`;
229
+ assert.equal(
230
+ failure.stdout,
231
+ keepErrorOutputTail
232
+ ? `[truncated]\n${redacted.slice(-4_000)}`
233
+ : `${redacted.slice(0, 4_000)}\n[truncated]`,
234
+ );
235
+ }).pipe(Effect.provide(NodeServices.layer)),
236
+ );
237
+
238
it.effect("redacts credentials from stdout in non-zero command failures", () => {
239
const spawner = ChildProcessSpawner.make(() =>
240
Effect.succeed(makeFailedProcess({ stdout: '{"credential":"pairing-secret"}\n' })),
packages/ssh/src/command.ts
+8
-5
@@ -39,6 +39,8 @@ export interface RunSshCommandOptions extends SshAuthOptions {
39
readonly remoteCommandArgs?: ReadonlyArray<string>;
40
readonly stdin?: string;
41
readonly timeoutMs?: number;
42
+ /** Keep the end of long failed-command stdout, where the final cause usually is. */
43
+ readonly keepErrorOutputTail?: boolean;
44
}
45
46
export function parseSshResolveOutput(alias: string, stdout: string): DesktopSshEnvironmentTarget {
@@ -133,14 +135,15 @@ const collectProcessOutput = <E>(stream: Stream.Stream<Uint8Array, E>): Effect.E
135
),
136
);
137
136
-function redactSshErrorOutput(output: string): string {
138
+function redactSshErrorOutput(output: string, keepTail = false): string {
139
const redacted = output.replace(
140
/("(?:access_token|bearerToken|credential|pairingToken|token)"\s*:\s*")[^"]+(")/giu,
141
"$1[redacted]$2",
142
);
141
- return redacted.length > MAX_SSH_ERROR_OUTPUT_LENGTH
142
- ? `${redacted.slice(0, MAX_SSH_ERROR_OUTPUT_LENGTH)}\n[truncated]`
143
- : redacted;
143
+ if (redacted.length <= MAX_SSH_ERROR_OUTPUT_LENGTH) return redacted;
144
+ return keepTail
145
+ ? `[truncated]\n${redacted.slice(-MAX_SSH_ERROR_OUTPUT_LENGTH)}`
146
+ : `${redacted.slice(0, MAX_SSH_ERROR_OUTPUT_LENGTH)}\n[truncated]`;
147
}
148
149
function normalizeSshErrorMessage(input: {
@@ -262,7 +265,7 @@ const runSshCommandInScope = Effect.fn("ssh/command.runSshCommand.inScope")(func
265
);
266
267
if (exitCode !== 0) {
265
- const diagnosticStdout = redactSshErrorOutput(stdout);
268
+ const diagnosticStdout = redactSshErrorOutput(stdout, input.keepErrorOutputTail);
269
yield* Effect.logWarning("ssh.command.failed", {
270
...sshTargetLogFields(target),
271
command: ["ssh", ...args],