Skip to content

fix(concurrent): drop per-child SIGINT escalation race - #3075

Merged
max-sixty merged 7 commits into
mainfrom
fix-sigint-flake
Jun 15, 2026
Merged

max-sixty merged 7 commits into
mainfrom
fix-sigint-flake

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

wt step <concurrent-alias> ran a per-pgroup SIGINT → SIGTERM → SIGKILL escalation on the first user signal. Under CI scheduling latency a SIGTERM from that chain could land on a child during the sub-second grace window, so the child died from SIGTERM and wt exited 143 instead of the 130 a user's Ctrl-C should produce. The walk was also serialized across pgroups, so mashing Ctrl-C could wait N × 400 ms for it to finish.

forward_to_pgids now forwards the user's signal once per pgroup with no per-child escalation, so cooperative children die from the signal the user actually sent and the exit code reflects intent (130 on Ctrl-C, 143 on SIGTERM). A second user signal SIGKILLs every still-live pgroup immediately. Stubborn children that ignore SIGINT need a second Ctrl-C, matching make and cargo.

This was written by Claude Code on behalf of max

max-sixty and others added 5 commits May 10, 2026 11:27
The concurrent listener was calling `forward_signal_with_escalation` per
pgid on the first signal, which sends SIGINT then escalates to SIGTERM
after a 200ms grace and SIGKILL after another. Under CI scheduling
latency, cooperative `sh -c '... sleep 30 ...'` children sometimes don't
die from SIGINT within 200ms; escalation lands SIGTERM, the child dies
from SIGTERM, and `wt step <alias>` exits 143 instead of 130 — even
though the user pressed Ctrl-C.

`test_alias_concurrent_receives_sigint` flaked once on the v0.49.0
release CI with `unix_wait_status(36608)` (= code 143). Reproduced
locally by setting the grace to 0ms.

Drop the per-child escalation. The listener now forwards the same
signal once on the first press and SIGKILLs every pgid on the second —
a path the listener already had for impatient users. Cooperative
children die from the user's signal, so `child.wait()` reports a cause
of death that matches intent (no override needed). Stubborn children
that ignore SIGINT now require a second Ctrl-C, matching `make` /
`cargo` behavior.

The single-command path in `Cmd::stream` is unchanged: it has no
second-press fallback, so escalation remains the only way to kill a
stubborn single child there, and its existing `seen_signal` override
handles the same race for that path.

Co-Authored-By: Claude <[email protected]>
PR #2734 unified signal forwarding into src/signal_forwarder.rs while this
branch was modifying the now-deleted SignalForwarder in src/output/concurrent.rs.
Take main's deletion and port the fix into the unified module:
forward_to_pgids now forwards the user's same signal once (no per-pgid
escalation) and SIGKILLs on the second press, matching the intent of
commit 92a6bdd.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…n test

The test was pinning the old escalation contract (SIGINT-trapping
children die from wt's escalated SIGTERM, override the exit code back
to 130). That escalation path is gone, so update the test to pin the
new contract: a single SIGINT against SIGINT-trapping children does
NOT kill them (matching make / cargo); the test then cleans up via a
second SIGINT (impatient-SIGKILL path, already covered separately).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint is red on cargo fmt — the killpg call in the new forward_to_pgids body needs to collapse onto one line (clippy and the rest of the suite are unaffected). Inline suggestion below; happy to push the fmt fix if you'd rather.

The signal logic itself reads correctly: forwarding the user's signal once and reserving SIGKILL for the second press lines the exit code up with the project's 130-SIGINT / 143-SIGTERM convention, and the two tests pin both halves of the no-escalation contract.

Comment thread src/signal_forwarder.rs Resolved
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Jun 14, 2026
@worktrunk-bot
worktrunk-bot dismissed their stale review June 14, 2026 18:50

codecov/patch failing — see follow-up COMMENT for analysis

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch is failing on src/signal_forwarder.rs (77.77%, 2 of 9 lines uncovered). Worktrunk's Coverage policy in CLAUDE.md requires explicit approval before merging with patch failing, so dismissing.

Uncovered lines, both inside the new forward_to_pgids match block:

118:    SIGTERM => nix::sys::signal::Signal::SIGTERM,
119:    _ => return,
  • Line 118 — the SIGTERM arm fires when wt is externally signalled (kill -TERM <wt-pid>) while running a concurrent alias. The existing test_alias_external_sigterm_reaches_child exercises the analogous path for the single-command Cmd::stream branch, but the concurrent (forward_to_pgids) path has no equivalent test. A concurrent-alias counterpart that sends SIGTERM to wt and asserts the child pgroup receives it would cover this.
  • Line 119 — the _ => return is defensive against a non-INT/non-TERM signal, which the listener can't deliver (signal_hook::Signals::new([SIGINT, SIGTERM]) is the only registration). Either a comment that this arm is unreachable + // LCOV_EXCL_LINE, or replacing it with unreachable!(), would let codecov ignore it.

Happy to either push tests for the SIGTERM branch (and either annotation for line 119) on confirmation, or you can ack the gap and merge.

The second-press SIGKILL branch and the unreachable non-SIGINT/SIGTERM
arm were uncovered (codecov/patch). The listener registers only SIGINT
and SIGTERM, so the catch-all collapses to two reachable arms: forward
the user's signal on the first press, SIGKILL on any later press. Moving
that pure logic into a helper makes every branch deterministically
testable without real-process signal timing.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 751e419 into main Jun 15, 2026
35 checks passed
@max-sixty
max-sixty deleted the fix-sigint-flake branch June 15, 2026 09:16
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.59.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **Picker frees digit keys for filtering; preview tabs move to `Alt`**: In the `wt switch` picker, plain digits now go to the filter, so a branch name with a number in it can be typed directly. Preview tabs jump with `Alt-1`–`Alt-5` or cycle with `Tab`/`Shift-Tab`. (Breaking: `1`–`5` no longer switch preview tabs) ([#3079](max-sixty/worktrunk#3079))

- **Squash templates use `commit_details` instead of `commits`**: The squash commit-message template's `{{ commits }}` variable (commit subjects) is deprecated in favor of `{{ commit_details }}`, which renders as the bare subject when printed directly and also exposes `.subject` and `.body`. `wt config update` migrates `commits` to `commit_details` as a plain rename. ([#2985](max-sixty/worktrunk#2985))

- **`wt step eval -v` lists template variables**: `wt step eval -v` now prints the available template variables on stderr in the gutter style, above the template-expansion view. That expansion (also shown by `wt switch -v`, hooks, aliases, and `wt -v list`) renders the template and its result as separate labeled `source` / `result` blocks rather than a shared gutter. The result still goes to stdout, so `$(wt step eval …)` is unchanged. Since `eval` mutates nothing and is experimental, its `--dry-run` flag (which dumped the raw variable context) is removed rather than deprecated. ([#3078](max-sixty/worktrunk#3078), [#3099](max-sixty/worktrunk#3099))

### Fixed

- **Picker no longer freezes on the first keystroke**: With many worktrees, typing the first character in the `wt switch` picker locked the UI for several seconds. The fuzzy matcher shares rayon's global thread pool with worktrunk's git collection, which floods it with blocking subprocess calls, so the matcher queued behind them. Collection and preview work now run on a dedicated pool, keeping the matcher responsive. ([#3087](max-sixty/worktrunk#3087), thanks @bendrucker; fixes [#2926](max-sixty/worktrunk#2926), thanks @mahume for reporting)

- **Tab-completion covers all hook types**: `wt hook <type> <Tab>` completed configured command names for only seven of the ten hook types; `pre-switch`, `post-switch`, and `post-remove` returned nothing. Completion now derives the type from the canonical hook list, so every type completes its command names. ([#3070](max-sixty/worktrunk#3070))

- **Ctrl-C on a concurrent alias reports the right exit code**: Interrupting `wt step <concurrent-alias>` could report exit 143 (SIGTERM) instead of 130 (SIGINT), because a per-child SIGINT → SIGTERM → SIGKILL escalation could land a SIGTERM on a child during the grace window; the escalation also serialized across process groups, so repeated Ctrl-C could wait. wt now forwards the user's signal once per process group, so a cooperative child dies from the signal actually sent (130 on Ctrl-C); a second signal kills any survivor immediately. ([#3075](max-sixty/worktrunk#3075))

### Documentation

- **Per-worktree env vars**: A Tips & Patterns section shows how to give each worktree its own environment variables with direnv or mise. ([#3074](max-sixty/worktrunk#3074))

### Internal

- The commit-generation command is not rewritten to disk when its value is unchanged. ([#3084](max-sixty/worktrunk#3084))

## Install worktrunk 0.59.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-installer.sh | sh && wt config shell install
```

### Install prebuilt binaries via powershell script

```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```

### Install prebuilt binaries via Homebrew

```sh
brew install worktrunk && wt config shell install
```

## Download worktrunk 0.59.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) |
| [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) |
| [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.59.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) |



### Install via Cargo

```sh
cargo install worktrunk && wt config shell install
```

### Install via Winget (Windows)

```sh
winget install max-sixty.worktrunk && git-wt config shell install
```

### Install via AUR (Arch Linux)

```sh
paru worktrunk-bin && wt config shell install
```

</pre>
  <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.59.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.59.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants