The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): allow slow backends to start before showing recovery (#26247)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Nov 1, 2026 at 07:37 UTC
01eb339371010c4c7048683a0fa07825655a5937
2 files changed
+40
-1
apps/desktop/src/backend/DesktopBackendManager.test.ts
+38
@@ -631,4 +631,42 @@ describe("DesktopBackendManager", () => {
631
}).pipe(Effect.provide(TestClock.layer())),
632
),
633
);
634
+
635
+ it.effect("waits out a slow startup and reports one that never becomes ready", () =>
636
+ Effect.scoped(
637
+ Effect.gen(function* () {
638
+ const reports = yield* Queue.unbounded<DesktopBackendManager.BackendStartupFailure>();
639
+ const startInstance = (status: Ref.Ref<number>, onReady?: Effect.Effect<void>) =>
640
+ makeTestInstance({
641
+ spawnerLayer: Layer.succeed(
642
+ ChildProcessSpawner.ChildProcessSpawner,
643
+ ChildProcessSpawner.make(() =>
644
+ Effect.succeed(makeProcess({ exitCode: Effect.never })),
645
+ ),
646
+ ),
647
+ httpClientLayer: layerHttpClient((request) =>
648
+ Ref.get(status).pipe(Effect.map((code) => responseForRequest(request, code))),
649
+ ),
650
+ onStartupFailure: (failure) => Queue.offer(reports, failure).pipe(Effect.asVoid),
651
+ ...(onReady ? { onReady } : {}),
652
+ }).pipe(Effect.tap((instance) => instance.start));
653
+
654
+ const slowStatus = yield* Ref.make(503);
655
+ const ready = yield* Deferred.make<void>();
656
+ yield* startInstance(slowStatus, Deferred.succeed(ready, undefined).pipe(Effect.asVoid));
657
+ yield* TestClock.adjust(Duration.seconds(66));
658
+ yield* Ref.set(slowStatus, 200);
659
+ yield* TestClock.adjust(Duration.millis(100));
660
+ yield* Deferred.await(ready);
661
+ assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
662
+
663
+ yield* startInstance(yield* Ref.make(503));
664
+ yield* TestClock.adjust(Duration.seconds(179));
665
+ assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
666
+ yield* TestClock.adjust(Duration.seconds(1));
667
+ const failure = yield* Queue.take(reports);
668
+ assert.equal(failure.reason, "The server started but did not become ready in time.");
669
+ }).pipe(Effect.provide(TestClock.layer())),
670
+ ),
671
+ );
672
});
apps/desktop/src/backend/DesktopBackendManager.ts
+2
-1
@@ -34,7 +34,8 @@ import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
34
const INITIAL_RESTART_DELAY = Duration.millis(500);
35
const MAX_RESTART_DELAY = Duration.seconds(10);
36
const MAX_PREFLIGHT_FAILURE_ATTEMPTS = 5;
37
-const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(1);
37
+// Large state databases can take over a minute to become ready.
38
+const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(3);
39
const DEFAULT_BACKEND_READINESS_INTERVAL = Duration.millis(100);
40
const DEFAULT_BACKEND_READINESS_REQUEST_TIMEOUT = Duration.seconds(1);
41
// Match the service launcher's grace period so backends can stop provider sessions.