Skip to content

WIP: respawn transport-set completeness: fork-state census + shared transport (rubash#2058) - #2188

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2058-respawn-transport
Oct 30, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2058-respawn-transport

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Refs #2058

Phase 1 — census (first commit)

Fork-state census for respawn children (process-substitution bodies,
async & function bodies, coproc bodies), probed against GNU bash
5.3.20 across 21 shape×context probes (script top level / inside a
function / inside a function under extdebug):
docs/design/respawn-transport-census.md.

Phase 2 — one shared transport mechanism

  • Executor::fork_context_transport_entries builds the
    __RUBASH_FORK_* stamp once; all four spawn sites (async/subshell
    wrapper, coproc, procsub consumer, procsub producer) merge it next
    to the 回归:bats 在 rubash 下零测试执行(文件名空白 + gather trace 文件消失),窗口 (46452a9e, e9802c0c](生态审计 DIV-D) #2032 positional stamp. The bottom frame is peeked, never
    installed — a fork does not materialize the parent's arrays.
  • Executor::new consumes it provenance-gated and strips it
    unconditionally: frames land in ShellState::inherited_fork_frames,
    the bottom seeds bash_arg_bottom, the codec-encoded cell seeds
    PIPESTATUS. The four dynamic views compose own frames above
    inherited ones; nested respawns re-stamp the composed views.
  • SHLVL: a validated respawn keeps the parent's value
    (keep_shlvl); the exec replacement path keeps the increment.
  • LINENO seeds: async wrapper + coproc now use the first leaf
    command's line (a compound node's own line is its closing line);
    the async wrapper's offset compensates the function prelude's
    newline count like the procsub consumer site already did (this
    also fixes a +1 drift in BASH_LINENO call lines inside async-fn
    children).

Verification

  • New pins tests/issue2058_respawn_transport_regressions.rs: 12/12
    (one per census item, GNU expectations; baseline-red evidence is
    the pre-fix census matrix on master 36dfeff with identical probes).
  • Post-fix census matrix: 12/21 probes byte-identical to GNU; the
    remaining 9 differ only in the mid-body $LINENO scalar — the
    documented deferred item (definition/intra-body lines need
    source-span transport; body start lines are exact, pinned).
  • cargo test --lib 970/0 (master baseline); procsub/coproc
    neighborhoods (2179/1220/1221/1659/2053/2057) green; cli_tests
    compat + process_substitution filters show only the two
    pre-existing [tests] 三组回归钉期望与 GNU 不符(history 两钉 + exec 重定向钉)+ issue151 环境形钉——只改测试 #2175 wrong-pin history failures also on master.

caomengxuan666 and others added 3 commits October 30, 2026 08:33
Refs #2058

Fork-state census for respawn children (process-substitution bodies,
async & function bodies, coproc bodies), probed shape-by-shape against
GNU bash 5.3.20 at script top level, inside a function, and inside a
function under extdebug. Each fork-inherited item gets a three-state
verdict (TRANSPORT / PROJECT / DELIBERATELY-OMIT):

- TRANSPORT, already landed: positional params (#2032), SECONDS,
  BASH_SUBSHELL, non-exported variables and local values (env merge).
- TRANSPORT, open: BASH_ARGV/BASH_ARGC frames and bottom frame
  (variables.c:1656 get_bashargcv / :5643 init_bash_argv semantics,
  including the unmaterialized state), FUNCNAME/BASH_SOURCE/
  BASH_LINENO stacks, PIPESTATUS at fork time, SHLVL (a fork is not a
  new shell), LINENO start for body-text shapes.
- PROJECT: $$/BASHPID/$!/$PPID per the #1582 ruling; the coproc
  spawn site lacks the __RUBASH_SHELL_PID stamp its siblings carry.
- DELIBERATELY-OMIT: RANDOM/SRANDOM sequences — variables.c:1412
  get_random_number reseeds in a subshell environment, so GNU itself
  carries no sequence across the fork; the contract is
  parent-untouched plus child-fresh.

Implementation follows as one shared transport mechanism at the four
spawn sites; see the issue for the full census table.
…nd SHLVL to respawn children

Refs #2058

GNU's fork-shaped children inherit the parent's call-stack arrays
and PIPESTATUS cell verbatim (variables.c; subst.c:6362
process_substitute, execute_cmd.c:1576 execute_in_subshell, coproc
make_child). The respawn transport set carried only the positional
window (#2032); this closes the rest of the census
(docs/design/respawn-transport-census.md) with one mechanism:

- One stamp builder, Executor::fork_context_transport_entries,
  merged at all four spawn sites next to the positional stamp:
  the parent's effective FUNCNAME/BASH_SOURCE/BASH_LINENO views,
  BASH_ARGV/BASH_ARGC frames, the materialized bottom frame under
  a presence-keyed stamp (variables.c:1656 get_bashargcv: an
  unmaterialized array stays unmaterialized in the child when the
  fork happened inside a function), in-function / main-frame
  flags, and the PIPESTATUS cell via the existing state codec.
  The stamp peeks the bottom frame — a fork does not materialize
  the parent's arrays, so the stamp must not either.
- One consumption site at Executor birth (provenance-gated,
  stripped unconditionally): frames land in
  ShellState::inherited_fork_frames and the four dynamic views
  compose the child's own frames above them; the bottom frame
  seeds bash_arg_bottom; the cell seeds the PIPESTATUS fields.
  Nested respawns re-stamp the composed views.
- SHLVL: a fork is not a new shell, so a validated respawn keeps
  the parent's value (initialize_fresh_shell_env_vars keep_shlvl);
  the exec replacement path keeps the increment.
- The coproc site gains the __RUBASH_SHELL_PID stamp its siblings
  carry, so the child's $$ takes the #1582 projection.
- LINENO seeds at the async-wrapper and coproc sites now name
  the first leaf command's line (a compound node's own line is
  its closing line), and the async wrapper's line offset
  compensates the function prelude's newline count like the
  output-procsub consumer site already did.

Regression pins: tests/issue2058_respawn_transport_regressions.rs
(12 pins, one per census item, GNU 5.3.20 expectations). Local:
lib 970/0, procsub/coproc neighborhoods green, cli_tests compat +
process_substitution filters show only the two pre-existing #2175
wrong-pin history failures also present on master.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 09:34
@caomengxuan666
caomengxuan666 merged commit 185a04e into master Oct 30, 2026
10 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2058-respawn-transport branch October 30, 2026 09:35
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