Skip to content

fix(tui): detach clipboard helper processes to survive SIGTSTP - #42233

Closed
g0rdonL wants to merge 1 commit into
anomalyco:devfrom
g0rdonL:fix/clipboard-detached-process
Closed

fix(tui): detach clipboard helper processes to survive SIGTSTP#42233
g0rdonL wants to merge 1 commit into
anomalyco:devfrom
g0rdonL:fix/clipboard-detached-process

Conversation

@g0rdonL

@g0rdonL g0rdonL commented Aug 13, 2026

Copy link
Copy Markdown

Bug

Clipboard helper processes spawned by packages/tui/src/clipboard.ts (e.g. wl-copy on Wayland) inherited opencode's process group. wl-copy forks into the background to keep serving the clipboard selection after the initiating process exits — but since it shares opencode's pgid, sending Ctrl-Z to the terminal delivers SIGTSTP to the whole foreground process group, suspending the still-running wl-copy along with opencode. Any subsequent paste then hangs indefinitely waiting on the stopped clipboard provider until it's manually resumed with SIGCONT.

Fix

Pass detached: true when spawning the clipboard helper in the shared command() helper, giving it its own process group so it's unaffected by signals sent to opencode's foreground group.

Verification

Reproduced the underlying mechanism locally (macOS, Node child_process) since I don't have a Wayland session on hand:

  • Spawned a long-running child without detached: it shares the parent's pgid (ps shows same PGID as parent), and kill -TSTP on the parent's process group stops it too.
  • Spawned the same child with detached: true: it gets its own pgid/session (ps shows STAT=Ss, distinct PGID), and is unaffected by SIGTSTP sent to the original parent's process group.

This is exactly the mechanism described in the report, so the fix directly addresses the root cause. Also ran the existing test suite and typecheck:

  • bun test in packages/tui: 193 pass, 0 fail (existing clipboard.test.ts covers copyCommand, unaffected by this change)
  • bun turbo typecheck: 30/30 packages pass

Small, isolated change — one spawn-option addition, no behavior change on macOS/Windows paths (osascript/powershell.exe are short-lived and exit on their own; detached is harmless for them too).

Note: I'm Atlas, an AI agent operating under Gordon Lee's (@g0rdonL) direction, opening this PR on his behalf after independently verifying the fix.

wl-copy (and other clipboard helpers that fork into the background to
keep serving a selection) inherited opencode's process group. When the
terminal sends SIGTSTP to the foreground process group (Ctrl-Z),
wl-copy is suspended along with opencode, so the next paste hangs
waiting on a stopped clipboard provider until the process is manually
resumed with SIGCONT.

Spawn clipboard helper processes with detached: true so they get their
own process group and are not affected by signals sent to opencode's
foreground group.

Verified the mechanism locally (macOS, Node child_process): a
non-detached child shares the parent's pgid and is stopped by
kill -TSTP on the parent's process group, while a detached child gets
its own pgid/session (ps STAT=Ss) and is unaffected.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 13, 2026
@github-actions github-actions Bot closed this Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants