Skip to content

Cap clipboard text scanning so huge pastes can't freeze the picker - #6568

Merged
dhh merged 1 commit into
omacom:quattrofrom
markbus-ai:fix-clipboard-search-freeze
Aug 9, 2026
Merged

dhh merged 1 commit into
omacom:quattrofrom
markbus-ai:fix-clipboard-search-freeze

Conversation

@markbus-ai

@markbus-ai markbus-ai commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

The clipboard picker freezes the whole desktop when searching if the history contains a large paste. Every keystroke scanned, lowercased, and split the full text of every entry — a single 1.6MB entry means hundreds of megabytes of work on the shell thread per character — and the preview pane then laid out the entire selection with WrapAnywhere, stalling the render thread.

displayRows now caps each entry to an 8KB prefix as it enters the display, so searching, previewing, and rendering all work on bounded text and the functions downstream stay untouched. The cut lands on a line break, so a file:// URI never truncates into a bogus path. Pasting still reads the full entry from history by index (--history-index), so nothing is lost.

— 🤖 Claude, posting on behalf of @dhh

Copilot AI balanced review requested due to automatic review settings August 6, 2026 04:48

Copilot AI 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.

Pull request overview

Caps clipboard search and preview processing to reduce shell freezes from large history entries while preserving full pastes by index.

Changes:

  • Limits searchable and rendered text prefixes.
  • Adds a file-list fast path and regression coverage.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
shell/plugins/clipboard/ClipboardHistory.js Adds clipboard text processing limits.
test/shell.d/clipboard-test.sh Tests limits and large-history behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings August 6, 2026 04:54

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +104 to +106
var text = String(entry.text || "")
if (text.length > searchTextLimit) text = text.slice(0, searchTextLimit)
return text + " " + fileEntryText(entry)
Copilot AI review requested due to automatic review settings August 6, 2026 05:04
@markbus-ai
markbus-ai force-pushed the fix-clipboard-search-freeze branch from 25a65ed to 17087b5 Compare August 6, 2026 05:04

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

shell/plugins/clipboard/ClipboardHistory.js:106

  • The filter scan is still unbounded for file-list entries: fileEntryText(entry) calls filePaths, which splits the entire original text whenever its prefix contains a URI. A large file list is therefore fully scanned on every keystroke despite text being truncated above. Build the metadata from the already-capped text so filtering remains bounded.
  return text + " " + fileEntryText(entry)

shell/plugins/clipboard/ClipboardHistory.js:127

  • Checking for file:// anywhere in the prefix lets an ordinary large log/document containing an early file URI fall through to split over the entire paste. Since actual file-list payloads begin with a URI, gate on the first non-whitespace content instead; otherwise the freeze this fast path targets remains reproducible.
  if (text.length > fileScanLimit && text.slice(0, fileScanLimit).indexOf("file://") < 0) return []

Copilot AI review requested due to automatic review settings August 6, 2026 05:23

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

shell/plugins/clipboard/Clipboard.qml:85

  • This also suppresses updates to image metadata. Image keys contain only the content-hash path, while capture.sh emits a fresh capturedAt each time the same image is copied; if that image is already first, this return preserves the stale timestamp instead of replacing the top entry as addEntry previously did. Restrict the large-entry shortcut to text entries.
    if (root.entryKey(normalized) === root.entryKey(root.history[0])) return

shell/plugins/clipboard/ClipboardHistory.js:136

  • This precheck treats an inline file:// occurrence as proof that the entry is a file list, although decodeFileUri only accepts a URI on its own trimmed line. A huge one-line JSON or log containing file:///... in its first 4 KiB will therefore still split and scan the entire paste, and displayRows invokes this path repeatedly per row on every keystroke. Match only a line-leading URI in the bounded prefix before allowing the full parse.
  if (text.length > fileScanLimit && text.slice(0, fileScanLimit + 7).indexOf("file://") < 0) return []

Copilot AI review requested due to automatic review settings August 6, 2026 05:28

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (3)

shell/plugins/clipboard/ClipboardHistory.js:144

  • This split remains unbounded whenever the prefix starts with file://. A large URI list—or any huge text beginning with a file URI—therefore allocates and scans the entire entry, and displayRows invokes this path repeatedly through filePaths, fullText, and previewText on each rebuild. That leaves a class of huge pastes capable of stalling the shell. Bound the parsing used to build display rows (and reuse its result) rather than only short-circuiting non-URI prefixes.
  var lines = text.split(/\r?\n/)

shell/plugins/clipboard/ClipboardHistory.js:183

  • The new preview cap is bypassed for file entries because fileText returns above this line. A single file:// URI with a very long filename can still place the whole filename in the row model and trigger the same expensive text layout this change is intended to prevent. Apply previewTextLimit to fileText before returning it as well.
  if (text.length > previewTextLimit) text = cappedText(text, previewTextLimit) + "…"

shell/plugins/clipboard/Clipboard.qml:85

  • This shortcut also applies to images, but image entries with the same content-derived path can carry a newer capturedAt value (the capture script emits the current time for every event). addEntry previously replaced the top entry with that fresh metadata; this return now silently keeps the stale timestamp. Restrict the optimization to text entries, which are the large-paste case targeted here.
    if (root.entryKey(normalized) === root.entryKey(root.history[0])) return

Copilot AI review requested due to automatic review settings August 6, 2026 05:57
@markbus-ai
markbus-ai force-pushed the fix-clipboard-search-freeze branch from 9e6c70f to c5537f9 Compare August 6, 2026 05:57

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

shell/plugins/clipboard/ClipboardHistory.js:144

  • When no newline exists within the cap, cut is -1 (or 0 after leading whitespace) and the fallback slices through the first URI. decodeFileUri then accepts that incomplete line as a real path, contradicting the partial-line guarantee and potentially showing a bogus file. Return no paths when there is no complete newline-terminated URI within the capped prefix.
    var cut = text.lastIndexOf("\n", fileScanLimit)
    text = cut > 0 ? text.slice(0, cut) : text.slice(0, fileScanLimit)

shell/plugins/clipboard/ClipboardHistory.js:145

  • Capping the list here loses the fact that paths is only a prefix. Downstream, a 5,000-file selection is therefore labeled as (roughly) 120 files, and its detail pane shows only those paths without an ellipsis because the decoded prefix is below fullTextLimit. Preserve a truncated flag (or equivalent source-length state) so both the count and full-text preview clearly indicate partial results.

This issue also appears on line 143 of the same file.

  if (text.length > fileScanLimit) {
    var prefix = text.slice(0, fileScanLimit).replace(/^\s+/, "")
    if (prefix.indexOf("file://") !== 0) return []
    var cut = text.lastIndexOf("\n", fileScanLimit)
    text = cut > 0 ? text.slice(0, cut) : text.slice(0, fileScanLimit)
  }

Every keystroke in the search box scanned, lowercased, and split the
full text of every history entry, and the preview pane laid out the
entire selection with WrapAnywhere. A single 1.6MB paste (or a large
file selection) turned that into hundreds of megabytes of work on the
shell thread and stalled the render thread — freezing the whole
desktop.

Cap each entry once as it enters the display, so searching, previewing,
and rendering all work on a bounded prefix. Pasting reads the full entry
back from history by index, so nothing is actually lost. The cut lands
on a line break, keeping a file:// URI from truncating into a bogus path.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 9, 2026 11:51
@dhh
dhh force-pushed the fix-clipboard-search-freeze branch from c5537f9 to 9b86790 Compare August 9, 2026 11:51

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

shell/plugins/clipboard/ClipboardHistory.js:185

  • The cap is applied only after normalizeEntry, whose text branch calls trim() on the original value. A paste with a huge leading or trailing whitespace run is therefore still scanned at full size on every rebuildDisplay, leaving the picker’s hot path unbounded and able to reproduce the freeze. Extract and cap raw text before normalizing it.
    var entry = cappedEntry(normalizeEntry(values[i]))

shell/plugins/clipboard/ClipboardHistory.js:171

  • When no newline occurs within the first 8,192 characters, cut is -1 and this fallback still slices in the middle of the line. If that line starts with file://, filePaths() then treats the truncated prefix as a valid path, so the row can expose a bogus path/previewImage despite the stated safeguard. Mark a partial URI line as non-file (or otherwise reject it in filePaths) and cover a no-newline URI longer than the cap.
  return { type: "text", text: entry.text.slice(0, cut > 0 ? cut : displayTextLimit) }

@dhh
dhh merged commit c4dda58 into omacom:quattro Aug 9, 2026
nick1udwig pushed a commit to nick1udwig/omarchy that referenced this pull request Sep 9, 2026
Every keystroke in the search box scanned, lowercased, and split the
full text of every history entry, and the preview pane laid out the
entire selection with WrapAnywhere. A single 1.6MB paste (or a large
file selection) turned that into hundreds of megabytes of work on the
shell thread and stalled the render thread — freezing the whole
desktop.

Cap each entry once as it enters the display, so searching, previewing,
and rendering all work on a bounded prefix. Pasting reads the full entry
back from history by index, so nothing is actually lost. The cut lands
on a line break, keeping a file:// URI from truncating into a bogus path.

Co-authored-by: markbusking <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

3 participants