Skip to content

Commit b088b88

Browse files
fix(server): a recording stop on a stuck tab reports a pending dialog first
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cd705c8 commit b088b88

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,10 @@ it.effect("a tab stuck in an agent action does not hold back setting changes for
25782578
input: { reuseExistingTab: false, show: false },
25792579
});
25802580
const stalled = stallColorScheme(contexts[0]!.page);
2581+
const applied = Promise.withResolvers<unknown>();
2582+
contexts[1]!.page.emulateMedia.mockImplementationOnce(async (options: unknown) => {
2583+
applied.resolve(options);
2584+
});
25812585
yield* broker
25822586
.invoke({
25832587
scope,
@@ -2594,8 +2598,7 @@ it.effect("a tab stuck in an agent action does not hold back setting changes for
25942598
tabId: PreviewTabId.make(other.tabId!),
25952599
colorScheme: "dark",
25962600
});
2597-
yield* TestClock.adjust("2 seconds");
2598-
expect(contexts[1]!.page.emulateMedia).toHaveBeenCalledWith({ colorScheme: "dark" });
2601+
expect(yield* Effect.promise(() => applied.promise)).toEqual({ colorScheme: "dark" });
25992602
}),
26002603
).pipe(Effect.provide(layer)),
26012604
);
@@ -2607,6 +2610,7 @@ it.effect(
26072610
Effect.gen(function* () {
26082611
const { broker, tabId } = yield* ready;
26092612
const page = contexts[0]!.page;
2613+
yield* broker.invoke({ scope, tabId, operation: "recordingStart", input: {} });
26102614
const stalled = stallColorScheme(page);
26112615
const stuck = yield* broker
26122616
.invoke<void>({
@@ -2652,6 +2656,13 @@ it.effect(
26522656
_tag: "PreviewAutomationControlInterruptedError",
26532657
reason: "dialogPending",
26542658
});
2659+
const stop = yield* broker
2660+
.invoke<void>({ scope, tabId, operation: "recordingStop", input: {}, timeoutMs: 1_000 })
2661+
.pipe(Effect.flip);
2662+
expect(stop).toMatchObject({
2663+
_tag: "PreviewAutomationControlInterruptedError",
2664+
reason: "dialogPending",
2665+
});
26552666
}),
26562667
).pipe(Effect.provide(layer)),
26572668
);

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,15 @@ const make = Effect.gen(function* () {
19301930
);
19311931
};
19321932

1933+
// Work blocked by a dialog outlives its request; point the agent at the dialog, not at `busy`.
1934+
const requireNoOverdueDialog = (tab: ServerTab, agentSessionId: string) => {
1935+
if (tab.dialog && tab.control.overdue && tab.control.agentCanActNow(agentSessionId))
1936+
throw new BrowserControlInterrupted({
1937+
message: "A browser dialog is pending. Read preview_status and use preview_dialog first.",
1938+
reason: "dialogPending",
1939+
});
1940+
};
1941+
19331942
const requireTab = async (request: PreviewAutomationRequest) => {
19341943
if (!request.agentSessionId)
19351944
throw new BrowserControlInterrupted({
@@ -2137,6 +2146,7 @@ const make = Effect.gen(function* () {
21372146
message: "No recording is active for this thread.",
21382147
});
21392148
}
2149+
requireNoOverdueDialog(tab, request.agentSessionId ?? "");
21402150
// A stop cannot act twice (a retry finds no recording);
21412151
// dropping a late one would leave capture running.
21422152
return tab.control.agent(request.agentSessionId ?? "", () => stopRecording(tab), signal, {
@@ -2188,12 +2198,7 @@ const make = Effect.gen(function* () {
21882198
return executeTabOperation(tab, request);
21892199
});
21902200
}
2191-
// An action blocked by a dialog outlives its request; point the agent at the dialog.
2192-
if (tab.dialog && tab.control.overdue && tab.control.agentCanActNow(agentSessionId))
2193-
throw new BrowserControlInterrupted({
2194-
message: "A browser dialog is pending. Read preview_status and use preview_dialog first.",
2195-
reason: "dialogPending",
2196-
});
2201+
requireNoOverdueDialog(tab, agentSessionId);
21972202
return tab.control.agent(
21982203
agentSessionId,
21992204
async () => {

0 commit comments

Comments
 (0)