Skip to content

Fix terminal clipboard getting stuck on Wayland - #25789

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/bug-clipboard-gets-stuck-on-wayland-sway-wlroots
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/bug-clipboard-gets-stuck-on-wayland-sway-wlroots

Conversation

@nwparker

@nwparker nwparker commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​466 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​449
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​988 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​972

ELI5

On Sway and similar Wayland desktops, copying text from a terminal could leave Orca pasting an old value forever. Terminal copies now use a small bundled clipboard owner, and Orca discards the stale value it had kept internally. Users do not need to install wl-copy.

What Changed

The terminal clipboard IPC uses Wayland's data-control protocol, which does not need the last keyboard or mouse event to accept a copy. The helper acknowledges the new owner before Orca clears Electron's old clipboard source/cache. The helper reports success only after its detached owner starts. It serves later pastes, survives Orca exit, and exits when replaced or disconnected. Requests and queued text are bounded; a paste expires only after two seconds without progress.

Desktops exposing neither supported data-control protocol retain the existing Electron backend. X11, macOS and Windows retain their existing verified writes. Linux packages build and validate a bundled x64 or arm64 helper against Ubuntu 20.04. Cached builds recover their executable mode, and packaging checks the actual copied helper before the existing binary compatibility gate.

Why

Electron can silently retain a rejected clipboard source: even its write-then-read verification returns the value that the compositor rejected. Skipping duplicate text only prevents one trigger; copying different text still reproduces the freeze. Publishing through data-control removes the stale input serial from terminal copies, and clearing Electron's old source also repairs an already-stuck session. Bundling the helper avoids an optional system-package dependency.

Upstream research found the same ownership defect in Electron #54645, currently open. Electron's clipboard redesign still uses Chromium's existing native writer. On isolated Sway, both Electron 44.5.1 / Chromium 152 and 45.0.0-alpha.15 / Chromium 156 reproduce the rejection and stale cache, despite awaiting the new Promise API. Renderer clipboard APIs also reproduce it. Clearing the cache alone repairs pastes but loses the attempted copy, so an upgrade or cache-only change does not replace the publisher.

Linked Issue

Fixes #23229

Visual Proof

These are CDP screenshots of an isolated Electron reproduction on headless Sway, exercising Orca's production OSC 52 parser and main clipboard writer through preload IPC. They are not screenshots of the full Orca UI.

Before: after an external app replaces B with C, an actual Ctrl+V still pastes B.

Before: Ctrl+V pastes the stale value B

After: terminal copies succeed, and a later external remote-external copy pastes correctly.

After: Ctrl+V pastes the latest external value

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Linux runtime verification used an SSH-accessed Ubuntu 24.04 x64 host, isolated Sway 1.9 / wlroots 0.17.1, and the checkout's Electron 43.7.5. Verified duplicate/different OSC 52 copies, later external copies with actual Ctrl+V, recovery of an already-stuck cache, byte-exact Unicode/CRLF text after Electron exit, and owner cleanup on replacement. All launches/tests used ORCA_BACKGROUND_LAUNCH=1 and native input stayed on the isolated display.

310 tests across 17 focused clipboard, OSC 52, shortcut, rejection, startup, process, packaging and compatibility suites passed. All 12 native fake-compositor tests passed, covering both protocols, repeated pastes, unsupported/missing displays, input limits, incoming offers, owner cancellation and bounded stalled receivers. x64 and cross-built arm64 helpers passed ELF architecture and glibc-floor checks. pnpm tc:node and pnpm run check:code-quality:changed passed.

Full Orca UI/Claude sessions, GNOME/KDE runtime, arm64 runtime and complete release installers have not been exercised. The resource-copy test covers the helper's packaged path and executable mode. The full lint/typecheck/test/build suite remains for CI.

Review

Four review passes checked payload limits, request ordering, owner startup/cancellation, capability loss, slow paste readers, cached executable mode, packaged resource presence and cross-platform/SSH boundaries. Six failure cases were reproduced with regression tests and fixed. The final pass has no unresolved findings; the runtime/platform coverage limits above still apply.

Agent skill upstream boundary

  • Not applicable: no agent skill implementation changes.

Notes

Clipboard ownership remains on the desktop client, including folder workspaces and terminal output from SSH hosts. No remote wire or execution-host requirements change. Ordinary/image clipboard and primary-selection writes are outside this change. Docker is a build prerequisite, not a user runtime dependency.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker
nwparker marked this pull request as ready for review October 6, 2026 05:22
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The change adds a native Wayland clipboard helper that supports two data-control protocols, plus Linux build and packaging steps for x64 and arm64. Terminal clipboard writes use the helper in detected Wayland sessions and retain the verified clipboard path for other sessions and specified unsupported-protocol cases. The change also centralizes Linux Wayland-session detection for startup GPU configuration and adds build, protocol, packaging, and clipboard-writer tests.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 6485e

Terminal copies on Wayland may be cleared immediately after a successful write. Resolve the post-write clear before merging unless that behavior is explicitly accepted.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 6485e

The new clipboard path limits input and concurrent work, preserves existing caller checks, and does not turn copied text into commands. No introduced security vulnerability was established. Remaining uncertainty concerns clipboard behavior across desktop implementations and the interaction between native ownership and Electron’s cache clearing.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The evidenced exposure is the selected Wayland seat’s desktop clipboard and its retained copied payload, not a new cross-tenant service or privileged system configuration. Clipboard recipients can obtain the copied text through the compositor; the detached owner extends retention beyond application exit by design.

Trust Boundaries and Controls

  • observed — Caller-controlled text reaches native execution as stdin, not as a command or executable path. The writer selects a fixed packaged or development helper, and the shared spawn resolution uses shell:false. Existing IPC checks restrict access to the trusted renderer or exact live dashboard WebContents.
  • observed — The dashboard installs the existing privileged navigation policy before use. New windows are denied, and renderer navigation outside the same file document or HTTP(S) origin is prevented. These controls and the dashboard sender exception predate the changed backend.

Resilience and Maintainability Implications

  • observed — Failure containment includes a 32-request writer limit, bounded aggregate queued text, a 16 MiB native input cap, eight concurrent paste transfers, and a two-second inactivity deadline refreshed by progress. Excess or failed transfer descriptors are closed, and owner termination closes remaining process resources.

Hardening Proposals

  • proposed — Validate the handoff using the shipped Electron version and a real supported compositor: begin with a stale Electron source, publish through the helper, clear Electron’s cache, and paste from another client. Include timeout-boundary and application-exit cases to establish actual retention and replacement behavior beyond mocked cache clearing.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 55 functions across 18 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #23229 requires reliable terminal OSC 52 copies on Sway/wlroots, including copies with different text and remote terminal output, without blocking the main process. The new terminal writer publi…
Out of Scope Changes check ✅ Passed The helper build and packaging changes, protocol tests, Wayland session detection, and documentation support the #23229 terminal clipboard fix. The startup change reuses the shared Wayland-session det…
Title check ✅ Passed The title clearly summarizes the main change: fixing terminal clipboard behavior on Wayland.
Description check ✅ Passed The description covers the required ELI5, changes, rationale, linked issue, visual proof, testing, review, upstream-boundary, notes, and checklist sections. It also reports uncompleted full-suite chec…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 55 functions across 18 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8cea5365-19c1-4a64-b53d-ebbbdbb98111
📥 Commits

Reviewing files that changed from the base of the PR and between 6c693ed and 6485eb1.

📒 Files selected for processing (22)
  • config/electron-builder.config.cjs
  • config/scripts/build-native-for-platform.mjs
  • config/scripts/build-native-for-platform.test.mjs
  • config/scripts/build-wayland-clipboard.mjs
  • config/scripts/build-wayland-clipboard.test.mjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/electron-builder-runtime-resources.test.mjs
  • config/wayland-clipboard-resources.cjs
  • docs/reference/linux-glibc-compatibility.md
  • native/wayland-clipboard/.dockerignore
  • native/wayland-clipboard/Dockerfile
  • native/wayland-clipboard/README.md
  • native/wayland-clipboard/protocol_test.py
  • native/wayland-clipboard/wayland-clipboard.c
  • src/main/startup/configure-process.ts
  • src/main/window/clipboard-dashboard-popout-access.test.ts
  • src/main/window/clipboard-ipc-handlers.test.ts
  • src/main/window/clipboard-ipc-handlers.ts
  • src/main/window/clipboard-terminal-text-write.test.ts
  • src/main/window/clipboard-terminal-text-write.ts
  • src/shared/linux-wayland-session.test.ts
  • src/shared/linux-wayland-session.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +67 to +72
if (result.code !== 0 || result.timedOut) {
throw new Error(WAYLAND_CLIPBOARD_WRITE_FAILED_ERROR)
}
dataControlAccepted = true
// Discard any rejected Chromium source after the helper has established the actual owner.
deps.clearCache()

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🌐 Web query:

Chromium 150 wayland_clipboard.cc Write nullptr SetSelectionSource clear source clipboard Electron 43

💡 Result:

If you’re asking whether `Write(nullptr)` clears the Wayland clipboard in Electron 43: **the Chromium implementation says yes, with an important caveat.**

In the Chromium `wayland_clipboard.cc` source, `Write()` treats a null or empty data map as a clear: it clears the cached offered data and resets its local data-source pointer. A failed data-source finish also calls `Write(nullptr)`. ([chromium.googlesource.com](https://chromium.googlesource.com/chromium/src/%2B/278e3bab7718860ba4df7274877acc4eb0636266/ui/ozone/platform/wayland/host/wayland_clipboard.cc))

However, that code path does **not** call `SetSelectionSource(nullptr)`. The shown `WaylandDataDevice::SetSelectionSource()` requires a non-null source (`DCHECK(source)`) and passes its Wayland object to `wl_data_device_set_selection()`. So these sources establish local source cleanup, but **do not establish that `Write(nullptr)` explicitly tells the compositor to clear the selection**. ([chromium.googlesource.com](https://chromium.googlesource.com/chromium/src/%2B/93a6ebbe22f1a093e6a0cb5e72ba78990fe39824/ui/ozone/platform/wayland/host/wayland_data_device.cc))

Electron 43.0.0 bundles Chromium 150.0.7871.46, but the Chromium source snapshot found here is a different, unidentified revision—not confirmed as that exact bundled version. ([releases.electronjs.org](https://releases.electronjs.org/release/v43.0.0?utm_source=openai))

Citations:

- 1: https://chromium.googlesource.com/chromium/src/%2B/278e3bab7718860ba4df7274877acc4eb0636266/ui/ozone/platform/wayland/host/wayland_clipboard.cc
- 2: https://chromium.googlesource.com/chromium/src/%2B/93a6ebbe22f1a093e6a0cb5e72ba78990fe39824/ui/ozone/platform/wayland/host/wayland_data_device.cc
- 3: https://releases.electronjs.org/release/v43.0.0?utm_source=openai

🏁 Script executed:

find node_modules -path '*/ui/ozone/platform/wayland/host/wayland_clipboard.cc' -o -name electron_api_clipboard.cc 2>/dev/null | head -12

Repository: stablyai/orca

Length of output: 151


🏁 Script executed:

printf '%s\n' '--- relevant writer and bindings ---'
nl -ba src/main/window/clipboard-terminal-text-write.ts | sed -n '1,135p'
rg -n -F -- 'clearCache: () => clipboard.clear()' src
rg -n -F -- 'writeTerminalClipboardText' src/main/window
printf '%s\n' '--- Electron version pins ---'
rg -n '"electron"|electron@|43\.7\.5|43\.7' package.json package-lock.json npm-shrinkwrap.json pnpm-lock.yaml yarn.lock 2>/dev/null || true
printf '%s\n' '--- Wayland helper selection ownership ---'
nl -ba native/wayland-clipboard/wayland-clipboard.c | sed -n '285,350p'
printf '%s\n' '--- clipboard API references in repository ---'
rg -n -F -- 'clipboard.clear()' src docs README.md native 2>/dev/null || true

Repository: stablyai/orca

Length of output: 8508


🌐 Web query:

Electron 43.7.5 Chromium version DEPS commit Chromium 150 Wayland clipboard Write nullptr SetSelectionSource

💡 Result:

Electron **v43.7.5** uses **Chromium 150.0.7871.250**. Its `DEPS` pins Chromium source to the same version string; the release page lists the Chromium version, and the tag’s `DEPS` confirms the pin. ([releases.electronjs.org](https://releases.electronjs.org/release/v43.7.5))

If you’re asking whether that Chromium revision fixes Wayland clipboard writes involving `SetSelectionSource(nullptr)`: **I couldn’t establish that from the available sources.** The Chromium 150 code/test result I found concerns **ChromeOS Exo’s `Seat::SetSelection(nullptr)`**, and checks that clearing the selection does not overwrite the regular clipboard. That is not evidence of a fix in Ozone’s Wayland clipboard path. ([sources.debian.org](https://sources.debian.org/src/chromium/150.0.7871.100-1~deb13u1/components/exo/seat_unittest.cc?utm_source=openai))

The closest Wayland source I found shows `WaylandDataDevice::SetSelectionSource` asserting that `source` is non-null, so that particular implementation does not support passing `nullptr`. However, it is not verified as the exact Chromium revision bundled by Electron 43.7.5. ([chromium.googlesource.com](https://chromium.googlesource.com/chromium/src/%2B/93a6ebbe22f1a093e6a0cb5e72ba78990fe39824/ui/ozone/platform/wayland/host/wayland_data_device.cc?utm_source=openai))

Citations:

- 1: https://releases.electronjs.org/release/v43.7.5
- 2: https://sources.debian.org/src/chromium/150.0.7871.100-1~deb13u1/components/exo/seat_unittest.cc?utm_source=openai
- 3: https://chromium.googlesource.com/chromium/src/%2B/93a6ebbe22f1a093e6a0cb5e72ba78990fe39824/ui/ozone/platform/wayland/host/wayland_data_device.cc?utm_source=openai

🌐 Web query:

Electron v43.7.5 GitHub DEPS chromium_revision Wayland wayland_clipboard.cc Write nullptr clipboard.clear docs version 43

💡 Result:

For **Electron v43.7.5**:

- **Chromium revision:** `DEPS` pins Chromium **150.0.7871.250**; it specifies that version as the Chromium checkout. ([github.com](https://github.com/electron/electron/blob/v43.7.5/DEPS))
- **Clipboard docs:** `clipboard.clear([type])` clears clipboard content. On Linux, the optional `type` can be `selection` or `clipboard`; `selection` is Linux-only. ([github.com](https://github.com/electron/electron/blob/v43.7.5/docs/api/clipboard.md))
- **Wayland `nullptr` detail:** I couldn’t verify the exact `wayland_clipboard.cc` code against the Chromium revision pinned by v43.7.5, so I can’t establish what the `nullptr` check means in that exact version. The Chromium source surfaced in search is a separate revision and should not be treated as v43.7.5’s source. ([chromium.googlesource.com](https://chromium.googlesource.com/chromium/src/%2B/278e3bab7718860ba4df7274877acc4eb0636266/ui/ozone/platform/wayland/host/wayland_clipboard.cc?utm_source=openai))

Citations:

- 1: https://github.com/electron/electron/blob/v43.7.5/DEPS
- 2: https://github.com/electron/electron/blob/v43.7.5/docs/api/clipboard.md
- 3: https://chromium.googlesource.com/chromium/src/%2B/278e3bab7718860ba4df7274877acc4eb0636266/ui/ozone/platform/wayland/host/wayland_clipboard.cc?utm_source=openai

Do not use clipboard.clear() for cache-only cleanup.

When the helper succeeds and owns the Wayland clipboard selection, clipboard.clear() can clear the text the helper just published. Electron 43.7.5 documents this API as clearing clipboard content, not only Chromium’s cached source. A later paste can therefore lose the copied text.

@kambarakun

Copy link
Copy Markdown
Contributor

GNOMEでの追加検証結果を#26917にまとめました: #26917 (comment)

このPRのhead 6485eb19297158e610d0271995c8e6c2a0d449b4 をFedora 44 arm64 / GNOME Shell・Mutter 50.5 / Electron 43.7.5の隔離したnative Wayland環境で実行しました。実際のterminal OSC 52 → 外部GTK4アプリのコピー → Ctrl+Vを測定すると、terminalとmain-process clipboard.readText()は古いB、同時点のwl-pasteは新しいCでした。同一内容・異なる内容のOSC 52の両方で再現しています。

このMutterでは ext_data_control_manager_v1 と zwlr_data_control_manager_v1 がなく、実際のterminal writerが呼んだhelperはexit 78でElectronへfallbackしました。対応compositor上のhelper成功経路を試した結果ではありません。AppImage/x86_64や実gnome-sessionの確認も未実施です。

新しいclipboard PRは作っていません。data-controlを公開しないGNOMEで残るfallback経路は、このPRの追加対象として扱う方針でしょうか。それとも、このPRの対応範囲を明示して別途設計するのがよいでしょうか。既存の対応環境での価値を否定する意図ではなく、GNOME coverageの不足を具体化する証拠として共有します。

@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded by merged #27772: #27772

The merged fix reuses this PR's native data-control implementation and adds the GNOME/Mutter clipboard bridge, ordinary UI text copies, and AppImage owner staging. Real clipboard publication and subsequent native pastes were verified on isolated Mutter and Sway displays, including copies after native input. It also links Electron #54645 and documents when the workaround can be removed.

Closing this older implementation to keep one merged fix for #23229 and #26917. Its native implementation and investigation were carried forward.

@nwparker nwparker closed this Oct 12, 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.

[Bug]: Clipboard gets stuck on Wayland (sway/wlroots) when OSC 52 and wl-copy write the same text

2 participants