fix(desktop): resolve O(n²) render cascade in activity sidebar#555
Merged
Conversation
The activity sidebar became unresponsive after 1-2 minutes when an agent was actively streaming events. Every new WebSocket event triggered a full transcript rebuild over all events and re-rendered every markdown block. Four-layer fix: - Store-level incremental transcript computation via processTranscriptEvent, with full-rebuild fallback for out-of-order arrivals and 800-event cap trim - useSyncExternalStore with snapshot caching for referential stability - Component cleanup: removed redundant buildTranscript useMemo and reverse-scan - React.memo on transcript items with spread-copy pattern (no in-place mutation) Correctness safeguards: out-of-order events trigger full rebuild, transcript stays in sync with event cap, cross-channel IDs include channelId prefix, latestSessionId remains channel-scoped. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
useSyncExternalStorewith snapshot caching, component cleanup, andReact.memoon transcript itemsApproach
Layer 1 — Store-level incremental transcript (
observerRelayStore.ts)Transcript is now computed incrementally per event (O(1)) instead of O(n) full rebuild per render. Falls back to full rebuild for out-of-order arrivals and when the 800-event cap trims.
Layer 2 —
useSyncExternalStorehooks (useObserverEvents.ts)Replaced
useState/useEffectsubscription pattern. Snapshot caching gives referential stability — React only re-renders when the snapshot reference actually changes.Layer 3 — Component cleanup (
ManagedAgentSessionPanel.tsx)Removed
buildTranscriptuseMemo and the[...events].reverse().find()scan. LightweightchannelIdfilter on pre-computed transcript.Layer 4 —
React.memoon transcript items (AgentSessionTranscriptList.tsx)Spread-copy pattern ensures unchanged items keep their object reference, so memo skips re-render. Only items with new content get new refs.
Correctness safeguards
latestSessionIdpropagates even when no transcript items changechannelIdprefix to prevent collisionslatestSessionIdderived from channel-scoped events (not global)Notable NITs (not addressed — cosmetic)
React.memoshallow comparison onTranscriptItemViewis intentional: memo saves renders for unchanged items, which is the winTest plan
pnpm buildpasses indesktop/🤖 Generated with Claude Code