Skip to content

Bound clipboard history and safely collect removed captures - #14919

Closed
thebytorsnowdog wants to merge 1 commit into
omacom:quattrofrom
thebytorsnowdog:codex/os-audit-clipboard
Closed

thebytorsnowdog wants to merge 1 commit into
omacom:quattrofrom
thebytorsnowdog:codex/os-audit-clipboard

Conversation

@thebytorsnowdog

Copy link
Copy Markdown
Contributor

Clipboard history currently allows large inputs to drive unbounded storage/parsing work, and removed image captures can remain on disk. Move persistence into one locked helper with bounded reads and writes, atomic publication and collection of unreferenced owned captures. QML requests storage operations asynchronously instead of parsing and rewriting the entire history for each event.

Enforce 1 MiB per text entry, 8 MiB serialized history, 16 MiB per image, 128 MiB retained images and 500 entries. Oversized captures are omitted with a notification; accepted content keeps all bytes, including trailing newlines. Oversized or unreadable legacy history remains intact until explicit Clear, which stays available when history cannot render.

Stable private entry IDs preserve selection across asynchronous updates. Clear invalidates captures already in flight, and image copying shares the collector lock so eviction cannot cause an older clipboard value to be pasted. Collection is confined to owned captures; new storage files are private. Existing sensitive-MIME exclusions remain, and failed MIME enumeration skips recording.

Validation: all 84 existing clipboard checks and 13 new storage groups pass. Coverage includes exact size boundaries, sparse oversized history under a memory limit, concurrent capture/clear, path confinement, complete-byte selection, private IDs, failed copies and legacy CLI readers. Qt 6 compiled the changed QML to bytecode; Python/Bash syntax and command metadata checks pass.

Release still needs live Quickshell acceptance for picker bindings, text/image copy, Clear, error presentation and responsiveness. No desktop latency improvement is claimed from fixture tests. History remains enabled by default; deletion does not erase independent snapshots or backups.

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Refactors clipboard history storage and adds size limits.

Preserve oversized legacy images before merging; loading the picker currently deletes them without Clear.

Findings

  1. P1 Legacy images disappear on load ▶
  2. P2 Interrupted writes block image retries ▶
  3. P2 Failed loads look empty ▶

Summary

This PR moves clipboard persistence into a shared locked helper and makes picker storage requests asynchronous.

  • Clipboard history now keeps saved entries within fixed size limits.
  • The clipboard picker loads and changes history through background storage requests.
  • Clipboard actions keep pointing to the chosen entry as history changes.

Live picker acceptance is explicitly deferred by thebytorsnowdog in the supplied PR description.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Clipboard[Clipboard change] --> Capture[Bounded capture]
  Capture --> Generation{Generation still matches?}
  Generation -->|Yes| Store[Locked storage helper]
  Generation -->|No| Drop[Discard capture]
  Picker[Clipboard picker] -->|Load, remove, clear| Store
  Store --> History[Atomic history write]
  History --> Collect[Collect unreferenced owned images]
  Store --> Reply[Bounded history reply]
  Reply --> Picker
  Picker -->|Selected ID| Copy[Read selected bytes under lock]
  Copy --> WlCopy[wl-copy]
Loading

Reviews (1) · Last reviewed commit: "Bound clipboard history and safely colle..." · Reviewed by Greptile

Comment on lines +174 to +175
if not stat.S_ISREG(info.st_mode) or info.st_size > IMAGE_BYTES:
return None

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.

P1 Legacy images disappear on load

A saved image over 16 MiB is deleted during load, without Clear. The old capture script allowed these images, and their history records can fit below 8 MiB. image_size returns None, bounded drops the entry, and transact rewrites history and deletes the saved copy.

Treat oversized legacy images as blocked history before writing or collecting, so users can preserve them before explicitly clearing.

Comment on lines +289 to +297
fd = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=self.images)
except FileExistsError:
info = os.stat(name, dir_fd=self.images, follow_symlinks=False)
if not stat.S_ISREG(info.st_mode) or info.st_uid != os.getuid() or info.st_size != len(data):
raise HistoryBlocked("The captured image could not be stored safely.")
else:
with os.fdopen(fd, "wb") as stream:
stream.write(data)

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.

P2 Interrupted writes block image retries

add_image writes directly to the final filename. If writing fails or the process stops midway, a partial file remains. Copying the same image again fails the existing-file size check before cleanup runs, so repeated copies are not recorded until another successful storage operation removes it.

Write to a private temporary file, rename it after the write succeeds, and clean up failed writes.

Comment on lines +108 to +110
} catch (error) {
console.warn("Clipboard history storage did not return a valid response")
}

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.

P2 Failed loads look empty

If the initial storage request times out or returns invalid JSON, acceptStorage only logs a warning. storageBlocked stays false and history stays empty, so the picker says the clipboard is empty and rejects Clear. Reopening does not retry the load.

Mark failed replies as blocked and provide a retry or reload when the picker opens.

@jandrusk

Copy link
Copy Markdown

Clipboard bounds + locked collect of removed captures is solid hardening (1 MiB text / 16 MiB image / 8 MiB history, flock, no symlink follow). Overlaps #14899 on Clipboard.qml (vim motions) — rebase whichever lands second. Also related: #11920, #10769.

@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at this far enough to classify it, and no further this time. I (Claude Opus 5.5) read it as a bug fix: on quattro, images captured into clipboard-images/ are never deleted when their entry is removed, cleared or evicted past 500, and a single copy has no size bound. A second model has to agree on that before it is labelled and tested, and that check (Codex Medium) did not run today because the machine's daily review limit was reached, so the classification is unsettled and this has no label yet. Nothing was run on a worker and the diff has not been reviewed line by line.

Two things that will matter whoever picks it up next: it no longer merges cleanly into quattro, with conflicts in shell/plugins/clipboard/Clipboard.qml and shell/plugins/clipboard/capture.sh, and #14899 also changes Clipboard.qml.

It goes round again in a later run, when both models can classify it; until then it waits on that, not on you.

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