Skip to content

[Bug]: Terminal freezes for seconds when pasting long text on Windows #5365

Closed

Description

@slashdevcorpse

Description

Pasting a large block of text (e.g., a 50KB code snippet or log) into a terminal pane makes the entire Orca app freeze for multiple seconds — completely unresponsive. This happens on the latest release (v1.4.68), on Windows.

Steps to Reproduce

  1. Open any terminal pane in Orca (PowerShell, WSL, whatever)
  2. Copy a large text block — 50KB+ of code or log output works reliably
  3. Paste via Ctrl+V
  4. Observe the app freeze — UI is completely blocked, nothing responds
  5. After a few seconds, the paste completes and the app recovers

Root Cause

The freeze is caused by xterm.js parsing the entire pasted string synchronously on the renderer thread with no yielding or chunking.

The call chain:

  1. TerminalPane.tsx captures the paste keydown → pasteTerminalClipboard() → await readClipboardText() (async IPC, fine)
  2. terminal-bracketed-paste.ts → pasteTerminalText() calls terminal.paste(text) synchronously with the entire text
  3. xterm.js's paste() method walks every single byte through its VT escape sequence parser on the main renderer thread — 50,000+ synchronous iterations for a 50KB paste
  4. During this, the browser's event loop is completely blocked: no frames render, no user input is processed

Key files:

File Role
src/renderer/src/components/terminal-pane/terminal-bracketed-paste.ts pasteTerminalText() and forceBracketedPaste() — the synchronous terminal.paste(text) call
src/renderer/src/components/terminal-pane/terminal-clipboard-paste.ts pasteTerminalClipboard() — dispatches to pasteTerminalText

Why the output scheduler doesn't help:

pane-terminal-output-scheduler.ts has sophisticated batching/coalescing (50ms background delay, 16ms drain interval) for PTY output, but paste input bypasses all of it entirely — it goes straight to terminal.paste().

Proposed Fix

Add chunked paste with microtask yielding in terminal-bracketed-paste.ts's pasteTerminalText():

  1. If text exceeds a threshold (~512 chars), split into chunks
  2. For each chunk, call terminal.paste(chunk)
  3. Between chunks, await new Promise(r => setTimeout(r, 0)) to yield the renderer thread
  4. Each chunk should complete in < 16ms to stay under frame budget

For the Windows multiline forceBracketedPaste path (which uses terminal.input() with BRACKETED_PASTE_START/END wrappers), emit the start sequence, loop chunks with yields, then emit the end sequence.

This keeps xterm's bracketed paste semantics intact (the PTY still receives the text as a single paste event) while preventing the multi-second renderer block.

Pseudocode:

const PASTE_CHUNK_SIZE = 512

async function chunkedPaste(terminal: PasteTerminal, text: string, write: (chunk: string) => void): Promise<void> {
  for (let i = 0; i < text.length; i += PASTE_CHUNK_SIZE) {
    write(text.slice(i, i + PASTE_CHUNK_SIZE))
    await new Promise(r => setTimeout(r, 0))
  }
}

Activity

  1. added
    bugSomething isn't working
    size/mMedium PR (≤600 added lines, ≤25 files)
    on Jun 25, 2026
  2. brennanb2025 commented on Jul 4, 2026

    @brennanb2025
    Contributor

    Verified this is already handled on current main, so closing as resolved.

    Mechanism. Large-paste handling is owned by the paste coordinator (planTerminalPasteWithYield → executeTerminalPastePlan). Any payload over TERMINAL_PASTE_DIRECT_MAX_BYTES (64 KB) is sent to the PTY as event-loop-yielding, backpressure-aware chunks inside a single bracketed frame — it never does a synchronous terminal.paste() of the whole payload, so it can't block the renderer main thread. Payloads ≤64 KB stay a single fast terminal.paste().

    Coverage. I checked every way text can enter a terminal as a paste, and they all funnel through the coordinator: keyboard (Ctrl/Cmd+V, Shift+Insert), the native paste event, app-menu paste, context-menu paste, middle-click / X11 primary-selection, programmatic paste, startup-command paste, Electron Edit›Paste, web/mobile remote clients, and SSH/remote terminals (runtime kind only lengthens the write timeout). The only two writes that bypass the coordinator can't cause this freeze: drag-and-drop pastes file paths (bounded), not file contents; and the main-process startup-draft seed is a PTY write, not a renderer terminal.paste().

    Regression coverage. The behavior is locked by src/renderer/src/components/terminal-pane/terminal-paste-coordinator.test.ts — it asserts a large paste is chunked, streamed as multiple bounded PTY writes with a yield between each, wrapped in exactly one bracketed frame.

    Thanks @riverpilot — #5648 tackled the same freeze from the renderer side; it's redundant only because main's coordinator already owns this path end to end.

    Caveat: this is verified via the paste code paths + unit tests. The freeze mechanism (blocking the main thread on a large synchronous write) is platform-independent, but since this was reported on Windows/ConPTY specifically, if a multi-MB paste still freezes on a current build, please reopen with the payload size and which paste action you used and we'll dig into the ConPTY write path.

  3. added theissue type on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsize/mMedium PR (≤600 added lines, ≤25 files)

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions