Skip to content

fix: signal trap coverage for all trappable signals (#1511) + part_036 job-notification visibility - #1527

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix4/slice-sig
Oct 25, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix4/slice-sig

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fourth-wave slice: signal trap coverage (#1511) + the part_036 in-process job-notification regression (no standalone issue; tracked since the slice-4 integration report). Two commits cherry-picked from the sig cluster branch onto current master, zero conflicts, patches identical to the cluster originals.

Fixes #1511


1. #1511 — traps on non-hosted signals never reached the kernel

Root cause. The kernel_signals backend in src/builtins/kill.rs managed kernel dispositions for only seven signals (HUP/INT/QUIT/TERM/USR1/USR2/PIPE) plus the SIGSEGV/SIGBUS fatal pair. A trap on any other signal was recorded in the trap table, but reconcile never installed a handler or SIG_IGN at the kernel:

  • trapped terminating signals (ILL TRAP ABRT FPE ALRM STKFLT XCPU XFSZ VTALRM PROF IO PWR SYS RTMIN..RTMAX) still killed the shell by their default action, handler never ran; trap '' SIG never became a real SIG_IGN;
  • trapped URG/WINCH (default-ignore) were never delivered;
  • a 30-signal trap storm died at SIGILL (rc=132, no output).

(The brief's older note that untrapped kill -SEGV $$ survived with rc=0 was already fixed by #1475 in slice 4 — re-measured on current master: untrapped SEGV/BUS die 139/135. Not re-fixed here.)

Fix (all in src/builtins/kill.rs).

  • Managed set extended to every trappable signal the trap table can name: the named signals plus the POSIX realtime block (SIGRTMIN()..=SIGRTMAX() on linux/android; no RT block on Darwin/BSD, matching GNU signames.c). SIGCHLD (owned by the reap dispatcher) and the stop signals TSTP/TTIN/TTOU stay unregistered by existing design.
  • ILL/FPE cannot go through signal-hook-registry (it panics on registration — hit during development), so they join SEGV/BUS in the fatal backend (array 2→4), whose si_code split routes kill-sent signals to shell semantics and chains genuine faults to the previous disposition.
  • Disposition state widened to two packed words; the trap-key table is built once at runtime (RT bounds are runtime values).
  • EXIT rerouting gate follows GNU's compile-time terminating set, oracle-verified: ALRM/ABRT/ILL/FPE/TRAP/PROF/SYS/XCPU reroute through an armed EXIT trap; RTMIN and URG/WINCH do not. ILL/FPE reroute in the fatal map; SEGV/BUS keep the [bug] SIGSEGV sent to the shell itself is swallowed (kill -SEGV $$ has no effect) #1475 no-reroute ruling.
  • Reconcile fast path is now a single prefix scan over the trap env keys instead of probing seven static keys.

Verification vs GNU bash 5.3.20. Per-signal matrix, 30 signals × 3 forms (trapped / untrapped / ignored): all OK. 30-signal storm byte-identical to GNU (rc=0, all 30 handlers run). EXIT-reroute probes (ALRM / URG / WINCH / XCPU + ILL/FPE spot checks) all match. Regression tests: tests/signal_trap_coverage_regressions.rs, 7 issue_1511_* tests with GNU expectations, in the same commit.

2. part_036 — background job completion became visible too early

Root cause. Regression introduced by slice 4 (PR #1509), recorded in its integration report. The per-command boundary reap applied a background job's completion to the job table the moment try_wait returned it. GNU's waitchld state becomes visible only at observation points: the reader pulling a new line, a blocking wait_for (which reaps background children while it blocks, jobs.c:3064), or an explicit wait/fg. In a single read (-c / in-process list), kill followed only by builtins has no observation point, so GNU still lists the job as Running; rubash listed Terminated (test_kill_jobspec_keeps_job_listed_until_reap failed; script-file form was unaffected because each line is its own read).

Fix (executor layer, main logic in src/executor/job_builtins.rs). Reap results for non-coproc jobs are stashed in pending_job_completions and applied when the observation mark (execute_ast generation, current reader line, foreground wait count) has advanced since the last refresh, or immediately at wait/fg entry points. Foreground wait count is wired into wait_external_child, pipeline tail/stage waits, and the native sleep fast path (GNU's sleep is a real child whose wait_for is an observation point; rubash's in-process sleep simulates one). Coproc disposal keeps its per-command contract (#1023); capture-writer retirement and forwarder joins stay immediate (I/O hygiene, not table visibility).

Verification. Four binary spot-check forms match GNU exactly (-c kill/printf/jobs/wait → Running + after:0; script file → Terminated; kill+sleep+jobs → Terminated; natural death + sleep → Done; after foreground pipeline wait → Done). executor_tests segmented run: part_036 33/33 (baseline 32/33, the failing test now passes unmodified), part_035 21/21.

Slice verification (integration tree)

  • cargo build --locked: PASS
  • tests/signal_trap_coverage_regressions.rs: in the gated pipeline run the storm test failed once under machine load (6/7); adjudicated in isolation on the same tree — storm test 3/3, full target 7/7 twice. The test fires 24 signals and is timing-sensitive under contention; the cluster tree also passed 7/7.
  • executor_tests part_036: 33/33; part_035: 21/21
  • cargo test --lib: 728 passed / 1 failed — the only failure is ownership_unary_operators_check_existing_file, the known root-environment item
  • 246 differential vs GNU 5.3.20: 244 PASS / 2 FAIL = {gl08, ms10}, the standing baseline set
  • Changed files: CR count 0. Formatting: the slice preserves the cluster commits byte-for-byte. The local rustfmt (1.10.0, 2026-10) reports re-wrap diffs against the repo's committed style — including 40 hunks on pristine master in files this slice does not touch — so this is toolchain version drift, not slice debt; the slice's new code follows the surrounding committed style.

Known residuals (as-is, recorded in the cluster report)

  • Fatal-set trap '' is handler-discard rather than a kernel SIG_IGN ([bug] SIGSEGV sent to the shell itself is swallowed (kill -SEGV $$ has no effect) #1475's existing trade-off, now inherited by ILL/FPE): after a real exec replacement, caught signals reset to SIG_DFL per kernel rules, whereas GNU's true SIG_IGN survives exec. Forked subshell paths are covered by the existing restore mechanism.
  • A genuine hardware ILL/FPE fault with a trap set does not fire the trap: the fatal handler chains si_code>0 faults to the previous disposition. Deliberate divergence — GNU's termsig handler likewise only sets a flag and returns into the faulting instruction (a loop); kill-sent delivery (si_code≤0) matches GNU exactly.
  • SIGCHLD trap delivery surface (driven from reap points) and stop-signal registration are unchanged from baseline by design.
  • part_036's observation-point model is an approximation: blocking builtins such as read also make waitchld state visible in GNU but are not counted as observation points here (no suite form exercises it; baseline behavior not worsened). REPL lines are covered via the execute_ast generation.

…511)

The kernel-signal backend managed dispositions for only seven
signals (HUP/INT/QUIT/TERM/USR1/USR2/PIPE) plus the SIGSEGV/SIGBUS
fatal pair. A trap on any other signal changed nothing at the
kernel: trapped terminating signals (ILL TRAP ABRT FPE ALRM STKFLT
XCPU XFSZ VTALRM PROF IO PWR SYS RTMIN..RTMAX) still killed the
shell by their default action with the handler never running,
trap '' SIG never installed SIG_IGN, and trapped URG/WINCH were
never delivered. A 30-signal trap storm died at SIGILL.

- Extend the managed set to every trappable signal the trap table
  can name: the named signals plus the POSIX realtime block
  (libc SIGRTMIN()..=SIGRTMAX() on linux/android). Disposition
  state widens to two packed words; the trap-key table and the
  boundary reconcile are built once at runtime. The reconcile fast
  path now detects armed traps with one __RUBASH_TRAP_SIG prefix
  pass instead of probing a fixed key list.
- SIGILL/SIGFPE cannot ride the signal_hook backend (its registry
  panics: "Attempted to register forbidden signal"), so they join
  the fatal set (SIGSEGV/SIGBUS) whose sigaction handler splits
  SENT deliveries (shell semantics) from hardware faults (chain).
- EXIT-trap reroute (sig.c:226-229) applies to the managed set
  except the default-ignore pair and the realtime block, which
  GNU's compile-time terminating set cannot name (oracle-verified);
  SIGILL/SIGFPE reroute through the fatal mapping, SIGSEGV/SIGBUS
  keep their existing no-reroute rule.

Oracle matrix (GNU bash 5.3.20): 30 signals x trapped/untrapped/
ignored forms all match, the 30-signal storm completes with every
handler run, EXIT-reroute probes match. SIGCHLD (owned by the reap
dispatcher) and the stop class stay unregistered by design.

Regression tests: tests/signal_trap_coverage_regressions.rs
(issue_1511_* — trapped/ignored/untrapped/reset forms, EXIT
reroute and its exclusions, the storm).
…_036)

Regression from the fourth slice (PR #1509): the per-command
boundary reap applied a background job's completion to the job
table the moment try_wait returned it, so in a single read
(-c / in-process list) `jobs` after a jobspec kill already listed
the job as Terminated. GNU bash 5.3.20 lists it as Running there:
waitchld state becomes visible only at observation points — the
reader pulling a new line, a blocking wait_for (which reaps
background children while it blocks, jobs.c:3064), or an explicit
wait/fg. Script-file form was unaffected (each line is its own
read) and still shows Terminated.

- refresh_background_jobs now stashes reap results for non-coproc
  jobs in pending_job_completions and applies them when the
  observation mark (execute_ast generation, reader command line,
  foreground wait count) has advanced since the previous refresh,
  or immediately when the refresh itself observes (wait/fg form,
  refresh_background_jobs_observed). Coproc disposal keeps its
  per-command contract (rubash#1023); capture-writer retirement
  and forwarder joins stay immediate (I/O hygiene, not table
  visibility).
- Foreground waits note the observation counter: the unix wait in
  wait_external_child, pipeline tail/stage waits (wait and
  wait_with_output forms), and the native sleep fast path — GNU
  sleep is a real child whose wait_for is an observation point,
  and rubash's in-process sleep emulates it (the part_036 suite
  itself uses `sleep 0.3` as the observation delay).

executor_tests part_036: 33/33 (baseline 32/33, the titled test
failing); part_035 stays 21/21; the remaining segment failures
match the baseline set name-for-name (modulo glob/cwd-sensitive
flakes). The titled test itself is the regression test — it
already asserted the GNU behavior and now passes unmodified.
@caomengxuan666
caomengxuan666 merged commit 6ae2a84 into master Oct 25, 2026
5 of 8 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 25, 2026
…e debugger design (#497) (#1535)

Both designs were approved as written by the owner on 2026-10-25 and are
finalized together as one 1.5.0 implementation program (split and
debugger interleaved, module by module).

- 1.5.0-session-api.md extends docs/design/1.5.0-workspace-and-engine-api.md
  (the #595 RFC): section 11 Q1-Q8 are decided per the recommendations
  recorded there, with a decision record in section 12. Q4: the syntax
  surface is tier-B api::syntax view types; the internal Ast is not
  frozen into tier A. Q5: the threading contract is explicitly
  single-threaded, one Session per thread.
- debugger-full-design.md extends docs/design/debugger-m0.md (the #497
  M0 draft of record) and does not supersede it: section 14 Q1-Q5 are
  decided per the recommendations recorded there (Q1 stop at first
  command; Q2 session core built in-tree now, shaped for rubash-core;
  Q3 conditions stay full shell commands; Q4 trace via the xtrace fd
  machinery; Q5 engine-level injectable command stream), with the
  finalization recorded in section 15. Prerequisites P-1 (#1184 f4,
  PR #1522) and P-2 (#1511, PR #1527) are marked landed.

Docs only; no code changes.

Co-authored-by: 曹梦轩 <[email protected]>
@caomengxuan666
caomengxuan666 deleted the fix4/slice-sig branch October 30, 2026 01:41
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.

[bug] Signal trap coverage gaps: 15 signals never run their trap; untrapped SIGSEGV/SIGBUS are swallowed (rc=0 survival)

1 participant