The best way to control Claude Code, Codex and more from any computer or phone
fix(preview): report navigation timeout accurately (#24356)
Ethereal49 committed
Oct 25, 2026 at 08:49 UTC
b8be6da0259e7774fa2d8497dd6b7fcdce374acf
4 files changed
+58
-5
apps/server/src/mcp/PreviewAutomationBroker.ts
+14
-1
@@ -205,6 +205,14 @@ function remoteDetailKind(detail: unknown): RemoteDetailKind {
205
}
206
}
207
208
+const readRemoteTimeoutMs = (detail: unknown): number | undefined => {
209
+ if (typeof detail !== "object" || detail === null || !("timeoutMs" in detail)) return undefined;
210
+ const timeoutMs = detail.timeoutMs;
211
+ return typeof timeoutMs === "number" && Number.isInteger(timeoutMs) && timeoutMs > 0
212
+ ? timeoutMs
213
+ : undefined;
214
+};
215
+
216
const MAX_REASON_CHARS = 500;
217
218
const classifyResponseError = (
@@ -253,11 +261,16 @@ const classifyResponseError = (
261
...context,
262
...remoteDiagnostics,
263
});
256
- case "PreviewAutomationTimeoutError":
264
+ case "PreviewAutomationTimeoutError": {
265
+ const remoteTimeoutMs = readRemoteTimeoutMs(error.detail);
266
return new PreviewAutomationTimeoutError({
267
...context,
268
...remoteDiagnostics,
269
+ ...(remoteTimeoutMs === undefined
270
+ ? {}
271
+ : { timeoutMs: Math.min(context.timeoutMs, remoteTimeoutMs) }),
272
});
273
+ }
274
case "PreviewAutomationControlInterruptedError": {
275
const reason = decodeControlReason(error.detail);
276
return new PreviewAutomationControlInterruptedError({
apps/server/src/preview/ServerBrowser.test.ts
+31
@@ -379,6 +379,37 @@ beforeEach(() => {
379
desktopConnections.length = 0;
380
});
381
382
+it.live("preview_open reports its navigation timeout instead of the request budget", () =>
383
+ Effect.scoped(
384
+ Effect.gen(function* () {
385
+ const { broker } = yield* ready;
386
+ initialNavigation = async () => {
387
+ throw Object.assign(new Error("page.goto: Timeout 15000ms exceeded."), {
388
+ name: "TimeoutError",
389
+ });
390
+ };
391
+
392
+ const error = yield* broker
393
+ .invoke<PreviewAutomationStatus>({
394
+ scope,
395
+ operation: "open",
396
+ input: {
397
+ url: "http://localhost:1337/",
398
+ reuseExistingTab: false,
399
+ show: false,
400
+ },
401
+ })
402
+ .pipe(Effect.flip);
403
+
404
+ expect(error).toMatchObject({
405
+ _tag: "PreviewAutomationTimeoutError",
406
+ timeoutMs: 15_000,
407
+ });
408
+ expect(error.message).toBe("Preview automation open timed out after 15000ms.");
409
+ }),
410
+ ).pipe(Effect.provide(layer)),
411
+);
412
+
413
it.live.each(["desktop" as const, undefined])(
414
"explicit desktop targets ($0 runtime) fail without creating a server tab",
415
(runtime) =>
apps/server/src/preview/ServerBrowser.ts
+4
-2
@@ -902,7 +902,9 @@ const make = Effect.gen(function* () {
902
(desktop || adopted) && page.url() === snapshot.navStatus.url
903
? page.reload(options)
904
: page.goto(snapshot.navStatus.url, options)
905
- ).then(constVoid);
905
+ ).then(constVoid, (cause: unknown) => {
906
+ throw ServerBrowserPage.toOperationError(cause, NAVIGATION_TIMEOUT_MS);
907
+ });
908
909
if (tab.control.agentId !== null) tab.control.track(tab.initialNavigation);
910
else void tab.initialNavigation.catch(constVoid);
@@ -1458,7 +1460,7 @@ const make = Effect.gen(function* () {
1460
`Navigation to ${url} failed: ${ServerBrowserPage.parseNetError(message).description}`,
1461
);
1462
}
1461
- throw cause;
1463
+ throw ServerBrowserPage.toOperationError(cause, timeout);
1464
});
1465
};
1466
apps/server/src/preview/ServerBrowserPage.ts
+9
-2
@@ -40,7 +40,10 @@ export class ServerBrowserOperationError extends Error {
40
}
41
}
42
43
-export const toOperationError = (cause: unknown): ServerBrowserOperationError => {
43
+export const toOperationError = (
44
+ cause: unknown,
45
+ timeoutMs?: number,
46
+): ServerBrowserOperationError => {
47
if (cause instanceof BrowserControlInterrupted)
48
return new ServerBrowserOperationError(
49
"PreviewAutomationControlInterruptedError",
@@ -51,7 +54,11 @@ export const toOperationError = (cause: unknown): ServerBrowserOperationError =>
54
const message = cause instanceof Error ? cause.message : String(cause);
55
const firstLine = message.split("\n")[0] ?? message;
56
if (cause instanceof Error && cause.name === "TimeoutError") {
54
- return new ServerBrowserOperationError("PreviewAutomationTimeoutError", firstLine);
57
+ return new ServerBrowserOperationError(
58
+ "PreviewAutomationTimeoutError",
59
+ firstLine,
60
+ timeoutMs === undefined ? undefined : { timeoutMs },
61
+ );
62
}
63
if (
64
/while parsing selector|Unknown engine|Unexpected token|strict mode violation/i.test(message)