Skip to content

Fix clipboard stale offer overwrite (C1) - #22

Merged
ElSargo merged 1 commit into
mainfrom
fix/clipboard-selection-generation
Sep 16, 2026
Merged

ElSargo merged 1 commit into
mainfrom
fix/clipboard-selection-generation

Conversation

@ElSargo

@ElSargo ElSargo commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Stamp Wayland clipboard offer reads with a selection generation (begin_offer_epoch / clear_clipboard_slot / set_clipboard_slot) so commits only apply when the epoch is still current.
  • spawn_offer_reader uses commit_clipboard_slot; a slow read of selection A can no longer overwrite selection B or an intervening ClipboardBridge::set_text.
  • Mark the clipboard race remitted in docs/frictions/ui-concurrency.md.
  • Add unit tests for stale vs current offer commits in clipboard.rs.

Test plan

  • RUSTFLAGS='-C linker=cc' cargo test -p brood-client --lib clipboard:: (4 passed)
  • Manual: rapidly change selections / copy while a large clipboard read is in flight; paste should reflect the newest value, never a superseded offer.

Residual risks

  • Superseded reader threads still finish pipe I/O; they only drop the result (no FD cancel). Harmless for correctness; minor wasted work under rapid selection churn.
  • Flush failure after begin_offer_epoch can leave an empty slot with no reader (pre-existing clear-before-receive behavior).

@ElSargo ElSargo left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brood QA — PR #22

Verdict: APPROVE (posted as comment — gh as ElSargo cannot formally APPROVE own PRs)

What this fixes

Audit C1 / ui-concurrency clipboard race: offer reader threads no longer unconditionally write latest_content. Reads are stamped with a selection generation (begin_offer_epoch → clear_clipboard_slot); commits go through commit_clipboard_slot and apply only while that epoch is still current. ClipboardBridge::set_text also bumps the generation so a slow prior offer cannot overwrite an explicit copy.

CI

Red job is infra ENOSPC (No space left on device while unpacking rust-std wasm target), not a compile/clippy/test failure on this diff. Not a merge blocker for correctness.

Verification

  • Reviewed clipboard.rs epoch helpers, ext_selection / wlr_selection, spawn_offer_reader, and bridge set_text/content.
  • Friction remittance in docs/frictions/ui-concurrency.md matches the code.
  • Local: RUSTFLAGS='-C linker=cc' cargo test -p brood-client --lib clipboard:: → 4 passed.

Residual (accepted)

  • Superseded readers still finish pipe I/O and drop the result (no FD cancel).
  • Flush/pipe failure after begin_offer_epoch can leave an empty slot with no reader (pre-existing clear-before-receive).
  • Optional manual churn test in the PR body remains unchecked; unit tests cover the epoch commit race.

No correctness blockers. Ship when convenient (re-run CI if you want a green check for process).

@ElSargo ElSargo left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brood QA review

Checked: diff/view; CI 35146185249; audit C1; friction doc update in-PR.

Code: Correct C1 fix. Selection generation via begin_offer_epoch / clear_clipboard_slot / set_clipboard_slot; commit_clipboard_slot drops stale offer commits; set_text bumps generation so in-flight readers cannot overwrite. Module unit tests cover stale vs current commits and superseded epochs. Residual (acknowledged): superseded readers still finish pipe I/O; flush failure after epoch bump can leave empty slot (pre-existing).

CI: FAILURE — runner ENOSPC during Nix build. Infra, not clipboard logic. Author: 4 clipboard:: tests passed locally.

Race-doc: Clipboard friction remitted accurately.

Desktop verify: Blocked (no nix / Wayland client build here). Manual rapid-selection paste still recommended once buildable.

Residual / merge: Doc conflicts with sibling remittance PRs. Re-run CI after disk relief before merge.

— Brood QA

Stamp each selection read with a generation and only commit when that
epoch is still current, so a slow offer A cannot replace selection B or
an intervening set_text. Mark the ui-concurrency friction remitted and
cover the race with module unit tests.
@ElSargo
ElSargo force-pushed the fix/clipboard-selection-generation branch from ec8276b to bdeffef Compare September 16, 2026 21:46
@ElSargo
ElSargo merged commit 403164b into main Sep 16, 2026
1 check failed
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