diff --git a/apps/desktop/src/main/terminal-host/pty-subprocess.ts b/apps/desktop/src/main/terminal-host/pty-subprocess.ts index a7fa12020ed..5778288dc84 100644 --- a/apps/desktop/src/main/terminal-host/pty-subprocess.ts +++ b/apps/desktop/src/main/terminal-host/pty-subprocess.ts @@ -57,6 +57,7 @@ const INPUT_QUEUE_HARD_LIMIT_BYTES = 64 * 1024 * 1024; // 64MB let outputChunks: string[] = []; let outputBytesQueued = 0; let outputFlushScheduled = false; +const OUTPUT_FLUSH_INTERVAL_MS = 16; // Match terminal-style frame batching (~60fps) const MAX_OUTPUT_BATCH_SIZE_BYTES = 128 * 1024; // 128KB max per flush // Backpressure - track if stdout is draining @@ -103,9 +104,9 @@ function queueOutput(data: string): void { if (!outputFlushScheduled) { outputFlushScheduled = true; - // Flush on the next event-loop turn so interactive echo feels immediate, - // while still coalescing bursts that arrive in the same PTY callback cycle. - setImmediate(flushOutput); + // Timed batching keeps TUI redraws coherent and avoids flooding the renderer + // with tiny per-turn frames while still staying under a single display frame. + setTimeout(flushOutput, OUTPUT_FLUSH_INTERVAL_MS); } } diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx index 91fef49597e..20435edf0dd 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx @@ -57,11 +57,12 @@ export const Terminal = ({ paneId, tabId, workspaceId }: TerminalProps) => { { enabled: isWorkspaceRunPane }, ); + const workspaceRunRestartCommand = isWorkspaceRunPane + ? buildTerminalCommand(workspaceRunConfig?.commands) + : null; const defaultRestartCommandRef = useRef(undefined); defaultRestartCommandRef.current = - (isWorkspaceRunPane - ? (buildTerminalCommand(workspaceRunConfig?.commands) ?? undefined) - : undefined) ?? pane?.workspaceRun?.command; + workspaceRunRestartCommand ?? pane?.workspaceRun?.command; const utils = electronTrpc.useUtils(); const updateWorkspace = electronTrpc.workspaces.update.useMutation({