Repository navigation
perf(agent-status): coalesce live status bursts into one render pass (STA-3328) - #12377
Conversation
…(STA-3328) Each live agent-status event arrives as its own IPC task, so a multi-agent burst paid one full React render pass per event (200-488ms main-thread tasks under heavy orchestration). Same-task store commits batch to a single render pass, so buffer a burst for one 33ms window and apply it in one task. The leading event still applies synchronously (zero added latency for single events), only an applied event arms the window (dropped/pending events stay immediate), and both clear paths purge queued sets so a coalesced event cannot resurrect a removed status.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdded a 33 ms burst buffer for live agent-status IPC events. The first eligible event applies immediately, and later events flush together in arrival order. Status-clear handling removes matching queued events. Effect cleanup cancels the timer and clears the queue. Tests cover immediate application, ordered batching, and prevention of status restoration after pane clearing. 🚥 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.
🧹 Nitpick comments (1)
src/renderer/src/hooks/useIpcEvents.test.ts (1)
6239-6321: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a teardown test for the burst timer and queue.
This test covers clear-vs-queued behavior well. No test in this change covers effect cleanup for the new burst state: that unmounting the hook while a flush is scheduled cancels
liveAgentStatusBurstTimerand clearsliveAgentStatusBurstQueue, so a pending burst does not apply a status after teardown. Add a test that queues a follower event, unmounts (or calls the effect's cleanup), advances the fake timer past the burst window, and assertssetAgentStatusdoes not fire again.Do you want me to draft this test?
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 26325905-055f-4e51-aa92-16746e58b523
📒 Files selected for processing (2)
src/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.ts
Electron QA — agent-status burst + terminal typingValidated the intended dev instance for Visible state matched the backing Zustand state: the worktree and terminal showed Working during status burst, with terminal input responsiveCompletion applied in FIFO orderNot exercised live: hidden-window timer clamping and an SSH/relay connection; those paths were reviewed and covered by the focused suite, but this Electron run used a local workspace. |
…(STA-3328) (stablyai#12377) * perf(agent-status): coalesce live status bursts into one render pass (STA-3328) Each live agent-status event arrives as its own IPC task, so a multi-agent burst paid one full React render pass per event (200-488ms main-thread tasks under heavy orchestration). Same-task store commits batch to a single render pass, so buffer a burst for one 33ms window and apply it in one task. The leading event still applies synchronously (zero added latency for single events), only an applied event arms the window (dropped/pending events stay immediate), and both clear paths purge queued sets so a coalesced event cannot resurrect a removed status. * fix(agent-status): preserve queued completion on teardown


Summary
Third installment of the STA-3328 typing-lag work (after #12359 spinner, #12371 tab-group amplifiers). This addresses the burst source: every live agent-status event arrives as its own IPC task, and each one committed the store and paid a full React render pass — profiled live as 200–488ms main-thread tasks (
Receive mojo message → applyAgentStatus → setAgentStatus → renderRootSync) under heavy orchestration, exactly matching Neil's "happens when using orchestration heavily" report.The design-defining fact (verified empirically with a real-store/real-React probe before writing any code): N zustand commits in the same macrotask produce exactly 1 React render pass — React 19 flushes external-store sync work at the microtask boundary. So no
setAgentStatusrefactor is needed; the fix is dispatch-level inuseIpcEvents:workingflushing 33ms after aclearwould resurrect a removed status (pinned by a dedicated test).Worst-case added status-visibility latency is 33ms — under half the spinner's own 83ms tick.
Screenshots
No visual change.
Testing
pnpm lint— oxlint, react-doctor changed-lines gate, oxfmt clean (pre-commit hook re-verified all three)pnpm typecheck— all three configs pass, 0 errorspnpm test— fulluseIpcEvents.test.tssuite: 98/98 pass (96 existing + 2 new); full suite left to CIpnpm build— left to CIAI Review Report
Reviewed for: ordering preservation (FIFO queue; leading precedes queued; per-event guards like the
receivedAtout-of-order rejection see the store state left by the previous event, identical to today's sequential arrival); clear-vs-set races (both the transient watermark path and the direct paneKey clear purge the burst queue using the same raw-paneKey/connectionId comparisons as the existing pending-retry purges); re-entrancy (queue is spliced before applying, mirroring the crash-9fc89529 guard pattern; the existingisFlushingAgentStatusesguard is untouched); timer lifecycle (cleared on effect teardown alongside the retry timer; queue emptied); occluded-window behavior (Chromium clamps the 33ms timer to 1s when hidden — status still applies, and a hidden window renders nothing anyway). Cross-platform: renderer-only dispatch change; the SSH/WSL connection-watermark semantics are exercised by the existing suite (98/98). The startup snapshot replay loop was already a single task (batches naturally) and is untouched.Security Audit
No input handling, command execution, path handling, auth, secrets, or IPC surface changes. Same events, same validation pipeline, same store actions — only dispatch timing is batched, with a bounded in-memory queue (drained every 33ms, purged on clears and teardown).
Notes
setTabLayoutstructural bailout, audit medium tier.