@devries-cameron20 / t3code-1 / commits / 713731f848
Fork 0

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

fix(server): a timed-out preview call no longer evicts the shared server browser (#36241)

Julius Marminge committed Nov 13, 2026 at 09:30 UTC 713731f8481bb6ce8b31d1d6543493e1df391735
2 files changed +55 -1
apps/server/src/mcp/PreviewAutomationBroker.test.ts
+50
@@ -18,8 +18,10 @@ import {
18 import * as Effect from "effect/Effect";
19 import * as Deferred from "effect/Deferred";
20 import * as Fiber from "effect/Fiber";
21 +import * as Queue from "effect/Queue";
22 import * as Result from "effect/Result";
23 import * as Stream from "effect/Stream";
24 +import * as TestClock from "effect/testing/TestClock";
25
26 import { PreviewBrowserRootError } from "../preview/PreviewBrowserHost.ts";
27 import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts";
@@ -950,6 +952,54 @@ it.effect("fails requests assigned to the stream that is replaced", () =>
952 }),
953 );
954
955 +it.effect(
956 + "keeps another thread's request alive when one request times out on the shared server browser",
957 + () =>
958 + Effect.gen(function* () {
959 + const broker = yield* makeBroker;
960 + const clientId = SERVER_BROWSER_AUTOMATION_CLIENT_ID;
961 + const delivered = yield* Queue.unbounded<RoutedRequest>();
962 + const requests = requestsFrom(
963 + yield* broker.connect(makeHost({ clientId }), { preferred: true }),
964 + );
965 + yield* Stream.runForEach(requests, (request) => Queue.offer(delivered, request)).pipe(
966 + Effect.forkScoped,
967 + );
968 + yield* Effect.yieldNow;
969 + const otherScope = {
970 + ...scope,
971 + requestNamespace: "provider-session-2",
972 + thread: {
973 + threadId: ThreadId.make("thread-2"),
974 + providerSessionId: "provider-session-2",
975 + providerInstanceId: ProviderInstanceId.make("codex"),
976 + },
977 + };
978 +
979 + const otherWait = yield* broker
980 + .invoke<string>({ scope: otherScope, operation: "waitFor", input: {}, timeoutMs: 40_000 })
981 + .pipe(Effect.result, Effect.forkScoped);
982 + const otherRequest = yield* Queue.take(delivered);
983 + // The browser never answers this one, as when it waits behind the thread's own running action.
984 + const stalled = yield* broker
985 + .invoke<string>({ scope, operation: "evaluate", input: {} })
986 + .pipe(Effect.flip, Effect.forkScoped);
987 + yield* Queue.take(delivered);
988 +
989 + yield* TestClock.adjust("16 seconds");
990 + expect((yield* Fiber.join(stalled))._tag).toBe("PreviewAutomationTimeoutError");
991 +
992 + yield* broker.respond({
993 + clientId,
994 + connectionId: otherRequest.connectionId,
995 + requestId: otherRequest.requestId,
996 + ok: true,
997 + result: "ready",
998 + });
999 + expect(yield* Fiber.join(otherWait)).toEqual(Result.succeed("ready"));
1000 + }),
1001 +);
1002 +
1003 it.effect("accepts responses only from the host that received the request", () =>
1004 Effect.gen(function* () {
1005 const broker = yield* makeBroker;
apps/server/src/mcp/PreviewAutomationBroker.ts
+5 -1
@@ -662,7 +662,11 @@ export const make = Effect.gen(function* PreviewAutomationBrokerMake() {
662 // The enclosing operation owns the span for this inline handler.
663 onNone: Effect.fnUntraced(function* () {
664 // Never replay possibly applied actions; slow metadata reads must not evict the host.
665 - if (input.updateCurrentTab !== false) {
665 + // The in-process server browser is shared by every thread and cannot hang its stream.
666 + if (
667 + input.updateCurrentTab !== false &&
668 + connection.clientId !== SERVER_BROWSER_AUTOMATION_CLIENT_ID
669 + ) {
670 yield* disconnect(connection.clientId, connection.queue, true);
671 }
672 return yield* new PreviewAutomationTimeoutError(requestContext);