Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(alias): report an alias child killed by a signal other than INT/TERM (#4523)

Maximilian Roos4874f33c292b
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index ad1ca568a..bbd3d2334 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -677,16 +677,36 @@ pub fn hook_error_wrapper(
/// Build the standard `ErrorWrapper` for alias steps.
///
-/// Children that report a child exit code surface as `AlreadyDisplayed` so
-/// `wt` propagates the alias's exit status. Anything else (template errors,
-/// spawn failures) is wrapped with the alias and configured member names.
+/// Children that exit with a code surface as `AlreadyDisplayed` so `wt`
+/// propagates the alias's exit status; the child reported its own failure.
+/// A child killed by any other signal than INT/TERM (those short-circuit in
+/// [`handle_command_error`]) surfaces as `Interrupted`, which renders
+/// `Killed by signal N` as a custom subcommand does: `wt` exits with
+/// `128 + N` rather than dying by the signal, so no shell reports it.
+/// Anything else (template errors, spawn failures) is wrapped with the alias
+/// and configured member names.
pub fn alias_error_wrapper(alias_name: String) -> ErrorWrapper {
- Box::new(move |cmd, error| match error.exit_code() {
- Some(code) => WorktrunkError::AlreadyDisplayed { exit_code: code }.into(),
- None => error.context(match &cmd.name {
- Some(name) => format!("Failed to run alias '{alias_name}' command '{name}'"),
- None => format!("Failed to run alias '{alias_name}'"),
- }),
+ Box::new(move |cmd, error| {
+ if let Some(WorktrunkError::ChildProcessExited {
+ physical_signal: Some(signal),
+ ..
+ }) = error
+ .chain()
+ .find_map(|cause| cause.downcast_ref::<WorktrunkError>())
+ {
+ return WorktrunkError::Interrupted {
+ signal: *signal,
+ hint: None,
+ }
+ .into();
+ }
+ match error.exit_code() {
+ Some(code) => WorktrunkError::AlreadyDisplayed { exit_code: code }.into(),
+ None => error.context(match &cmd.name {
+ Some(name) => format!("Failed to run alias '{alias_name}' command '{name}'"),
+ None => format!("Failed to run alias '{alias_name}'"),
+ }),
+ }
})
}
diff --git a/src/git/error.rs b/src/git/error.rs
index 88c5ce474..1e7f58975 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -1839,7 +1839,7 @@ pub enum WorktrunkError {
///
/// Exits `128 + signal`; Unix INT/TERM are passed to the parent shell.
/// Native job messages belong to that shell, while recovery hints belong
- /// to wt. Custom commands may also report other signal-derived exits here.
+ /// to wt. Custom commands and aliases also report other signal deaths here.
Interrupted { signal: i32, hint: Option<String> },
}
diff --git a/tests/integration_tests/step_alias.rs b/tests/integration_tests/step_alias.rs
index 9e35ded2d..9a711bb11 100644
--- a/tests/integration_tests/step_alias.rs
+++ b/tests/integration_tests/step_alias.rs
@@ -409,6 +409,25 @@ fail = "exit 42"
));
}
+/// An alias child killed by a signal other than INT/TERM is reported: the
+/// child printed nothing about its death, and wt exits `128 + signal` rather
+/// than dying by it, so no shell reports it either.
+#[cfg(unix)]
+#[rstest]
+fn test_step_alias_killed_by_signal(repo: TestRepo) {
+ repo.write_test_config(
+ r#"
+[aliases]
+crash = "kill -KILL $$"
+"#,
+ );
+
+ let settings = setup_snapshot_settings(&repo);
+ let _guard = settings.bind_to_scope();
+
+ assert_cmd_snapshot!(make_snapshot_cmd(&repo, "step", &["crash"], None));
+}
+
/// Alias from user config works
#[rstest]
fn test_step_alias_from_user_config(mut repo: TestRepo) {
diff --git a/tests/snapshots/integration__integration_tests__step_alias__step_alias_killed_by_signal.snap b/tests/snapshots/integration__integration_tests__step_alias__step_alias_killed_by_signal.snap
new file mode 100644
index 000000000..f0ca0b3f7
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_alias__step_alias_killed_by_signal.snap
@@ -0,0 +1,63 @@
+---
+source: tests/integration_tests/step_alias.rs
+assertion_line: 428
+info:
+ program: wt
+ args:
+ - step
+ - crash
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_ALLOW_PROTOCOL: file
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_AUTHOR_EMAIL: [email protected]
+ GIT_AUTHOR_NAME: Test User
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_EMAIL: [email protected]
+ GIT_COMMITTER_NAME: Test User
+ GIT_CONFIG_COUNT: "2"
+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
+ GIT_CONFIG_KEY_0: user.useConfigOnly
+ GIT_CONFIG_KEY_1: rerere.enabled
+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
+ GIT_CONFIG_VALUE_0: "true"
+ GIT_CONFIG_VALUE_1: "false"
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 137
+----- stdout -----
+
+----- stderr -----
+✗ Killed by signal 9