Repository navigation
fix(remove): continue after per-target execution failures - #4357
Merged
Merged
Conversation
Ordinary hook and removal failures now report their diagnostics and allow the remaining validated targets to run. Preserve immediate cancellation for interrupted children and return a failing batch status after partial success. Build JSON entries from each successful target so failures cannot shift branch identities. Cover foreground and background hook failures, execution-time dirty refusals, current-last ordering, and SIGINT/SIGTERM cancellation.
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
This changes what wt remove a b c deletes after a failure. Before, a pre-remove hook failure or a Git failure on a stopped the batch, so b and c (and the current worktree, which runs last) were kept. Now those later targets are removed. Each target still has its own validation, pre-remove hook, and Git dirty check, and the user named every target, so this looks intended. But it widens when worktrunk deletes, so under the repo's data-loss hold (.claude/skills/running-tend/references/review-pr.md) the merge decision stays with @max-sixty and this review doesn't approve it.
max-sixty
added a commit
that referenced
this pull request
Oct 20, 2026
…4533) ## What regressed Since v0.80.0, Ctrl-C during `wt remove a b c` no longer stops the batch when the pre-remove hook catches SIGINT and exits normally, as pre-commit does (`trap '...' INT; exit 130`). Reproduced with a hook that traps INT, exits 130 and otherwise sleeps, plus a process-group SIGINT: v0.80.0 stops at `a` and keeps every worktree; current main removes `b` and `c`, branches included, and runs their hooks. `wt step prune` did the same with a hook that exits 0 after catching the key: every candidate was removed and wt exited 0. Two changes combined. #4400 moved foreground children into the caller's native job group and followed the shell's wait-and-cooperative-exit rule, so a child that handles the key keeps its own exit status. #4357 made a multi-target remove continue past a failing target. ## The rule Max chose the batch-runner convention (make, ninja, cargo) over the shell's: Ctrl-C that wt itself receives stops the current command. The terminal delivers SIGINT to the whole foreground job, so wt receives the key alongside the child. A shell waits and exits only if the child died of the signal, because the child might be an interactive program using Ctrl-C as input. A batch runner's steps aren't interactive, and the user pressing Ctrl-C means "stop the batch". For a destructive loop like remove or prune, that rule is also the one the data-safety principle asks for. The child still handles the key its own way, and wt never signals it for INT. Once the child exits, the command starts nothing more and exits interrupted (native SIGINT re-raise / 130), whatever status the child chose. Numeric exit codes such as 130 are still never read as cancellation; wt's own receipt is the evidence. ## What changes - `src/signal_forwarder.rs`: the existing per-operation cancellation (`CommandOperation`) gains a SIGINT flag beside its SIGTERM one. Foreground scopes register it, so the scope reports cancellation when its child exits, and later admissions in the same command are refused. The output drain's fresh flag, which existed to ignore keys the children had already handled, is gone. - Covered loops: hook pipelines (including Warn-strategy post-* hooks), multi-step aliases, `for-each`, multi-target `remove` and `prune`. - A command's final interactive child keeps the key as input and its own exit status: help and `config show` pagers, `--execute` programs and custom `wt-*` subcommands opt in through `Cmd::hand_off_terminal` (`TerminalInterrupt::ChildInput`). So does an alias's last serial step (`ForegroundStdin::HandOff`), since the alias is the whole command; `agent = "claude"` keeps claude's status after the user stops a turn with Ctrl-C. Otherwise pressing Ctrl-C in `less`, a REPL started by `-x` or such an alias, then quitting normally, would turn into exit 130. Earlier alias steps, concurrent groups and every hook step still cancel. - Unchanged: between children, idle SIGINT still kills wt natively. Detached background hooks, timeout-bounded captures in their own process group and the picker hold no foreground scope. A SIGINT sent only to wt is still not forwarded to the child; wt waits for it to finish, then stops. Windows is unchanged: wt installs no console Ctrl-C handler, so the default handler already ends wt and nothing more starts. - AGENTS.md "Signal Handling" and the `signal_forwarder` / `shell_exec` / `concurrent` module docs state the new rule. ## Verification - New unix integration tests, each pressing Ctrl-C (a group SIGINT) after wt has admitted a child that catches it: `remove` with a hook exiting 130 and with one exiting 0 keeps both targets; a post-start pipeline doesn't run its next step after a step exits 130; `for-each` visits one worktree when the child exits 0. All four fail on the old semantics. `test_alias_last_step_keeps_status_after_caught_ctrl_c` covers the alias handoff. The exit-0 remove case also fails if the scope stops reporting the latch and only refuses later admissions, since the current target would still be removed. - Existing tests that asserted the old rule now assert cancellation: the PTY `caught_keyboard_interrupt_cancels_following_step`, `test_alias_pid_signal_policy` (PID-only INT) and `test_alias_group_sigint_does_not_escalate`. The children still handle every key exactly once and wt never dies while they run. `test_alias_caught_sigint_preserves_successful_descendant_output` is deleted because its premise is the old rule. The pager and custom-subcommand cases in `custom_commands_and_help_pagers_preserve_native_signals` pass unchanged. - The alias signal harness moved to `tests/common` as `SignalJob` for reuse. - `cargo nextest run --all-features` (5377 passed), `cargo clippy --all-targets --all-features -- -D warnings`, pre-commit on the changed files. Manual repro of remove and prune before and after. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 task
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.
A pre-remove hook or synchronous Git failure in one target currently stops a multi-target removal before later targets are attempted. Continue with the remaining valid targets, report each ordinary failure, and return exit status 1 if any target failed. JSON includes successful targets in execution order, including branch-only removal and the current worktree executed last.
SIGINT and SIGTERM cancel the batch immediately with exit status 130 or 143. Preserve the underlying error in foreground removal diagnostics so a captured Git interruption reaches the batch cancellation check.
Validation: 5,068 tests passed (one skipped), doctests and documentation build passed, and all final pre-commit checks passed. Integration coverage exercises hook and execution-time removal failures in foreground/background modes, correct JSON attribution, and hook/Git interruptions, including a detached checkout. Four Git-interruption regressions fail against the original executable and pass with this change; independent review found no remaining issues. Help and generated documentation checks passed after updating from main.