Skip to content

[BUG] Linux X11: arboard clipboard silently lost — “Copied” toast shows but clipboard is empty #684

Closed

Description

@iwanro

Problem
Selecting text in the jcode TUI shows the “Copied selection” toast, but the system clipboard remains unchanged. Previous clipboard contents
are preserved.

Environment
• OS: Kali Linux Rolling 2026.3 (also reproduced on Ubuntu-based X11)
• jcode: v0.64.2 (6c6fbba)
• Display server: X11 (DISPLAY=:0, WAYLAND_DISPLAY unset, XDG_SESSION_TYPE=x11)
• Terminal: GNOME Terminal 3.52.0 (VTE 0.76.0)
• Installed clipboard tools: xclip 0.13, xsel 1.2.1, wl-clipboard 2.2.1

Root cause analysis
The Linux clipboard path in crates/jcode-tui/src/tui/app/helpers.rs tries wl-copy, then arboard, then OSC 52.

  1. wl-copy — fails fast in ~11ms (no Wayland display). Falls through correctly.
  2. arboard — Clipboard::new() opens a new X11 connection, sets the selection via set_text(), returns Ok, then the Clipboard object is dropped.
    The X11 connection closes. The clipboard data is immediately lost because no X client is holding the selection.
  3. OSC 52 — gnome-terminal supports it, but by this point the function already returned true from step 2.

The core issue: arboard on X11 does not fork a background process to keep the X11 selection owner alive (unlike xsel which does fork() +
setsid() to stay alive). When the Clipboard handle is dropped, the selection vanishes before anything can paste it.

Verification
┌─ [Alt] [⇧] [S]
│ $ echo "test" | xsel --clipboard --input # works, stays alive
│ $ xclip -selection clipboard -o # returns "test"

│ $ python3 -c "import arboard; ..." # arboard sets then drops
│ $ xclip -selection clipboard -o # returns empty / old content
└─

xsel and xclip work correctly on this system. The issue is specifically how arboard manages the X11 selection lifetime inside the TUI.

Comparison with opencode
OpenCode (Go) calls xclip -selection clipboard directly via child process, which keeps the process alive until paste. This works correctly on
the same system.
╷
Suggested fix │
On Linux X11, after arboard sets the clipboard, keep the X11 connection alive until a paste occurs, or fork a background process (like xsel │
does) to serve selection requests. Alternatively, consider calling xclip/xsel as a subprocess on Linux (like OpenCode does) instead of relying │
on arboard’s in-process X11 implementation. ╵

Activity

  1. iwanro commented on Jul 31, 2026

    @iwanro
    Author

    ### fix(tui): add xclip/xsel clipboard fallback on Linux X11

    Problem

    │
    │ Selecting text in the jcode TUI on Linux X11 shows "Copied selection" toast,
    │ but the system clipboard remains empty. Issues #497 (Windows), #504 (Linux),
    │ and #505 (macOS) all describe variants of this. The macOS and Windows fixes
    │ use arboard as authoritative, but on Linux the fallback chain is:
    │
    │ 1. wl-copy -- fails fast on X11 (correct)
    │ 2. arboard -- sets text, drops X11 connection immediately, clipboard lost
    │ 3. OSC 52 -- too late
    │
    │ arboard does not fork a background process to keep the X11 selection owner
    │ alive. When the Clipboard handle is dropped, the X11 connection closes
    │ and the selection vanishes before anything can paste it.
    │
    │ ## Fix
    │
    │ Insert xclip and xsel as subprocess calls between wl-copy and arboard.
    │ Both tools fork a background process that serves paste requests, matching
    │ how opencode (Go) handles clipboard on Linux.
    │
    │ New Linux clipboard order:
    │ wl-copy (Wayland) -> xclip (X11) -> xsel (X11) -> arboard -> OSC 52
    │
    │ Uses the same subprocess+poll pattern already established for wl-copy:
    │ spawn with piped stdin, write text, poll 150ms for early failure, treat
    │ a still-running child as success and reap in background.
    │
    │ ## Verified
    │
    │ - Kali Linux Rolling 2026.3, X11, GNOME Terminal 3.52.0
    │ - xclip 0.13, xsel 1.2.1, wl-clipboard 2.2.1
    │ - cargo build --release succeeds
    │ - Python simulation of exact code path: clipboard content verified

  2. matthewhua commented on Jul 31, 2026

    @matthewhua

    I ran into this bug before too

  3. 1jehuang commented on Jul 31, 2026

    @1jehuang
    Owner

    Confirmed and fixed in 5b092b582 on master. Your root-cause analysis was exactly right.

    jcode now tries xclip then xsel before arboard on non-Wayland Linux, for the reason you gave: both fork a process that keeps owning the X11 selection until a paste, whereas arboard's selection dies with the Clipboard handle. The spawn logic (shared with wl-copy) moved into its own module with tests covering success, nonzero exit, missing binary, and the non-blocking contract, so a long-lived clipboard owner cannot stall the UI thread.

    OSC 52 remains the final fallback for genuinely headless/remote sessions. Thanks for the clear verification steps and the opencode comparison.


    — Jcode agent (automated triage), on behalf of @1jehuang

  4. added
    bug
    priority: high
    triage: reproducible
    triage: fixed-pending-release
    autonomous: clear
    on Jul 31, 2026
  5. added a commit that references this issue on Jul 31, 2026
    5b092b5
  6. added a commit that references this issue on Jul 31, 2026
  7. added 10 commits that reference this issue on Aug 30, 2026
    062f848
    52ca3cc
    1f1d1f0
    c4aca36
    01f7018
    0f76865
    750c1f7
    02cce47
    8c3106d
    820d140
  8. added 2 commits that reference this issue on Sep 18, 2026
    2fdd184
    e3651f9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: clearbugpriority: hightriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions