@devries-cameron20 / t3code-1 / commits / e3c7c082cf
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): a backend busy right after startup no longer ends in a fatal HTTP 500 screen (#34918)

Julius Marminge committed Nov 14, 2026 at 20:51 UTC e3c7c082cfecb84e3fae3ebf1512a8a016e3b1ae
2 files changed +34 -1
apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts
+32
@@ -1,11 +1,13 @@
1 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2 import { assert, describe, it } from "@effect/vitest";
3 +import * as Clock from "effect/Clock";
4 import * as Deferred from "effect/Deferred";
5 import * as Duration from "effect/Duration";
6 import * as Effect from "effect/Effect";
7 import * as Fiber from "effect/Fiber";
8 import * as Layer from "effect/Layer";
9 import * as Ref from "effect/Ref";
10 +import * as Result from "effect/Result";
11 import * as HttpClient from "effect/http/HttpClient";
12 import * as HttpClientRequest from "effect/http/HttpClientRequest";
13 import * as HttpClientResponse from "effect/http/HttpClientResponse";
@@ -238,4 +240,34 @@ describe("DesktopLocalEnvironmentAuth", () => {
240 assert.strictEqual(yield* Ref.get(requestCount), 1);
241 }).pipe(Effect.provide(TestClock.layer())),
242 );
243 +
244 + it.effect("waits through a backend that stalls for 30 seconds after it is ready", () =>
245 + Effect.gen(function* () {
246 + const requestCount = yield* Ref.make(0);
247 + const layerHttpClient = Layer.succeed(
248 + HttpClient.HttpClient,
249 + HttpClient.make((request) =>
250 + Effect.gen(function* () {
251 + yield* Ref.update(requestCount, (count) => count + 1);
252 + const now = yield* Clock.currentTimeMillis;
253 + return now < 30_000 ? yield* Effect.never : tokenResponse(request);
254 + }),
255 + ),
256 + );
257 + const auth = yield* DesktopLocalEnvironmentAuth.DesktopLocalEnvironmentAuth.pipe(
258 + Effect.provide(
259 + DesktopLocalEnvironmentAuth.layer.pipe(
260 + Layer.provide(Layer.mergeAll(layerPool, layerHttpClient, NodeCrypto.layerMac)),
261 + ),
262 + ),
263 + );
264 +
265 + const fiber = yield* auth.getBearerToken.pipe(Effect.result, Effect.forkChild);
266 + yield* TestClock.adjust(Duration.seconds(45));
267 + const result = yield* Fiber.join(fiber);
268 +
269 + assert.isTrue(Result.isSuccess(result));
270 + assert.strictEqual(yield* Ref.get(requestCount), 4);
271 + }).pipe(Effect.provide(TestClock.layer())),
272 + );
273 });
apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts
+2 -1
@@ -17,7 +17,8 @@ import * as HttpClient from "effect/http/HttpClient";
17
18 import * as DesktopBackendPool from "./DesktopBackendPool.ts";
19
20 -const BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT = Duration.seconds(15);
20 +// Each /oauth/token attempt may take 10 s, so a backend busy after ready needs several attempts.
21 +const BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT = Duration.seconds(60);
22 const BOOTSTRAP_TRANSIENT_RETRY_INTERVAL = Duration.millis(500);
23 const TRANSIENT_BOOTSTRAP_STATUS_CODES = new Set([502, 503, 504]);
24