Repository navigation
fix(desktop): stop chat panes polling the transcript while inactive - #6349
andyst-dev wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThe chat pane registry now passes pane activity state to the workspace chat display. Active panes continue polling chat snapshots. Inactive panes retain cached data without interval or background polling. ChangesChat pane polling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized change stops inactive chat panes from polling while preserving polling for active panes and existing call sites; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
No issues found across 5 files
Architecture diagram
sequenceDiagram
participant PaneRegistry as usePaneRegistry
participant ChatPane as ChatPane
participant ChatPaneInterface as ChatPaneInterface
participant useChatDisplay as useChatDisplay (useWorkspaceChatDisplay)
participant RQ as React Query Cache
participant Backend as Backend API (getSnapshot)
Note over PaneRegistry,Backend: Chat Pane Polling Flow
PaneRegistry->>ChatPane: Render ChatPane with ctx.isActive
ChatPane->>ChatPaneInterface: Pass isActive (default true)
ChatPaneInterface->>useChatDisplay: Call hook with sessionId, enabled, isActive
useChatDisplay->>useChatDisplay: Build queryOptions
alt isActive is true (active tab)
useChatDisplay->>useChatDisplay: refetchInterval = refetchIntervalMs (250ms)
useChatDisplay->>useChatDisplay: refetchIntervalInBackground = true
useChatDisplay->>RQ: query chat.getSnapshot (enabled)
loop Every 250ms while active
RQ->>Backend: Fetch full transcript snapshot
Backend-->>RQ: Transcript data
RQ-->>useChatDisplay: Update cached snapshot
end
else isActive is false (background tab)
Note over useChatDisplay: NEW: Polling disabled for inactive panes
useChatDisplay->>useChatDisplay: refetchInterval = false
useChatDisplay->>useChatDisplay: refetchIntervalInBackground = false
useChatDisplay->>RQ: Initial query only (no interval)
RQ-->>useChatDisplay: Cached snapshot stays mounted
Note over useChatDisplay: No background refetching - reduces renderer load
end
Note over PaneRegistry,useChatDisplay: When pane becomes active again, polling resumes
PaneRegistry->>useChatDisplay: isActive flips to true (via prop re-render)
useChatDisplay->>RQ: Resume interval polling (250ms)
RQ->>Backend: Fresh snapshot fetch
Backend-->>RQ: Latest transcript
RQ-->>useChatDisplay: Updated data
Every v2 chat pane polls chat.getSnapshot on a timer (4fps / 250ms) with refetchIntervalInBackground: true, gated only on sessionId existing — not on pane visibility. An idle/background chat pane therefore refetches the whole conversation 4x/sec forever, and the serialize/parse cost scales with transcript length. With several projects each holding a chat pane open, that additive work on the single renderer thread degrades responsiveness (ParadevAI#6339). Gate the polling on the pane being the active tab: propagate ctx.isActive from the pane registry through ChatPane and ChatPaneInterface into useChatDisplay, which now sets refetchInterval to false (and disables background polling) while the pane is not active. The cached snapshot stays mounted, so returning to the pane resumes fresh. Defaults to true when the prop is omitted, so other call sites keep polling as before. Fixes ParadevAI#6339
2acc5de to
b92deff
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Closing as obsolete: the legacy mastra chat this PR modified was deleted on main in |
Fixes #6339
Problem
Superset becomes unresponsive with more than ~3 projects open, each with several tabs/panes. The triage bot's highest-suspicion path (and "smallest change with largest expected win") is chat snapshot polling.
Root cause
Every v2 chat pane polls
chat.getSnapshoton a timer —fps: 4→refetchInterval: 250ms, withrefetchIntervalInBackground: true— and the query is gated only onsessionIdexisting, not on pane visibility orisRunning. An idle/background chat pane therefore refetches the entire transcript 4×/sec forever. The cost per tick is O(transcript length) in host-service serialize + renderer parse/compare, so it grows as conversations grow, and all panes share the single renderer thread. Several open panes → additive load that turns the app sluggish.Fix
Gate the polling on the pane being the active tab, mirroring how
TerminalPanealready gates its queries withctx.isActive:usePaneRegistry.tsx— passctx.isActiveinto<ChatPane>.ChatPane.tsx/ChatPaneInterface.tsx/types.ts— thread the newisActiveprop through touseChatDisplay.useChatDisplay.ts—refetchIntervalis nowisActive ? refetchIntervalMs : false(andrefetchIntervalInBackground: isActive). While the pane is not the active tab it stops polling entirely; the cached snapshot stays mounted, so returning to the pane resumes fresh.isActivedefaults totruewhen omitted, so any other call site keeps polling as before.Tests
No unit test harness exists for the tRPC-coupled
useChatDisplayhook in this repo (the polling options are built inside a React hook). Verified by:tsc --noEmiton apps/desktop — 0 errors;Note
This is the first and cheapest of the triage bot's fix directions for #6339. The other two (xterm WebGL→DOM latch; GitWatcher per-worktree registration) are larger, separate changes and are intentionally out of scope here.
Summary by cubic
Stops chat panes from polling the transcript while their tab is inactive, reducing renderer load and UI lag with many open tabs. Previously every v2 chat pane polled 4×/sec regardless of visibility; now polling runs only when the pane is active and resumes on focus, with cached data preserved.
useWorkspaceChatDisplayusingisActive(refetchInterval: false,refetchIntervalInBackground: falsewhen inactive).ctx.isActivefromusePaneRegistryintoChatPane→ChatPaneInterface→ hook.isActivedefaults totruefor other call sites; no migration required.Written for commit b92deff. Summary will update on new commits.
Summary by CodeRabbit