Repository navigation
Bound clipboard history bytes and keep large copies as files - #11920
Ahmed-Sinkeat wants to merge 11 commits into
Conversation
Clipboard history capped how many entries it kept but never how many bytes, and the shell held all of them: a copy was carried whole through the watcher line, re-serialised on every later capture, and read back whole at every start. omacom#6568 bounded search and display; this bounds the rest while keeping its promise that nothing is lost. - capture.sh streams text to a file first. Up to 2 MiB it is decoded as before; a larger copy is kept as clipboard-text/<sha256>.txt with an 8 KB preview in history, converted from UTF-16 as a stream when needed. A copy over 256 MiB is skipped, and the picker says so. - ClipboardHistory.js bounds inline entries (2 MiB), the whole history (8 MiB serialised, alongside the 500-entry limit) and large copies (1 GiB, oldest first), refuses an oversized watcher line before parsing it, and reports an unreadable history as unreadable instead of empty. - load-history.sh checks the history file before QML reads it. Symlinks, special files, files over 32 MiB and invalid JSON are renamed aside, never followed or overwritten. The 32 MiB ceiling covers the heaviest file the budget can produce, so the loader never rejects a history it wrote. - Clipboard.qml reads history only through that helper, starts the watchers once it has loaded, never saves before a successful load, and pastes a large copy with omarchy-clipboard-paste-file. - prune-text.sh deletes large copies history no longer uses. It never deletes a path read out of a file, and does nothing while a rejected history may still need them.
A clipboard owner controls the stream capture.sh reads. Images were written whole with cat before any size check, and no read had a deadline, so an arbitrarily large or never-ending stream could fill the disk or hold a watcher. - read_copy reads at most the limit plus one byte into the temporary file, under a 10 second deadline (SIGTERM, then SIGKILL), for images and text, watched and one-shot. A copy over its limit or cut off by the deadline is deleted and reported as skipped. - Images are capped at 64 MiB. - A trap removes the temporary files however the script ends, killed included. - The skipped note no longer names the text limit, since images and slow copies now reach it too.
Automated AI review
Verified: for new copies, the PR bounds clipboard data as described. Capture is limited in bytes and by the read deadline, copies over 2 MiB (up to 256 MiB) are stored as
Three issues remain at the edges the tests do not reach, mostly for histories that already exist. Existing histories: oversized entries are dropped, and pastes can use the wrong entry until the next save
In an isolated run with stub Two related upgrade cases:
Impact: on upgrade, users with large existing entries lose them, can paste or copy the wrong entry until the next save, and can see their whole history disappear without explanation. Suggested change: migrate at load by writing oversized inline entries out as Any rejected history permanently disables large-copy pruning
Impact: after any rejection, the 1 GiB large-copy budget no longer bounds disk use: Suggested change: limit the guard to the file names the rejected history actually references, or let the guard expire. Since rejected files can be oversized, invalid or empty, a format-independent scan such as The byte budget evicts all older entries at the first one that does not fit
Impact: a few ordinary copies just under the 2 MiB inline limit (a log, a JSON dump) permanently wipe the rest of the history, since the result is saved to disk. Copies over 2 MiB are not affected this way, because they go to files and add only a short preview to the budget. Suggested change: large copies already use Related open PRs
Smaller notes
Optional test improvement: in a mutation run, each of these changes still passed all 98 tests: removing the loader's size ceiling or accepting non-array JSON; removing Review informationTest scope: Source review of the head, base and current AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
…y-bounds # Conflicts: # test/shell.d/clipboard-test.sh
|
Deleting the entire history left the .migrated-* and .rejected-* recovery copies on disk, so cleared clipboard text survived the clear, and the large copies those backups referenced stayed protected from pruning. The save that commits the cleared history now removes them under the same lock. Also clear the save failure notice once a later save succeeds, and drop recovery notices when the history they refer to is cleared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@llstrk thanks for the thorough review. All three are addressed: 1. Existing histories (4452616). Loading now goes through 2. Pruning after a rejection (4452616, e9fc96a). The blanket guard is gone. 3. Budget eviction (4452616). On a merge with current |
The cleared history is already committed when backups are removed, so an unlink error made the save exit 3 and the picker claimed the previous history was kept. Warn about the backup instead and say so in the picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Heads-up: #14919 covers much of the same ground (bounded clipboard history, one locked storage helper, atomic writes). This branch has also conflicted with |
Summary
Clipboard history limits entry count but previously carried arbitrarily large copies through capture, the watcher, every save, and startup. This change bounds those paths while keeping large copies in files with small previews. Existing history is migrated before the picker reads it, and actions use the selected entry rather than a position in a potentially stale save.
clipboard-text/<sha256>.txtwith an 8 KiB preview and pasted from the full file.Bounds and recovery
Inline text is capped at 256 KiB, serialized history at an 8 MiB UTF-8 budget alongside 500 entries, retained large-copy content at 1 GiB, individual large copies at 256 MiB, and images at 64 MiB. Clipboard payload reads and MIME discovery have a 10-second deadline. The 32 MiB ceiling applies to the JSON returned to QML; legacy input is migrated as a stream under a 30-second deadline.
The lower inline threshold keeps even heavily JSON-escaped copies below the history budget. For existing history, the loader also converts an inline entry to a file if keeping it inline would exhaust that budget. Entries that exceed the per-copy, entry-count, or large-content limits remain in an exact recovery backup while usable entries load normally, with a visible recovery notice. I/O failures leave saved history intact and disable writes until it can load safely.
Symlinks, special files, malformed JSON, and non-array histories are renamed aside without following or opening non-regular inputs. Empty or whitespace-only histories are accepted as empty. Recovery originals remain on disk; their referenced files are protected independently of the active history's retention budget. Cleanup deletes only stale regular hash-named files in
clipboard-text, plus stale capture temporaries.Validation
clipboard-test.sh: 155 passing checks, including capture limits, timeouts, cleanup on termination, UTF-16 handling, re-copy timestamps, failed MIME lookup, sensitive-state exclusion, and stdin snapshot actions.clipboard-privacy-test.sh: 10 passing checks covering failed, partially failed, and timed-out MIME lookups for watched text, images, and one-shot capture, plus password hints without the sensitive-state flag. The watched-text failure reproduced before the fix; no rejected payload is persisted.clipboard-upgrade-test.sh: 56 passing checks covering large legacy text, streamed Unicode/control escapes, strict JSON rejection, recovery backups, retention, cleanup protection, selected-entry actions, and queued saves/reloads.clipboard-roundtrip-test.sh: 14 passing checks. Actual save/load round trips preserve retained CJK, emoji, and heavily escaped control text; migration preserves all 96 entries from a legacy CJK history written with the former UTF-16 budget.clipboard-storage-test.sh: 14 passing checks covering oversized-entry recovery, the exact per-copy boundary, concurrent migration/save locking, rejected saves, and atomic-commit failure cleanup.clipboard-lifecycle-test.sh: 3 passing offscreen Quickshell checks using temporary history and stub clipboard commands: copy while an editor remains open, queued saves through file notifications, and periodic cleanup after copying stops. The fixture uses a regular Qt window and does not exercise native Wayland layering.qmllintand shell syntax checks pass.quattroat8b4eae66, preserving Omasnap image opening and the mapped overlay window../test/clisuite fails atvscode generated theme references current theme file. The identical failure reproduces on untouchedquattroat8b4eae66.The full shell suite and VM graphical acceptance suite were not run.