Skip to content

fix(renderer): drive agent working spinner on the compositor (STA-3328) - #12359

Merged
brennanb2025 merged 3 commits into
mainfrom
brennan/sta-3328-user-says-typing-in-orca-in-mac-can-sometimes-be-laggy
Aug 4, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennan/sta-3328-user-says-typing-in-orca-in-mac-can-sometimes-be-laggy

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Typing lag on Mac (STA-3328) was root-caused live on a production instance to the shared agent-spinner JS clock: a 12Hz setInterval writing el.style.transform on 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-motion still freezes the ring and the existing filled-top-border static marker is unchanged. agent-spinner-clock.ts is deleted; the data-agent-spinner hook attribute stays.

Measured impact (live prod instance, user actually typing, A/B by stopping the clock's writes):

real-keystroke input delay JS clock (before) writes stopped (after-equivalent)
p50 7.3ms 3.3ms
p90 363ms 19ms
DOM attribute mutations 453/s 15/s (0 from spinners)
long-task total per 2min 10.8s 6.6s

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):

sta3328-dev-full.png

sta3328-dev-card.png

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 pass
  • pnpm test — targeted: AgentWorkingSpinner, AgentStateDot, StatusIndicator, TerminalTabLeadingIcon (20 tests pass); full suite left to CI
  • pnpm build — left to CI
  • Added AgentWorkingSpinner.test.tsx: pins the component→main.css wiring (class present in markup; .agent-working-spinner rule exists with steps(12, end) and a reduced-motion animation: none override) 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 — registerStaleDocumentVisibilityRecovery and window-visibility-interval have other consumers and are untouched); reduced-motion behavior (media query disables the animation; existing motion-reduce:border-t-yellow-500 fills the ring, matching the old frozen-state rendering, #9515); phase-sync lifecycle safety (only the matching CSS animation is anchored with startTime = 0 at 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 startTime assignment; it does not mutate DOM attributes or install a timer. Test file reads main.css from the repo only.

Notes

  • Root-cause evidence and measurement methodology (CDP rig, DOM-mutation census, content traces) are recorded in the Linear ticket thread; the second lag mechanism (synchronous per-status render bursts: applyAgentStatus → setAgentStatus → renderRootSync, 200–488ms tasks under heavy orchestration) is intentionally out of scope here and needs its own ticket.
  • The deleted clock's design goal (don't keep the frame pipeline awake per element) was measured against compositor CPU; this PR optimizes for input latency instead, which the compositor path cannot affect by construction.

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.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The working-agent spinner now uses the agent-working-spinner CSS class with a 12-step, one-second rotation animation. AgentWorkingSpinner synchronizes its animation phase from document.timeline when available. Reduced-motion styling disables the animation. Component and status tests now verify the class, animation declaration, spinner data, and reduced-motion behavior. The shared timer-based spinner clock and its tests were removed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: moving the agent working spinner to compositor-driven rendering.
Description check ✅ Passed The description covers all required sections with implementation details, screenshots, testing status, AI review, security audit, and scope notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 25213ec and fc79c4c.

📒 Files selected for processing (7)
  • src/renderer/src/assets/main.css
  • src/renderer/src/components/AgentStateDot.test.ts
  • src/renderer/src/components/AgentWorkingSpinner.test.tsx
  • src/renderer/src/components/AgentWorkingSpinner.tsx
  • src/renderer/src/components/sidebar/StatusIndicator.test.ts
  • src/renderer/src/lib/agent-spinner-clock.test.ts
  • src/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

Comment on lines +4 to +6
// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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-L19
  • src/renderer/src/components/AgentWorkingSpinner.tsx#L26-L28
  • src/renderer/src/components/AgentWorkingSpinner.test.tsx#L19-L21
  • src/renderer/src/components/AgentStateDot.test.ts#L25-L26
  • src/renderer/src/components/sidebar/StatusIndicator.test.ts#L25-L26

Source: Coding guidelines

@brennanb2025

brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Post-review Electron validation

Validated pushed head f6d5cabae5 in an isolated Orca dev instance attached to this exact worktree. I selected the workspace through the rendered UI, seeded 40 working child-agent rows through the renderer store to reproduce the production-scale workload, and exercised trusted keyboard input through the real terminal surface.

  • 43 real AgentWorkingSpinner components: every animation had startTime = 0
  • 11 distinct 30° steps sampled over 1.26s; 0/14 phase-mismatch samples
  • 0 spinner attribute mutations, 0 long tasks, 0 animation-start callbacks after settled mount
  • Terminal keydown delay: p50 0.4ms, p90 0.6ms, max 1.3ms (32 samples)
  • Reduced motion: 0 active animations and the filled static ring; restoring motion recreated 43 animations exactly once, all re-anchored to startTime = 0, with 0 DOM mutations
  • Focused component and formerly CI-failing suites: 35/35 pass; renderer/web TypeScript, focused oxlint, and diff check pass
  • Final inherited-model subagent review: CLEAN

Final-head rendered workspace state (getAnimations available; all 3 visible surfaces anchored at startTime = 0):

sta3328-review-final-head.png

43-spinner agent/subagent scale state:

sta3328-review-43-spinners.png

@brennanb2025
brennanb2025 merged commit 0ea3c9c into main Aug 4, 2026
42 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant