Repository navigation
fix(concurrent): report originating signal as wt's exit code after escalation - #2724
Merged
Merged
Conversation
…calation `wt step <concurrent-alias>` interrupted by Ctrl-C could exit with code 143 (SIGTERM) instead of 130 (SIGINT) under load. The signal forwarder in `run_concurrent_commands` sends SIGINT to each child's process group, then waits 200ms before escalating to SIGTERM. Under CI load the propagation chain (signal_hook polls → killpg → child receives → sh forwards to sleep → sleep dies → sh dies → pgroup empty) exceeds 200ms, so wt escalates and the child dies from SIGTERM. `interrupt_exit_code()` reads the child's actual death signal and reports `128 + 15 = 143` even though the user only ever sent SIGINT. Record the user's first signal in a shared `Arc<AtomicI32>` set by the forwarder thread. After every child has been waited on, override any per- child `ChildProcessExited::signal` whose value differs from the originating one. wt's exit code now reflects what the user pressed (130 for SIGINT) regardless of which signal the escalation chain used to actually kill the child. Fix is contained to `run_concurrent_commands`. The single-step `shell_exec.rs::stream` path has the same escalation logic but isn't exercised by the failing test; if the equivalent flake shows up there, the same pattern can be applied. Adds a regression test where children trap SIGINT so only the SIGTERM escalation kills them — without the fix it reproduces the exact CI failure mode (`unix_wait_status(36608)` = exit 143). Co-Authored-By: Claude <[email protected]>
worktrunk-bot
previously approved these changes
May 11, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
codecov/patch is failing on a single uncovered line: src/output/concurrent.rs:207 — the return; in override_with_originating_signal's let-else that fires when an outcome is Err but not a signal-derived ChildProcessExited. None of the new tests reach that branch (all the SIGINT-traps children exit via signal). A tiny unit test on the private helper closes the gap; happy to push if you want.
worktrunk-bot
dismissed
their stale review
May 11, 2026 22:26
codecov/patch failed — src/output/concurrent.rs:207 uncovered. Posted analysis in the follow-up review.
The four-way table covers `Ok`, non-`WorktrunkError` `Err`, exit-code `ChildProcessExited` (no signal), same-signal, and different-signal cases. Closes the codecov/patch gap on the early-out arm that the integration regression test doesn't reach. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
May 11, 2026
Co-Authored-By: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
May 12, 2026
…2734) ## Summary `shell_exec.rs::stream` (single child) and `output/concurrent.rs` (N children) each carried their own copy of the same pattern — install a `signal_hook` SIGINT/SIGTERM handler before spawning, run a listener thread that records the user's first signal and forwards it (with graceful escalation) to the child or child-groups, then close the handle and join the thread on shutdown, reporting the *originating* signal so wt's exit code reflects what the user pressed even when escalation killed the child with a later signal. Follow-up to #2724, which added the originating-signal tracking to `concurrent.rs` — at that point both sites had the same logic, just duplicated. ## Changes New `src/signal_forwarder.rs`: - `ForegroundSignals::install()` — register wt's handler *before* spawning children (a signal arriving mid-spawn is queued, not default-killing wt and orphaning already-spawned children). - `forward_to_pid(pid, share_parent_pgroup)` — single child. Shared-pgroup mode delivers a single shot by PID (the kernel already broadcast the tty signal to the child; explicit forwarding only matters for externally-delivered signals like `kill -TERM <wt-pid>`, and skipping escalation avoids wedging an interactive child mid-tty-restore). Otherwise per-PID escalation SIGINT → SIGTERM → SIGKILL. - `forward_to_pgids(pgids)` — N children, per-PGID escalation, plus a second-signal SIGKILL-all impatient path (per-PGID escalation is serialized, so a user mashing Ctrl-C would otherwise wait N × 400 ms for the chain to walk). - `ActiveForwarder::stop()` — tear down and return the originating signal. A private `run_listener` holds the shared scaffolding (own the handle, spawn the listener thread, package into `ActiveForwarder`) so each `forward_to_*` body is just its policy. Both call sites drop ~30 lines of plumbing each: `concurrent.rs` deletes its `SignalForwarder` struct + `spawn_signal_forwarder`; `shell_exec.rs::stream` deletes its inline ~60-line listener block. `shell_exec::forward_signal_to_pid` is now `pub` so the new module can call it. No behavior change. `concurrent.rs` keeps its per-outcome originating-signal override — that's the multi-child outcome shape, not signal forwarding. ## Test plan - `cargo run -- hook pre-merge --yes`: 3669 tests pass, lints clean. - The alias signal tests (`test_alias_concurrent_receives_sigint`, `test_alias_concurrent_sigint_reports_origin_after_escalation`, `test_alias_concurrent_second_sigint_kills`, `test_alias_external_sigint_reaches_child`) all pass against the unified module. --------- Co-authored-by: Claude <[email protected]>
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.
Summary
wt step <concurrent-alias>interrupted by Ctrl-C could exit with code 143 (SIGTERM) instead of 130 (SIGINT) under load. The race lives insrc/output/concurrent.rs's signal forwarder: it sends SIGINT to each child's process group, then waits 200ms before escalating to SIGTERM. Under CI load the pathsignal_hook polls → killpg → child receives → forwards to sleep → sleep dies → sh dies → pgroup emptyexceeds 200ms, so wt escalates and the child dies from SIGTERM. Wt'sinterrupt_exit_code()reads the child's actual death signal and reports128 + 15 = 143even though the user only ever sent SIGINT.This was the cause of the
affected tests (linux, advisory)failure on #2709 (selectedtest_alias_concurrent_receives_sigintbecause that PR touchedsrc/main.rs, dragging in coverage of nearly every wt invocation path) — diagnosis recorded there, not a regression from the approval refactor.Fix
Record the user's first signal in a shared
Arc<AtomicI32>set by the signal forwarder thread. After every child has been waited on, override any per-childChildProcessExited::signalwhose value differs from the originating one. wt's exit code now reflects what the user pressed (130 for SIGINT) regardless of which signal the escalation chain ended up using to actually kill the child.The fix is contained to
run_concurrent_commands. The single-stepshell_exec.rs::streampath has the same escalation logic but isn't exercised by the failing test; if the equivalent flake shows up there, the same pattern can be applied.Test plan
test_alias_concurrent_sigint_reports_origin_after_escalation(tests/integration_tests/step_alias.rs:1406) — childrentrap "" INTso SIGINT is ignored and only the SIGTERM escalation kills them. Verified to reproduce the exact CI failure mode (unix_wait_status(36608)= exit 143) without the fix and pass with it.test_alias_concurrent_receives_sigintandtest_alias_concurrent_second_sigint_killsstill pass.cargo run -- hook pre-merge --yes: 3667 tests pass, lints clean.