Repository navigation
fix(alias): share parent pgroup so interactive TUIs don't freeze - #2444
Conversation
Aliases that exec interactive children (e.g. `wt switch`'s skim picker) froze with a blank screen: the alias child was put in a new process group via `cmd.process_group(0)`, so when skim's tuikit called `tcsetattr` on `/dev/tty` to enter raw mode the kernel raised SIGTTOU on the background pgroup and stopped the child mid-render. `Cmd::inherit_stdin()` now both inherits stdin and keeps the child in the parent's process group. `execute_shell_command` uses it for the interactive (no-stdin-payload) path, which covers aliases. The kernel already delivers terminal signals to every process in the shared foreground pgroup, so the new-pgroup isolation only mattered for `killpg`-based teardown — redundant for interactive aliases. The signal listener still runs in the shared-pgroup case so a signal-derived child exit surfaces as `WorktrunkError::ChildProcessExited` with `signal: Some(_)`; we just skip the no-op `killpg` call. Closes the freeze reported in #406. Co-Authored-By: Claude Opus 4.7 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The fix is correct and the regression test directly exercises the invariant (alias child shares wt's pgroup). One concern with the description, no code blockers.
Wrong issue reference. "Closes the freeze reported in #406" — issue #406 is "Support shorthand" (closed, unrelated to TTY freezes). Merging will silently no-op because the issue is already closed, but the reference is misleading and pollutes the commit message in git log. Either drop the line or replace it with the actual report (e.g., a link to the comment thread or describe the user-facing symptom without an issue number).
Optional doc nit (not blocking). The doc comment for inherit_stdin and the stream() skip-block describe terminal signals as "already delivered to every process in the foreground pgroup." That is true for tty-initiated signals (Ctrl-C → SIGINT, Ctrl-Z → SIGTSTP, hangup → SIGHUP). It is not true for an external kill -TERM <wt-pid> — only wt receives it, and with the new code we no longer forward it (and can't, since the child isn't a pgroup leader so killpg(child_pid, …) would target a non-existent group or, worst case, an unrelated recycled pgid). Practical impact is small (interactive aliases aren't usually kill-ed externally), but the comment slightly overstates the equivalence — saying "tty-initiated signals" instead of "terminal signals" would be more precise.
The kernel only auto-delivers signals to every process in the foreground pgroup for tty-initiated signals (SIGINT from Ctrl-C, SIGTSTP from Ctrl-Z, SIGHUP on hangup). An external `kill -TERM <wt-pid>` only reaches wt; with the new shared-pgroup path we no longer forward it. Tighten the doc comments accordingly. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Both fair — addressed:
|
In shared-pgroup mode (`Cmd::stream()` with `.inherit_stdin()`), the listener was skipping signal forwarding entirely on the assumption the kernel would broadcast tty signals to the whole foreground pgroup. That holds for Ctrl-C and SIGHUP, but `kill -TERM <wt-pid>` only delivers to wt — leaving the alias child running indefinitely while wt sat latched on `seen_signal`. Forward via `kill(child.id(), sig)` instead of skipping. Single-shot, no SIGINT→SIGTERM→SIGKILL escalation: the caller chose the signal, and an unsolicited SIGKILL would skip the child's tty restore (raw- mode reset, cursor-show) and leave the terminal wedged. Co-Authored-By: Claude Opus 4.7 <[email protected]>
The rationale for the two `Cmd::stream` shapes (isolated vs shared-tty) and how each interacts with the kernel's foreground-pgroup signal broadcast was scattered across three field/method docstrings. Pull a single summary up to the module head so a reader can pick up the model without reconstructing it from the call site. No code change; refactors comments only. Co-Authored-By: Claude Opus 4.7 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch failed at 95.34% (target 96.73%, the project baseline) — 41/43 patch lines hit, 2 uncovered.
Likely culprit: the SIGINT arm of forward_signal_to_pid in src/shell_exec.rs. test_alias_external_sigterm_reaches_child exercises the SIGTERM path (the SIGTERM match arm and the kill() call show as covered), but no test sends SIGINT through the shared-pgroup path, so the SIGINT match arm and likely one neighboring line stay at zero hits.
Practically, the SIGINT branch is narrow: kernel-broadcast Ctrl-C already reaches the child via the foreground pgroup, so forward_signal_to_pid(child_pid, SIGINT) only matters for an externally-delivered kill -INT <wt-pid> — uncommon for interactive aliases. Two reasonable responses:
- Mirror
test_alias_external_sigterm_reaches_childwith a SIGINT variant to close the gap. - Accept the 2-line miss as the cost of carrying a defensive branch for a rare external-signal case.
Happy to push the SIGINT variant test if you prefer the first option. No prior approval to dismiss.
Mirrors test_alias_external_sigterm_reaches_child for SIGINT. PID-targeted `kill -INT <wt-pid>` bypasses kernel pgroup broadcast, so the alias child only receives SIGINT via wt's re-delivery path — closes the codecov gap on the SIGINT match arm of `forward_signal_to_pid`. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Went with option 1 — added |
## Summary Follow-up to #2444. The `forward_signals` docstring mentioned that the listener "still runs" in the shared-pgroup case but didn't say what it does — leaving readers to infer that signal-derived child exits surface but no explicit forwarding happens. With #2444's PID forwarding for externally-delivered signals, the doc lagged the implementation. Two extra lines spelling out the actual behavior. No code change. ## Test plan - [x] `cargo check` clean. - [x] No code paths affected; doc-only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 <[email protected]>
Summary
wt switch's skim picker) froze with a blank screen because the alias child was put in a new process group; the kernel then raised SIGTTOU when the picker calledtcsetattron/dev/tty, stopping the child mid-render.Cmd::inherit_stdin()builder both inherits stdin and keeps the child in the parent's process group.execute_shell_commanduses it for the interactive (no-stdin-payload) path, which covers aliases.kill(child.id(), sig)so externally-delivered signals (e.g.kill -TERM <wt-pid>) reach the child — they otherwise stop at wt because the kernel only multicasts tty-initiated signals to the foreground pgroup. Single-shot, no SIGINT→SIGTERM→SIGKILL escalation: the caller chose the signal, and a premature SIGKILL would skip the child's tty restore (raw-mode reset, cursor-show) and leave the terminal wedged.WorktrunkError::ChildProcessExited { signal: Some(_) }accounting is preserved.shell_exec.rssummarizes the twoCmd::streamshapes (isolated vs shared-tty), how each interacts with the structuredChildProcessExitedchannel used by loop callers, and why detached/concurrent spawn paths isolate.Hooks (which still get JSON-on-stdin via
stdin_bytes) are unaffected — they go through thestdin_data/piped branch and never callinherit_stdin().Test plan
test_alias_child_shares_parent_pgroup: spawns wt as its own pgroup leader, runs an alias that records its shell pgid viaps -o pgid= -p \$\$, asserts the recorded pgid equals wt's pid (i.e. the alias child shares wt's pgroup).test_alias_external_sigterm_reaches_childandtest_alias_external_sigint_reaches_child: target wt with PID-onlykill -<sig>(not the pgroup) and assert the alias child's signal trap fires. Without the PID-forwarding fix the test would block until the child'ssleep 30completes; with it, each settles in ~1.3s. Together they exercise both arms offorward_signal_to_pid.test_alias_concurrent_receives_sigintandtest_alias_concurrent_second_sigint_killsstill pass — concurrent aliases use a separate executor (output/concurrent.rs) that's unaffected by this change.step_alias(70 tests) anduser_hooks(108 tests) suites green locally.wt sw(aliased towt switch {{ args }}) now renders the picker instead of hanging.