The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a preview_open whose first load fails no longer leaves a hidden tab behind (#29865)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Alex Southwell committed
Nov 3, 2026 at 23:23 UTC
8ca8fddbeba83937b28ef6585de03e98e6e70f97
2 files changed
+60
-2
apps/server/src/preview/ServerBrowser.test.ts
+50
-1
@@ -481,7 +481,8 @@ it.live("tells the desktop once per thread when its agent turns start and end",
481
it.live("preview_open reports its navigation timeout instead of the request budget", () =>
482
Effect.scoped(
483
Effect.gen(function* () {
484
- const { broker } = yield* ready;
484
+ const { broker, tabId } = yield* ready;
485
+ const manager = yield* Manager.PreviewManager;
486
initialNavigation = async () => {
487
throw Object.assign(new Error("page.goto: Timeout 15000ms exceeded."), {
488
name: "TimeoutError",
@@ -505,6 +506,54 @@ it.live("preview_open reports its navigation timeout instead of the request budg
506
timeoutMs: 15_000,
507
});
508
expect(error.message).toBe("Preview automation open timed out after 15000ms.");
509
+ // The failed open returned no tabId, so its tab must not linger and block later opens.
510
+ const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
511
+ expect(sessions.map((session) => session.tabId)).toEqual([tabId]);
512
+ expect(contexts[1]!.page.close).toHaveBeenCalled();
513
+ }),
514
+ ).pipe(Effect.provide(layer)),
515
+);
516
+
517
+it.live("an initial download stays available after preview_open reports the navigation error", () =>
518
+ Effect.scoped(
519
+ Effect.gen(function* () {
520
+ const { broker, tabId } = yield* ready;
521
+ const manager = yield* Manager.PreviewManager;
522
+ const released = Promise.withResolvers<void>();
523
+ initialNavigation = async () => {
524
+ contexts[1]!.page.emit("download", {
525
+ failure: async () => null,
526
+ delete: async () => released.resolve(),
527
+ saveAs: (path: string) => NodeFSP.writeFile(path, "a,b"),
528
+ suggestedFilename: () => "report.csv",
529
+ url: () => "http://localhost:1337/report.csv",
530
+ });
531
+ throw new Error("page.goto: Download is starting");
532
+ };
533
+ const error = yield* broker
534
+ .invoke<PreviewAutomationStatus>({
535
+ scope,
536
+ operation: "open",
537
+ input: { url: "http://localhost:1337/report.csv", reuseExistingTab: false, open: false },
538
+ })
539
+ .pipe(Effect.flip);
540
+ expect(error.message).toContain("Download is starting");
541
+ yield* Effect.promise(() => released.promise);
542
+ const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
543
+ expect(sessions).toHaveLength(2);
544
+ const downloadTabId = PreviewTabId.make(sessions.find((tab) => tab.tabId !== tabId)!.tabId);
545
+ const status = yield* broker.invoke<PreviewAutomationStatus>({
546
+ scope,
547
+ tabId: downloadTabId,
548
+ operation: "status",
549
+ input: {},
550
+ });
551
+ expect(status.downloads).toEqual([
552
+ expect.objectContaining({ fileName: "report.csv", sizeBytes: 3 }),
553
+ ]);
554
+ expect(yield* (yield* FileSystem.FileSystem).readFileString(status.downloads![0]!.path)).toBe(
555
+ "a,b",
556
+ );
557
}),
558
).pipe(Effect.provide(layer)),
559
);
apps/server/src/preview/ServerBrowser.ts
+10
-1
@@ -2013,7 +2013,16 @@ const make = Effect.gen(function* () {
2013
if (existing) {
2014
if (url) await navigate(tab, url, "load", navigationTimeout);
2015
} else {
2016
- await tab.initialNavigation;
2016
+ // A failed open returns no tabId; a leftover hidden tab would block later reuse.
2017
+ await tab.initialNavigation?.catch(async (cause: unknown) => {
2018
+ // Playwright rejects downloads too; their tab must survive to save the file.
2019
+ if (cause instanceof Error && cause.message.includes("Download is starting")) {
2020
+ throw cause;
2021
+ }
2022
+ await runPromise(manager.close({ threadId: tab.threadId, tabId: tab.tabId }));
2023
+ dropTab(tab, false);
2024
+ throw cause;
2025
+ });
2026
}
2027
const reveal = open.open ?? open.show;
2028
if (reveal !== false) {