Skip to content

Stop GTK file copies from looping, and store received bundles by content - #16

Open
jondkinney wants to merge 2 commits into
standardagents:mainfrom
jondkinney:fix/file-clip-echo-loop
Open

jondkinney wants to merge 2 commits into
standardagents:mainfrom
jondkinney:fix/file-clip-echo-loop

Conversation

@jondkinney

Copy link
Copy Markdown

Problem

Copying a GIF from a GTK 4 app on Linux (a GIF picker that uses Gdk.FileList) put the daemon into a loop: it re-broadcast the unchanged clipboard as a new clip about 13 times a second. The paired Mac extracted every one to ~/.local/state/ssh-clipboard/files/<clip id>/, and over a few weeks that reached 189,000 copies of the same GIF (263 GB) and filled the disk.

Cause

GTK 4 file copies also offer the XDG document portal's application/vnd.portal.filetransfer and application/vnd.portal.files. Every read of those registers a fresh transfer key:

$ wl-paste -t application/vnd.portal.filetransfer | sha256sum   # a5ff04010555…
$ wl-paste -t application/vnd.portal.filetransfer | sha256sum   # ba21656c2746…
$ wl-paste -t text/uri-list | sha256sum                         # e5791ff7018b… (both reads)

Capture includes every offered format in the snapshot fingerprint, so the fingerprint changed on every poll and previous.fingerprint == snapshot.fingerprint never matched.

Fix

  1. Skip the portal formats at capture (is_host_local_format). The keys can only be redeemed on the copying machine, and the file already travels as text/uri-list plus the bundle.
  2. Store received bundles by content. files/<sha256 of bundle> replaces files/<clip id>, the same approach as the Linux image cache (Clipboard-<sha256>.<ext>). Repeats of the same files reuse one copy, so a future echo loop costs one directory, not the disk. Reusing an existing copy now checks it against the bundle and rebuilds it if a pasted file was edited or deleted in place. Previously that returned the stale copy or failed with existing copied-file bundle is incomplete.

filebundle::materialize no longer takes a clip id. The daemon and tests/headless_x11.rs are updated.

Testing

  • Reproduced on Hyprland with the real GTK 4 helper and GIF. ssh-clipboard monitor --json showed 80 local clips in 6 s on v0.2.18 and exactly 1 with this branch, which still carries text/uri-list, the file bundle, and image/gif.
  • cargo test --lib --bins: 92 pass. New tests: portal_transfer_keys_are_not_captured, identical_bundles_share_one_directory, reuses_an_intact_copy_and_rebuilds_a_changed_one.
  • cargo clippy --all-targets is clean and all integration tests compile. I couldn't run headless_x11 or container_service locally (no Xvfb).

🤖 Generated with Claude Code

https://claude.ai/code/session_01YWDws5xQ8VkLWBi9SLC7ih

jondkinney and others added 2 commits November 23, 2026 10:55
GTK 4 file copies (Gdk.FileList) also offer the XDG document portal's
application/vnd.portal.filetransfer and application/vnd.portal.files
formats. Each read of those registers a fresh transfer key, so the
captured snapshot's fingerprint changed on every poll and an unchanged
file clipboard was broadcast as a new clip roughly 13 times a second.

Every peer then materialized each clip again. Copying one GIF from a
GTK 4 GIF picker on Linux left the clipboard in that state and wrote
189,000 copies of it to a paired Mac's state directory (263 GB) before
the disk filled.

The keys are only redeemable on the copying machine, and the file
already travels as text/uri-list plus the bundle, so skip both formats
at capture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YWDws5xQ8VkLWBi9SLC7ih
Each received file clip was extracted to files/<clip id>, so the same
files copied again added another full copy every time, and nothing ever
removes them. Name the directory after the bundle's SHA-256 instead,
like the Linux image cache, so repeats reuse one copy. Any future echo
loop then costs one directory instead of filling the disk.

Reuse now checks the existing copy against the bundle and rebuilds it
if a pasted file was edited or deleted in place, where it previously
returned the stale copy or failed with "existing copied-file bundle is
incomplete".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YWDws5xQ8VkLWBi9SLC7ih
@jondkinney
jondkinney force-pushed the fix/file-clip-echo-loop branch from 27ffb8d to f4d3377 Compare November 23, 2026 16:55
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.

1 participant