Repository navigation
bats: background wrapper trap re-arm for respawned children (Refs #2982) - #3012
Merged
Merged
Conversation
…er prelude (Refs #2982) The background wrapper child (rubash -c) re-defines the parent's functions from a textual prelude, so its function table is incomplete until the prelude has been evaluated — and under functrace/errtrace reset_for_subshell_child leaves the DEBUG and ERR traps live, so they can fire while handler functions (or their callees) do not exist yet, and the failure cascades through the ERR trap (whose handler is likewise undefined). GNU's forked async child never has this window: execute_cmd.c:1576 execute_in_subshell copies the table whole, so the traps only ever fire with every function defined (GNU trap.c:1467/1526: DEBUG kept only under functrace, ERR only under errtrace). Fix: reset_traps_for_background_wrapper (trap.rs) force-resets DEBUG and ERR in the transported table for wrapper spawns only (in-process subshells keep the shared rule), and background_trap_rearm_source ( compound_exec.rs) emits trap '<action>' DEBUG/ERR after the prelude and before the body, so the body still runs traced exactly as GNU's forked child. Single-line, no newline, so the prelude line-offset math is unaffected. Honesty note: the observed trap errors were downstream of the prelude parse truncation (rubash#2982 defect C1, fixed on master by #2990), which left the table partial when the trap fired before the body; this reset closes the window as defense-in-depth for the textual respawn. A minimized inline probe with live DEBUG/ERR traps and a fully-parsing prelude passes on base 3/3 — C2's standalone necessity is therefore NOT independently proven; it is verified behavior-preserving (probe-trap9 10/10, probe-kill4 byte-identical to GNU). This branch stacks on #2990's C1/C3. Pins: tests/issue2982_background_wrapper_trap_prelude_regressions.rs (3 tests) and tests/issue2983_background_wrapper_pgrp_kill_regressions.rs (1 test, guards the pgrp mechanism only — #2983's bats-stack root is Finding E, blocked on #2995, and gets NO PR from this lane).
…-depth The three issue2982 pins cover the prelude rendering regressions (quoted-empty [[ ]] word, for-word carrier leak) fixed by merged #2990 (fb96e74), not by this PR's C2 trap reset. Rewriting the file header so the attribution is accurate, and recording the honesty note: no independently fail-first probe shape for C2 alone was found (definitions skip DEBUG, the respawned child reads no startup file, the prelude is definitions-only), so C2 stays defense-in-depth, behavior-preserving, not pin-proven. Refs #2982
caomengxuan666
marked this pull request as ready for review
November 7, 2026 21:13
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.
Refs #2982.
Root cause: the background wrapper child is respawned from text rendered
by background_function_prelude(). The [[ ]]/for/select rendering defects
(C1/C3) were fixed on master by #2990 (fb96e74); this PR adds the
remaining defect:
(C2) inherited DEBUG/ERR traps stayed live while the prelude re-defined
functions, so traps fired against an incomplete table (GNU's forked
async child never has this window: execute_cmd.c:1576
execute_in_subshell). Fix: reset DEBUG/ERR for the wrapper child and
re-arm them after the prelude (src/builtins/trap.rs,
src/executor/compound_exec.rs). See lane REPORT for the C2 honesty note
(standalone necessity not independently proven; closes a window GNU's
fork never has).
Regression pins: tests/issue2982_background_wrapper_trap_prelude_regressions.rs
(3 tests) and tests/issue2983_background_wrapper_pgrp_kill_regressions.rs
(1 test, pgrp mechanism), fail-first on base, green after fix. Based on
the current master tip (includes #2990's C1/C3).
#2983 (file_setup_teardown #8) is NOT closed by this PR: its root is
Finding E (bats-stack SIGINT/teardown fails only in the full
driver→suite→file→test process tree; exec-file/exec-test die by SIGINT
instead of running their INT traps), blocked on filed #2995 (sleep
fastpath) + a dedicated engine investigation. A redirect-target
hypothesis (C4, 0x13 in
>> $VARtargets) was investigated andREFUTED (the child's lexer consumes its own marker; the pin did not
fail-first) and reverted. See lane REPORT.
Self-verification (rebased onto master 874d12c, verified 2026-11-08):
pin stems 3/3 + 1/1; lib three-counts 1188/0/4, identical to master;
RUSTFLAGS="-D warnings" cargo check rc=0; hygiene script clean;
per-file rustfmt clean; release full-file: file_setup_teardown.bats
16/17 (#8 = Finding E, blocked on #2995).