fix(desktop): throttle hidden preview rendering #7445
Mergedt3-code-bot[bot](GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/7445/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/preview/Manager.ts line 1719OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1692,3 +1709,11 @@16921709 window: BrowserWindow,16931710 ) {16941711 yield* Ref.set(mainWindowRef, Option.some(window));1712+ yield* SynchronizedRef.modifyEffect(frameCaptureSessionsRef, (sessions) =>1713+ Effect.gen(function* () {1714+ if (sessions.size > 0) {1715+ yield* setFrameCaptureBackgroundThrottling(false);1716+ }1717+ return [undefined, sessions] as const;1718+ }),1719+ );
- apps/desktop/src/preview/Manager.ts line 650Resolvedby t3-code-bot[bot](GitHub profile, opens in a new tab)@@ -610,7 +622,19 @@610- ] as const;611- });622+ });623+ if (remainingSessions.size === 0) {624+ yield* setFrameCaptureBackgroundThrottling(true);625+ }626+ return [current.scope, remainingSessions] as const;627+ }),628+ );612629 if (captureScope) {613630 yield* Scope.close(captureScope, Exit.void).pipe(Effect.ignore);614631 }615632 });616633634+ const stopAllRecordings = Effect.fn("PreviewManager.stopAllRecordings")(function* () {635+ const sessions = yield* SynchronizedRef.get(frameCaptureSessionsRef);636+ yield* Effect.forEach(sessions.keys(), (tabId) => stopFrameCapture(tabId, "recording"), {637+ concurrency: "unbounded",638+ discard: true,639+ });640+ });
- apps/desktop/src/preview/Manager.ts lines 2647 to 2651OutdatedResolvedby t3-code-bot[bot](GitHub profile, opens in a new tab)@@ -2597,3 +2643,9 @@25972643 );25982644 const created = yield* SynchronizedRef.modifyEffect(frameCaptureSessionsRef, (sessions) => {25992645 return Effect.gen(function* () {2646+ if (!frameCaptureWindowOpen) {2647+ return yield* new PreviewOperationError({2648+ operation: "frameCapture.start",2649+ tabId,2650+ cause: new Error("Cannot start preview frame capture while the main window is closed."),2651+ });
- apps/desktop/src/preview/Manager.ts line 596Resolvedby t3-code-bot[bot](GitHub profile, opens in a new tab)@@ -586,11 +592,14 @@592+ if (window.isDestroyed()) return;593+ yield* attempt({ operation: "frameCapture.setBackgroundThrottling" }, () =>594+ window.webContents.setBackgroundThrottling(enabled),595+ );596+ });597+ const setFrameCaptureBackgroundThrottling = Effect.fnUntraced(function* (enabled: boolean) {598+ const mainWindow = yield* Ref.get(mainWindowRef);599+ if (Option.isNone(mainWindow)) return;600+ yield* setWindowBackgroundThrottling(mainWindow.value, enabled);601+ });586602 const stopFrameCapture = Effect.fn("PreviewManager.stopFrameCapture")(function* (587603 tabId: string,588604 consumer: FrameCaptureConsumer,589605 ) {590- const captureScope = yield* SynchronizedRef.modify(frameCaptureSessionsRef, (sessions) => {591- const current = sessions.get(tabId);592- if (!current || !current.consumers.has(consumer)) {593- return [undefined, sessions] as const;594- }595- const consumers = new Set(current.consumers);596- consumers.delete(consumer);
- apps/desktop/src/preview/Manager.ts line 1741Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1691,7 +1725,15 @@16911725 const setMainWindow = Effect.fn("PreviewManager.setMainWindow")(function* (16921726 window: BrowserWindow,16931727 ) {1694- yield* Ref.set(mainWindowRef, Option.some(window));1695- window.once("closed", () => {1696- runFork(closeAllPictureInPicture());1697- });1728+ if (mainWindowCleanupFiber) {1729+ yield* Fiber.join(mainWindowCleanupFiber);1730+ mainWindowCleanupFiber = undefined;1731+ }1732+ yield* SynchronizedRef.modifyEffect(frameCaptureSessionsRef, (sessions) =>1733+ Effect.gen(function* () {1734+ if (sessions.size > 0) {1735+ yield* setWindowBackgroundThrottling(window, false);1736+ }1737+ yield* Ref.set(mainWindowRef, Option.some(window));1738+ frameCaptureWindowOpen = true;1739+ window.once("closed", () => {
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
3a02c9c· PR result:7281787· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.