Skip to content

Commit 5ae9578

Browse files
shivamhwpPR Batch Testerclaude
authored
fix(desktop): agents see visible:true while the desktop shows their tab (pingdotgg#23589)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 046efd7 commit 5ae9578

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,47 @@ it.effect("a stalled desktop viewer still gets its size, control and reconnect",
19611961
).pipe(Effect.provide(layer)),
19621962
);
19631963

1964+
it.live("the tab the desktop shows is visible and picked for agents without a tab", () =>
1965+
Effect.scoped(
1966+
Effect.gen(function* () {
1967+
const broker = yield* Broker.PreviewAutomationBroker;
1968+
const manager = yield* Manager.PreviewManager;
1969+
yield* ServerBrowser.ServerBrowser;
1970+
yield* Effect.yieldNow;
1971+
const openDesktopTab = Effect.fn("openDesktopTab")(function* (url: string) {
1972+
desktopRendersNext = true;
1973+
const opened = yield* manager.open({
1974+
threadId: scope.thread.threadId,
1975+
url,
1976+
runtime: "server",
1977+
});
1978+
const tabId = PreviewTabId.make(opened.tabId);
1979+
yield* broker.invoke({ scope, tabId, operation: "status", input: {} });
1980+
return tabId;
1981+
});
1982+
const recentTab = yield* openDesktopTab("http://localhost:5173/recent");
1983+
const shownTab = yield* openDesktopTab("http://localhost:5173/shown");
1984+
// Opened first and used last, so recency or insertion order alone picks it.
1985+
yield* broker.invoke({ scope, tabId: recentTab, operation: "status", input: {} });
1986+
1987+
shownDesktopTabs.add(shownTab);
1988+
const status = yield* broker.invoke<PreviewAutomationStatus>({
1989+
scope: asSession("agent-b"),
1990+
operation: "status",
1991+
input: {},
1992+
});
1993+
expect(status).toMatchObject({
1994+
tabId: shownTab,
1995+
visible: true,
1996+
tabs: [
1997+
expect.objectContaining({ tabId: recentTab, visible: false }),
1998+
expect.objectContaining({ tabId: shownTab, visible: true }),
1999+
],
2000+
});
2001+
}),
2002+
).pipe(Effect.provide(layer)),
2003+
);
2004+
19642005
it.live("agents read a human's tab with no arguments and act on it only while nobody drives", () =>
19652006
Effect.scoped(
19662007
Effect.gen(function* () {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,7 @@ const make = Effect.gen(function* () {
15111511
.sort((left, right) => right.createdAt - left.createdAt)[0] ??
15121512
threadTabs.sort(
15131513
(left, right) =>
1514-
Number(right.viewers.size > 0) - Number(left.viewers.size > 0) ||
1515-
right.usedAt - left.usedAt,
1514+
Number(isVisible(right)) - Number(isVisible(left)) || right.usedAt - left.usedAt,
15161515
)[0]
15171516
);
15181517
};
@@ -1621,7 +1620,7 @@ const make = Effect.gen(function* () {
16211620
const viewport = tab.desktop ? await layoutSize(tab) : tab.page.viewportSize();
16221621
const status = {
16231622
available: true,
1624-
visible: tab.viewers.size > 0,
1623+
visible: isVisible(tab),
16251624
tabId: tab.tabId,
16261625
url: url === "about:blank" ? null : url,
16271626
title: null,
@@ -1648,7 +1647,7 @@ const make = Effect.gen(function* () {
16481647
...(candidate.openerTabId === undefined ? {} : { openerTabId: candidate.openerTabId }),
16491648
owner: tabOwner(candidate),
16501649
ownedByCaller: candidate.control.agentId === agentSessionId,
1651-
visible: candidate.viewers.size > 0,
1650+
visible: isVisible(candidate),
16521651
...(candidate.profileId === undefined ? {} : { profileId: candidate.profileId }),
16531652
})),
16541653
...profileStatus(),

0 commit comments

Comments
 (0)