Skip to content

Commit dc23e27

Browse files
saphidclaude
authored andcommitted
fix(server): a preview_open whose first load fails no longer leaves a hidden tab behind
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8c9945d commit dc23e27

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ it.live("tells the desktop once per thread when its agent turns start and end",
481481
it.live("preview_open reports its navigation timeout instead of the request budget", () =>
482482
Effect.scoped(
483483
Effect.gen(function* () {
484-
const { broker } = yield* ready;
484+
const { broker, tabId } = yield* ready;
485+
const manager = yield* Manager.PreviewManager;
485486
initialNavigation = async () => {
486487
throw Object.assign(new Error("page.goto: Timeout 15000ms exceeded."), {
487488
name: "TimeoutError",
@@ -505,6 +506,10 @@ it.live("preview_open reports its navigation timeout instead of the request budg
505506
timeoutMs: 15_000,
506507
});
507508
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();
508513
}),
509514
).pipe(Effect.provide(layer)),
510515
);

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,12 @@ const make = Effect.gen(function* () {
20092009
if (existing) {
20102010
if (url) await navigate(tab, url, "load", navigationTimeout);
20112011
} else {
2012-
await tab.initialNavigation;
2012+
// A failed open returns no tabId; a leftover hidden tab would block later reuse.
2013+
await tab.initialNavigation?.catch(async (cause: unknown) => {
2014+
await runPromise(manager.close({ threadId: tab.threadId, tabId: tab.tabId }));
2015+
dropTab(tab, false);
2016+
throw cause;
2017+
});
20132018
}
20142019
const reveal = open.open ?? open.show;
20152020
if (reveal !== false) {

0 commit comments

Comments
 (0)