Repository navigation
Cap clipboard text scanning so huge pastes can't freeze the picker - #6568
Conversation
There was a problem hiding this comment.
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.
| var text = String(entry.text || "") | ||
| if (text.length > searchTextLimit) text = text.slice(0, searchTextLimit) | ||
| return text + " " + fileEntryText(entry) |
25a65ed to
17087b5
Compare
There was a problem hiding this comment.
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)callsfilePaths, which splits the entire original text whenever its prefix contains a URI. A large file list is therefore fully scanned on every keystroke despitetextbeing 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 tosplitover 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 []
There was a problem hiding this comment.
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.shemits a freshcapturedAteach time the same image is copied; if that image is already first, this return preserves the stale timestamp instead of replacing the top entry asaddEntrypreviously 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, althoughdecodeFileUrionly accepts a URI on its own trimmed line. A huge one-line JSON or log containingfile:///...in its first 4 KiB will therefore still split and scan the entire paste, anddisplayRowsinvokes 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 []
There was a problem hiding this comment.
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, anddisplayRowsinvokes this path repeatedly throughfilePaths,fullText, andpreviewTexton 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
fileTextreturns above this line. A singlefile://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. ApplypreviewTextLimittofileTextbefore 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
capturedAtvalue (the capture script emits the current time for every event).addEntrypreviously 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
9e6c70f to
c5537f9
Compare
There was a problem hiding this comment.
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,
cutis-1(or0after leading whitespace) and the fallback slices through the first URI.decodeFileUrithen 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
pathsis 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 belowfullTextLimit. Preserve atruncatedflag (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]>
c5537f9 to
9b86790
Compare
There was a problem hiding this comment.
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 callstrim()on the original value. A paste with a huge leading or trailing whitespace run is therefore still scanned at full size on everyrebuildDisplay, 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,
cutis-1and this fallback still slices in the middle of the line. If that line starts withfile://,filePaths()then treats the truncated prefix as a valid path, so the row can expose a boguspath/previewImagedespite the stated safeguard. Mark a partial URI line as non-file (or otherwise reject it infilePaths) and cover a no-newline URI longer than the cap.
return { type: "text", text: entry.text.slice(0, cut > 0 ? cut : displayTextLimit) }
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]>
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.displayRowsnow 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 afile://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