Skip to content

Commit c2e2e23

Browse files
committed
Fix preview automation resize resilience and broker host selection
- Make waitForRenderedViewport best-effort in resize handler so a committed server-side resize is not reported as failure when layout verification times out (bug: MCP resize fails after success) - Skip viewport verification for fill-mode resizes on hidden tabs to avoid confirming placeholder dimensions as accurate measurements (bug: hidden fill reports wrong size) - Reorder broker host selection sort to prefer focused hosts over hosts with larger operation sets, using capability size only as a tiebreaker (bug: capability size beats focus)
1 parent 014ba12 commit c2e2e23

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

apps/server/src/mcp/PreviewAutomationBroker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ export const make = Effect.gen(function* PreviewAutomationBrokerMake() {
393393
)
394394
.sort(
395395
(left, right) =>
396-
right.supportedOperations.size - left.supportedOperations.size ||
397396
Number(right.focused) - Number(left.focused) ||
398-
right.focusOrder - left.focusOrder,
397+
right.focusOrder - left.focusOrder ||
398+
right.supportedOperations.size - left.supportedOperations.size,
399399
)[0];
400400
if (!connection) {
401401
if (!hasLiveAssignment) assignments.delete(assignmentKey);

apps/web/src/components/preview/PreviewAutomationHosts.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,31 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
375375
throw squashAtomCommandFailure(result);
376376
}
377377
applyPreviewServerSnapshot(threadRef, result.value);
378-
const viewport = await waitForRenderedViewport(
379-
ready.tabId,
380-
setting,
381-
input.timeoutMs ?? request.timeoutMs,
382-
);
378+
// Best-effort viewport verification: the server-side resize has
379+
// already committed so we must not fail the MCP request if layout
380+
// takes longer than expected. For hidden fill-mode tabs the webview
381+
// renders at placeholder dimensions that won't match the eventual
382+
// panel size, so skip verification to avoid reporting those values
383+
// as confirmed.
384+
let viewport: PreviewRenderedViewportSize | null = null;
385+
const tabVisible =
386+
useBrowserSurfaceStore.getState().byTabId[ready.tabId]?.visible ?? false;
387+
if (tabVisible || setting._tag !== "fill") {
388+
try {
389+
viewport = await waitForRenderedViewport(
390+
ready.tabId,
391+
setting,
392+
input.timeoutMs ?? request.timeoutMs,
393+
);
394+
} catch {
395+
// Verification timed out but server state is already committed.
396+
}
397+
}
398+
viewport ??= await readRenderedViewport(ready.tabId).catch(() => null);
399+
viewport ??=
400+
setting._tag !== "fill"
401+
? { width: setting.width, height: setting.height }
402+
: { width: 1280, height: 800 };
383403
return {
384404
tabId: ready.tabId,
385405
setting,

0 commit comments

Comments
 (0)