From af28c7eb51eb5303704bd341ebaed618d129ba44 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 07:40:41 +0000 Subject: [PATCH 1/2] test(desktop): server tab captures should lift main window throttling (#23139) A hidden, minimized or covered main window commits no frames while throttled, so agent snapshots of server tabs time out. This test fails on main: the capture never turns the main window's throttling off. AI-assisted; verified with the tests and tools listed above. --- apps/desktop/src/preview/Manager.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/desktop/src/preview/Manager.test.ts b/apps/desktop/src/preview/Manager.test.ts index a178edeb9753f..ab529f2b302c4 100644 --- a/apps/desktop/src/preview/Manager.test.ts +++ b/apps/desktop/src/preview/Manager.test.ts @@ -2096,6 +2096,12 @@ describe("PreviewManager", () => { yield* manager.createTab("tab_1", { serverTab }); yield* manager.registerWebview("tab_1", 42); yield* Deferred.await(attached); + const setBackgroundThrottling = vi.fn(); + yield* manager.setMainWindow({ + isDestroyed: () => false, + once: vi.fn(), + webContents: { setBackgroundThrottling }, + } as never); // Navigating rebuilds the tab's state, which must keep the server tab it answers for. yield* manager.navigate("tab_1", "https://example.com/next"); yield* Queue.clear(capturing); @@ -2114,6 +2120,8 @@ describe("PreviewManager", () => { expect(yield* Queue.take(capturing)).toBe(true); screenshot.resolve({ data: "" }); expect(yield* Queue.take(capturing)).toBe(false); + // A hidden, minimized or covered main window commits no frames while throttled. + expect(setBackgroundThrottling.mock.calls).toEqual([[false], [true]]); }).pipe(Effect.provide(managerLayer()), Effect.scoped), ); From 7190b74d17005f37fdd16edf30d93455d2813e2d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 07:45:58 +0000 Subject: [PATCH 2/2] fix(desktop): agent snapshots of preview tabs no longer stall while the window is hidden Server tab captures ask the client to paint the guest, but the main window stayed background-throttled, so a minimized, hidden or covered window drew no frames and the capture timed out. Keep the main window unthrottled while any server tab is being painted for a capture, the same way recording and picture-in-picture already do. Fixes pingdotgg/t3code#23139 AI-assisted; verified with the tests and tools listed above. --- apps/desktop/src/preview/Manager.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts index 7f39a92bdb769..8dfbe8a1dbfb1 100644 --- a/apps/desktop/src/preview/Manager.ts +++ b/apps/desktop/src/preview/Manager.ts @@ -598,6 +598,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function let pendingRecording: PendingRecording | null = null; const displayMediaHandlerSessions = new WeakSet(); let frameCaptureWindowOpen = true; + // Server tabs the client paints for a capture; guarded by frameCaptureSessionsRef like sessions. + const paintingServerTabs = new Set(); let currentMainWindow: BrowserWindow | undefined; let mainWindowCleanupFiber: Fiber.Fiber | undefined; const tabLifecycleLocks = new Map< @@ -817,7 +819,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function yield* restoreFrameCaptureWebContentsBackgroundThrottling( current.unthrottledWebContentsIds, ); - if (remainingSessions.size === 0) { + if (remainingSessions.size === 0 && paintingServerTabs.size === 0) { yield* setFrameCaptureBackgroundThrottling(true).pipe( Effect.retry({ times: 2 }), Effect.catch((error) => @@ -1675,7 +1677,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function Effect.gen(function* () { // Cleanup or lock acquisition can outlive the replacement window. if (window.isDestroyed()) return [undefined, sessions] as const; - if (sessions.size > 0) { + if (sessions.size > 0 || paintingServerTabs.size > 0) { yield* setWindowBackgroundThrottling(window, false); } yield* Ref.set(mainWindowRef, Option.some(window)); @@ -2820,12 +2822,13 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function }), ] as const; } - if (sessions.size === 0) { + const mainWindowThrottled = sessions.size === 0 && paintingServerTabs.size === 0; + if (mainWindowThrottled) { yield* setFrameCaptureBackgroundThrottling(false); } yield* setFrameCaptureWebContentsBackgroundThrottling(wc, false).pipe( Effect.onError(() => - sessions.size === 0 + mainWindowThrottled ? setFrameCaptureBackgroundThrottling(true).pipe(Effect.ignore) : Effect.void, ), @@ -3428,6 +3431,24 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function readonly key: { readonly threadId: string; readonly tabId: string }; readonly active: boolean; }) { + // A hidden, minimized or covered main window commits no frames while throttled. + yield* SynchronizedRef.modifyEffect(frameCaptureSessionsRef, (sessions) => + Effect.gen(function* () { + const key = `${painting.key.threadId}\u0000${painting.key.tabId}`; + if (paintingServerTabs.has(key) === painting.active) + return [undefined, sessions] as const; + if (painting.active) paintingServerTabs.add(key); + else paintingServerTabs.delete(key); + if (sessions.size === 0 && paintingServerTabs.size === (painting.active ? 1 : 0)) { + yield* setFrameCaptureBackgroundThrottling(!painting.active).pipe( + Effect.catch((error) => + Effect.logWarning("Failed to update preview capture throttling.", { error }), + ), + ); + } + return [undefined, sessions] as const; + }), + ).pipe(Effect.uninterruptible); const tab = [...(yield* SynchronizedRef.get(tabsRef)).values()].find( (candidate) => candidate.serverTab?.threadId === painting.key.threadId &&