Skip to content

WIP: fix stage-context fd 3 delivery (Refs #2484) - #2519

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2484-stage-fd3-delivery
Nov 2, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2484-stage-fd3-delivery

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2484 — cluster C4.

Re-adjudicated on master b3ae3b8 (after the #2515 stage-0 rework and the #2516 streaming-sandwich path merged): the bats_tee cell still failed two coupled ways, both now fixed by mechanism:

  1. Dev-fd operand attach clobber (src/executor/dev_fd_operands.rs): the attach recorded raw parent descriptor numbers for /dev/fd/N operands; the carrier handle systematically landed on the parent's lowest free fd (3 — the shell's fd 3 is virtual), and the child's ambient pin pass overwrote it with the stage pipe before the attach pass read it. tee's operand then bound the pipe (lines doubled downstream, carrier empty). Attach sources are now parked above the fd table's number range at record time (F_DUPFD_CLOEXEC), unreachable by pin targets and pin staging.

  2. Procsub consumer capture-blind backing (src/executor/external_setup.rs, src/executor/trap_exec.rs): the consumer fork (GNU subst.c:6362 inherits the whole ambient table) resolved a dup'd Stdout-marker fd through the process-stdout handle even when its rubash#223 dup record named the live capture scope. The adjudication now returns the capture scope's shared pipe write end for the live generation (new ProcsubSpawnFd::CaptureWrite), the consumer registers as a capture writer, and the scope close drains its bytes into the capture buffer.

Verification (captain re-runs): mini2212_t118 TAP byte-identical to GNU with rc 0/0; new pins tests/issue2484_stage_fd3_delivery.rs 4/4; guards issue2212 15/15, issue2483 6/6, issue2385 19/19, issue2479 8/8, issue2256 25/25, issue2502 6/6, issue2476 7/7 (all via scrubbed cargo). Residuals (ordering of consumer bytes vs the stage's own buffered writes; parked-generation records; consumer stdio ambient bindings; bare wait not settling deferred consumers) are itemized in the cluster report.

@caomengxuan666
caomengxuan666 force-pushed the fix/2484-stage-fd3-delivery branch from f32ddb5 to 2347a61 Compare November 2, 2026 01:00
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 2, 2026 01:04
Two coupled defects in the bats_tee shape (a pipeline-stage
function running exec 3<&1; tee >(cat >&3)):

- dev-fd operand attach recorded raw parent descriptor numbers;
  the carrier handle systematically landed on the parent's lowest
  free fd (3 — the shell's fd 3 is virtual) and the child's
  ambient pin pass overwrote it with the stage pipe before the
  attach pass read it, so tee's /dev/fd operand bound the pipe
  instead of the carrier (doubled lines, empty carrier). Attach
  sources are now parked above the fd table's number range at
  record time.
- A procsub consumer's dup'd Stdout-marker fd resolved through
  the process-stdout backing even when its dup record named the
  live capture scope, so its bytes never reached the stage
  output. The ambient adjudication now returns the capture
  scope's shared pipe write end for the live generation
  (ProcsubSpawnFd::CaptureWrite), the consumer registers as a
  capture writer, and the scope close drains its bytes into the
  capture — GNU's one-description merge for the
  process_substitute fork (subst.c:6362).

New pins in tests/issue2484_stage_fd3_delivery.rs cover the
stage-fn consumer, the verbatim bats_tee routing, the operand
attach, and the final-stage-in-comsub face.
@caomengxuan666
caomengxuan666 force-pushed the fix/2484-stage-fd3-delivery branch from fef3663 to 081f86e Compare November 2, 2026 01:40
The input-procsub producer spawn's CaptureWrite arm pushed to
ambient_pins without the #[cfg(unix)] gate its three sibling arms
carry; ambient_pins itself is cfg(unix)-only, so the Windows build
failed with E0425 (CI goldens + Windows compile check on 081f86e).
Harvest fix by the captain; behavior on unix is unchanged.

Refs #2484
@caomengxuan666

Copy link
Copy Markdown
Member Author

[win-acceptance] #2519 PASS on the pinned/mini faces; one Windows platform residual flagged (pre-existing, not a regression) — pin issue2484_stage_fd3_delivery is #![cfg(unix)] (0 tests on Windows by design). Live minimal bats_tee-shape probe on Windows: run_stage(){ exec 3<&1; printf ... | tee >(cat >&3) > r.log; }; run_stage > o.txt → stage rc=0 and the tee→file leg identical to WSL GNU Bash 5.3.20, but the procsub-consumer copy (>(cat >&3) → the fd 3 file) comes out empty on rubash Windows while GNU lands all three lines in BOTH files. A/B against pre-fd-family master d529b35 (built this session): identical empty result — pre-existing Windows face of the #2484 family, the PR's machinery (F_DUPFD_CLOEXEC parking, CaptureWrite) being unix-side. Probe: D:/repo/win-accept/wave2/probes/p2484.sh.

Guards re-run x2 green this session on this tree: issue2212 14/14, issue2483 (pin unix-gated; live probe identical), issue2479 8/8, issue2502 6/6.

Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 9348b8d (= this PR's merge), oracle wsl /usr/local/bin/bash 5.3.20. No BLOCKER.

@caomengxuan666
caomengxuan666 deleted the fix/2484-stage-fd3-delivery 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