The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): force-close stalled Linux MIME cache helpers (#25210)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
maria committed
Oct 29, 2026 at 17:55 UTC
efb940dbaf97674c455f9f74d33ca5fc34a1de83
2 files changed
+72
apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
+71
@@ -1,7 +1,11 @@
1
import * as NodeServices from "@effect/platform-node/NodeServices";
2
import { assert, describe, it } from "@effect/vitest";
3
+import * as HostProcess from "@t3tools/shared/HostProcess";
4
+import * as Cause from "effect/Cause";
5
import * as Deferred from "effect/Deferred";
6
import * as Effect from "effect/Effect";
7
+import * as Exit from "effect/Exit";
8
+import * as Fiber from "effect/Fiber";
9
import * as FileSystem from "effect/FileSystem";
10
import * as Layer from "effect/Layer";
11
import * as Option from "effect/Option";
@@ -9,6 +13,8 @@ import * as Path from "effect/Path";
13
import * as PlatformError from "effect/PlatformError";
14
import * as Sink from "effect/Sink";
15
import * as Stream from "effect/Stream";
16
+import * as TestClock from "effect/testing/TestClock";
17
+import * as ChildProcess from "effect/process/ChildProcess";
18
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
19
20
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
@@ -56,6 +62,7 @@ const layerHandler = (
62
recorded: RecordedRegistration,
63
input: {
64
readonly environment?: Record<string, unknown>;
65
+ readonly processSpawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];
66
readonly updateDesktopDatabaseExitCode?: number;
67
readonly updateDesktopDatabaseStalled?: boolean;
68
readonly updateDesktopDatabaseStarted?: Deferred.Deferred<void>;
@@ -106,6 +113,7 @@ const layerHandler = (
113
Layer.succeed(
114
ChildProcessSpawner.ChildProcessSpawner,
115
ChildProcessSpawner.make((command) => {
116
+ if (input.processSpawner) return input.processSpawner.spawn(command);
117
const childProcess = command as unknown as {
118
readonly command: string;
119
readonly args: ReadonlyArray<string>;
@@ -358,6 +366,69 @@ describe("DesktopLinuxUrlHandler", () => {
366
assert.deepEqual(writeFailed.commands, []);
367
});
368
});
369
+
370
+ it.effect.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
371
+ "continues registration after a timed-out cache helper ignores SIGTERM",
372
+ () =>
373
+ Effect.gen(function* () {
374
+ const realSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
375
+ const nodeExecutable = yield* HostProcess.ExecutablePath;
376
+ const recorded = emptyRecording();
377
+ const spawned = yield* Deferred.make<ChildProcessSpawner.ChildProcessHandle>();
378
+ const ready = yield* Deferred.make<void>();
379
+ const processSpawner = ChildProcessSpawner.make((command) =>
380
+ Effect.gen(function* () {
381
+ if (!ChildProcess.isStandardCommand(command)) {
382
+ return yield* Effect.die("expected a single registration command");
383
+ }
384
+ recorded.commands.push({ command: command.command, args: command.args });
385
+ if (command.command !== "update-desktop-database") return mockProcess(0);
386
+ const child = yield* realSpawner.spawn(
387
+ ChildProcess.make(
388
+ nodeExecutable,
389
+ [
390
+ "-e",
391
+ // The watchdog makes the unfixed case exit with a distinguishable code.
392
+ "process.on('SIGTERM', () => setTimeout(() => process.exit(99), 5000));" +
393
+ "process.stdout.write('ready\\n'); setInterval(() => {}, 2147483647);",
394
+ ],
395
+ { ...command.options, stdout: "pipe" },
396
+ ),
397
+ );
398
+ yield* Deferred.succeed(spawned, child);
399
+ yield* Stream.runHead(child.stdout);
400
+ yield* Deferred.succeed(ready, undefined);
401
+ return child;
402
+ }),
403
+ );
404
+ const registration = yield* runRegister(recorded, { processSpawner }).pipe(
405
+ Effect.forkScoped,
406
+ );
407
+ const child = yield* Deferred.await(spawned);
408
+ yield* Effect.addFinalizer(() =>
409
+ child.isRunning.pipe(
410
+ Effect.flatMap((running) =>
411
+ running ? child.kill({ killSignal: "SIGKILL" }) : Effect.void,
412
+ ),
413
+ Effect.ignore,
414
+ ),
415
+ );
416
+ yield* Deferred.await(ready);
417
+ yield* TestClock.adjust("5 seconds");
418
+ yield* Fiber.join(registration);
419
+
420
+ const exit = yield* Effect.exit(child.exitCode);
421
+ if (Exit.isFailure(exit)) {
422
+ assert.include(Cause.pretty(exit.cause), "SIGKILL");
423
+ } else {
424
+ assert.fail(`cache helper exited with ${exit.value} instead of being force-killed`);
425
+ }
426
+ assert.deepEqual(
427
+ recorded.commands.map(({ command }) => command),
428
+ ["update-desktop-database", "xdg-mime"],
429
+ );
430
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
431
+ );
432
});
433
434
interface ThemeIconRun {
apps/desktop/src/app/DesktopLinuxUrlHandler.ts
+1
@@ -174,6 +174,7 @@ export const make = Effect.gen(function* () {
174
stdin: "ignore",
175
stdout: "ignore",
176
stderr: "ignore",
177
+ forceKillAfter: "1 second",
178
},
179
);
180
const handle = yield* spawner.spawn(command);