fix(desktop): stop chat panes polling the transcript while inactive
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.getSnapshot on a timer — fps: 4 → refetchInterval: 250ms, with refetchIntervalInBackground: true — and the query is gated only on sessionId existing, not on pane visibility or isRunning. 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 TerminalPane already gates its queries with ctx.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.
isActive defaults to true when omitted, so any other call site keeps polling as before.
Tests
No unit test harness exists for the tRPC-coupled useChatDisplay hook in this repo (the polling options are built inside a React hook). Verified by:
tsc --noEmiton apps/desktop — 0 errors;- biome check — clean.
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.
- Gates chat snapshot polling in
useWorkspaceChatDisplayusingisActive(refetchInterval: false,refetchIntervalInBackground: falsewhen inactive). - Propagates
ctx.isActivefromusePaneRegistryintoChatPane→ChatPaneInterface→ hook. isActivedefaults totruefor other call sites; no migration required.
Summary by CodeRabbit
- Performance Improvements
- Chat panes now refresh conversation updates only when active.
- Inactive panes retain cached content without background polling, reducing unnecessary activity.
- Switching to a chat pane resumes updates automatically.