Skip to content

perf(ui): keep chat, sidebar, and composer responsive while subagents run - #1853

Merged
bvsr365 merged 1 commit into
masterfrom
perf-subagent-ui-lag
Nov 25, 2026
Merged

bvsr365 merged 1 commit into
masterfrom
perf-subagent-ui-lag

Conversation

@bvsr365

@bvsr365 bvsr365 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Problem

When several subagents or background threads run at once, typing in the composer, moving the caret, and scrolling the conversation become sluggish—even inside an idle thread.

The window was receiving every background thread's and subagent's live message stream over Electron IPC only to discard it, re-rendering the open chat and sidebar on unrelated subagent churn, and re-rendering the composer and writing the full workspace to localStorage on every keystroke and caret move.

Change

  • Stop forwarding unselected background transcripts across Electron IPC (src/main/ipc/registerGuiIpc.ts, src/main/mms/protocolEventBridge.ts, src/main/notifications/threadNotificationTarget.ts): Main now drops thread.message, thread.message-updated, and non-replace thread.messages events for known non-side-chat threads that the window is not viewing. The selected thread, side chats, unlisted bot chats, and background undo replacements (replace: true) continue to forward as before.
  • Remove duplicate state broadcasts and unnecessary batcher flushes (src/main/ipc/registerGuiIpc.ts, src/renderer/App.tsx): window-event skips bridging events already broadcast by routeWindowState, avoiding duplicate orchestrator:turn-state and threads:activity IPC messages. The renderer flushes its per-frame transcript batcher only when the selected thread's own turn state changes, not on background subagent turn updates.
  • Stop re-rendering idle chats and the sidebar on background subagent activity (src/renderer/components/OrchestratorChat.tsx, src/renderer/hooks/useRunOnDevices.ts, src/renderer/components/SubagentParentBar.tsx, src/renderer/components/SubagentComposerBanner.tsx, src/renderer/components/ThreadRowStatus.tsx, src/renderer/components/ThreadsSidebar.tsx, src/renderer/stores/appStore.ts):
    • Replaced whole-list threads and subagentsByParent subscriptions in OrchestratorChat, useRunOnDevices, SubagentParentBar, and SubagentComposerBanner with narrow selectors for the viewed thread.
    • Skipped redundant store writes in setSubagents and setBackgroundWork when the payload matches held data.
    • Extended sameListedActivity to compare rolled-up visible-thread states (while still waking on any awaiting_input or pending-row change) so subagents flipping between processing, waiting, completed, and idle under an already-working parent do not re-render ThreadsSidebar.
  • Keep composer typing and caret movement off the transcript and storage hot paths (src/renderer/components/ChatComposer.tsx, src/renderer/chat/components/MousseAgentChatShell.tsx, src/renderer/chat/components/agent-elements/agent-chat.tsx, src/renderer/stores/appStore.ts):
    • Tracked the caret without updating React state unless entering, moving inside, or leaving an @mention query, and memoized the Markdown backdrop.
    • Memoized AgentChat and stabilized its onSend/onStop callbacks in MousseAgentChatShell so typing in the composer does not re-render AgentChat or MessageList.
    • Applied a 300 ms leading-and-trailing throttle to composerDrafts-only workspace persistence, flushing immediately on draft clear, other workspace edits, profile switches, beforeunload, pagehide, and visibilitychange.

Verification

Tier 4 (cross-area: main IPC + renderer store and UI).

  • Main IPC filtering and deduplication (tests/backgroundSubagentIpcFilter.test.ts): verified through registered registerGuiIpc handlers that unselected subagent and background thread streaming updates emit 0 renderer IPC messages, while selected threads, side chats, unlisted bot threads, and replace: true undo snapshots still forward, and turn.state emits orchestrator:turn-state once.
  • Renderer render counts and draft throttling (tests/renderer/subagentAndComposerPerformance.test.ts): mounted ThreadsSidebar and OrchestratorChat with countRender and verified 0 renders of ThreadsSidebar, OrchestratorChat, AgentChat, and MessageList during background subagent activity churn, unrelated touches, and other parents' Nest updates; verified sidebar still updates on awaiting_input and final completion; verified 0 ChatComposer renders when moving the caret across ordinary text while @mention still opens/closes; verified 0 AgentChat/MessageList renders during rapid typing with throttled localStorage writes and immediate flush on beforeunload/clear.
  • Focused suite (16 files, 197 tests passed):
    npx vitest run tests/backgroundSubagentIpcFilter.test.ts tests/renderer/subagentAndComposerPerformance.test.ts tests/renderer/nonTextPushRenders.test.ts tests/renderer/streamingRenderCounts.test.ts tests/renderer/composerDraftAfterQuit.test.ts tests/composerRenderingPerformance.test.ts tests/composerMentionList.test.ts tests/renderer/composerKeys.test.ts tests/renderer/subagentOptimisticWorking.test.ts tests/subagentThreadView.test.ts tests/subagentComposerBanner.test.ts tests/renderer/titleBarNav.test.ts tests/renderer/remoteComposerOptionsRetry.test.ts tests/guiWindowCatchUp.test.ts tests/guiWindowRealService.test.ts tests/guiIpcThreadRouting.test.ts
  • Web typecheck passed:
    tsc --noEmit -p tsconfig.web.json
  • Node typecheck (tsc --noEmit -p tsconfig.node.json): fails on Linux with the same 2 pre-existing Cannot find module 'koffi' errors in src/mms/git/windowsGitProcess.ts and src/mms/harness/windowsJobProcess.ts as origin/master; no errors in any changed file.
  • Not checked locally: interactive end-to-end Electron frame timing in a packaged build.

Notes

No issue

@bvsr365
bvsr365 merged commit 935771f into master Nov 25, 2026
9 checks passed
@bvsr365
bvsr365 deleted the perf-subagent-ui-lag branch November 25, 2026 10:05
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