Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export function ChatPaneInterface({
organizationId,
cwd,
isFocused,
isActive,
getOrCreateSession,
onResetSession,
onUserMessageSubmitted,
Expand Down Expand Up @@ -294,6 +295,7 @@ export function ChatPaneInterface({
sessionId,
workspaceId,
enabled: Boolean(sessionId),
isActive,
});
const {
commands,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export interface ChatPaneInterfaceProps {
organizationId: string | null;
cwd: string;
isFocused: boolean;
/**
* True while this chat pane is the focused/active tab. Gates background
* chat polling so idle/background panes stop refetching the full
* transcript on a timer (#6339).
*/
isActive?: boolean;
getOrCreateSession: () => Promise<string>;
onResetSession: () => Promise<void>;
onUserMessageSubmitted?: (message: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ interface UseChatDisplayOptions {
workspaceId: string;
enabled?: boolean;
fps?: number;
/**
* True while this chat pane is the focused/active tab. Idle panes in the
* background keep polling the full transcript on a timer even when nothing
* is running — that serialize/parse work scales with transcript length and
* adds up across several open panes (#6339). Gate background polling on
* this so hidden panes don't refetch until they become active again.
*/
isActive?: boolean;
}

// Retention window for an inactive session's cached snapshot (full message
Expand Down Expand Up @@ -117,16 +125,27 @@ function getLegacyImagePayload(
}

export function useChatDisplay(options: UseChatDisplayOptions) {
const { sessionId, workspaceId, enabled = true, fps = 4 } = options;
const {
sessionId,
workspaceId,
enabled = true,
fps = 4,
isActive = true,
} = options;
const [commandError, setCommandError] = useState<unknown>(null);
const queryInput =
sessionId === null ? undefined : { sessionId, workspaceId };
const isQueryEnabled = enabled && Boolean(sessionId);
const refetchIntervalMs = toRefetchIntervalMs(fps);
const queryOptions = {
enabled: isQueryEnabled && queryInput !== undefined,
refetchInterval: refetchIntervalMs,
refetchIntervalInBackground: true,
// Only poll while this pane is the active tab. Idle/background panes
// otherwise refetch the whole transcript on a timer forever, and that
// serialize/parse cost scales with conversation length — it adds up
// across several open panes and degrades responsiveness (#6339). The
// cached snapshot stays mounted, so returning to the pane resumes fresh.
refetchInterval: isActive ? refetchIntervalMs : false,
refetchIntervalInBackground: isActive,
refetchOnWindowFocus: false,
gcTime: CHAT_QUERY_GC_TIME_MS,
} as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ export function usePaneRegistry({
<ChatPane
workspaceId={workspaceId}
sessionId={data.sessionId}
isActive={ctx.isActive}
onSessionIdChange={(id) =>
ctx.actions.updateData({ ...data, sessionId: id })
}
Expand Down