Skip to content

TUI: "Copied to clipboard" toast shown even when nothing was copied (OSC52 "attempted" treated as success) #59664

Open

Description

@MostDef2000

Environment

  • opencode 2.2.0, TUI, Linux (app runs inside a Docker sandbox)
  • Host terminal: GNOME Terminal (VTE-based). VTE does not implement OSC 52 — long-standing open feature request, open since 2017: https://bugzilla.gnome.org/show_bug.cgi?id=795774
  • WAYLAND_DISPLAY inside the sandbox points to a minimal compositor stub

What happens

Mouse-selection copy in the TUI shows the "Copied to clipboard" toast, but the text never reaches the host clipboard. Pasting later returns whatever was in the clipboard before the copy — in our case a stale literal undefined string from an earlier broken copy, which made the failure very confusing to debug.

Root cause

packages/tui/src/clipboard.ts, write() (as of v2.2.0 sources):

const result = await clipboard.writeText(text.replaceAll("\0", ""), {
  destination: "all-available",
  selection: "clipboard",
})
if (result.host.status === "written" || result.terminal.status === "attempted") return

With destination: "all-available", OpenTUI writes via the host backend and emits OSC 52 to the terminal. In this environment the host write never fires (verified: zero Wayland protocol traffic from the TUI on copy attempts — no set_selection / data-control activity, observed in the compositor stub's log), so the only delivery channel is OSC 52.

terminal.status is "attempted" — per OpenTUI's own docs, "OSC 52 attempted does not confirm the terminal accepted it". That status is treated as success: the promise resolves and util/selection.ts shows the toast:

clipboard
  .write(clipboardText)
  .then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
  .catch(toast.error)

VTE-based terminals (GNOME Terminal, XFCE terminal, Tilix, Terminator — the defaults on most Linux desktops) silently ignore OSC 52, so nothing is copied while the user is told it was.

This is not limited to sandbox setups: the same lying toast occurs in any SSH/TUI session where the host clipboard path is unavailable and the local terminal lacks OSC 52 support — a very common combination.

Expected behavior

  • Treat OSC 52 "attempted" as unverified, not success. OpenTUI already has an OSC 52 capability query (isOsc52Supported(), XTGETTCAP-style). When the reported capability is unknown/unsupported and the host write did not succeed, the feedback should reflect that (e.g. "Copied — delivery not confirmed", or an error), not an unqualified success toast.
  • (Secondary) The native Wayland host backend appears to enter a terminal failed/unsupported state after the initial connect and never retries subsequent writes — worth a look for robustness.

Verification

Marker test: selected a unique string that had never been in any clipboard; the "Copied" toast appeared; wl-paste on the host machine returned the previous clipboard content, not the marker. Repeated with the same result.

Activity

  1. opencode-agent commented on Oct 27, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I reproduced this on 2.2.0, and it still happens on the latest dev (96ae220).

    What I did: ran the TUI on Linux with no host clipboard (no DISPLAY, no WAYLAND_DISPLAY, no clipboard helpers), in a virtual terminal that ignores OSC 52, like VTE. Then I drag-selected some text on the home screen. The recording and screenshot below show the "Copied to clipboard" toast, even though nothing received the text.

    In the same environment, OpenTUI's host clipboard returns unsupported, so the only thing sent was the OSC 52 sequence, with status attempted. As you pointed out, write() in packages/tui/src/clipboard.ts counts that as success, so the success toast is shown. The script below reproduces it.

    I did not test your second point, that the Wayland host backend never retries after it first fails, because that needs a compositor. Related: #50208 (the same false toast over SSH + tmux) and #59052 (the same all-available clipboard setting).

    recording.mp4

    Screenshot

    Reproduction script (drive.ts)
    // Repro for #59664: TUI shows "Copied to clipboard" although no clipboard received the text.
    // Sandbox: Linux, no DISPLAY / WAYLAND_DISPLAY, no clipboard helpers -> host write can't succeed.
    // The drive's virtual terminal ignores OSC 52 (like GNOME Terminal / VTE).
    import { Effect } from "effect"
    import { OpenCodeDriver } from "opencode-drive"
    
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        tui: { recording: true, pointerOverlay: { leadMs: 180, lingerMs: 700, motionMs: 500, curve: 0.06 } },
      },
      ({ ui }) =>
        Effect.gen(function* () {
          yield* ui.waitFor("Ask anything")
          yield* Effect.sleep("800 millis")
          // Drag-select the "~/files" directory label on the home screen (row 25, cols 13-20)
          yield* ui.mouse({ action: "move", x: 13, y: 25 })
          yield* ui.mouse({ action: "down", x: 13, y: 25, button: "left" })
          yield* ui.mouse({ action: "move", x: 17, y: 25 })
          yield* ui.mouse({ action: "move", x: 20, y: 25 })
          yield* ui.mouse({ action: "up", x: 20, y: 25, button: "left" })
          yield* ui.waitFor("Copied to clipboard")
          yield* ui.screenshot("copied-toast")
          yield* Effect.log(
            `DISPLAY=${JSON.stringify(process.env.DISPLAY ?? "")} WAYLAND_DISPLAY=${JSON.stringify(process.env.WAYLAND_DISPLAY ?? "")} -> no host clipboard exists, yet the toast says "Copied to clipboard"`,
          )
          yield* Effect.sleep("2000 millis")
        }),
    )

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

  2. MostDef2000 commented on Oct 28, 2026

    @MostDef2000
    Author

    Follow-up: root cause was on our side — native Wayland copy works; the toast issue stands

    Update after deeper debugging (opencode 2.2.0, same environment). The "host write never fires" observation in the original report was an artifact of our minimal compositor stub, not an OpenTUI/opencode behavior. Two bugs on our side, both fixed:

    1. Blocking backup channel in the compositor stub. The stub ran a blocking urlopen(timeout=6) inline in its single-threaded event loop after each delivery. Any gateway response slower than OpenTUI's 1s host-clipboard timeout (DEFAULT_CLIPBOARD_TIMEOUT_MS = 1_000, host-clipboard.internal.ts) wedged the client backend, whose failed phase is terminal — it never wrote again. The first two copies in a session worked; everything after a slow response died silently.

    2. Missing cancelled event on selection replacement. Our stub did not send the protocol-mandated cancelled to the previous data source when a selection was replaced. OpenTUI's provider pool (wayland.zig: canPublishProvider admits a new provider only while < 2 un-cancelled providers exist per selection type; retireProvider frees a slot only after cancelled AND in-flight transfers completed) then exhausts after exactly two copies — the third copy fails with selectionFailure(.provider) before any network traffic. This part is our protocol non-conformance, not an OpenTUI bug; real compositors send cancelled.

    After fixing the stub, mouse-copy → host clipboard works reliably: 5+ consecutive copies verified in the compositor log, each correctly cancelling the previous, plus interleaved external wl-copy clients.

    What remains valid upstream feedback (the core of this issue):

    • The toast still lies on the failure path. packages/tui/src/clipboard.ts write() resolves success when terminal.status === "attempted" even if host.status is "failed"/skipped — during the wedged period above, every copy showed "Copied to clipboard" while nothing was delivered anywhere (OSC 52 into a VTE terminal goes nowhere). Suggestion: treat a failed host write as a failure (or surface a warning toast) instead of masking it with the terminal "attempted" status.
    • The host backend's failed phase is terminal for the lifetime of the process. A transient compositor stall permanently disables host clipboard writes until the app restarts. Suggestion: allow the backend to recover (retry on the next write, or re-init on display reconnect).

    Happy to provide the stub logs or a minimal non-conformant-compositor reproducer if useful.

  3. dboeckli commented on Nov 15, 2026

    @dboeckli

    Additional data point from a Docker-sandbox setup (Docker Sandboxes / sbx), host terminal = JetBrains IDE terminal (JediTerm, no OSC 52).

    Environment

    • opencode 2.3.0 (@opencode/cli 2.x), TUI running inside a Docker Sandboxes microVM
    • Host: Windows 11, Docker Desktop 4.96.3; sandbox CLI sbx v0.53.0
    • Terminal: IntelliJ IDEA terminal (JediTerm) — does not implement OSC 52
    • Inside the sandbox: WAYLAND_DISPLAY=wayland-0 with a real socket (/run/user/1000/wayland-0, the sandbox's clipboard bridge) and working clipboard shims — printf test | wl-copy exits 0, same for xclip -selection clipboard

    Symptoms (same family as yours)

    • Mouse-selection copy shows "Copied to clipboard", nothing reaches the host clipboard
    • Text paste (prompt.paste, default ctrl+v) silently does nothing; the terminal's own paste (ctrl+shift+v) works fine
    • The binary's error strings show why: Clipboard write failed (host: …, terminal: …), the Wayland compositor has no data-control protocol, which writes need, Clipboard read timed out

    What makes this environment interesting

    1. Text copy never uses the shims. The 2.3.0 binary contains no reference to wl-copy, xclip, sbx-clipboard-* or pbcopy — only the OpenTUI clipboard service (host = Wayland data-control, terminal = OSC 52/kitty). The sandbox's Wayland bridge deliberately serves only the shim CLIs and exposes no data-control protocol, so the host backend can never succeed there.
    2. Because of that, the sandbox's own opt-in (sbx settings set clipboard.textCopy true, which enables the shims) has no effect on V2 — the shims work, V2 just never calls them.
    3. Text paste has no working channel at all inside the sandbox: there is a sbx-clipboard-write shim but no sbx-clipboard-read, so any text clipboard.read() can only succeed through an OSC 52 query — which the terminal does not answer.

    Suggestion (beyond fixing the success status reported in this issue)

    1. Fall back to shims for text write when the host backend is not written and the terminal write is only attempted: wl-copy → xclip -selection clipboard. That is what makes container/SSH/sandbox setups work without any terminal-side support.
    2. In read(), prefer wl-paste/xclip for text when they are present (they are already used for images, cf. tui: image paste fails silently on WSL when no clipboard tool is installed (V2) #49895) instead of relying on the OSC 52 query.
    3. Keep the toast honest: report success only on host.status === "written" or a confirmed terminal write.

    Happy to test a build with a shim fallback against this exact setup.

  4. dboeckli commented on Nov 15, 2026

    @dboeckli

    Follow-up with the decisive v1-vs-v2 comparison, since it shows this is a regression rather than a missing feature.

    v1 (1.19.5) has exactly the fallback this issue asks for — from the bundled code of [email protected]:

    function dt(e, o, r) {                              // e = platform, o = Boolean(WAYLAND_DISPLAY), r = which()
      if (e === "darwin" && r("osascript")) return ["osascript"]
      if (e === "linux" && o && r("wl-copy")) return ["wl-copy"]
      if (e === "linux" && r("xclip")) return ["xclip", "-selection", "clipboard"]
      if (e === "linux" && r("xsel")) return ["xsel", "--clipboard", "--input"]
      if (e === "win32" && r("powershell.exe")) return ["powershell.exe", …, "Set-Clipboard -Value …"]
    }
    async function Oe(e) { ut(e); await (await mt())(e) }   // OSC 52 write AND the native tool

    So v1 writes OSC 52 and spawns wl-copy/xclip/xsel. In the sandbox WAYLAND_DISPLAY is set and wl-copy exists (a shim to the host clipboard), which is why copy works in v1 there.

    v2 (2.3.0) contains zero references to wl-copy, xclip, xsel, pbcopy or sbx-clipboard-*; only OpenTUI's clipboard service. Confirmed by strings on both binaries.

    Paste is a separate regression, also worth fixing

    Reading the clipboard is impossible in this sandbox for any version (the host only provides a write shim):

    $ wl-paste      → exit 1, empty
    $ xsel --clipboard --output → "xsel: host clipboard text reads are not supported"
    

    v1 still pastes because Ctrl+V ends up as the terminal's bracketed paste. v2 binds prompt.paste to ctrl+v and consumes the key while its own clipboard.read() has nothing to read, so nothing is pasted. Two things would fix that: make read() report failure and fall back to accepting terminal paste, and/or let an unbound prompt.paste pass the key through. (Workaround on the user side: "keybinds": { "prompt.paste": "none" } in cli.json restores the terminal behaviour.)

    So the ask is: restore the v1 write chain in v2 instead of relying on OSC 52 + Wayland data-control only.

  5. mhoel commented on Nov 18, 2026

    @mhoel

    Another data point with the JetBrains terminal. Here, the host clipboard path fails even though an X server is available.

    Environment

    • opencode 2.3.0, TUI, Linux container inside WSL2 (no WSL interop, so clip.exe is unavailable)
    • Terminal: IntelliJ IDEA terminal (JediTerm), which ignores OSC 52
    • Two X servers are reachable:
      • DISPLAY=192.0.2.1:0: an X server on the Windows host, reached over TCP
      • /tmp/.X11-unix/X0: WSLg (X.Org)

    Observations

    Test Result
    OSC 52 (printf '\e]52;c;…\a') in JediTerm Not copied
    echo test | xclip -selection clipboard with DISPLAY=192.0.2.1:0 Copied to the Windows clipboard
    echo test | DISPLAY=:0 xclip -selection clipboard Copied to the Windows clipboard
    opencode copy with DISPLAY=192.0.2.1:0 "Copied to clipboard" toast, clipboard unchanged
    opencode copy with DISPLAY=:0 opencode Copied to the Windows clipboard

    The native X11 host backend appears to support only local Unix sockets (/tmp/.X11-unix/X<n>) and to ignore the TCP host part of DISPLAY. I inferred this from strings in the binary and from the behavior above; I have not confirmed it in the source. The TCP X server is not X.Org, so a server-specific incompatibility is also possible.

    Either way, the host write fails, OSC 52 is only "attempted", and the success toast hides the failure. A v1-style xclip/xsel/wl-copy fallback would have handled this case, because xclip works against the same DISPLAY.

    Workaround: DISPLAY=:0 opencode when a local X socket is available.

  6. Flamefire commented on Nov 24, 2026

    @Flamefire

    It seems like in v2 the clipboard code was changed. In v1 it used OSC52 and the platform specific method, e.g. xclip (see #11994)
    This worked even over SSH with GNOME Terminal if X-forwarding was enabled. I.e. echo test | xclip -selection clipboard-like works

    V2 doesn't seem to do this anymore as it uses OpenTUI(?)
    My agent found allowRemoteHost: true which can be passed to OpenTUI to support this case: https://opentui.com/docs/core-concepts/clipboard/?utm_source=chatgpt.com#remote-sessions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions