Repository navigation
fix(trap): ERR-trap nested-context semantics — collapse suppression, flat-region fire, return attribution (rubash#720) - #831
Conversation
CR verdict: REQUEST-CHANGESThe three claimed forms are correct and byte-pinned (I re-derived every transcript independently against WSL GNU 5.3.0(1) via the stdin oracle; 12/12 new tests + issue797 8/8 pass on my own runs). What blocks merge is R1: the PR's central coverage claim — "every region close path runs close_flat_region_err_adjudication after the parent-state restore" (commit message; ast_exec.rs close-path comments) — is falsified by three reachable flat-region exits that run no close at all (neither state restore nor form-2 fire). All three are byte-divergent vs GNU and byte-identical to base R1 — three flat-region close paths have no close: missed form-2 fire + permanent ShellState/
|
d297f7b to
e2fcb78
Compare
…bash#720) The CR round overturned the "every region close path adjudicates" claim with three reachable flat-region exits that neither restored the saved parent state nor ran the :769 fire; probing found a fourth (brace-group Ok(true)) and the catch-alls of the four early dispatch arms shared the same leak. All fixed structurally now: - and_or_list / brace / simple_pipeline / main-dispatch (plus the pipeline, inverted, time, background and time-prefixed arms): the fall-through and Ok-arms run close_subshell_region_if_ended!, and every catch-all closes before the unwind crosses the boundary — the saved parent state (variables, subshell_depth, trap table) can no longer leak across `f() ( ... )` exits. - `return N` inside a flat region is absorbed at the boundary as a plain status-N completion: GNU's return.def:57-76 return_builtin longjmps the CHILD's own return_catch and the child exits N; the parent observes the wait status and the function continues after the region (the node-form boundary already documented this absorption). `f() ( x=v; return 4 ); f` now fires twice with the region text `( x=v; return 4 )` and x stays clean — the first cut leaked x=v and reported a stale BASH_SUBSHELL. - lastpipe `exit N` inside a region is likewise a child completion (the "current shell" of the region's stand-in), absorbed instead of unwinding to the top level; the top-level propagation keeps the #74 G2 semantics. - and-or non-last elements no longer fire the ERR trap: GNU marks every &&/|| operand CMD_IGNORE_RETURN except the finally-executed one (execute_cmd.c:2943; execute_cmd.c:1000 refuses on ignore_return) — `g() ( false && true ); g` fired `false` where GNU fires only the region and the call. CR nits: the return.def anchor corrected (:112-115 was dead — the mechanism is return.def:57-76 return_builtin + get_exitstat, builtins/common.c); CHANGELOG Unreleased entry added. Tests: +5 cases in tests/issue720_err_trap_nested_context_regressions.rs (17 total), each the literal WSL GNU bash 5.3.0(1) transcript. Final 14-form battery identical to GNU; goldens 74/74, issue797 8/8, audit harness 45 cases (same 4 known findings, none new), full-suite no-fail-fast comparison against the stashed origin/master baseline: zero new failures.
CR round 2 — addressed (e2fcb78, rebased on a87f826/#823)Coverage — accepted in full, and widened. All three cited paths reproduce and are fixed, plus two more of the same class found while enumerating the walker:
The structural form: every catch-all in the walker now runs State leak — zero. Two adjacent classes fixed in the same sweep:
Nits — both done. The Verification: |
CR round 2 — verified, verdict: APPROVE-WITH-NITSAll checks re-run independently (WSL GNU 5.3.0(1) stdin/file oracle vs Coverage (①) — confirmed byte-identical, all five shapes:
State leak (②) — zero, byte-proven: Walker completeness (③) — the round-2 structural rule is sound (every catch-all closes before
Also pre-existing (base-identical, diagnostic-only, note for the tracker): and_or marker change (pipeline_exec.rs) — parity-checked: Suites (④) — pass on my runs: issue720 17/17, issue797 8/8, audit harness 45 cases / same 4 known divergences (#825/#826). fmt clean. Hygiene (⑤) — clean: round-1 content is byte-identical after the rebase onto a87f826 (diffed No merge from my side; worktree |
…flat-region fire, return attribution (rubash#720) Three facets of the set -E ERR adjudication at subshell boundaries, all byte-pinned against WSL GNU bash 5.3.0(1) (stdin oracle): - Form 1, nested subshell fire count: GNU marks a user subshell's WHOLE body CMD_NO_FORK when it is a single subshell command (execute_cmd.c:1799-1806) and dispatches it in place — no make_child/wait_for — so the middle frame of ( (false) ) never adjudicates and GNU fires twice, not three times. Rubash now scopes a subshell_fork_collapse flag around exactly that body shape (node form in execute_subshell_command_with_redirects, flat form at the ast_exec region open) and skips the aggregate ERR adjudication under it, including the set -e early conversion (command_execute.rs). - Form 2, f() ( ) flat region: the completion ERR fire belongs to the frame that waited (execute_cmd.c:756-778, no &&/|| exemption, LINENO = the subshell's close-paren line per execute_cmd.c:696, BASH_COMMAND = the region's print_cmd text per the :703-710 fork preamble). The forkless region had no boundary fire — f() ( false ); f fired twice where GNU fires three. The parser now stamps the opener's end_line with the ) line, and every region close path runs close_flat_region_err_adjudication after the parent-state restore. - Form 4, return-in-until attribution: a return N unwinding through dispatch is the builtin's own completion (return.def:112-115); the dispatcher gate fired with the loop condition's stale status and lost the N. The gate now passes Err(Return) through to the function/source boundary, which stamps exit_code = N before the call's own gate adjudicates — ERR:7 / exit 7, matching GNU. Form 3 (cat <(false), the procsub copy path) stays tracked in #720 — it is the PR #715 read/procsub reaping area, not a trap-context fix. Companion #713 second pass: docs/audit/context-inheritance.md (the context x property inheritance/isolation table), nested-context-probes extended 24 -> 45 cases, and two new defect tickets found by the audit (#825 -T DEBUG not inherited into $( ), #826 compound redirection-failure diagnostic bypassing the ordered fd table). Tests: tests/issue720_err_trap_nested_context_regressions.rs (12 cases, one per form/edge, GNU transcripts pinned). Goldens 70/70, issue797 8/8, full-suite bidirectional comparison against origin/master shows no new failures.
…bash#720) The CR round overturned the "every region close path adjudicates" claim with three reachable flat-region exits that neither restored the saved parent state nor ran the :769 fire; probing found a fourth (brace-group Ok(true)) and the catch-alls of the four early dispatch arms shared the same leak. All fixed structurally now: - and_or_list / brace / simple_pipeline / main-dispatch (plus the pipeline, inverted, time, background and time-prefixed arms): the fall-through and Ok-arms run close_subshell_region_if_ended!, and every catch-all closes before the unwind crosses the boundary — the saved parent state (variables, subshell_depth, trap table) can no longer leak across `f() ( ... )` exits. - `return N` inside a flat region is absorbed at the boundary as a plain status-N completion: GNU's return.def:57-76 return_builtin longjmps the CHILD's own return_catch and the child exits N; the parent observes the wait status and the function continues after the region (the node-form boundary already documented this absorption). `f() ( x=v; return 4 ); f` now fires twice with the region text `( x=v; return 4 )` and x stays clean — the first cut leaked x=v and reported a stale BASH_SUBSHELL. - lastpipe `exit N` inside a region is likewise a child completion (the "current shell" of the region's stand-in), absorbed instead of unwinding to the top level; the top-level propagation keeps the #74 G2 semantics. - and-or non-last elements no longer fire the ERR trap: GNU marks every &&/|| operand CMD_IGNORE_RETURN except the finally-executed one (execute_cmd.c:2943; execute_cmd.c:1000 refuses on ignore_return) — `g() ( false && true ); g` fired `false` where GNU fires only the region and the call. CR nits: the return.def anchor corrected (:112-115 was dead — the mechanism is return.def:57-76 return_builtin + get_exitstat, builtins/common.c); CHANGELOG Unreleased entry added. Tests: +5 cases in tests/issue720_err_trap_nested_context_regressions.rs (17 total), each the literal WSL GNU bash 5.3.0(1) transcript. Final 14-form battery identical to GNU; goldens 74/74, issue797 8/8, audit harness 45 cases (same 4 known findings, none new), full-suite no-fail-fast comparison against the stashed origin/master baseline: zero new failures.
e2fcb78 to
c0005ff
Compare
…-free — failglob verdicts stay in the child (753.11) The gate expands the async command's words in the PARENT as an eligibility probe (background_direct_external_command -> expand_command_words); on failglob that probe (a) printed `no match` in the parent — the wrapper fallback's child re-reported it, doubling the diagnostic on the `&` line — and (b) armed the parent-side expansion latches (command_expansion_failed, evalerror_pending, evalerror_failglob_pending, exit_code=1), whose reader-level discard swallowed the rest of the launch line (`set -- /no/such/*.zzz & echo BG_after` lost its echo entirely). GNU expands the forked child's words inside the child: the parent never observes the verdict, the diagnostic prints once, and the launch line's remaining commands run. Fix: the probe runs under an expansion_probe_active flag — report_failglob stays silent while it is set — and the Err path restores the expansion latches and the pre-probe exit code before falling back to the wrapper, whose child reports exactly once. Attribution note: this is a master regression from the #809 train (28744c8 + CR rounds), reproduced on 5d51376 WITHOUT any #831 change; the bisect is 0d87020/e2fcb78f PASS -> c0005ff (rebase onto 5d51376) FAIL. It surfaced on this branch only because the rebase picked the regression up. The CR-round-2 collapse hypothesis does not hold — the failing shape is a background `&`, not `( (… ) )`, and the collapse flag is inert without a flat region. Tests: tests/regression.rs issue_753 suite 17/17 (case_11 included); failglob x collapse on/off battery (( (… ) ) collapsed, multi-command uncollapsed, f() ( ) flat, `&` gate, plain ( )) byte-identical with WSL GNU 5.3.0(1); issue720 17/17, issue797 8/8, goldens 74/74, audit harness 45 cases (same 4 known findings); ERR 14-form battery identical.
CR round 3 — case_11 fixed (63f40f3); attribution corrected: master regression, not the collapse flagBisect (case_11
The collapse-mechanism hypothesis does not hold: the failing shape is a background Mechanism (confirmed in code): Fix (63f40f3): the probe is now side-effect-free — it runs under Verification:
|
CR round 3 — 63f40f3 (probe side-effect fix): verdict APPROVEAll four review points re-verified independently (WSL GNU 5.3.0(1) oracle, own scripts): ① Flag mechanism — boundaries tight, no leak paths. ② Err recovery — complete and exact. The five latches the reachable probe surface can arm ( ③ Cherry-pick coexistence — zero coupling. The flag gates only the diagnostic print; no ERR-attribution site reads it, and the latch restore lands before any parent-side adjudication, so the silence window can neither create nor suppress an ERR fire. Empirically, ④ Suites — pass on my runs: regression.rs Two standing notes, unchanged from round 2 and non-blocking: the "goldens 74/74" arithmetic still reads 73+1 on my run (the same pre-existing No merge from my side; |
Closes the three fixable faces of #720 (form 3 stays tracked there); second #713 pass ships in the same train: the nested-context inheritance/isolation audit doc, the probe harness extension, and two defect tickets filed from it (#825, #826).
Forms fixed (all byte-pinned against WSL GNU bash 5.3.0(1), stdin oracle)
Form 1 —
( (false) )fired 3, GNU fires 2 (nested subshell over-fire)GNU marks a user subshell's WHOLE body
CMD_NO_FORKwhen it is a single subshell command (execute_cmd.c:1799-1806 in the vendored 5.3 mirror) and dispatches it in place (execute_cmd.c:662-663) — no secondmake_child/wait_for, so the middle frame never observes the failure and its :769run_error_trapnever runs. Rubash's forkless( )runs every body in place, so its middle frame "waited" and over-fired. Fix: asubshell_fork_collapseexecutor flag scoped to exactly that body shape (node form inexecute_subshell_command_with_redirects; flat form at the ast_exec region open), consulted by the aggregate ERR site and by theset -eearly conversion. Non-collapsed middles still fire (( (false); false ),( { (false); } )keep the middle fire — probes included).Form 2 —
f() ( false ); ffired 2, GNU fires 3 (flatf() ( )region under-fire)The body subshell's completion ERR adjudication belongs to the frame that waited for its fork (execute_cmd.c:756-778 — no
&&/||exemption there;$LINENO= the subshell's own)line per execute_cmd.c:696;BASH_COMMAND= the region's print_cmd text fixed by the :703-710 fork preamble). The forkless flat region had no boundary fire. Fix: the parser stamps the region opener'send_linewith the)line (parse_parenthesized_function_body), and every flat-region close path runsclose_flat_region_err_adjudicationafter the parent-state restore. The call-site fire now reports( false )like GNU instead off.Form 4 —
until false; do f; donewithf(){ return 7; }printedERR:1/exited 1, GNU printsERR:7/exits 7A
return Nunwinding through dispatch is the builtin's own completion (return.def:112-115 jumps only for an out-of-range count); the function boundary stampsexit_code = Nand the CALL's gate adjudicates. The dispatcher gate was firing with the loop condition's stale status and consuming theReturnunwind. Fix: the gate passesErr(Return)through in function/source context; the boundary stamps; the call's gate fires with 7 and converts underset -e.Not in this PR
Form 3 (
cat <(false), the process-substitution copy path) is the PR #715 read/procsub reaping area — stays tracked in #720.#713 second pass (audit, not fixes)
docs/audit/context-inheritance.md— the context × property inheritance/isolation table (( )/$( )/ pipeline stage / function /sh -c/&against fd table, traps, diagnostic ownership, compound-redirect status, stdin/EOF, dup ordering), each cell marked matches-GNU / intended divergence / unknown, anchored to vendored trap.c/execute_cmd.c file:line.scripts/audit/nested-context-probes.pyextended 24 → 45 cases; current run:cases=45 divergences=4(all four are the two new defects below).set -TDEBUG trap not inherited into$( )(GNU keeps it: trap.c:1469-1471 clears only whenfunction_trace_mode == 0).2>err.txtcapture dropped, leaks across a subshell's2>err.txt(status is correct everywhere; redirection & fd:2>&1 >fileorder, builtin write-error routing, closed-stderr status, subshell-uncapturedcderror, bare-catsame-file #699-family, new faces + probes).Verification
tests/issue720_err_trap_nested_context_regressions.rs— 12 cases, one per form/edge, GNU transcripts pinned. 12/12 green.--test regression(GNU goldens + upstream snapshots): 74/74 green (rebased on fix(tilde,cd,pushd): one HOME baseline per operation — GNU missing-vs-empty (rubash#754) #819).issue797_bash_preexec_debug_trap_regressions(fix(prompt,source): PROMPT_COMMAND leaves $_ at the user's last word; source scopes the DEBUG entry trap in the trap table (#797); pin the #798 sandbox truth #807's ignore-shape suite): 8/8 green — the fix(prompt,source): PROMPT_COMMAND leaves $_ at the user's last word; source scopes the DEBUG entry trap in the trap table (#797); pin the #798 sandbox truth #807 trap-table-membership semantics are untouched;get_trap_action's Some/None remains the only trapped/untrapped source of truth.wsl -e bash -svsrubash -c, identical script): IDENTICAL on the full 10-form battery — counts,$BASH_SUBSHELL,$LINENO,$BASH_COMMAND, exit statuses.origin/master(stashed baseline build, same worktree): failure sets identical except one flaky path-cache unit test that passes 5/5 in isolation on this branch; zero new failures. ~30 pre-existing local-environment failures (helpers/external-process suites) are identical on both sides.cargo fmtapplied; GPL red line respected (anchors and quotes are file:line references and <10-word excerpts of the vendored mirror).