fix(tui): detach clipboard helper processes to survive SIGTSTP - #42233
Closed
g0rdonL wants to merge 1 commit into
Closed
fix(tui): detach clipboard helper processes to survive SIGTSTP#42233g0rdonL wants to merge 1 commit into
g0rdonL wants to merge 1 commit into
Conversation
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.
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Clipboard helper processes spawned by
packages/tui/src/clipboard.ts(e.g.wl-copyon Wayland) inherited opencode's process group.wl-copyforks into the background to keep serving the clipboard selection after the initiating process exits — but since it shares opencode's pgid, sendingCtrl-Zto the terminal deliversSIGTSTPto the whole foreground process group, suspending the still-runningwl-copyalong with opencode. Any subsequent paste then hangs indefinitely waiting on the stopped clipboard provider until it's manually resumed withSIGCONT.Fix
Pass
detached: truewhen spawning the clipboard helper in the sharedcommand()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:detached: it shares the parent's pgid (psshows same PGID as parent), andkill -TSTPon the parent's process group stops it too.detached: true: it gets its own pgid/session (psshowsSTAT=Ss, distinct PGID), and is unaffected bySIGTSTPsent 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 testinpackages/tui: 193 pass, 0 fail (existingclipboard.test.tscoverscopyCommand, unaffected by this change)bun turbo typecheck: 30/30 packages passSmall, isolated change — one spawn-option addition, no behavior change on macOS/Windows paths (
osascript/powershell.exeare short-lived and exit on their own;detachedis 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.