Skip to content

Commit d9196b3

Browse files
TDanks2000claude
andcommitted
fix(server): idle sweep no longer closes agent tabs the desktop app shows
Desktop-rendered server tabs have no streamed viewers, and input in the desktop's webview never reaches the server, so a tab the user was reading closed 30 minutes after the agent's last call. The desktop's tab strip owns those tabs; the sweep now leaves them alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent aaf0004 commit d9196b3

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

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

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

1245+
it.live("an idle agent tab the desktop renders stays open for the person browsing it", () =>
1246+
Effect.scoped(
1247+
Effect.gen(function* () {
1248+
const broker = yield* Broker.PreviewAutomationBroker;
1249+
yield* Effect.yieldNow;
1250+
const open = broker.invoke<PreviewAutomationStatus>({
1251+
scope,
1252+
operation: "open",
1253+
input: { reuseExistingTab: false, show: false },
1254+
});
1255+
desktopRendersNext = true;
1256+
const desktopTab = yield* open;
1257+
const headlessTab = yield* open;
1258+
const later = (yield* Clock.currentTimeMillis) + 31 * 60 * 1000;
1259+
const clock = vi.spyOn(Date, "now").mockReturnValue(later);
1260+
yield* Effect.addFinalizer(() => Effect.sync(() => clock.mockRestore()));
1261+
// Opening sweeps idle tabs first: only the unwatched headless one closes.
1262+
const reopened = yield* open;
1263+
const manager = yield* Manager.PreviewManager;
1264+
const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
1265+
const openTabIds = sessions.map((session) => session.tabId);
1266+
expect(openTabIds).toContain(desktopTab.tabId);
1267+
expect(openTabIds).toContain(reopened.tabId);
1268+
expect(openTabIds).not.toContain(headlessTab.tabId);
1269+
}),
1270+
).pipe(Effect.provide(layer)),
1271+
);
1272+
12451273
it.live("an agent answers the page's file picker or sets files on a file input", () =>
12461274
Effect.scoped(
12471275
Effect.gen(function* () {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,20 @@ const make = Effect.gen(function* () {
12331233
);
12341234
};
12351235

1236-
/** Closes agent tabs that no one watches and the agent stopped using. */
1236+
/**
1237+
* Closes agent tabs that no one watches and the agent stopped using. A tab
1238+
* the desktop renders is in its tab strip, where the person browsing it
1239+
* without the server seeing their input closes it themselves.
1240+
*/
12371241
const closeIdleAgentTabs = () => {
12381242
const cutoff = Date.now() - AGENT_TAB_IDLE_MS;
12391243
for (const tab of tabs.values()) {
1240-
if (tab.control.agentId !== null && tab.viewers.size === 0 && tab.usedAt < cutoff)
1244+
if (
1245+
tab.control.agentId !== null &&
1246+
tab.desktop === null &&
1247+
tab.viewers.size === 0 &&
1248+
tab.usedAt < cutoff
1249+
)
12411250
dropTab(tab, true);
12421251
}
12431252
};

0 commit comments

Comments
 (0)