Repository navigation
WIP: fix(2255) §8 — stage-0 numbered bindings in ≥3-stage pipelines (shell-writer admission decline) - #2289
Merged
Conversation
…wn numbered redirects
Section 8 of the reopened issue: in a >=3-stage pipeline whose
downstream stages are all concurrent-eligible externals
(`sh -c 'cat <&3' 3<seed.txt | cat | wc -c`), stage 0's own
numbered binding was lost entirely — the child had NO fd 3 at
all (GNU prints 10).
Root cause: execute_shell_writer_pipeline claimed stage 0 as a
"streamable external producer" without inspecting its ordered
redirects list, and run_shell_writer_pipeline spawns the
consumers on pre-created pipes BEFORE running the producer
through the sequential stage spawner. The producer child is
therefore forked while foreign anonymous pipes (the consumer
chain's ends) occupy the low descriptor slots; one parks
exactly on the fd-delivery pin's target slot, and
pin_ambient_fds_in_child's exec-error-channel guard
(rubash#1626, stdio-alias refinement rubash#2284) cannot tell
that foreign pipe apart from std's error channel, so it skips
the pin — apply_external_fd_delivery had opened the binding,
but the dup2 onto its slot never ran (strace: the staged pin
copy is closed without a dup2). The 2-stage composition
escapes because its only foreign pipe is the stage's own
stream pipe, which the stdio-alias check recognizes; fd >= 4
targets escape because the foreign pipes only reach the
lowest slots; middle stages escape because the concurrent
specs already decline list-only members there.
Fix: decline the shell-writer path for an external producer
carrying a list-only redirect (fd > 2 or {var}) — the same
decline the concurrent admissions make for such members — so
the sequential stage loop spawns stage 0 in a clean fd layout
and the shared delivery lands (GNU: execute_cmd.c:2620
execute_pipeline forks every element; redir.c:237
do_redirections applies the element's own list in the child).
Compound and function producers bind numbered redirects
through their own stage funnels, not the pin, and keep the
streaming path. The #2284 pin guard is untouched.
Pins: four new tests in tests/issue2255_pipeline_stage_redirects.rs
(stage-0 input in 3- and 4-stage pipelines, stage-0 output in a
3-stage pipeline, middle-stage control). Per compile rationing
they are NOT run locally; the collector batch-verifies the full
issue2255 target under a scrubbed fd environment.
Refs #2255
…-opening them; narrow the §8 decline to non-stdio-dup bindings Collector batch on eecde6d: issue2255 target 9/11 — both numbered OUTPUT pins failed (the pre-existing 2-stage pin and the new 3-stage pin), each on the o.txt contents poll. Adjudication against the master-content build (0d253a5, 7/7 there): (1) >=3-stage stage-0 output WAS already broken on master, by the SAME §8 mechanism as the input face (shell-writer guard skip: the child had no fd 3 — `sh: 1: 3: Bad file descriptor`, o.txt created empty by the delivery open). Not a different mechanism at stage 0, so the pin stays and the decline already routes the shape here. (2) The decline exposed a SECOND, distinct mechanism in the sequential composition: route_pipeline_stage_streams re-runs the ordered output walk AFTER the stage executed, and the walk's open_command_output_target performs a create/truncate validation open for every numbered target. GNU performs ONE open per redirection, in the element's fork (execute_cmd.c:2620 execute_pipeline; redir.c:237 do_redirections). Slow-writer probes: the child's bytes land in the file during its run, then the post-stage open truncates them away. On master this same mechanism wipes MID- and LAST-stage numbered output (the binding is delivered there; the content is destroyed at routing time) — strace shows the shell process opening the target O_TRUNC a fourth time, after the child exited. Fix: OutputFdState gains resolve_only_numbered, set only by route_pipeline_stage_streams. The walk still resolves the full ordered list (a dup chain like `3>f 2>&3` resolves and its captured stream flushes by append exactly as before), but for fd > 2 it records the target with no filesystem open: the plain arm skips its validation open, and the /dev/fd arm records the alias resolver's path instead of fresh-opening it again. Fds 1/2 keep full apply semantics — this walk IS their realization, and their opens stay validated pre-run by pipeline_stage_stdio_targets. Three new pins cover the mid-stage, last-stage, and dup-chain output faces. (3) The original decline also regressed an unpinned 2-stage shape: `sh -c 'echo o >&3' 3>&1 | wc -c` printed 2 on master (the writer path delivers a stdio dup there — the producer child's only foreign pipe is its own stream pipe, the stdio alias the #2284 guard recognizes) but EBADF after declining, because the sequential spawner's delivery cannot dup a capture-pipe stdio endpoint onto a numbered slot. That sequential defect is pre-existing (mid/last-stage stdio dups fail on master too) and is not a §8 shape, so the decline now exempts pure stdio dups (DuplicateInput/DuplicateOutput carrying an `&N`/`&N-` spelling of fd 0/1/2, no {var}) via redirect_is_stdio_dup. File, close, and dup-of-a-non-stdio-fd bindings keep the decline: `3>&-` at 2 stages stays fixed by it, and dup-of-file / append / readwrite producers verified fixed by it at >=3 stages. At >=3 stages the stdio dup is lost on both paths today; the exemption preserves master behaviour there instead of changing its shape. Verification (this workdir, scrubbed fd environment): issue2255 target 14/14 (11 + 3 new), issue1963 6/6, issue2235 11/11, issue2250 5/5, issue2256 25/25; regression goldens show only the four known local stock reds (master-red in this VM, CI-green); streaming spot checks (yes | head -3, yes | head -1 | wc -l, compound writer | head -2) intact. A 19-case GNU-oracle battery over the output/dup face matches GNU on 17; the two remaining diffs (stage `2>file`, stage `3>/dev/fd/N` fresh-open) are byte-identical on the master build — pre-existing, untouched here, and recorded in the cluster REPORT addendum. Refs #2255
This was referenced Oct 30, 2026
caomengxuan666
marked this pull request as ready for review
October 30, 2026 23:40
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP: §8 face of the reopened #2255 — stage-0 numbered bindings in ≥3-stage pipelines.
Root cause.
execute_shell_writer_pipelineclaimed stage 0 as a "streamable external producer" without inspecting its ordered redirects list, andrun_shell_writer_pipelinespawns the consumers on pre-created pipes before running the producer through the sequential stage spawner. The producer child is therefore forked while foreign anonymous pipes (the consumer chain's ends) occupy the low descriptor slots; one parks exactly on the fd-delivery pin's target slot, andpin_ambient_fds_in_child's exec-error-channel guard (rubash#1626, stdio-alias refinement in #2284) cannot tell that foreign pipe apart from std's error channel, so it skips the pin.apply_external_fd_deliveryhad opened the binding, but the dup2 onto its slot never ran — strace shows the staged pin copy being closed with no dup2, and the child's fd table shows the seed only at the delivery's raw open slot (fd 8), with no fd 3 at all. The 2-stage composition escapes because its only foreign pipe is the stage's own stream pipe (recognized by the stdio-alias check); fd ≥ 4 targets escape because the foreign pipes only reach the lowest slots; middle stages escape because the concurrent specs already decline list-only members there.Fix. Decline the shell-writer path for an external producer carrying a list-only redirect (fd > 2 or
{var}) — the same decline the concurrent admissions make for such members — so the sequential stage loop spawns stage 0 in a clean fd layout and the shared delivery lands. GNU ground truth: execute_cmd.c:2620execute_pipelineforks every element; redir.c:237do_redirectionsapplies the element's own list in the child. Compound and function producers bind numbered redirects through their own stage funnels, not the pin, and keep the streaming path. The #2284 pin guard is untouched.Pins. Four new tests in
tests/issue2255_pipeline_stage_redirects.rs: stage-0 input in 3- and 4-stage pipelines, stage-0 output in a 3-stage pipeline, and a middle-stage control (already green; guards the routing).Verification split. Run locally:
cargo check(lib) andcargo check --test issue2255_pipeline_stage_redirects, per-file rustfmt, LF check — all clean. NOT run locally (compile rationing): the pin target itself. Diagnosis evidence against the resident #2284-branch binary (4d5f760): fd-table dumps + strace of the pin skip, fd-4/fd-9 target controls, builtin-middle control forcing the sequential loop (delivers). The collector batch-verifies the full issue2255 target under a scrubbed fd environment; probes are in the cluster workdir (probes/).Refs #2255 — this PR does not close the issue; the collector closes it after the full 2255 pin set re-verifies.