Skip to content

fix: #795/#796 — 2026-10-18 wave regressions (field-split eligibility, assignment guard byte, jobspec kill notice) - #811

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/795-796-wave-regressions
Oct 19, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/795-796-wave-regressions

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Closes #795, closes #796.

Rebased on master (bd4f703, post-#836). Three byte-level regressions from the 2026-10-18 PR wave, each root-caused below and pinned with differential tests byte-verified against the WSL GNU bash 5.3.0(1)-release oracle.

CR round update (F1 resolution): rebased onto current master; the nquote.snap conflict is resolved by keeping master's version (this PR carries NO nquote.snap change — only the exp.snap re-record). The corrected snapshot story: master's trailing foo line in nquote4.sub is the GNU-consistent alias face under the #812 suite driver; the earlier no-foo golden was the CRLF-era divergence adjudicated in #803. upstream_suite_slice_snapshots is fully green (13 slices) on this branch.

1. Field-split eligibility: a ${...} span IS an unquoted parameter expansion (#795 both cases, #796 @k face)

#789's per-character scan raw_word_has_unquoted_parameter_expansion_outside_quotes skipped the whole ${...} body while hunting for expansions outside quote segments — hiding the very expansion the span performs. When the $ introducing the span sits outside any quote segment, the word carries an unquoted expansion regardless of the body (quotes inside are the expansion's own word syntax). That lost the field split for three faces:

face GNU 5.3.0 master before after
for f in "${a[@]+\"${a[@]}\"}" ["p] [q"] ["p q"] ["p] [q"]
echo Unquoted: H${$+<nl>}H Unquoted: H H (one line) two lines one line
echo assoc:${assoc[@]@K} no trailing space trailing space no trailing space

Quoted introducers ("${x}") keep skipping the body — a quoted result never field-splits.

Re-enabling the split re-armed #743's quoted-segment IFS marking for words whose escaped quotes the marking simulation mis-modeled (the lexer cooks an escaped quote outside any quote span to its data-quote marker): the simulation now reproduces both spellings, restoring part_063's quoted-trailing-space pin.

Snapshot: exp.snap re-recorded per the tests/regression.rs protocol (this PR is the named engine change) — the X${c}X face now splits XY/YX under IFS=0x01 exactly like GNU (the committed golden had encoded the pre-#789 no-split divergence).

2. Assignment guard byte (#796 case 1)

v2=$'p\nq'$(echo r)s stored 6 characters (GNU: 5, p \n q r s). #791's marker-zone extension made the mixed command-substitution splice re-encode the bare ANSI_C_IFS_GUARD as an E400 E401 pair — indistinguishable from #735 user data, which the assignment tail strip must preserve. The guard is split transport and an assignment value never splits, so the drop now happens at the fragment boundary BEFORE the splice (prefix + suffix).

3. Jobspec kill completion notice (#796 case 3)

kill %1 + jobs/wait printed ``[1]+ Exit 143 while true; do true; done'' where GNU prints nothing: a non-interactive reader suppresses the notice of a job the kill builtin itself terminated (jobs.c notify_of_job_status, DONT_REPORT_SIGINT/SIGPIPE/SIGTERM + trapped arm) and cleans the dead job up. Restored with the status-preserving removal: kill %1; jobs lists nothing, no notice at the wait, a pid-shaped `wait $!` still resolves 143 (#737's contract), and `kill -9 %1` keeps the entry so the reap still announces `Killed` (GNU-verified).

Differential evidence (before → after vs GNU)

probe GNU master before after
nested guard printf <"p><q"> <"p q"> <"p><q">
${$+<nl>} unquoted Unquoted: H H Unquoted: H\nH Unquoted: H H
comsub assignment len len=5 len=6 (bare U+E401 in cell) len=5
${assoc[@]@K} unquoted assoc:two "beta" one "alpha" trailing space byte-identical
${assoc[@]@K} quoted trailing space kept kept kept
kill %1; jobs; wait kill:0 only kill:0 + [1]+ Exit 143 ... kill:0 only
kill $!; wait $! s:143 s:143 s:143

New pins: escaped_quote_guard_class_splits_vs_gnu, assignment_comsub_fragments_store_clean_values, test_parameter_transform_at_k_trailing_separator_splits_away_unquoted, test_kill_jobspec_leaves_no_completion_notice, test_kill_pid_operand_then_wait_reports_signal_status; the ten ticket-named pinned tests are green.

Scope notes

  • ${a[@]+\"'...\"}-style doubly-nested alternates and the non-whitespace-IFS nested-guard face diverge from GNU on master too (pre-wave); untouched — separate issues if wanted.
  • 3 commits, one per root cause; cargo fmt clean (hook-verified); rebased on current master.

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review verdict: REQUEST-CHANGES

The three code fixes are correct and well-evidenced (independently re-verified against WSL GNU bash 5.3.0(1)-release), but the branch is based on a pre-#803 master and its nquote.snap restoration is merge-blocking on current master.

F1 (blocker): nquote.snap restoration reverts the #803 LF-normalization contract and conflicts on current master

  • This branch is based on 74e60b01; current origin/master has since landed c8719d9 (#803), which (a) changed run_suite_snapshot (tests/regression.rs:461-492 on master) to strip CRLF while copying suite files into the scratch dir, and (b) re-recorded nquote.snap including the nquote4.sub face — alias foo=$'echo foo\n\nquux\n' now expands and prints the foo line (tests/regression/snapshots/nquote.snap:81 on master).
  • git merge-tree --write-tree origin/master cr-811 → CONFLICT (content): Merge conflict in tests/regression/snapshots/nquote.snap. Resolving with the PR's side would pin the no-foo (CRLF-era) bytes under the LF-normalizing driver, turning upstream_suite_slice_snapshots red on the merged tree.
  • Empirical checks (independent worktrees, both engines built from origin/master and this PR):
    • WSL GNU 5.3 on an LF nquote4.sub prints foo — the foo face is the GNU-matching one (#803's own 1230-byte evidence; re-confirmed here).
    • Under a driver-equivalent LF harness, this PR's engine reproduces master's committed nquote.snap byte-for-byte (85 lines incl. foo) — the PR's engine changes do not shift this face at all.
    • The PR branch's test passes only because its base predates the driver change and the CRLF copy keeps the alias face silent — the exact divergence #803 removed.
  • The PR description's "nquote.snap returns byte-identical to the original GNU-diffed recording (1f30c09)" is byte-true but endorses the pre-#803 bytes; and "the wave's truncation (f7eaebf/0ac17515) was an artifact of the transient breakage" is right about the truncation but the correct rebase target for this file is master's current version, not 1f30c09.
  • Fix: rebase onto current master and drop the nquote.snap hunk entirely. (exp.snap is unaffected: master did not touch it, and the changed face now matches the repo's GNU oracle tests/gnu-compat/upstream-rights/exp.right exactly at that position, with all other divergences pre-existing and untouched.)

F2 (nit): the two new kill tests under-pin the stated contracts (tests/executor_command_chaining/part_036.rs:328-378)

  • test_kill_jobspec_leaves_no_completion_notice asserts only the redirected output file; the "no [1]+ Exit 143 notice" contract goes to the process stderr, which the in-process harness never captures — a notice regression would not fail this test.
  • No jobspec-shaped pin exists for kill -9 %1 still announcing Killed (the keep-entry arm this PR promises; issue550's test is pid-shaped) nor for kill %1; wait $! → 143 (the completed_statuses preservation the new branch relies on). Both behaviors were verified correct vs GNU in this review, but they are un-pinned; one test each would lock them.

F3 (nit): fabricated 143 in the zombie window (src/executor/limit_builtins.rs:120-142)

  • The branch fires whenever kill(2) reports success, stashing 128+sig even if the child had already exited with 0 but was not yet reaped; GNU's wait $! would then report 0 while rubash now reports 143. Narrow race; consider a try_wait probe before fabricating.
  • The branch also skips forget_background_runtime (unlike the wait path, src/executor/job_builtins.rs:906) and leaves the dead child to the boundary reap — benign today because the Windows emulation terminates with exit code 128+signal (src/builtins/kill.rs:1491) so the later mark_completed is idempotent, but that invariant is undocumented coupling.

Independently verified (no findings)

  • Fix 1 (src/executor/command_words.rs:638-669): unquoted-introducer ${ early-returns true; quoted introducer skips the body with brace depth; \'/\" never toggle quote state (lines 617-619), so \"${x}\" classifies like bare ${x} and "${a[@]+\"${a[@]}\"}" keeps its no-split classification — matches GNU 5.3 probes (["p] ["q"], <"p><q">, one-line Unquoted: H H).
  • Fix 1b (src/executor/command_prepare.rs:4040-4067): escaped quote outside any span → DATA_SQUOTE/DATA_DQUOTE (0x17/0x18) exactly matches the lexer (src/lexer/quotes.rs:380-389); inside spans stays a pair; simulation mismatch still bails safely.
  • Fix 2 (src/executor/assignment_expansion.rs:1316-1320, 1350-1354): strip_ansi_c_ifs_guard is E400-aware (src/executor/markers.rs:831-855) — bare E401 at this boundary can only be the lexer guard (the guard producer writes the marker directly, markers.rs:796-798; user U+E401 arrives E400-escaped), and the drop must precede append_expanded_shell_text because the splice would E400-encode the guard into an indistinguishable pair. v2 len=5 matches GNU.
  • Fix 3: the silent set {INT, PIPE, TERM, trapped} mirrors report_pending_signal_notices (src/executor/job_builtins.rs:622-668); GNU probes confirm all four faces (kill %1 silent cleanup, kill %1; wait $! → 143, kill -9 %1 → Killed, trapped TERM silent).
  • Gates: compared failing-target sets on origin/master vs this PR in identical sandboxes — 0 new failures; 4 tests flip red→green (both part_036 kill tests, part_061 test_parameter_plus_allows_newline_word, bashdb_compat::bash_compat_debugger_options_run_init_file_before_script); the ticket-named nested_quoted_guard_class, assignment_positions_store_clean_values, test_parameter_transform_prints_key_value_pairs are red on master and green here. cargo fmt --check clean; GPL scan clean (MIT repo, no third-party code transcribed); diff scope = 4 src + 4 tests + 2 snapshots, no ride-alongs.
  • The "recho 污染 2 条假新增" gate note could not be reproduced (snapshots pass with proper helpers); plausible but unverifiable here — and subsumed by F1's snapshot-narrative correction.

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR follow-up (re-verified against master@5ace807e / post-#835)

R1 verdict stands: REQUEST-CHANGES with F1 as the only blocker; F2/F3 remain nits. PR head is unchanged (20dce8e); master has advanced by #810-#835. Re-verification performed on the actual merged tree (cr-811 + origin/master, nquote.snap conflict resolved to the master side), including the #812 space-free THIS_SH pin and the #809/#834/#835 background direct-spawn wave:

  • F1 re-confirmed, resolution unchanged: git merge-tree --write-tree origin/master cr-811 still conflicts in exactly one file — tests/regression/snapshots/nquote.snap. On the merged tree with master's side kept, upstream_suite_slice_snapshots is green (all 13 slices: exp from this PR's side, nquote from master's side, under the new THIS_SH-pinned driver). Master's exp.snap is untouched (74e60b0..master diff empty), so the PR's exp.snap hunk applies cleanly and stays. Rebase instruction: keep exp.snap, drop the nquote.snap hunk entirely (master's version wins). The R1 note about the description's "nquote.snap byte-identical to 1f30c09" claim also stands — the no-foo bytes are the CRLF-era divergence; foo (nquote4.sub alias foo=$'echo foo\n\nquux\n') is the GNU-matching face.
  • No new failures on current master: same failing-target set compared on origin/master vs the merged tree in identical sandboxes — merged-tree failures are a strict subset (0 new). 3 tests flip red→green on the merged tree (both part_036 kill tests, part_061 test_parameter_plus_allows_newline_word); the other 37 are the pre-existing sandbox-environmental set, identical on both sides. The R1 bashdb flip no longer appears because the #809-#835 wave fixed it on master independently.
  • Fix faces survive the wave on the merged tree: arrdefault 11/11 (nested_quoted_guard_class), issue379 12/12 (assignment_positions_store_clean_values), parameter_transform 18/18 (@K), executor_tests part_036 33/33 (kill), part_061 15/15. #809's background direct-spawn gate (compound_exec.rs) does not touch command_words.rs's scanner (master's copy at :605 is still the pre-PR version), so there is no semantic coupling.
  • F2/F3 unchanged: the stderr-capture gap in test_kill_jobspec_leaves_no_completion_notice and the missing jobspec-shaped pins (kill -9 %1 → Killed, kill %1; wait $! → 143) are still open; the limit_builtins.rs:120-142 zombie-window fabrication + forget_background_runtime coupling note still applies (file untouched by master).

Actionable for merge: rebase onto current master; in the nquote.snap conflict take master's side (equivalently: revert this PR's nquote.snap hunk); optionally update the PR description's snapshot narrative. Everything else is approved as-is.

@caomengxuan666
caomengxuan666 force-pushed the fix/795-796-wave-regressions branch from 20dce8e to f3b8a5a Compare October 18, 2026 23:43
… state (#795)

#789's per-character scan for split-eligible words
(raw_word_has_unquoted_parameter_expansion_outside_quotes) skipped the
whole ${...} span while hunting for expansions outside quote segments.
A braced span IS a parameter expansion: when the dollar introducing it
sits outside any quote segment, the word carries an unquoted expansion
regardless of what the body contains. Skipping the body wholesale
dropped three word classes off the split path:

- "${a[@]+"${a[@]}"}"-with-escaped-quotes: the guard fragment's
  alternate \"${a[@]}\" re-lexes with escaped quotes as DATA (never
  quote toggles), so it must classify exactly like a bare ${x} and
  split its joined result: GNU 5.3.0 gives ["p]/[q"], master gave one
  ["p q"] field.
- H${$+<newline>}H - the unquoted expansion result must field-split
  at the newline: GNU prints 'Unquoted: H H' on one line, master
  printed two lines.
- ${assoc[@]@k} - the transform's trailing separator must fall off
  through the unquoted field split (GNU drops it unquoted and keeps
  it in the quoted face).

When the introducer itself is quoted ("${x}"), the span's result
never field-splits, so the scan keeps skipping the body.

The eligibility re-enable also re-armed #743's quoted-segment IFS
protection for words whose escaped quotes the marking simulation
mis-modeled: the lexer cooks an escaped quote OUTSIDE any quote span
to its data-quote marker (single-quote escapes to 0x17, double-quote
escapes to 0x18), and the simulation must reproduce that or it bails
and a quoted blank loses its protection (a replacement word with
escaped-quote affixes plus a quoted trailing space lost that space,
part_063). Model the two spellings; span-internal backslashes stay
verbatim pairs.

Snapshot re-recorded per the tests/regression.rs protocol (this
commit is the named engine change): exp.snap's X${c}X face now splits
XY/YX under IFS=0x01 exactly like GNU bash (the committed golden had
encoded the pre-#789 no-split divergence; WSL GNU 5.3.0(1)-release
probe, 2026-10-13). nquote.snap intentionally stays at master's
version: its trailing `foo` line is the GNU-consistent nquote4.sub
alias face under the #812 suite driver, and the no-foo golden was the
CRLF-era divergence already adjudicated in #803 - carrying this
fix's transient recording forward would resurrect those bytes.

New GNU-verified differential pins:
arrdefault_quoted_array_default_regressions::
escaped_quote_guard_class_splits_vs_gnu and parameter_transform_tests::
test_parameter_transform_at_k_trailing_separator_splits_away_unquoted.
…d splice (#796)

v2=$'p\nq'$(echo r)s stored 6 characters where GNU bash 5.3.0
stores 5 (p newline q r s): one ANSI_C_IFS_GUARD byte reached the
cell. #791 extended the marker zone to cover U+E401 (rubash#735),
which re-routes the guard through the mixed command-substitution
splice's payload re-encoding: the bare guard crosses
append_expanded_shell_text and materializes as an E400-escaped pair,
and the assignment funnel's tail strip must then PRESERVE that pair
as #735 user data - so the transport carrier survived into storage.

The guard is field-split transport (rubash#379), and an assignment
value never field-splits, so the boundary that drops it is the
fragment boundary BEFORE the payload splice. Strip the bare guard
from the prefix and suffix fragments of
expand_mixed_command_substitution_assignment.

Differential pins (tests/issue379_ansic_blank_between_comsubs_
regressions.rs::assignment_comsub_fragments_store_clean_values,
byte-verified against the WSL GNU 5.3.0(1)-release oracle): prefix,
suffix and both-adjacent fragments store clean lengths 5/4/5, and the
for-list face keeps the decoded newline literal while field-splitting
only the substitution output.
kill %1 followed by jobs/wait printed '[1]+  Exit 143  while true; do
true; done' where GNU bash 5.3.0 prints nothing: a non-interactive
reader suppresses the completion notice of a job the kill builtin
itself terminated (jobs.c notify_of_job_status, the
DONT_REPORT_SIGINT/SIGPIPE/SIGTERM + trapped arm - nothing printed,
the dead job is cleaned up), and #790 (rubash#737) had dropped the
jobspec-kill table cleanup to keep wait resolving the signal status.

Restore the cleanup with the status-preserving removal: stash the
signal status, close the coproc endpoints, drop the entry via
remove_job_by_pid_preserve_status. kill %1; jobs lists nothing, no
notice fires at the reap boundary, and a pid-shaped wait still
resolves 143 through completed_statuses (#737's contract). The signal
set follows the DONT_REPORT arm (SIGINT/SIGPIPE/SIGTERM or trapped,
the same set report_pending_signal_notices already implements):
kill -9 %1 keeps the entry so the async reap still announces Killed
(GNU-verified), and pid operands are untouched for the #737
wrapper-death flow.

Differential pins (part_036): test_kill_jobspec_leaves_no_completion_
notice and test_kill_pid_operand_then_wait_reports_signal_status,
byte-verified against the WSL GNU 5.3.0(1)-release oracle.
@caomengxuan666
caomengxuan666 force-pushed the fix/795-796-wave-regressions branch from f3b8a5a to 6b9065f Compare October 18, 2026 23:46
@caomengxuan666

Copy link
Copy Markdown
Member Author

F1 resolved — force-pushed 6b9065f3 (rebased on bd4f7030):

  • nquote.snap conflict: resolved with master's version winning — this PR now carries no nquote.snap change; only the exp.snap re-record remains. On the rebased tree upstream_suite_slice_snapshots is fully green (74 tests / 13 slices, including the nquote4.sub path coverage under the errors slice snapshot is machine-dependent across Windows hosts: 'after exit:'/'after shift:' status lines diverge both directions vs golden (errors10.sub ${THIS_SH} suspect) #812 driver).
  • PR description + commit message corrected: the 'byte-identical to 1f30c09' claim is retracted. Master's trailing foo line in nquote4.sub is the GNU-consistent alias face; the no-foo golden was the CRLF-era divergence adjudicated in [P1][regression] master goldens red: nquote snapshot stdout differs from golden (upstream_suite_slice_snapshots, 69/70) — red since 98794cb7 or earlier #803, and carrying my transient recording forward would have resurrected those bytes. Both the PR body and the snapshot-protocol commit message now state the corrected story.
  • Post-rebase verification: release build clean; ticket suites green (arrdefault 11, issue379 12, parameter_transform 18, part_036 kill 7, part_061 2, part_063 4, regression 70); GNU spot-probes byte-identical (nested guard <"p><q">, ${$+<nl>} one-line, comsub assign len=5, @k no trailing space, kill-then-jobs/wait kill:0 only, wait $! after pid kill = 143).
  • 全量回归抽验 (cargo test --release --no-fail-fast -- --test-threads=1): 24 failures — byte-identical set to the pre-rebase branch run and a strict subset of the pre-existing environment-face failures at origin/master (fd_redirects c_external 族, tilde_user, untrapped_sig*, cd/pwd, mapfile_nul, git_rev_specs, part_080/043/005/031, cat_dash, function_call_file_redirect, issue705_cd_stdout, windows_listing_cache) — 零新增。
  • CI on head 6b9065f3: all checks pass (cross-target, GNU goldens/canaries, Rust tests ×2, shell functionality).

F2/F3 acknowledged as non-blocking; will pick them up with the next face touching those spots.

@caomengxuan666
caomengxuan666 merged commit 992d5c5 into master Oct 19, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/795-796-wave-regressions branch October 21, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant