The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep visible renderer animations running on blur
brooklyn!3cad0f312b59
diff --git a/apps/desktop/DESIGN.md b/apps/desktop/DESIGN.mdindex 8f310339213..a1c33275b9b 100644--- a/apps/desktop/DESIGN.md+++ b/apps/desktop/DESIGN.md@@ -275,6 +275,8 @@ Sizes: `default`, `xs`, `overlay` (titlebar glyph counts).## Motion+- Visible windows keep animating when another app takes focus. Hidden/minimized+ windows and inactive panes may pause; background polling stays focus-gated.- Quick, functional transitions (~100ms on controls). Respect`prefers-reduced-motion` for anything beyond a fade.- Choreographed exits (e.g. onboarding's "matrix" fade-down) stagger per-elementdiff --git a/apps/desktop/e2e/glyph-spinner.spec.ts b/apps/desktop/e2e/glyph-spinner.spec.tsindex 8d2e97f552b..c7228eafd63 100644--- a/apps/desktop/e2e/glyph-spinner.spec.ts+++ b/apps/desktop/e2e/glyph-spinner.spec.ts@@ -173,11 +173,9 @@ test.describe('GlyphSpinner (compositor animation)', () => {expect(parked.playState).toBe('paused')expect(parked.willChange).toBe('auto')- // 2. The global gate: window blur / minimize / document-hidden, which- // main.tsx drives by arming this attribute on the root. The strip must- // be named in that rule, or every spinner keeps animating behind an- // inactive window — the CPU burn the original ticker's pause- // controller existed to avoid.+ // 2. The global gate: window minimize / document-hidden, which+ // main.tsx drives by arming this attribute on the root. Visible windows+ // keep animating even when another app has focus.const globallyPaused = await page.evaluate(strip => {const root = document.documentElementconst had = root.hasAttribute('data-renderer-animations-paused')diff --git a/apps/desktop/src/app/right-sidebar/terminal/persistent.tsx b/apps/desktop/src/app/right-sidebar/terminal/persistent.tsxindex f40fcedf6c3..c0c5936c781 100644--- a/apps/desktop/src/app/right-sidebar/terminal/persistent.tsx+++ b/apps/desktop/src/app/right-sidebar/terminal/persistent.tsx@@ -210,7 +210,7 @@ export function PersistentTerminal({ onAddSelectionToChat }: PersistentTerminalPscheduleMeasure('ancestor-mutation')})- pauseController = createRendererLoopPauseController(handleVisibilityChange)+ pauseController = createRendererLoopPauseController(handleVisibilityChange, { pauseWhenUnfocused: true })if (measure('initial')) {scheduleMeasure('settle')diff --git a/apps/desktop/src/components/chat/image-generation-placeholder.test.tsx b/apps/desktop/src/components/chat/image-generation-placeholder.test.tsxindex 6d439afb0d1..029e4c2dd25 100644--- a/apps/desktop/src/components/chat/image-generation-placeholder.test.tsx+++ b/apps/desktop/src/components/chat/image-generation-placeholder.test.tsx@@ -83,7 +83,7 @@ describe('DiffusionCanvas scheduling', () => {delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop})- it('cancels its loop while inactive and resumes only when the window is observable', () => {+ it('keeps animating while unfocused but cancels its loop while minimized', () => {const raf = installRaf()render()@@ -93,7 +93,7 @@ describe('DiffusionCanvas scheduling', () => {act(() => {window.dispatchEvent(new Event('blur'))})- expect(raf.pending()).toBe(0)+ expect(raf.pending()).toBe(1)act(() => {window.dispatchEvent(new Event('focus'))diff --git a/apps/desktop/src/components/pet/use-pet-roam.test.tsx b/apps/desktop/src/components/pet/use-pet-roam.test.tsxindex c306800ecfa..c9e761235a7 100644--- a/apps/desktop/src/components/pet/use-pet-roam.test.tsx+++ b/apps/desktop/src/components/pet/use-pet-roam.test.tsx@@ -98,14 +98,14 @@ describe('usePetRoam RAF scheduling', () => {expect(vi.getTimerCount()).toBe(1)})- it('suspends idle movement while unfocused and cleans up its wake timer on unmount', () => {+ it('keeps idle movement scheduled while unfocused and cleans up on unmount', () => {const raf = installRaf()mount.render(<RoamHarness />)expect(vi.getTimerCount()).toBe(1)act(() => window.dispatchEvent(new Event('blur')))- expect(vi.getTimerCount()).toBe(0)+ expect(vi.getTimerCount()).toBe(1)act(() => window.dispatchEvent(new Event('focus')))expect(vi.getTimerCount()).toBe(1)diff --git a/apps/desktop/src/components/ui/glyph-spinner.tsx b/apps/desktop/src/components/ui/glyph-spinner.tsxindex 0056a083e00..2238d0abcee 100644--- a/apps/desktop/src/components/ui/glyph-spinner.tsx+++ b/apps/desktop/src/components/ui/glyph-spinner.tsx@@ -77,7 +77,7 @@ export function GlyphSpinner({}: GlyphSpinnerProps) {const spin = FRAMES_BY_NAME[spinner] ?? FRAMES_BY_NAME.braille!// Pause when this surface is a hidden (kept-alive) tab: N mounted tabs each- // animating burns CPU for pixels nobody can see. Window blur / minimize /+ // animating burns CPU for pixels nobody can see. Window minimize /// document-hidden are handled globally instead, by the// `:root[data-renderer-animations-paused]` rule in styles.css that// main.tsx's installRendererAnimationPauseState() drives — the samediff --git a/apps/desktop/src/lib/budgeted-loop.test.ts b/apps/desktop/src/lib/budgeted-loop.test.tsindex edcc027e87d..eb96c20bbf6 100644--- a/apps/desktop/src/lib/budgeted-loop.test.ts+++ b/apps/desktop/src/lib/budgeted-loop.test.ts@@ -71,7 +71,7 @@ describe('createBudgetedLoop', () => {loop.dispose()})- it('pauses while the window is not observable and resumes when it is', () => {+ it('keeps drawing while unfocused but pauses while minimized', () => {const raf = installRaf()const draw = vi.fn()const loop = createBudgetedLoop(draw)@@ -79,7 +79,9 @@ describe('createBudgetedLoop', () => {expect(raf.pending()).toBe(1)window.dispatchEvent(new Event('blur'))- expect(raf.pending()).toBe(0)+ expect(raf.pending()).toBe(1)+ raf.runNext(1000)+ expect(draw).toHaveBeenCalledTimes(1)window.dispatchEvent(new Event('focus'))expect(raf.pending()).toBe(1)diff --git a/apps/desktop/src/lib/budgeted-loop.ts b/apps/desktop/src/lib/budgeted-loop.tsindex 2d2aff658ad..5bb65b236ab 100644--- a/apps/desktop/src/lib/budgeted-loop.ts+++ b/apps/desktop/src/lib/budgeted-loop.ts@@ -9,8 +9,8 @@* - **fps budget** — paints are skipped until `1000 / fps` elapsed; the loop* still rides rAF so Chromium can align and pause it natively.* - **observability pause** — wired to `createRendererLoopPauseController`:- * the loop cancels while the window is hidden, minimized, or unfocused and- * resumes when observable.+ * the loop cancels while the window is hidden or minimized and resumes+ * when visible, even if another window has focus.* - **idle dormancy** — when `idleWhen()` returns true after a draw, the loop* parks (zero pending frames, zero timers) until `wake()` is called. This* is the piece every hand-rolled loop forgot: "nothing visible to animate"@@ -43,7 +43,7 @@ export interface BudgetedLoopOptions {* animation finished). Checked after every draw; when true the loop parks* until `wake()`. Omit for loops that should run whenever observable. */idleWhen?: () => boolean- /** Forwarded to the pause controller. Default true (pause on blur). */+ /** Forwarded to the pause controller. Default false (animate while visible). */pauseWhenUnfocused?: boolean}@@ -60,7 +60,7 @@ export interface BudgetedLoop {export function createBudgetedLoop(draw: (now: number) => void,- { fps = 15, idleWhen, pauseWhenUnfocused = true }: BudgetedLoopOptions = {}+ { fps = 15, idleWhen, pauseWhenUnfocused = false }: BudgetedLoopOptions = {}): BudgetedLoop {const frameInterval = 1000 / fpslet frame = 0diff --git a/apps/desktop/src/lib/renderer-loop-pause.test.ts b/apps/desktop/src/lib/renderer-loop-pause.test.tsindex 46563c627a4..6e96a498d57 100644--- a/apps/desktop/src/lib/renderer-loop-pause.test.ts+++ b/apps/desktop/src/lib/renderer-loop-pause.test.ts@@ -8,7 +8,7 @@ describe('installRendererAnimationPauseState', () => {vi.restoreAllMocks()})- it('pauses on blur, resumes on focus, and cleans up its root state', () => {+ it('keeps visible animations running across blur and focus, and cleans up its root state', () => {let focused = truevi.spyOn(document, 'hasFocus').mockImplementation(() => focused)@@ -17,7 +17,7 @@ describe('installRendererAnimationPauseState', () => {focused = falsewindow.dispatchEvent(new Event('blur'))- expect(document.documentElement.hasAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)).toBe(true)+ expect(document.documentElement.hasAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)).toBe(false)focused = truewindow.dispatchEvent(new Event('focus'))diff --git a/apps/desktop/src/lib/renderer-loop-pause.ts b/apps/desktop/src/lib/renderer-loop-pause.tsindex 55fb19b1c78..b66dc5ad3e2 100644--- a/apps/desktop/src/lib/renderer-loop-pause.ts+++ b/apps/desktop/src/lib/renderer-loop-pause.ts@@ -5,7 +5,7 @@ interface WindowStatePayload {export const RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE = 'data-renderer-animations-paused'-export function createRendererLoopPauseController(onChange: () => void, { pauseWhenUnfocused = true } = {}) {+export function createRendererLoopPauseController(onChange: () => void, { pauseWhenUnfocused = false } = {}) {let windowPaused = falselet windowFocused = document.hasFocus()@@ -37,8 +37,10 @@ export function createRendererLoopPauseController(onChange: () => void, { pauseW})document.addEventListener('visibilitychange', onVisibilityChange)- window.addEventListener('blur', onBlur)- window.addEventListener('focus', onFocus)+ if (pauseWhenUnfocused) {+ window.addEventListener('blur', onBlur)+ window.addEventListener('focus', onFocus)+ }return {dispose: () => {diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsxindex e71435b83c0..682422ad9da 100644--- a/apps/desktop/src/main.tsx+++ b/apps/desktop/src/main.tsx@@ -59,7 +59,7 @@ if (winParam === 'overlay') {void import('./app/wake-indicator/wake-indicator-root').then(({ mountWakeIndicator }) => mountWakeIndicator())} else {// CSS animations do not inherit Chromium's JS-loop pause policy. Mirror the- // main window's focus/visibility state to :root so decorative infinite+ // main window's visibility state to :root so decorative infinite// animations stop producing frames when nobody can see them.installRendererAnimationPauseState()diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.cssindex a06e8af50a7..464315cc0d6 100644--- a/apps/desktop/src/styles.css+++ b/apps/desktop/src/styles.css@@ -32,9 +32,9 @@}}-/* Continuous decorative animations otherwise keep Chromium's renderer awake- behind another app. main.tsx owns this attribute only for the primary- window; wake/pet overlays retain their purpose-built visibility behavior. */+/* Pause continuous animations only when the window is hidden/minimized, not+ merely unfocused. main.tsx owns this attribute for the primary window;+ wake/pet overlays retain their purpose-built visibility behavior. */:root[data-renderer-animations-paused]:is(.shimmer,