From 1cb1cb930a79ef2bb4fcccca3dc52b4af34394d7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 01:33:27 +0000 Subject: [PATCH 1/4] test(server): a desktop resize that never draws fails instead of succeeding Reproduces pingdotgg/t3code#40008: when the desktop window cannot paint (for example while minimized), preview_resize returns isError:false with the old viewport, so agents keep working at the wrong size. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/preview/ServerBrowser.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/server/src/preview/ServerBrowser.test.ts b/apps/server/src/preview/ServerBrowser.test.ts index 3bc4eba2f240c..ada36810bb650 100644 --- a/apps/server/src/preview/ServerBrowser.test.ts +++ b/apps/server/src/preview/ServerBrowser.test.ts @@ -3069,6 +3069,25 @@ it.effect("a desktop tab reports the size the desktop draws after a resize", () height: 760, }); expect(yield* status).toEqual({ width: 560, height: 760 }); + // A desktop that never draws the new size, such as a minimized window, fails the resize. + const unpainted = Promise.withResolvers(); + heldStill = () => unpainted.promise; + const undrawn = yield* broker + .invoke({ + scope, + tabId, + operation: "resize", + input: { mode: "freeform", width: 1440, height: 900 }, + }) + .pipe(Effect.exit, Effect.forkScoped); + let undrawnEvent = yield* PubSub.take(events); + while (undrawnEvent.type !== "resized" || undrawnEvent.tabId !== tabId) { + undrawnEvent = yield* PubSub.take(events); + } + yield* TestClock.adjust("1 second"); + expect(Exit.isFailure(yield* Fiber.join(undrawn))).toBe(true); + heldStill = null; + unpainted.resolve(); expect(yield* resize({ mode: "fill" }, 1234, 700)).toEqual({ width: 1234, height: 700 }); // No page resize or load since that read, so status answers without reading again. let reads = 0; From 1386aac218ff040bd035c485b2329a8c74e82f91 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 01:59:44 +0000 Subject: [PATCH 2/4] fix(server): a desktop preview resize the window never draws now fails When the T3 Code window does not paint (for example while minimized), the desktop never draws the guest at the new size, but preview_resize returned success with the old viewport. It now fails with an error that says to show or restore the window, as preview_snapshot does. Fixes pingdotgg/t3code#40008 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/preview/ServerBrowser.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/server/src/preview/ServerBrowser.ts b/apps/server/src/preview/ServerBrowser.ts index 0a0dad06fb50d..9541b2a0058b0 100644 --- a/apps/server/src/preview/ServerBrowser.ts +++ b/apps/server/src/preview/ServerBrowser.ts @@ -2833,6 +2833,7 @@ const make = Effect.gen(function* () { // The desktop draws the new size after the session update; its page resize says it has. // Half the time left keeps room for the read, which runs even if nothing was drawn, // because a page can keep another size than the one asked for. + let undrawn = false; if (changed) { // Electron resizes no hidden guest it does not paint; a pending capture makes the desktop paint it. let waiting = true; @@ -2842,13 +2843,25 @@ const make = Effect.gen(function* () { } })().catch(constVoid); try { - await within(drawn, Math.min(DESKTOP_RESIZE_WAIT_MS, remainingMs() / 2)); + undrawn = + (await within( + drawn.then(() => true), + Math.min(DESKTOP_RESIZE_WAIT_MS, remainingMs() / 2), + )) === null; } finally { waiting = false; } } const changes = tab.desktopViewportChanges; const measured = await within(measureDesktopViewport(tab), remainingMs()); + // A window that does not paint, such as a minimized one, never draws the new size. + if (undrawn && (measured?.width !== to?.width || measured?.height !== to?.height)) { + throw new ServerBrowserPage.ServerBrowserOperationError({ + tag: "PreviewAutomationExecutionError", + message: + "The desktop did not draw the page at the new size. Show or restore the T3 Code window and try again.", + }); + } // Only a read after the draw, with no page resize or load during it, measures this resize. return { tabId: tab.tabId, From 23032419b50dc6709a310f3fcad79f711b7c7344 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 03:47:34 +0000 Subject: [PATCH 3/4] fix(server): retrying an undrawn desktop resize waits for the draw again Co-Authored-By: Claude Opus 5.5 --- apps/server/src/preview/ServerBrowser.test.ts | 15 +++++++++++++++ apps/server/src/preview/ServerBrowser.ts | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/server/src/preview/ServerBrowser.test.ts b/apps/server/src/preview/ServerBrowser.test.ts index ada36810bb650..78c6414d8435c 100644 --- a/apps/server/src/preview/ServerBrowser.test.ts +++ b/apps/server/src/preview/ServerBrowser.test.ts @@ -3086,6 +3086,21 @@ it.effect("a desktop tab reports the size the desktop draws after a resize", () } yield* TestClock.adjust("1 second"); expect(Exit.isFailure(yield* Fiber.join(undrawn))).toBe(true); + // The same size again still waits for a draw rather than reporting the old size. + const retried = yield* broker + .invoke({ + scope, + tabId, + operation: "resize", + input: { mode: "freeform", width: 1440, height: 900 }, + }) + .pipe(Effect.exit, Effect.forkScoped); + let retriedEvent = yield* PubSub.take(events); + while (retriedEvent.type !== "resized" || retriedEvent.tabId !== tabId) { + retriedEvent = yield* PubSub.take(events); + } + yield* TestClock.adjust("1 second"); + expect(Exit.isFailure(yield* Fiber.join(retried))).toBe(true); heldStill = null; unpainted.resolve(); expect(yield* resize({ mode: "fill" }, 1234, 700)).toEqual({ width: 1234, height: 700 }); diff --git a/apps/server/src/preview/ServerBrowser.ts b/apps/server/src/preview/ServerBrowser.ts index 9541b2a0058b0..9cfca15bdc626 100644 --- a/apps/server/src/preview/ServerBrowser.ts +++ b/apps/server/src/preview/ServerBrowser.ts @@ -385,6 +385,8 @@ interface ServerTab { desktopViewportChanges: number; /** Settles at the desktop page's next main-frame resize. */ desktopResize: PromiseWithResolvers; + /** The last resize failed undrawn, so the tab's setting is a size the page never took. */ + desktopResizeUndrawn: boolean; loading: boolean; loadError: PreviewAutomationLoadError | undefined; /** The renderer crash this page died of, or the one the page it replaced died of. */ @@ -1189,6 +1191,7 @@ const make = Effect.gen(function* () { desktopViewportStale: true, desktopViewportChanges: 0, desktopResize: Promise.withResolvers(), + desktopResizeUndrawn: false, loading: false, loadError: undefined, // The page a crash left behind is blank; the session still names what crashed. @@ -2821,7 +2824,8 @@ const make = Effect.gen(function* () { viewport: tab.page.viewportSize() ?? UNATTACHED_FILL_VIEWPORT, }; } - const changed = from?.width !== to?.width || from?.height !== to?.height; + const changed = + tab.desktopResizeUndrawn || from?.width !== to?.width || from?.height !== to?.height; const remainingMs = () => Math.max(0, deadlineMs - performance.now()); const within = (promise: Promise, ms: number) => runPromise( @@ -2855,7 +2859,9 @@ const make = Effect.gen(function* () { const changes = tab.desktopViewportChanges; const measured = await within(measureDesktopViewport(tab), remainingMs()); // A window that does not paint, such as a minimized one, never draws the new size. - if (undrawn && (measured?.width !== to?.width || measured?.height !== to?.height)) { + tab.desktopResizeUndrawn = + undrawn && (measured?.width !== to?.width || measured?.height !== to?.height); + if (tab.desktopResizeUndrawn) { throw new ServerBrowserPage.ServerBrowserOperationError({ tag: "PreviewAutomationExecutionError", message: From d4daa057005efec48ecfe25b983f80653ba558b2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 05:57:35 +0000 Subject: [PATCH 4/4] fix(server): a desktop fill resize with no draw reports the measured size Co-Authored-By: Claude Opus 5.5 --- apps/server/src/preview/ServerBrowser.test.ts | 17 ++++++++++++++++- apps/server/src/preview/ServerBrowser.ts | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/server/src/preview/ServerBrowser.test.ts b/apps/server/src/preview/ServerBrowser.test.ts index 78c6414d8435c..9d1460c9befd5 100644 --- a/apps/server/src/preview/ServerBrowser.test.ts +++ b/apps/server/src/preview/ServerBrowser.test.ts @@ -3069,9 +3069,24 @@ it.effect("a desktop tab reports the size the desktop draws after a resize", () height: 760, }); expect(yield* status).toEqual({ width: 560, height: 760 }); - // A desktop that never draws the new size, such as a minimized window, fails the resize. const unpainted = Promise.withResolvers(); heldStill = () => unpainted.promise; + // Fill asks for no size, so a page that keeps its size without a resize is not undrawn. + const kept = yield* broker + .invoke({ + scope, + tabId, + operation: "resize", + input: { mode: "fill" }, + }) + .pipe(Effect.forkScoped); + let keptEvent = yield* PubSub.take(events); + while (keptEvent.type !== "resized" || keptEvent.tabId !== tabId) { + keptEvent = yield* PubSub.take(events); + } + yield* TestClock.adjust("1 second"); + expect((yield* Fiber.join(kept)).viewport).toEqual({ width: 560, height: 760 }); + // A desktop that never draws the new size, such as a minimized window, fails the resize. const undrawn = yield* broker .invoke({ scope, diff --git a/apps/server/src/preview/ServerBrowser.ts b/apps/server/src/preview/ServerBrowser.ts index 9cfca15bdc626..26203fc1a63c8 100644 --- a/apps/server/src/preview/ServerBrowser.ts +++ b/apps/server/src/preview/ServerBrowser.ts @@ -2859,8 +2859,11 @@ const make = Effect.gen(function* () { const changes = tab.desktopViewportChanges; const measured = await within(measureDesktopViewport(tab), remainingMs()); // A window that does not paint, such as a minimized one, never draws the new size. + // Fill asks for no size, so only a fixed one can be missed. tab.desktopResizeUndrawn = - undrawn && (measured?.width !== to?.width || measured?.height !== to?.height); + undrawn && + to !== null && + (measured?.width !== to.width || measured?.height !== to.height); if (tab.desktopResizeUndrawn) { throw new ServerBrowserPage.ServerBrowserOperationError({ tag: "PreviewAutomationExecutionError",