Skip to content

Commit 01eb339

Browse files
shivamhwpPR Batch Testerclaude
authored
fix(desktop): allow slow backends to start before showing recovery (pingdotgg#26247)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 033a753 commit 01eb339

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,4 +631,42 @@ describe("DesktopBackendManager", () => {
631631
}).pipe(Effect.provide(TestClock.layer())),
632632
),
633633
);
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+
);
634672
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
3434
const INITIAL_RESTART_DELAY = Duration.millis(500);
3535
const MAX_RESTART_DELAY = Duration.seconds(10);
3636
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);
3839
const DEFAULT_BACKEND_READINESS_INTERVAL = Duration.millis(100);
3940
const DEFAULT_BACKEND_READINESS_REQUEST_TIMEOUT = Duration.seconds(1);
4041
// Match the service launcher's grace period so backends can stop provider sessions.

0 commit comments

Comments
 (0)