worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Flaky test: shell_wrapper_preserves_native_compound_interrupts fails because wt is SIGKILLed at launch

Open max-sixty opened this issue 1 month ago • 2 comments

foreground_jobs::shell_wrapper_preserves_native_compound_interrupts failed in all 6 cases during one local pre-merge gate on macOS (v0.81.0, 2026-10-20). The failure looks like a Ctrl-C status bug, but the real wt was killed by SIGKILL as it started, so wt's interrupt handling never ran. I couldn't reproduce it. If it doesn't recur by 2026-11-03, close this issue.

What failed

Every case panicked at the status assertion after the real-wt loop (foreground_jobs.rs#L1535), with 0 or 137 where 130 was expected. In the bash and /bin/bash cases, the captured terminal output contains bash's job report twice, once for wt switch main --yes and once for wt hook post-start --yes --foreground, and no output from wt itself:

Killed: 9                  WORKTRUNK_DIRECTIVE_CD_FILE="$cd_file" command "${execution[@]}"
Killed: 9                  WORKTRUNK_DIRECTIVE_CD_FILE="$cd_file" command "${execution[@]}"
wrapper-prompt>
  left: "0"
 right: "130"
  • 137 (the /bin/bash cases, where the shell continues past the interrupted command) is 128 + 9, the status of the SIGKILLed wt.
  • 0 (the other cases) is the status of the trailing printf. Unlike SIGINT, SIGKILL doesn't make the shell abandon the rest of the compound line.

The panic is after the test's earlier assertions, so those had passed. In a separate run in the same worktree, all 6 cases failed in 0.2s at the test's first wt config shell init, and a rebuild cleared that failure. No stderr was captured for that run.

This doesn't explain #4509. That nightly failure is a 20s hang in a different test, with wt still alive after its children exited.

What was ruled out

  • Nothing in wt SIGKILLs its own process group. terminate_process_group and the capture-timeout kill target only groups wt itself created.
  • The reap and fsmonitor sweeps skip these processes.
  • Shell's Drop in the test only signals groups in its own session.
  • cargo replaces target/debug/wt with a new file on every nextest invocation, but the test runs a pinned hard link under target/debug/wt-test-bin/, which keeps the old file.

Reproduction attempts

All of these ran on main at 93beb0670, and none produced a failure:

  • 24 runs of the 6 cases with 24 CPU busy-loops.
  • 48 runs while cargo re-copied target/debug/wt in a loop.
  • 234 runs beside two concurrent full test suites.
  • The real pre-merge gate with 12 busy-loops and a kernel log stream.
  • 540 runs of copy, hard-link, then exec, the pattern cargo's macOS notes say can get a binary killed (rust-lang/cargo#7821).
  • 240 runs of a #! launcher that is executed, rewritten in place, then executed again.

This test differs from its siblings that passed in one way: it rewrites its launcher script wrapper-recording-binary in place (foreground_jobs.rs#L1507) before the real-wt loop, while the others write theirs once. That makes it the leading suspect, but the rewrite repro above didn't trigger a kill. The macOS unified log for the failure window had rotated away before anyone looked, so the kernel's reason for the kill is unknown.

If it recurs

Capture evidence within about 10 minutes, before the unified log rotates:

/usr/bin/log show --last 10m --predicate 'eventMessage CONTAINS "wt-test-bin" OR eventMessage CONTAINS "Terminating process" OR eventMessage CONTAINS "CODE SIGNING"'

Then run the pinned binary by hand (target/debug/wt-test-bin/*/wt --version) to check whether the kill sticks to that file. Keep the test's temp directory, including wrapper-recording-binary, rather than rebuilding first.

This was written by Claude Code on behalf of max-sixty

max-sixty avatar Oct 21 '26 02:10 max-sixty

No fix or reproduction PR from triage: the kill happened on a local macOS machine, so CI can't observe it, and the 2026-11-03 close-by date already covers the follow-up.

The test hasn't failed in CI either. Since 2026-10-07, every failed workflow run whose logs mention shell_wrapper_preserves_native_compound_interrupts lists all of its cases as ok. That covers seven nightly runs, including 39376521570 behind #4509. Those logs come from the Linux feature-powerset job, so they don't rule out a macOS-only kill. They do show that the test itself isn't flaky in CI.

worktrunk-bot avatar Oct 21 '26 02:10 worktrunk-bot

Closing per the 2026-11-03 close-by date above: no recurrence has been reported here, and none of the 25 failed ci or nightly runs since 2026-10-21 lists shell_wrapper_preserves_native_compound_interrupts as failed. If the SIGKILL shows up again on macOS, reopen with the run or gate output.

worktrunk-bot avatar Nov 05 '26 07:11 worktrunk-bot