Skip to content

WIP: fix #2521 carrier restore crossing - #2559

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2521-carrier-restore
Nov 2, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2521-carrier-restore

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2521

Regression

The #2333 child startup-restore carrier crossing is back: a child that
inherits two or more heredoc/file carriers reads each carrier's content
from the NEXT carrier's descriptor (n3 gets body-four, n4 gets EOF).

Bisected with tests/issue2333_inherited_carrier_restore_regressions.rs:
7/7 at 7a664134 (PR #2470), 5 red at e6ccbf14 (PR #2471). Regressing
commit: ec40a88 ("deliver ambient std-stream fds across child
spawns"), which added an occupancy probe to the startup restore:
"prefer the stamped descriptor when it is open in this child".

Root cause

GNU: a forked child inherits the parent's whole descriptor table, each
descriptor keeping its own open file description (bash-5.3
execute_cmd.c, execute_in_subshell, :1576). rubash materializes that
inheritance via spawn-time pins + __RUBASH_FD_HANDLE_<slot> stamps,
and two transports give the stamp different meanings:

The probe cannot distinguish them: the pin pass stages each carrier
above the ceiling and dup2s it onto its slot, leaving staging sources
open, so in a pin-delivered child the stamped number of slot N is open
and holds a leftover copy of ANOTHER slot's carrier. The probe adopted
the leftovers — a +1 rotation of every carrier.

Fix

The spawner declares its delivery contract; the restore obeys the
declaration instead of inferring from fd occupancy:

  • execute_background_ast_command (the only whitelist spawner) sets
    __RUBASH_FD_AT_STAMPED=1 in the child env.
  • Startup transport-key consumption removes the key (never a shell
    variable, never in the env mirror) and the restore adopts the stamped
    descriptor only under at-stamped declaration. The fcntl occupancy
    probe is deleted; the [bug] 子壳继承 ≥2 个 ambient heredoc 载体时启动恢复串线(#2292 面残差) #2333 at-slot rule is unchanged for all pin
    transports; the Windows path (stamped value verbatim) is untouched.

Verification (build slot, scrubbed_cargo.py cargo test)

  • issue2333_inherited_carrier_restore_regressions: 7/7 (was 2/7)
  • issue2212_bats_remainder_regressions: 15/15 (respawn face preserved)
  • issue2256_devfd_fresh_open_regressions: 25/25
  • issue2479_devfd_reopen_cursor_regressions: 8/8
  • issue2502_pipeline_alias_delivery_regressions: 6/6
  • issue2476_born_closed_stdout_regressions: 7/7
  • issue2484_stage_fd3_delivery: 4/4

Full write-up: ~/workspace/rubash-wave-20261102/w1-carrier/REPORT.md
(cluster workspace).

…livery contract

Refs #2521

Regression of the #2333 carrier restore, bisected: the pins in
tests/issue2333_inherited_carrier_restore_regressions.rs pass 7/7 at
7a66413 (PR #2470) and fail 5/7 at e6ccbf1 (PR #2471). The regressing
commit is ec40a88 ("deliver ambient std-stream fds across child
spawns"), which added an occupancy probe to the startup restore:
"prefer the stamped descriptor when it is open in this child".

GNU semantics (the spec): a forked child inherits the parent's whole
descriptor table, each descriptor keeping its own open file
description (bash-5.3 execute_cmd.c, execute_in_subshell, :1576).
rubash materializes that inheritance through spawn-time pins plus the
__RUBASH_FD_HANDLE_<slot> stamps, and the restore must reconstruct
each slot from the descriptor the TRANSPORT actually delivered:

- pin transports (external ambient pass, input/output procsub,
  coproc): the carrier is pinned AT the slot fd; the stamp records
  the PARENT's descriptor number, which designates nothing in the
  child (the #2333 at-slot adoption rule, 8105a63).
- whitelist respawn transport (fd::spawn_whitelisted, sole caller
  execute_background_ast_command): each extra crosses AT its stamped
  number; the child's raw slot fd can be its own read-only script
  file (the #2212 EBADF case ec40a88 was protecting).

The occupancy probe cannot tell these apart: the pin pass stages each
carrier above the ceiling and dup2s it onto its slot, leaving the
staging sources open — so in a pin-delivered child the stamped number
of slot N is open and holds a leftover copy of ANOTHER slot's
carrier. The probe adopted those leftovers and rotated every carrier
by one (n3 got body-four, n4 got the already-consumed carrier: EOF).

Fix by mechanism: the spawner declares its delivery contract and the
restore obeys the declaration instead of inferring it from fd
occupancy. execute_background_ast_command — the only whitelist
spawner — now sets __RUBASH_FD_AT_STAMPED=1 in the child env; the
startup transport-key consumption removes it (it never surfaces as a
shell variable or rides the env mirror) and the restore adopts the
stamped descriptor only when the key declared at-stamped delivery.
The fcntl occupancy probe is deleted; the #2333 at-slot rule is
unchanged for every pin transport, and the Windows path (stamped
value verbatim) is untouched.

Verification (build slot, scrubbed_cargo.py cargo test):
issue2333_inherited_carrier_restore_regressions 7/7 (was 2/7),
issue2212_bats_remainder_regressions 15/15,
issue2256_devfd_fresh_open_regressions 25/25,
issue2479_devfd_reopen_cursor_regressions 8/8,
issue2502_pipeline_alias_delivery_regressions 6/6,
issue2476_born_closed_stdout_regressions 7/7,
issue2484_stage_fd3_delivery 4/4.
@caomengxuan666
caomengxuan666 force-pushed the fix/2521-carrier-restore branch from 99f9a5a to d2a1600 Compare November 2, 2026 04:45
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 2, 2026 05:36
@caomengxuan666
caomengxuan666 merged commit c02e493 into master Nov 2, 2026
11 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

[win-acceptance] #2559 PASS — issue2333_inherited_carrier_restore_regressions (the 5/5-red regression battery this fix targets; 7 tests on Windows) 7/7 ×2 on Windows. Direct issue-repro A/B vs WSL GNU 5.3.20 (script files) byte-identical for the mixed-carrier headline: parent exec 3<<HD3 (heredoc carrier) + exec 4<fc.txt (file carrier), external child cat <&3; cat <&4 → c3=[carrier3] c4=[FILECARRIER] rc=0, stderr empty — each carrier lands on its own fd in the child, no +1 rotation, no crossing. Probe: D:/repo/win-accept/wave3/probes/p2521.*. No BLOCKER.

Environment: Windows 10 19045 real machine, MSVC Rust debug build of master b41e8b6 (contains this merge), oracle wsl /usr/local/bin/bash 5.3.20. Logs: D:/repo/win-accept/wave3/logs/issue2333_inherited_carrier_restore_regressions.r{1,2}.log.

@caomengxuan666
caomengxuan666 deleted the fix/2521-carrier-restore branch November 3, 2026 09:05
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