Skip to content

Commit 3b744af

Browse files
SunkenInTimeclaudejuliusmarminge
authored
fix(desktop): preserve signals in backend exit logs (pingdotgg#15406)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 29d4610 commit 3b744af

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,30 @@ describe("DesktopBackendManager", () => {
431431
}),
432432
);
433433

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+
434458
it.effect("reports output stream failures with process and stream context", () =>
435459
Effect.gen(function* () {
436460
const outputCause = PlatformError.systemError({

‎apps/desktop/src/backend/DesktopBackendManager.ts‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,22 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
568568
yield* probeReadiness().pipe(Effect.repeat({ while: (ready) => !ready }), Effect.forkScoped);
569569

570570
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(
573587
new BackendProcessExitStatusError({
574588
executablePath: options.executablePath,
575589
entryPath: options.entryPath,
@@ -578,7 +592,8 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
578592
pid: Number(handle.pid),
579593
cause,
580594
}),
581-
),
595+
);
596+
}),
582597
Effect.exit,
583598
);
584599
yield* options.onExitObserved?.() ?? Effect.void;
@@ -592,11 +607,7 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
592607
if (Exit.isFailure(exit)) {
593608
return yield* Effect.failCause(exit.cause);
594609
}
595-
const exitCode = exit.value;
596-
return {
597-
code: Option.some(exitCode),
598-
reason: `code=${exitCode}`,
599-
} satisfies BackendProcessExit;
610+
return exit.value;
600611
});
601612

602613
export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (

0 commit comments

Comments
 (0)