Repository navigation
fix(renderer): drive agent working spinner on the compositor (STA-3328) - #12359
Conversation
The shared 12Hz JS clock wrote el.style.transform on every mounted spinner (41 live = ~490 main-thread style writes/s), keeping style perpetually dirty and delaying keystroke dispatch (measured typing inputDelay p90 363ms; 19ms with the writes stopped). Replace it with a steps(12) CSS transform animation so rotation runs on the compositor; one mount-time animation-delay write preserves the shared-epoch phase sync.
📝 WalkthroughWalkthroughThe working-agent spinner now uses the 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3592c0a7-2687-44e2-b135-7e69a41cf3e5
📒 Files selected for processing (7)
src/renderer/src/assets/main.csssrc/renderer/src/components/AgentStateDot.test.tssrc/renderer/src/components/AgentWorkingSpinner.test.tsxsrc/renderer/src/components/AgentWorkingSpinner.tsxsrc/renderer/src/components/sidebar/StatusIndicator.test.tssrc/renderer/src/lib/agent-spinner-clock.test.tssrc/renderer/src/lib/agent-spinner-clock.ts
💤 Files with no reviewable changes (2)
- src/renderer/src/lib/agent-spinner-clock.ts
- src/renderer/src/lib/agent-spinner-clock.test.ts
| // Why: one animation-delay write at mount aligns every ring to a shared 1s | ||
| // epoch — the phase sync the retired JS clock provided, without its per-tick | ||
| // main-thread style writes (STA-3328). No cleanup needed: the value is inert. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Keep spinner rationale comments concise.
Reduce each rationale to one line. Remove comments that only restate the matching assertion.
src/renderer/src/components/AgentWorkingSpinner.tsx#L4-L6: Keep only the shared-phase rationale.src/renderer/src/components/AgentWorkingSpinner.tsx#L17-L19: Keep only the compositor-performance rationale.src/renderer/src/components/AgentWorkingSpinner.tsx#L26-L28: Keep only the static-marker rationale.src/renderer/src/components/AgentWorkingSpinner.test.tsx#L19-L21: Keep one cross-file wiring rationale.src/renderer/src/components/AgentStateDot.test.ts#L25-L26: Remove the assertion-restating comment.src/renderer/src/components/sidebar/StatusIndicator.test.ts#L25-L26: Remove the assertion-restating comment.
As per coding guidelines, “Comments must be concise, limited to non-obvious information, and preferably one line; do not explain obvious code or describe how it works.”
📍 Affects 4 files
src/renderer/src/components/AgentWorkingSpinner.tsx#L4-L6(this comment)src/renderer/src/components/AgentWorkingSpinner.tsx#L17-L19src/renderer/src/components/AgentWorkingSpinner.tsx#L26-L28src/renderer/src/components/AgentWorkingSpinner.test.tsx#L19-L21src/renderer/src/components/AgentStateDot.test.ts#L25-L26src/renderer/src/components/sidebar/StatusIndicator.test.ts#L25-L26
Source: Coding guidelines
Post-review Electron validationValidated pushed head
Final-head rendered workspace state ( 43-spinner agent/subagent scale state: |
…8) (stablyai#12359) * fix(renderer): drive agent working spinner on the compositor (STA-3328) The shared 12Hz JS clock wrote el.style.transform on every mounted spinner (41 live = ~490 main-thread style writes/s), keeping style perpetually dirty and delaying keystroke dispatch (measured typing inputDelay p90 363ms; 19ms with the writes stopped). Replace it with a steps(12) CSS transform animation so rotation runs on the compositor; one mount-time animation-delay write preserves the shared-epoch phase sync. * fix(renderer): lock agent spinner phases to document time * fix(renderer): tolerate missing spinner animation API


Summary
Typing lag on Mac (STA-3328) was root-caused live on a production instance to the shared agent-spinner JS clock: a 12Hz
setIntervalwritingel.style.transformon every mounted working-spinner. With 41 spinners mounted that is ~490 main-thread style writes/s (97% of all DOM mutation traffic), keeping style perpetually dirty — single style-recalc passes of 96–120ms — and delaying keystroke dispatch.This PR replaces the clock with a compositor-driven CSS animation (
steps(12, end), 30° per tick — the exact cadence the clock used). Each ring's CSS Animation is anchored once to the document timeline at mount (and when recreated after a reduced-motion change), keeping every ring in exact lockstep.prefers-reduced-motionstill freezes the ring and the existing filled-top-border static marker is unchanged.agent-spinner-clock.tsis deleted; thedata-agent-spinnerhook attribute stays.Measured impact (live prod instance, user actually typing, A/B by stopping the clock's writes):
The residual long tasks are a separate mechanism (per-agent-status synchronous render bursts — follow-up ticket to come) and are unaffected by this PR.
Verified in a dev build of this branch (CDP-driven): 43 concurrent spinners → 0 attribute mutations and 0 long tasks over 8s; computed-transform sampling shows exactly 12 distinct angles/s in 30° steps; all spinners report identical angles at the same instant (phase sync intact).
Screenshots
Dev instance of this branch — worktree card, agent row, and tab indicator spinners render identically to prod (same ring geometry/colors; only the animation driver changed):
Testing
pnpm lint— repo-wide oxlint clean, react-doctor changed-lines gate clean, max-lines ratchet OK (localization verifies not run; no string changes)pnpm typecheck— all three configs passpnpm test— targeted: AgentWorkingSpinner, AgentStateDot, StatusIndicator, TerminalTabLeadingIcon (20 tests pass); full suite left to CIpnpm build— left to CIAgentWorkingSpinner.test.tsx: pins the component→main.csswiring (class present in markup;.agent-working-spinnerrule exists withsteps(12, end)and a reduced-motionanimation: noneoverride) so neither side can be renamed or dropped alone. Updated AgentStateDot/StatusIndicator tests that pinned the old clock-driven contract.AI Review Report
Reviewed the change for: dangling imports of the deleted module (none —
registerStaleDocumentVisibilityRecoveryandwindow-visibility-intervalhave other consumers and are untouched); reduced-motion behavior (media query disables the animation; existingmotion-reduce:border-t-yellow-500fills the ring, matching the old frozen-state rendering, #9515); phase-sync lifecycle safety (only the matching CSS animation is anchored withstartTime = 0at mount/recreation, with no retained animation refs, timers, or cleanup); visual cadence parity (measured 30°/12Hz, identical to the clock). Cross-platform: the change is renderer-only CSS/Chromium behavior, identical on macOS, Linux, and Windows; no shortcuts, labels, paths, or shell behavior touched; SSH and folder-workspace surfaces render the same component. The old clock's occluded-window concern is moot: Chromium stops producing frames for occluded windows, so the CSS animation costs nothing when hidden, and unlike the JS clock it needs no stale-visibility recovery wiring to survive macOS occlusion-tracker glitches.Security Audit
No input handling, command execution, path handling, auth, secrets, or IPC changes. Net code deletion (a timer module and its DOM writes); one per-creation Web Animations
startTimeassignment; it does not mutate DOM attributes or install a timer. Test file readsmain.cssfrom the repo only.Notes
applyAgentStatus→setAgentStatus→renderRootSync, 200–488ms tasks under heavy orchestration) is intentionally out of scope here and needs its own ticket.