Skip to content

Commit c60aa1a

Browse files
fix(server): explain how to close unclaimed browser tabs (pingdotgg#29205)
Co-authored-by: Julius Marminge <[email protected]>
1 parent db470a3 commit c60aa1a

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
@@ -1101,6 +1101,30 @@ it.live("enforces provider ownership and explicit targets when a session has mul
11011101
});
11021102
expect(result).toBe("evaluated");
11031103
expect(contexts).toHaveLength(2);
1104+
1105+
const manager = yield* Manager.PreviewManager;
1106+
const unclaimed = yield* manager.open({
1107+
threadId: scope.thread.threadId,
1108+
runtime: "server",
1109+
});
1110+
const closeUnclaimed = yield* broker
1111+
.invoke<void>({
1112+
scope,
1113+
tabId: PreviewTabId.make(unclaimed.tabId),
1114+
operation: "close",
1115+
input: {},
1116+
})
1117+
.pipe(Effect.flip);
1118+
expect(closeUnclaimed).toMatchObject({
1119+
_tag: "PreviewAutomationControlInterruptedError",
1120+
reason: "unclaimedTab",
1121+
});
1122+
expect(closeUnclaimed.message).toBe(
1123+
"This tab has no agent owner. Ask the user to close it in the browser panel.",
1124+
);
1125+
expect((yield* manager.list({ threadId: scope.thread.threadId })).sessions).toContainEqual(
1126+
expect.objectContaining({ tabId: unclaimed.tabId }),
1127+
);
11041128
}),
11051129
).pipe(Effect.provide(layer)),
11061130
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,10 +2378,10 @@ const make = Effect.gen(function* () {
23782378
const tab = await requireTab(request);
23792379
// Closing must unblock an action waiting on a dialog, without queueing behind it.
23802380
if (request.operation === "close") {
2381-
if (tab.control.agentId !== request.agentSessionId)
2381+
if (tab.control.agentId === null)
23822382
throw new BrowserControlInterrupted({
2383-
message: "Only the agent session that opened this tab can close it.",
2384-
reason: "agentMismatch",
2383+
message: "This tab has no agent owner. Ask the user to close it in the browser panel.",
2384+
reason: "unclaimedTab",
23852385
});
23862386
if (tab.control.controller !== null)
23872387
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)