Skip to content

fix(wave3): P3 batch — xtrace case word, redirect message fidelity, caller stack limit, trap -p ERR display, extdebug DEBUG-skip sites, syntax-error echo, job signal notice (#517 #518 #519 #520 #521 #522 #550) - #569

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/wave3-p3-batch
Oct 12, 2026

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

P3 batch (Wave3): seven issues, each root-caused against the vendored GNU bash 5.3.0 C source (third_party/bash @ b4608166) and byte-verified against WSL GNU Bash 5.3.0 (script-file / stdin-harness probes, 2026-10-12).

Issue Root cause Fix GNU anchor
#517 xtrace case head printed the quote-stripped lexer value; the 0x13 PARAM_NAME_END_MARKER boundary byte leaked raw (+ case $x^S in) trace the raw word (word_metadata.raw), decoded at the output boundary xtrace_print_case_command_head print_cmd.c:742-749 (prints word->word with source quotes)
#518 (a) dup word operand carried the 0x1d STORAGE_WORD_PREFIX role marker -> wrong class + marker leak; the function-invocation fast path bypassed the redirect gate; (b) append-open errors propagated bare OS errors, so the renderer dropped the word strip the role marker in expand_redirect_target; run reject_invalid_redirects on the function path; path_error-map every append open redir.c:784-843 (TRANSLATE_REDIRECT), redir.c:149-176 (redirection_error), redir.c:246 (do_redirections for every command kind)
#519 indexed_array_stack("FUNCNAME") padded a synthetic main frame unconditionally -> caller 2 at g→f depth invented 10 main <path> rc=0 gate the push behind has_script_main_frame() (same as the dynamic_stack_array_values view) shell.c:1636-1648 open_shell_script pushes FUNCNAME "main" for script files only; caller.def:108-121 absent element -> EXECUTION_FAILURE
#520 trap -p ERR inside a function showed the inherited trap; the display disagreed with the (already correct) non-inherited firing save/clear the ERR action at function entry unless set -E, restore at exit execute_cmd.c:5279-5286 restore_default_signal (ERROR_TRAP) + uw_maybe_set_error_trap
#521 DEBUG-skip decision computed then ignored at compound fire sites; the predicate itself was status==2 with no extdebug gate predicate is now extdebug && status != 0; decision honored at case/select head, for header, arith-for init/test/update, pipeline stage, function entry; $? preserved across a firing execute_cmd.c:3057/3191/3532/3672/3924/4157/4510/5391; $? preservation probe-verified (trap 'false' DEBUG; true; echo $? -> 0)
#522 arith-for syntax error echoed a normalized (( i=0; i<3 )) with no line N: error node carries its line; the between-parens text is rebuilt verbatim from token leading_ws+raw error.c:300-316 parser_error; parse.y:6813-6826 print_offending_line
#550 cell 2: SIGKILL job notice printed Signal 9; cell 1 (~root:x) cell 2: Windows fallback maps the invariant signal numbers to the glibc strsignal wording (Killed); cell 1 intentionally unchanged — the lookup logic already matches GNU (unresolvable users stay literal on both); /root comes from Linux's user DB which Windows lacks — platform discount per the issue's own recommendation jobs.c:1955 j_strsignal; lib/tilde/tilde.c:361-410 getpwnam failure path

Verification

  • New tests: tests/issue5{17,18,19,20,21,22}_*.rs, tests/issue550_job_notice_and_tilde_regressions.rs — 36 cases, all green, expectations byte-verified against WSL GNU Bash 5.3.0.
  • Full cargo test --no-fail-fast: the failing set is identical to fresh origin/master (db3218a) by test name in both directions — 44 failed names / 8 failing targets on each side (--lib, cli_tests, executor_tests, issue298_299, issue377, issue382, parameter_transform_tests, regression — all pre-existing master reds, untouched). wave3 runs 173 green targets vs master's 166: exactly the 7 new files.
  • cargo fmt --check clean; no debug instrumentation left.

Out of scope / notes

  • The pipeline-stage DEBUG skip models GNU's in-child fire as an empty-output stage with the trap's status (rubash stages are captured in-process; the pipe chain stays intact). huck#268 deferred this site for fd-plumbing reasons that do not apply to rubash's string-pipe model.
  • GNU corner left unverified (out of the issue corpus): a DEBUG trap action ending in a failed top-level return N has exotic GNU-specific behavior not replicated here.
  • for ((i=0;i<3;)) (empty update section): GNU accepts it (infinite loop); rubash reports ;' unexpected — pre-existing divergence, untouched by this PR.

Rebase note (2026-10-12, post-#561/#562/#563)

Rebased onto origin/master 2183fc9 (the auto-merge needed one semantic adaptation):

Post-rebase verification (all green): full probes re-run byte-identical to WSL GNU 5.3.0; 7 new suites (36 cases) green; full cargo test --no-fail-fast failing set identical to fresh origin/master 2183fc9 by test name in both directions (55 failed names / 8 failing targets on each side — the same pre-existing master reds); cargo fmt --check clean.

…ntax-echo/job-notice (#517 #518 #519 #520 #521 #522 #550)

#517 xtrace case head (src/executor/compound_exec.rs): trace the RAW word
(word_metadata.raw, the WORD_DESC-text equivalent) instead of the
quote-stripped lexer value, decoding at the output boundary. GNU
xtrace_print_case_command_head (print_cmd.c:742-749) prints
case_command->word->word, which still carries the source quotes. The old
path leaked the PARAM_NAME_END_MARKER boundary byte (0x13) into the
trace: `+ case $x^S in` -> `+ case "$x" in`.

#518 redirection message fidelity:
- expand_redirect_target strips the fully-quoted-word role marker
  (STORAGE_WORD_PREFIX) from the expanded operand; the marker corrupted
  dup-word classification and leaked 0x1d into diagnostics.
  `r <&"${X[0]}"` (X set-empty) is one anchored empty field, not
  ambiguous; all_digits("") vacuous + valid_number("") fail -> dest -1 ->
  EBADF with the raw word: `"${X[0]}": Bad file descriptor`
  (redir.c:784-843 + redirection_error redir.c:149-176).
- the function-invocation fast path (command_prepare.rs
  execute_function_command_invocation) now runs the same
  reject_invalid_redirects gate as execute_materialized_command — GNU
  applies one do_redirections list for every simple command kind
  (redir.c:246).
- append-open errors map through posix_errors::path_error at every bare
  open site (redirection.rs open_command_output_target,
  builtin_redirects.rs, external_redirects.rs open_external_combined_
  target): redirection_error (redir.c:149-176) carries the target word,
  so `cmd >> word &` reports `word: No such file or directory` on every
  attempt instead of a wordless strerror line.

#519 caller (src/executor/arrays/executor.rs indexed_array_stack): the
synthetic FUNCNAME bottom frame "main" is pushed ONLY when
has_script_main_frame() (GNU shell.c:1636-1648 open_shell_script pushes
funcname_a "main" for script files; bash -s/-c never enter it), matching
the dynamic_stack_array_values view. caller.def:108-121 fails with
EXECUTION_SUCCESS=1 and no output when FUNCNAME[expr+1] is absent, so
`caller 1`/`caller 2` at g->f depth are empty rc=1 — no fabricated
`10 main <path>` line.

#520 trap -p ERR in functions (src/builtins/trap.rs, function_calls.rs):
execute_cmd.c:5279-5286 removes the inherited ERR trap for the function
body unless error_trace_mode (set -E), with uw_maybe_set_error_trap
restoring it at exit. Rubash now saves/clears/restores the ERR action at
the function boundary, so `trap -p ERR` shows an empty context while the
firing behavior (already GNU-correct) is unchanged.

#521 extdebug DEBUG-skip (trap_exec.rs run_debug_trap + fire sites): the
skip rule is now `extdebug && trap status != 0` — GNU's fire-site
contract (execute_cmd.c:3057/3191/3532/3672/3924/4157/4510/5391) —
replacing the old status==2-without-extdebug rule, and $? is preserved
across a DEBUG firing (probe: `trap 'false' DEBUG; true; echo $?` -> 0).
The decision is now HONORED at: case head (3672: skip whole case, status
SUCCESS), select head (3532), for header (3057: continue — skip the
iteration, next word runs; final-iteration skip leaves the trap's
status), arith-for init/test/update (3191-3199: expression evaluates as
0 with ok=1), pipeline stage (4510 in the element child: empty output,
stage status = trap status), function entry (5391: skip body and RETURN
trap, call status SUCCESS). Statuses after skips follow the probes:
skipped simple/case/select/function leave $? = 0 (m1/k9/m2); the
pipeline of two skipped stages is 1 (i521d).

#522 arith-for syntax error echo (src/parser/parse_loop.rs): the error
node carries its line (`line N:` prefix via
parser_diagnostic_prefix_for_line) and the between-parens text is
rebuilt VERBATIM from token leading_ws+raw (`((i=0; i<3))`, not the
normalized `(( i=0; i<3 ))`) — GNU error.c:300-316 parser_error +
parse.y:6813-6826 print_offending_line echo the source as read.

#550 cell 2, job signal notices (src/builtins/kill.rs
signal_death_description): the Windows fallback maps the invariant
signal numbers to the glibc strsignal wording the oracle prints
(SIGKILL -> `Killed`, jobs.c:1955 j_strsignal), keeping j_strsignal's
`Signal %d` only beyond the table. Cell 1 (`~root:x`) is NOT changed:
the lookup logic already matches GNU (unresolvable users stay literal on
both); `/root` comes from Linux's user database, which Windows does not
have — platform discount per the issue's own recommendation.

Tests: tests/issue5{17,18,19,20,21,22}_*.rs,
tests/issue550_job_notice_and_tilde_regressions.rs (36 cases, all
byte-verified against WSL GNU Bash 5.3.0 script-file/stdin probes).
Full cargo test --no-fail-fast: the failing set is IDENTICAL to fresh
origin/master (db3218a) by test name in both directions (44 failed
names, 8 failing targets on each side; the master reds are pre-existing
and untouched).
…Rejection protocol

#561 reshaped reject_invalid_redirects to classify rejections
(RedirectRejection::Command / FatalNounset). The function-invocation
fast path follows the execute_materialized_command consumer shape:
FatalNounset raises the same finish_heredoc_expansion_error the
materialized path raises (rubash#535's main-shell/child split), Command
skips the call with the tempenv restore and process-substitution
finishes still applied.
@caomengxuan666
caomengxuan666 merged commit 8453879 into master Oct 12, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/wave3-p3-batch branch October 13, 2026 02:00
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
M0 design draft for rubash#497, written to be startable as-is:

- Scope pinned: one debuggee topology (script in the host process,
  pdb/debugpy model), DAP minimal surface over stdio (launch /
  same-process-spawn-only attach / setBreakpoints by file:line /
  stackTrace / scopes / variables / evaluate / pause-continue-step).
- Stop substrate anchored to the existing run_debug_trap seam family —
  all 11 dispatch points enumerated with file:line at 7f18b44
  (trap_exec.rs:716 funnel; ast_exec.rs:541; compound_exec.rs:334/982/
  1135/1170/1232/2305; function_calls.rs:531; loop_select.rs:117;
  pipeline_exec.rs:672; select_exec.rs:64) plus the function-return
  patch point (trap_exec.rs:781) for the extdebug force-return hole.
- Breakpoint injection: recommends executor PC hooks (the seam family is
  the PC, GNU DEBUG-trap distribution is the stop-site set, no second
  admission list per #117) with the parse-tree line walk
  (parser/nodes.rs:1252 CommandNode.line) used only for verified:false
  resolution at setBreakpoints time; reasons stated.
- Frame/scope/evaluate reuses landed structures: funcname_stack /
  bash_source_stack / bash_lineno_view (dynamic_arrays.rs:683/687/409),
  main-frame rule (#519, dynamic_arrays.rs:389-395), ERR entry-state
  parity pattern (#520), function_definition_locations
  (function_calls.rs:495-511); extdebug surface (#569 sites,
  trap_exec.rs:773-775) and #571 bind -v registry as the CLI's
  readline foundation.
- Non-goals, acceptance (golden DAP transcripts + bashdb oracle),
  scale estimate (~3,000-4,500 LOC, no new crates), M1 outlook, and
  three owner decision points (frontend order; --debug flag semantics;
  M0 stop-site granularity).
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.

1 participant