Skip to content

fix: keep wayland clipboard copies responsive - #3015

Merged
ogulcancelik merged 2 commits into
masterfrom
akbash/3014-wayland-clipboard-freeze
Aug 24, 2026
Merged

fix: keep wayland clipboard copies responsive#3015
ogulcancelik merged 2 commits into
masterfrom
akbash/3014-wayland-clipboard-freeze

Conversation

@akbash-bot

Copy link
Copy Markdown
Collaborator

Issue

On Wayland, double-clicking a token can freeze Herdr while wl-copy keeps serving the clipboard selection. Existing and newly attached clients then stop responding.

Problem

Herdr waited for wl-copy to exit after sending the copied text. A clipboard owner can stay alive until another application replaces the selection, so that wait blocked Herdr's control path.

How did we fix it?

Herdr now returns after handing the text to wl-copy and reaps the clipboard owner on a dedicated thread when it eventually exits. Other Linux clipboard helpers still wait for and report their exit status as before.

Verification

The regression test blocked before the fix while a fake wl-copy remained alive. It now verifies immediate return, exact arguments and text, and eventual child reaping. Focused tests, formatting, and clippy pass. The full suite passed 3,487 of 3,488 tests; live_server_holds_one_pty_master_fd_per_pane still fails because its replacement server does not appear, and the same failure reproduces with this change removed.

refs #3014

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 101d8eec-f36c-4fe3-961e-ead17cc29cd7

📥 Commits

Reviewing files that changed from the base of the PR and between 96d0530 and 334b965.

📒 Files selected for processing (2)
  • docs/next/CHANGELOG.md
  • src/platform/linux.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/next/CHANGELOG.md

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Wayland clipboard writes now wait for startup, then return after wl-copy becomes a persistent owner. Background reaping handles long-lived processes. Tests cover cleanup, fallback, payloads, arguments, and finite command statuses. The changelog records the fix.

Changes

Wayland clipboard handling

Layer / File(s) Summary
Nonblocking clipboard process lifecycle
src/platform/linux.rs
wl-copy uses startup polling and detaches persistent owners to a named reaper thread. Cleanup remains synchronous when polling or reaper setup fails. Failed Wayland writes allow X11 fallback.
Clipboard behavior validation and changelog
src/platform/linux.rs, docs/next/CHANGELOG.md
Tests verify persistent-owner cleanup, fallback behavior, payload and argument preservation, and finite-command exit statuses. The changelog adds the unreleased Wayland clipboard fix.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Merge Risk: ⚪ Minimal · up to 334b9

The change prevents Wayland clipboard operations from blocking the application while preserving clipboard delivery and child-process cleanup. No actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant run_clipboard_command
  participant wl-copy
  participant clipboard_reaper_thread
  run_clipboard_command->>wl-copy: Start process and send clipboard data
  wl-copy-->>run_clipboard_command: Become persistent clipboard owner
  run_clipboard_command-->>run_clipboard_command: Return success without waiting
  clipboard_reaper_thread->>wl-copy: Wait for process exit
  clipboard_reaper_thread->>clipboard_reaper_thread: Reap owner and handle exit status
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 1 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: keeping Wayland clipboard copies responsive. It is concise and specific.
Description check ✅ Passed The description explains the Wayland clipboard freeze, the asynchronous process reaping fix, verification results, and the related issue.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 1 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch akbash/3014-wayland-clipboard-freeze

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 20, 2026
@mmazur

mmazur commented Aug 24, 2026

Copy link
Copy Markdown

Yup, wl-copy instances need to be able to run in the background (and lifecycled) indefinitely without interfering with the main process. That's just wayland.

@ogulcancelik

Copy link
Copy Markdown
Collaborator

@akbash-bot the implementation review is clean. please rebase onto current master, resolve the changelog conflict, and rerun checks and both review bots.

@akbash-bot

Copy link
Copy Markdown
Collaborator Author

Rebased onto 7d56b4c5 and resolved the changelog conflict. The focused clipboard tests pass. A clean-environment just check passed 3,518 of 3,519 tests; the sole live-handoff failure reproduces unchanged on current master.

I cannot update this PR head because akbash-bot currently has push: false on herdrdev/herdr, and the canonical push returns 403. The rebased commit is available as 404a3f67 on akbash-bot/herdr:akbash/3014-wayland-clipboard-freeze. Please restore canonical write access or update the PR branch to that commit. I can then rerun CI, CodeRabbit, and Greptile on the new head.

@ogulcancelik
ogulcancelik force-pushed the akbash/3014-wayland-clipboard-freeze branch from 96d0530 to 334b965 Compare August 24, 2026 23:51
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown

Greptile Summary

This PR prevents Wayland clipboard writes from blocking Herdr on a long-lived wl-copy owner.

  • Polls briefly for immediate wl-copy startup failures so existing fallback behavior remains available.
  • Reaps a successfully started clipboard owner on a dedicated background thread.
  • Adds regression coverage for responsiveness, child reaping, fallback behavior, arguments, and payload delivery.
  • Documents the fix in the upcoming changelog.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue identified.

The changed Wayland path returns after transferring the long-lived child to a reaper while still detecting immediate startup failures, and the focused tests cover responsiveness, fallback, payload integrity, arguments, and eventual reaping.

Important Files Changed

Filename Overview
src/platform/linux.rs Adds bounded startup polling and asynchronous child reaping for wl-copy, preserving synchronous status handling for finite clipboard helpers and adding focused lifecycle tests.
docs/next/CHANGELOG.md Adds an accurate release-note entry for the Wayland clipboard responsiveness fix.

Sequence Diagram

sequenceDiagram
    participant H as Herdr
    participant W as wl-copy
    participant R as Reaper thread
    participant C as Wayland compositor
    H->>W: Start with piped clipboard text
    H->>W: Poll exit status for up to 100 ms
    alt Immediate exit
        W-->>H: Success or failure status
    else Still running
        H->>R: Transfer child handle
        H-->>H: Resume control path
        W->>C: Serve clipboard selection
        C-->>W: Selection replaced
        W-->>R: Exit
        R->>R: Reap child
    end
Loading

Reviews (1): Last reviewed commit: "fix: preserve clipboard fallback after w..." | Re-trigger Greptile

@ogulcancelik
ogulcancelik merged commit 6e8b138 into master Aug 24, 2026
7 checks passed
@kangal-bot kangal-bot removed the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 25, 2026
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.

4 participants