Skip to content

Commit 8e342ff

Browse files
committed
fix(server): explain how to close unclaimed browser tabs
1 parent 0b6f482 commit 8e342ff

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,30 @@ it.live("enforces provider ownership and explicit targets when a session has mul
10081008
});
10091009
expect(result).toBe("evaluated");
10101010
expect(contexts).toHaveLength(2);
1011+
1012+
const manager = yield* Manager.PreviewManager;
1013+
const unclaimed = yield* manager.open({
1014+
threadId: scope.thread.threadId,
1015+
runtime: "server",
1016+
});
1017+
const closeUnclaimed = yield* broker
1018+
.invoke<void>({
1019+
scope,
1020+
tabId: PreviewTabId.make(unclaimed.tabId),
1021+
operation: "close",
1022+
input: {},
1023+
})
1024+
.pipe(Effect.flip);
1025+
expect(closeUnclaimed).toMatchObject({
1026+
_tag: "PreviewAutomationControlInterruptedError",
1027+
reason: "unclaimedTab",
1028+
});
1029+
expect(closeUnclaimed.message).toBe(
1030+
"This tab has no agent owner. Ask the user to close it in the browser panel.",
1031+
);
1032+
expect((yield* manager.list({ threadId: scope.thread.threadId })).sessions).toContainEqual(
1033+
expect.objectContaining({ tabId: unclaimed.tabId }),
1034+
);
10111035
}),
10121036
).pipe(Effect.provide(layer)),
10131037
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,10 +2274,10 @@ const make = Effect.gen(function* () {
22742274
const tab = await requireTab(request);
22752275
// Closing must unblock an action waiting on a dialog, without queueing behind it.
22762276
if (request.operation === "close") {
2277-
if (tab.control.agentId !== request.agentSessionId)
2277+
if (tab.control.agentId === null)
22782278
throw new BrowserControlInterrupted({
2279-
message: "Only the agent session that opened this tab can close it.",
2280-
reason: "agentMismatch",
2279+
message: "This tab has no agent owner. Ask the user to close it in the browser panel.",
2280+
reason: "unclaimedTab",
22812281
});
22822282
if (tab.control.controller !== null)
22832283
throw new BrowserControlInterrupted({

‎packages/contracts/src/previewAutomation.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ export class PreviewAutomationTimeoutError extends Schema.TaggedError<PreviewAut
794794

795795
export const PreviewAutomationControlReason = Schema.Literals([
796796
"agentMismatch",
797+
"unclaimedTab",
797798
"humanControl",
798799
"tabRequired",
799800
"closed",
@@ -814,6 +815,8 @@ export class PreviewAutomationControlInterruptedError extends Schema.TaggedError
814815
override get message(): string {
815816
if (this.reason === "agentMismatch")
816817
return "This browser tab belongs to another agent session or a human. Open your own tab.";
818+
if (this.reason === "unclaimedTab")
819+
return "This tab has no agent owner. Ask the user to close it in the browser panel.";
817820
if (this.reason === "humanControl")
818821
return "A human controls this browser tab. Wait until they release control.";
819822
if (this.reason === "tabRequired")

0 commit comments

Comments
 (0)