Skip to content

Commit 53ca474

Browse files
TDanks2000claudejuliusmarminge
authored
fix(preview): keep desktop-rendered tabs out of idle cleanup (pingdotgg#18147)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 1675674 commit 53ca474

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,34 @@ it.live("an agent's tabs stop at the limit until an unwatched idle tab closes",
15211521
).pipe(Effect.provide(layer)),
15221522
);
15231523

1524+
it.live("an idle agent tab the desktop renders stays open for the person browsing it", () =>
1525+
Effect.scoped(
1526+
Effect.gen(function* () {
1527+
const broker = yield* Broker.PreviewAutomationBroker;
1528+
yield* Effect.yieldNow;
1529+
const open = broker.invoke<PreviewAutomationStatus>({
1530+
scope,
1531+
operation: "open",
1532+
input: { reuseExistingTab: false, show: false },
1533+
});
1534+
desktopRendersNext = true;
1535+
const desktopTab = yield* open;
1536+
const headlessTab = yield* open;
1537+
const later = (yield* Clock.currentTimeMillis) + 31 * 60 * 1000;
1538+
const clock = vi.spyOn(Date, "now").mockReturnValue(later);
1539+
yield* Effect.addFinalizer(() => Effect.sync(() => clock.mockRestore()));
1540+
// Opening sweeps idle tabs first: only the unwatched headless one closes.
1541+
const reopened = yield* open;
1542+
const manager = yield* Manager.PreviewManager;
1543+
const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
1544+
const openTabIds = sessions.map((session) => session.tabId);
1545+
expect(openTabIds).toContain(desktopTab.tabId);
1546+
expect(openTabIds).toContain(reopened.tabId);
1547+
expect(openTabIds).not.toContain(headlessTab.tabId);
1548+
}),
1549+
).pipe(Effect.provide(layer)),
1550+
);
1551+
15241552
it.live("an agent answers the page's file picker or sets files on a file input", () =>
15251553
Effect.scoped(
15261554
Effect.gen(function* () {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,17 @@ const make = Effect.gen(function* () {
12631263
);
12641264
};
12651265

1266+
// Desktop browsing bypasses streamed viewers and server input tracking,
1267+
// so these idle signals only apply to headless tabs.
12661268
const closeIdleAgentTabs = () => {
12671269
const cutoff = Date.now() - AGENT_TAB_IDLE_MS;
12681270
for (const tab of tabs.values()) {
1269-
if (tab.control.agentId !== null && tab.viewers.size === 0 && tab.usedAt < cutoff)
1271+
if (
1272+
tab.control.agentId !== null &&
1273+
tab.desktop === null &&
1274+
tab.viewers.size === 0 &&
1275+
tab.usedAt < cutoff
1276+
)
12701277
dropTab(tab, true);
12711278
}
12721279
};

0 commit comments

Comments
 (0)