fix(server): remote viewers reach a tab the desktop cannot paint #27735
Openillumin3dpb-ship-it(GitHub profile, opens in a new tab)wants to merge 9 commits into
main fromrefs/pull/27735/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- @@ -2482,7 +2488,14 @@24822488 });24832489 });24842490 void broadcastViewport(tab).catch(constVoid);2485- yield* Effect.promise(() => startScreencast(1));2486- // An idle page does not repaint for a new screencast, so the viewer2487- // starts from a still unless a live frame beat it.2488- if (!screencastStarted) yield* Effect.promise(pushStill);2491+ const firstFrame = Effect.promise(async () => {2492+ await startScreencast(1);2493+ // An idle page does not repaint for a new screencast, so the viewer2494+ // starts from a still unless a live frame beat it.2495+ if (!screencastStarted) await pushStill();2496+ });2497+ if (tab.desktop) {2498+ const painted = yield* firstFrame.pipe(Effect.timeoutOption(DESKTOP_FIRST_FRAME_TIMEOUT));2499+ // A minimized host window paints no guest, so this page can never reach the viewer.2500+ // Reconnecting moves the tab to headless Chromium, which needs no display.2501+ if (Option.isNone(painted) && !screencastStarted) yield* moveTabToHeadless(tab);
- apps/server/src/preview/ServerBrowser.ts lines 2520 to 2523OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2482,7 +2488,14 @@24822488 });24832489 });24842490 void broadcastViewport(tab).catch(constVoid);2485- yield* Effect.promise(() => startScreencast(1));2486- // An idle page does not repaint for a new screencast, so the viewer2487- // starts from a still unless a live frame beat it.2488- if (!screencastStarted) yield* Effect.promise(pushStill);2491+ const firstFrame = Effect.promise(async () => {2492+ await startScreencast(1);2493+ // An idle page does not repaint for a new screencast, so the viewer2494+ // starts from a still unless a live frame beat it.2495+ if (!screencastStarted) await pushStill();2496+ });2497+ if (tab.desktop) {2498+ const painted = yield* firstFrame.pipe(Effect.timeoutOption(DESKTOP_FIRST_FRAME_TIMEOUT));2499+ // A minimized host window paints no guest, so this page can never reach the viewer.2500+ // Reconnecting moves the tab to headless Chromium, which needs no display.2501+ if (Option.isNone(painted) && !screencastStarted) yield* moveTabToHeadless(tab);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -551,0 +603,21 @@603+604+ const items = yield* Queue.clear(stalled.output);605+ expect(items.map((item) => item._tag)).toContain("reconnect");606+ const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });607+ const moved = sessions.find((session) => session.tabId === tabId);608+ expect(moved?.headless).toBe(true);609+610+ desktopPaintsNothing = false;611+ yield* browser.attachViewer(viewerInput(tabId, true));612+ expect(contexts.at(-1)!.page.goto).toHaveBeenCalledWith(613+ url,614+ expect.objectContaining({ waitUntil: "commit" }),615+ );616+ const kept = yield* browser.openDownload({617+ threadId: scope.thread.threadId,618+ tabId,619+ downloadId,620+ });621+ // Cleanup is not awaited and has no milestone, so only real time can show it never ran.622+ // oxlint-disable-next-line t3code/no-real-time-wait-in-tests -- proving a delete did not land623+ yield* Effect.promise(() => new Promise((resolve) => setTimeout(resolve, 100)));apps/server/src/preview/ServerBrowser.ts line 747OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -729,10 +732,16 @@729732 else void tab.page.close().catch(constVoid);730733 if (tab.isolatedContext) void tab.page.context().close().catch(constVoid);731734 void tab.recording?.encoder.close().catch(constVoid);732- void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);735+ if (!movedDownloads.has(key)) {736+ void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);737+ }733738 reportLiveTabs();734739 if (closeSession) {735740 runFork(manager.close({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore));736741 }737742 };738743744+ const moveTabToHeadless = Effect.fnUntraced(function* (tab: ServerTab) {745+ const key = tabKey(tab.threadId, tab.tabId);746+ yield* manager747+ .markHeadless({ threadId: tab.threadId, tabId: tab.tabId, reload: true })apps/server/src/preview/ServerBrowser.ts line 749OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -729,10 +732,18 @@729732 else void tab.page.close().catch(constVoid);730733 if (tab.isolatedContext) void tab.page.context().close().catch(constVoid);731734 void tab.recording?.encoder.close().catch(constVoid);732- void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);735+ if (!movedDownloads.has(key)) {736+ void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);737+ }733738 reportLiveTabs();734739 if (closeSession) {735740 runFork(manager.close({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore));736741 }737742 };738743744+ const moveTabToHeadless = Effect.fnUntraced(function* (tab: ServerTab) {745+ const key = tabKey(tab.threadId, tab.tabId);746+ yield* manager747+ .markHeadless({ threadId: tab.threadId, tabId: tab.tabId, reload: true })748+ .pipe(Effect.ignore);749+ movedDownloads.set(key, tab.downloads);@@ -729,10 +732,20 @@729732 else void tab.page.close().catch(constVoid);730733 if (tab.isolatedContext) void tab.page.context().close().catch(constVoid);731734 void tab.recording?.encoder.close().catch(constVoid);732- void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);735+ if (!movedDownloads.has(key)) {736+ void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);737+ }733738 reportLiveTabs();734739 if (closeSession) {735740 runFork(manager.close({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore));736741 }737742 };738743744+ const moveTabToHeadless = Effect.fnUntraced(function* (tab: ServerTab) {745+ const key = tabKey(tab.threadId, tab.tabId);746+ yield* manager747+ .markHeadless({ threadId: tab.threadId, tabId: tab.tabId, reload: true })748+ .pipe(Effect.ignore);749+ movedDownloads.set(key, tab.downloads);750+ dropTab(tab, false);751+ yield* findTab(tab.threadId, tab.tabId).pipe(Effect.ignore);@@ -771,3 +790,5 @@771790 const createTab = async (snapshot: PreviewSessionSnapshot): Promise<ServerTab> => {772791 const adopted = adoptedPages.get(tabKey(snapshot.threadId, snapshot.tabId));773792 adoptedPages.delete(tabKey(snapshot.threadId, snapshot.tabId));793+ const keptDownloads = movedDownloads.get(tabKey(snapshot.threadId, snapshot.tabId));794+ movedDownloads.delete(tabKey(snapshot.threadId, snapshot.tabId));
tanstack-source added labelsbug
juliusmarminge added labelstakeover:in-progress
- @@ -914,10 +920,17 @@914920 if (tab.isolatedContext) void closed.then(() => page.context().close()).catch(constVoid);915921 }916922 void tab.recording?.encoder.close().catch(constVoid);917- void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);923+ if (!movedTabs.has(key)) {924+ void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);925+ }918926 reportLiveTabs();919927 if (closeSession) {920928 runFork(manager.close({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore));921929 }922930 };923931932+ const moveTabToHeadless = Effect.fn("ServerBrowser.moveTabToHeadless")(function* (933+ tab: ServerTab,934+ ) {935+ const key = tabKey(tab.threadId, tab.tabId);936+ yield* manager.markHeadless({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore);@@ -914,10 +920,20 @@914920 if (tab.isolatedContext) void closed.then(() => page.context().close()).catch(constVoid);915921 }916922 void tab.recording?.encoder.close().catch(constVoid);917- void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);923+ if (!movedTabs.has(key)) {924+ void NodeFSP.rm(downloadDir(tab), { recursive: true, force: true }).catch(constVoid);925+ }918926 reportLiveTabs();919927 if (closeSession) {920928 runFork(manager.close({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore));921929 }922930 };923931932+ const moveTabToHeadless = Effect.fn("ServerBrowser.moveTabToHeadless")(function* (933+ tab: ServerTab,934+ ) {935+ const key = tabKey(tab.threadId, tab.tabId);936+ yield* manager.markHeadless({ threadId: tab.threadId, tabId: tab.tabId }).pipe(Effect.ignore);937+ // Another viewer that timed out on this tab may have moved it already.938+ if (tabs.get(key) !== tab) return;939+ movedTabs.set(key, { url: tab.page.url(), downloads: tab.downloads });
juliusmarminge added labelstakeover:needs-julius
juliusmarminge removed labelstakeover:in-progress
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
Sign in to join this conversation.



Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
We couldn’t complete this review. Comment
@codex reviewto try again.631eb3cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.