Skip to content

fix(expansion): apply arithmetic writes in list-subject substring expansion (rubash#3649) - #3769

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3649
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3649

Conversation

@arookieofc-ai

@arookieofc-ai arookieofc-ai commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3649.

Problem

${a[@]:$((i+=1))} and ${@:…} sliced correctly but silently dropped the offset/length arithmetic's write: GNU prints i=1, rubash printed i=0.

Root cause

The whole-word list fan-outs (array_at_word_values, quoted_positional_at_word_values) expand these forms through the &self substring parse, whose offset arithmetic ran on a cloned env and discarded the writes; the fan-out then returns the sliced values directly, so the &mut substring parse (which applies writes live) never runs for them.

Fix

  • eval_parameter_substring_offset now returns the offset/length arithmetic's write deltas alongside the value (eval_conditional_arith_value_categorized_with_writes); parse_parameter_substring_impl threads them out through writes_out.
  • New parse_parameter_substring_with_writes returns the deltas with the parse result; the nine consumer sites that USE a result commit them exactly once via queue_pending_subscript_writes, only inside the arm that uses the result. Probes and the error pre-scan keep the plain parse and discard the writes, so a bare scalar ${v:i+=1} still evaluates exactly once.
  • Drain the deferred writes at every fan-out success return in expand_command_word and expand_for_word_values_impl, so sequential words observe the write left-to-right (GNU order).
  • The plain eval_conditional_arith_value_categorized loses its only caller and is removed, with its executor re-export.

Evidence

  • GNU oracle (bash 5.2.21): 29/30 matrix cases byte-identical (seed, @/*/a[*], offset+length, for-list, comsub isolation, unset/out-of-range no-eval, indirect, compound assignment). The one diff is a pre-existing diagnostic wording gap (syntax error vs arithmetic syntax error, rc=1 both), verified byte-identical on the unfixed tree.
  • New regression suite tests/issue3649_substring_offset_writes.rs: 20/20 pass; 14/20 fail on the unfixed tree (fail-first verified via stash).
  • cargo test --lib: 1249 passed, 0 failed, 4 ignored. Neighbor suites (substring, expansion, array, positional, for-list): all green.
  • cargo fmt --check and git diff --check clean; build with 0 warnings.

Limitations / out of scope

  • Sequential &self segment/arg/compound-element writes (e.g. a second slice in the same word via at_slice_segment_values, comsub/printf args, compound-assignment elements) still compute from the pre-write live value; the final i lands at the next drain but may be short of GNU for multi-write shapes. Values are identical to today — no regression.
  • The new regression suite does not run in CI (the "Run all integration test stems" step is skipped because the fail-fast lib step fails first on the known flaky issue2875; baseline behaves the same), so the suite's evidence is the box run above.
  • No new API items, so the canary ledger is untouched.

…ansion (rubash#3649)

${a[@]:$((i+=1))} and ${@:…} sliced correctly but silently dropped
the offset/length arithmetic's write (`i` stayed 0): the whole-word
list fan-outs expand these forms through the `&self` substring parse,
whose offset evaluation ran on a cloned env and discarded the writes,
and the fan-out returns the values directly, so the `&mut` parse that
applies writes live never runs for them.

Make the offset/length writes ride with the parse result
(`parse_parameter_substring_with_writes`) and commit them exactly once,
only at the consumer that uses the result; probes (and the error
pre-scan) keep the plain parse and discard them, so a bare scalar
${v:i+=1} still evaluates exactly once. Drain the deferred writes
at every fan-out success return so sequential words observe the write
left-to-right. The plain `eval_conditional_arith_value_categorized`
loses its only caller and is removed with its re-export.

GNU oracle (bash 5.2.21): 29/30 matrix cases byte-identical; the one
diff is a pre-existing diagnostic wording gap (`syntax error` vs
`arithmetic syntax error`, rc=1 both), verified identical on the
unfixed tree. New regression suite tests/issue3649_*.rs: 20/20 (14/20
fail on the unfixed tree). cargo test --lib: 1249 passed, 0 failed.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger labels Nov 16, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 16, 2026
@caomengxuan666 caomengxuan666 added P3-low 低:优化、文档、远期规划,有机会再做 area:expansion word splitting, quote removal, parameter/brace expansion labels Nov 16, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you for the fix, @arookieofc-ai. Per the owner's rule, external PRs are reviewed by the captain first — this PR is queued for captain review; I am leaving a first-pass check here, not a merge and not a request for changes.

First pass (verified from the PR and CI logs, not a re-run):

  • Scope: 11 files, +388/−34, head d2b33007, one commit ahead of current tip 2815ed3b (0 behind), mergeable, not a draft. It touches the expansion/substring path (parameter_core.rs, parameter_words.rs, expand_braced_indices.rs, arrays/executor.rs, command_words.rs, command_prepare.rs, command_substitution_values.rs, assignment_expansion.rs, arithmetic/mod.rs) plus the new regression suite. No overlap with the two known guard-order items (script_driver.rs / external_finish.rs).
  • Mechanism matches the description: the offset/length arithmetic writes now ride with the parse result (parse_parameter_substring_with_writes) and are committed at the consumer that uses the result via queue_pending_subscript_writes; probes keep the plain parse and discard the writes, so a bare scalar ${v:i+=1} still evaluates exactly once.
  • New suite verified present: tests/issue3649_substring_offset_writes.rs carries exactly 20 #[test]s, matching the claimed 20/20. The claimed fail-first (14/20 on the unfixed tree), GNU oracle 29/30 matrix, and cargo test --lib 1249/0 rest on the author's local run — the new stem is not in CI's nextest table, so CI cannot prove it; that stays for the captain's re-run.
  • CI: 3 red legs (GNU regression goldens and canaries, Rust tests, Rust tests (macOS)) — I checked the failed logs, and all three fail on the single known flaky precondition test api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell ("no rubash binary found", rubash#3292), outside this change's touch. Goldens show 1351 passed / 1 failed. All other legs are green (API ledger tripwire, Compatibility CLI tests, cross-target checks, Shell functionality tests, Windows tests compile check, niubash builds against this tree).

Points for the captain's review:

  1. The author-admitted limitation — sequential &self multi-write shapes may still land short of GNU for the final i (values unchanged, no regression claimed). Whether that needs a follow-up issue is for the captain to decide.
  2. The removed eval_conditional_arith_value_categorized (plus its executor re-export) is claimed to have lost its only caller — worth confirming no other consumer remains at review time.
  3. The PR body has no "what this PR deleted" section; the removed function should be recorded there at merge time.

No other PR targets #3649, and #3649 itself stays open pending this review. Thanks again for the thorough evidence section.

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3769 第1轮 — 建议:PASS
head: d2b3300 base(merge-base): 2815ed3 文件: 11 个 +388/-34
关联 issue: #3649(状态:open,我核过的时间:2026-11-16 18:20 UTC)

机制核查:

腿(逐项给数字与名字):

  • 钉自跑:issue3649_substring_offset_writes head 20 passed / 0 failed(seed_array_at_quoted、positional_at_quoted/unquoted、array_at_unquoted、scalar_control_already_green、scalar_bare_offset_applies_once/with_length、positional_star_quoted、array_star_quoted、offset_and_length_writes、length_write、two_words_observe_write_left_to_right、for_list_array_at、comsub_does_not_leak_write、unset_array_offset_not_evaluated、out_of_range_offset_length_not_evaluated、bare_arith_offset_array_at、indirect_ref_slice、compound_assignment_slice、assoc_slice 全 ok)
  • fail-first:base 2815ed3 上同钉 6 passed / 14 failed,红名 = {seed_array_at_quoted, array_at_unquoted, positional_at_quoted, positional_at_unquoted, positional_star_quoted, array_star_quoted, offset_and_length_writes, length_write, two_words_observe_write_left_to_right, for_list_array_at, indirect_ref_slice, compound_assignment_slice, assoc_slice, bare_arith_offset_array_at, out_of_range_offset_length_not_evaluated},失败形态统一为值正确但 i=0(写入丢失;two_words 更输出 q r q r/i=0,第二词读到陈旧 i);绿名 = {scalar_control_already_green, scalar_bare_offset_applies_once, scalar_bare_offset_with_length(标量路径本就活写), comsub_does_not_leak_write, unset_array_offset_not_evaluated}——红绿分布与 PR 声称的缺陷面完全一致
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1351 passed/1 failed/4 ignored)/ base 失败名集 {同}(1351/1/4)/ 差集 ∅(issue2084 为本机 Windows 基线,双侧同现)
  • -D warnings:cargo check --locked --lib --bins 0 警告通过;--tests 全量在 tests/issue2473_procsub_operand_marker_regressions.rs:29 unused import 处失败——不在本 PR diff 内、merge-base 同样存在,属预存基线警告;本 PR 文件自身无警告
  • 卫生:rustfmt --edition 2021 --check 全部 11 个 PR 文件 clean;check-marker-literals.py OK(117 registry consts, 268 allowlisted sites);check-utf8-boundary-hygiene.sh clean
  • CI(head d2b3300):红 = GNU regression goldens and canaries / Rust tests / Rust tests (macOS),逐一核日志均为单测 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell("no rubash binary found" 前置条件,rubash#3292)= 已知基线;其余 job 全 pass
  • GNU 对照:WSL /usr/local/bin/bash = Bash 5.3.20(1)-release(PR 正文引 5.2.21,本审计以 5.3 复核)。探针 target/devin-dispatch/u2-3769-gnu-probe.sh 15 形状 + u2-3769-residual.sh/u2-3769-rubash-residual.sh 9 残差形状,rubash head 与 GNU 逐字节一致,包括:相邻双 slice 同词 "${a[@]:$((i+=1))}${a[@]:$((i+=1))}" → q rr/i=2;内嵌 x..y..z → xq ryrz/i=2;printf 双参数 → q/r/r/i=2;标量相邻 → bcdefcdef/i=2;跨数组词左到右 → q r R/i=2;i++ 后缀 → p q r q r/i=2;嵌套 $((x+=i+=1)) → 空/i=1 x=6;${a[@]:off:-d} → 空/i=1;comsub 隔离 i=0;unset/out-of-range 不求值长度(i=5 j=0)

F 点:无

正文卫生备注(不阻塞):PR 正文含 Fixes #3649 关单词+issue 编号同句——合入即自动关单,供队长知悉;钉文件头注释亦称期望值对 GNU 5.2.21 核过,本审计已用 5.3.20 复核全部形状一致。

已披露限制复核:正文称「sequential &self segment/arg/compound-element writes 仍从写前活值计算」——本审计 9 个残差形状(含同词相邻 slice、跨参数、嵌套赋值)在 head 上与 GNU 5.3 逐字节一致,该限制在所测形状上未复现;可能已被 overlay/边界 drain 覆盖,或残留面更窄,建议队长按需复核。

续作记录:无(本轮未改代码)

未跑/VOID 的腿:无

备注:本 PR 下有一条 2026-11-16T07:56:10Z 的 captain intake 评论(id=6910699194,"queued for captain review"),距本审计约 10 小时;调度方补充明确本批「已过 24h,正常审计」,故按指令完成审计,仅供队长知悉。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3769 第2轮 — 建议:PASS(已合并 squash c5b988bd0554260edc2abee34dd9ba69a980ce3b)
head: d2b330075d7755d0afbf3027a856cb4b6ef89c34(自 U2 未变)base(merge-base): 2815ed3bc096efa446f9dedc9ac01cf5808fe496
关联 issue: #3649(已由本 lane 手工关闭,completed)

V 波收网复核:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:expansion word splitting, quote removal, parameter/brace expansion bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants