Skip to content

fix(desktop): stop chat panes polling the transcript while inactive - #6349

Closed
andyst-dev wants to merge 1 commit into
ParadevAI:mainfrom
andyst-dev:fix/chat-pane-background-polling
Closed

andyst-dev wants to merge 1 commit into
ParadevAI:mainfrom
andyst-dev:fix/chat-pane-background-polling

Conversation

@andyst-dev

@andyst-dev andyst-dev commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

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 — pass ctx.isActive into <ChatPane>.
  • ChatPane.tsx / ChatPaneInterface.tsx / types.ts — thread the new isActive prop through to useChatDisplay.
  • useChatDisplay.ts — refetchInterval is now isActive ? refetchIntervalMs : false (and refetchIntervalInBackground: 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 --noEmit on 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 useWorkspaceChatDisplay using isActive (refetchInterval: false, refetchIntervalInBackground: false when inactive).
  • Propagates ctx.isActive from usePaneRegistry into ChatPane → ChatPaneInterface → hook.
  • isActive defaults to true for other call sites; no migration required.

Written for commit b92deff. Summary will update on new commits.

Review in cubic

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.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 570263b7-0bd5-42ee-9490-0ef33b6f434b

📥 Commits

Reviewing files that changed from the base of the PR and between 65f0344 and b92deff.

📒 Files selected for processing (4)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/WorkspaceChatInterface/ChatPaneInterface.tsx
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/WorkspaceChatInterface/types.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/hooks/useWorkspaceChatDisplay/useWorkspaceChatDisplay.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/usePaneRegistry.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/usePaneRegistry.tsx
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/WorkspaceChatInterface/types.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/WorkspaceChatInterface/ChatPaneInterface.tsx
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/hooks/useWorkspaceChatDisplay/useWorkspaceChatDisplay.ts

📝 Walkthrough

Walkthrough

The 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.

Changes

Chat pane polling

Layer / File(s) Summary
Propagate pane activity state
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/WorkspaceChatInterface/types.ts, apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/WorkspaceChatInterface/ChatPaneInterface.tsx, apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/usePaneRegistry.tsx
ChatPaneInterfaceProps accepts isActive. The pane registry passes the value to ChatPane, which forwards it to useChatDisplay.
Gate inactive-pane polling
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/hooks/useWorkspaceChatDisplay/useWorkspaceChatDisplay.ts
useChatDisplay defaults isActive to true. Inactive panes disable interval refetching and background polling while retaining cached snapshots.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b92de

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)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #6339 by reducing background chat polling that can contribute to unresponsiveness with multiple projects and panes.
Out of Scope Changes check ✅ Passed All changes support the stated polling optimization, and the description explicitly excludes unrelated triage directions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The description clearly explains the problem, root cause, fix, scope, linked issue, and validation steps.
Title check ✅ Passed The title uses conventional commit format and clearly describes the main fix for inactive chat pane polling.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Re-trigger cubic

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
@andyst-dev
andyst-dev force-pushed the fix/chat-pane-background-polling branch from 2acc5de to b92deff Compare August 14, 2026 13:52
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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.

@andyst-dev

Copy link
Copy Markdown
Contributor Author

Closing as obsolete: the legacy mastra chat this PR modified was deleted on main in delete legacy mastra chat in favor of chat-v3 (#6461). The ChatPane/WorkspaceChatInterface/useWorkspaceChatDisplay hierarchy no longer exists; the v2 workspace now ships ChatV3Pane. There is no surviving code to rebase onto — the polling-while-inactive fix would need to be re-derived against chat-v3 from scratch, so closing rather than leaving a green-but-dead branch. No action needed.

@andyst-dev andyst-dev closed this Aug 22, 2026
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.

Superset isn't responsive when there are more than 3 projects running with multiple tabs

1 participant