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, 01:45 UTC
fix(desktop): preserve signals in backend exit logs (#15406)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Dara Adedeji committed
Oct 19, 2026 at 16:25 UTC
3b744af49a88f1be5cc4694ac392f0dfc9117e30
2 files changed
+43
-8
apps/desktop/src/backend/DesktopBackendManager.test.ts
+24
@@ -431,6 +431,30 @@ describe("DesktopBackendManager", () => {
431
}),
432
);
433
434
+ it.effect("reports a SIGKILL exit without an exit code", () =>
435
+ Effect.gen(function* () {
436
+ const exitCause = PlatformError.systemError({
437
+ _tag: "Unknown",
438
+ module: "ChildProcess",
439
+ method: "exitCode",
440
+ cause: new Error("Process interrupted due to receipt of signal: 'SIGKILL'"),
441
+ });
442
+ const layerSpawner = Layer.succeed(
443
+ ChildProcessSpawner.ChildProcessSpawner,
444
+ ChildProcessSpawner.make(() =>
445
+ Effect.succeed(makeProcess({ exitCode: Effect.fail(exitCause) })),
446
+ ),
447
+ );
448
+
449
+ const exit = yield* DesktopBackendManager.runBackendProcess({
450
+ ...baseConfig,
451
+ desktopTelemetryStream: Stream.empty,
452
+ }).pipe(Effect.scoped, Effect.provide(Layer.merge(layerSpawner, layerHealthyHttpClient)));
453
+
454
+ assert.deepEqual(exit, { code: Option.none(), reason: "killed by SIGKILL" });
455
+ }),
456
+ );
457
+
458
it.effect("reports output stream failures with process and stream context", () =>
459
Effect.gen(function* () {
460
const outputCause = PlatformError.systemError({
apps/desktop/src/backend/DesktopBackendManager.ts
+19
-8
@@ -568,8 +568,22 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
568
yield* probeReadiness().pipe(Effect.repeat({ while: (ready) => !ready }), Effect.forkScoped);
569
570
const exit = yield* handle.exitCode.pipe(
571
- Effect.mapError(
572
- (cause) =>
571
+ Effect.map((exitCode) => ({
572
+ code: Option.some(exitCode),
573
+ reason: `code=${exitCode}`,
574
+ })),
575
+ Effect.catch((cause) => {
576
+ // Effect's Node spawner exposes signal exits only through this cause message.
577
+ const signal =
578
+ cause.cause instanceof Error
579
+ ? /^Process interrupted due to receipt of signal: '(SIG[A-Z0-9]+)'$/.exec(
580
+ cause.cause.message,
581
+ )?.[1]
582
+ : undefined;
583
+ if (signal !== undefined) {
584
+ return Effect.succeed({ code: Option.none(), reason: `killed by ${signal}` });
585
+ }
586
+ return Effect.fail(
587
new BackendProcessExitStatusError({
588
executablePath: options.executablePath,
589
entryPath: options.entryPath,
@@ -578,7 +592,8 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
592
pid: Number(handle.pid),
593
cause,
594
}),
581
- ),
595
+ );
596
+ }),
597
Effect.exit,
598
);
599
yield* options.onExitObserved?.() ?? Effect.void;
@@ -592,11 +607,7 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
607
if (Exit.isFailure(exit)) {
608
return yield* Effect.failCause(exit.cause);
609
}
595
- const exitCode = exit.value;
596
- return {
597
- code: Option.some(exitCode),
598
- reason: `code=${exitCode}`,
599
- } satisfies BackendProcessExit;
610
+ return exit.value;
611
});
612
613
export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (