Skip to content

fix(nameref): sync typed array cell with mirror on declare/local and circular-fallback writes (Refs #2655) - #3484

Merged
arookieofc-ai merged 1 commit into
masterfrom
ai-fix/rubash-2655
Nov 13, 2026
Merged

arookieofc-ai merged 1 commit into
masterfrom
ai-fix/rubash-2655

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Fixes #2655 — PANIC (crash class) when assigning through a nameref to an array element.

Root cause

A write through a nameref updated only one of rubash's two variable representations (typed cell vs mirror string), and the debug-only command-boundary verifier then panicked (typed cell disagrees with its mirror, variable_state.rs:1095 indexed / :1109 assoc). Two one-sided write paths, one mechanism family:

  • declare/local/typeset through a nameref wrote the resolved target's mirror only: the post-declare sync (sync_typed_assignments) synced the operand name (b), never the resolved target (a for b -> a[0]). It now also syncs the chain target's base (src/builtins/declare.rs). This covers nameref18/21/22/23.sub (e.g. declare b+=1 moved the mirror to 6 while the cell still held 5).
  • A write through a circular nameref (assign_circular_fallback) wrote the global namesake's array/assoc mirror snapshot only, never the typed snapshot beside it. It now rebuilds the saved typed cell from the same render (src/executor/variable_state.rs). This covers nameref15.sub (a=X through a -> a moved the mirror to "X" while the cell kept "0").

The plain-assignment funnel already synced both sides, so the issue's minimal snippet (f 'a[0]' failing sh_invalidid) never panicked on its own.

Tests

  • New regression pins: tests/issue2655_nameref_array_element_write_regressions.rs — 8 tests (circular indexed/assoc/append, declare bind/append through nameref, local -A compound, invalid-id guard). All pass.
  • run-nameref upstream suite (scripts/run-bash-upstream-tests.sh run-nameref): no longer panics — 0 panic mentions (baseline: 10). nameref15/21/22/23 match the pinned 5.3 .right with zero diff; nameref18's remaining diff is the pre-existing recho harness gap, also present on master.
  • nameref15/18/21/22/23.sub run standalone: stdout byte-identical to GNU bash (5.2.21) on all five; exit codes match GNU (0, 127, 0, 0, 0).
  • Related Rust suites, all green: nameref regressions (issue1707/2712/3246/530), declare/local/array/assignment regressions, typed_cell_coherence_fuzz, issue1719, sync corpus (issue2036/2043), cargo test --lib (1250 tests), cargo fmt --check clean.
  • Pre-existing failures confirmed on clean master, untouched by this PR: issue1046_groups_variable_regressions (GROUPS order on this host) and issue2043_a2_comsub_basename_extra_operand (system basename prints Unicode quotes).

…circular-fallback writes (Refs #2655)

Assignment through a nameref to an array element updated only one of
rubash's two variable representations, and the debug-only
command-boundary verifier panicked on the next check
("typed cell disagrees with its mirror", variable_state.rs:1095
indexed / :1109 assoc). Two one-sided write paths:

* declare/local/typeset through a nameref wrote the resolved target's
  mirror only: the post-declare sync (sync_typed_assignments) synced
  the operand name (b), never the resolved target (a for b -> a[0]).
  It now also syncs the chain target's base (nameref18/21/22/23.sub).
* a write through a circular nameref (assign_circular_fallback)
  wrote the global namesake's array/assoc mirror snapshot only, never
  the typed snapshot beside it. It now rebuilds the saved typed cell
  from the same render (nameref15.sub).

Regression pins: tests/issue2655_nameref_array_element_write_regressions.rs
(8 tests). The run-nameref suite no longer panics; nameref15/18/21/22/23
match GNU byte-for-byte on stdout (5.2.21) and nameref15/21/22/23 match
the pinned 5.3 .right with zero diff.
@caomengxuan666 caomengxuan666 added the bug Something isn't working label Nov 13, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 13, 2026
@caomengxuan666 caomengxuan666 added P1-high 高:核心语义或高频路径受损,影响日常使用/发布 gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger labels Nov 13, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you for this PR — and for taking on #2655, the harvest V1 nameref PANIC (typed cell vs mirror desync, variable_state.rs).

What I have captured from the PR description:

  • Two one-sided write paths, one mechanism: declare/local through a nameref synced only the operand name, never the resolved target's base (src/builtins/declare.rs); and the circular-nameref fallback rebuilt only the mirror snapshot, never the typed snapshot beside it (src/executor/variable_state.rs).
  • 8 new regression pins in tests/issue2655_nameref_array_element_write_regressions.rs, plus the claim that the upstream run-nameref suite no longer panics (0 panic mentions, baseline 10) with nameref15/21/22/23 matching the pinned 5.3 .right.

What happens next: per the owner's rule, external PRs go through captain review first — this PR is now queued for captain review, and CI is being watched. One thing already visible: the Rust tests check currently shows fail while the run is still in progress (other legs passing or pending), but its logs are not available yet, so I am not drawing any conclusion about the cause — the captain review will read the failed logs once they are published, and will re-run the new nail stem itself rather than trusting CI green alone.

No merge from intake, and no change requests from me at this stage — the review above is a first-pass intake note only.

@arookieofc-ai
arookieofc-ai merged commit 71f54b7 into master Nov 13, 2026
11 of 14 checks passed
@arookieofc-ai
arookieofc-ai deleted the ai-fix/rubash-2655 branch November 13, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P1-high 高:核心语义或高频路径受损,影响日常使用/发布

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[upstream] PANIC: assignment through a nameref to an array element desyncs typed cell vs mirror store (variable_state.rs:1092/1106)

2 participants