Repository navigation
WIP: fix fd seams #2589 #2590 #2591 - #2592
Merged
Merged
Conversation
caomengxuan666
force-pushed
the
fix/2589-fd-seams
branch
from
November 2, 2026 10:50
45aa756 to
2538567
Compare
A spelled /dev/fd/N operand is a fresh open on HAVE_DEV_FD builds: bash redir.c:601-603 only enables the RF_DEVFD dup emulation when HAVE_DEV_FD is absent, and redir.c:725 redir_open falls through to open(). When a pipeline stage leaves a materialized Text/ProcessSubstitution copy that still names a regular-file origin, serve the origin bytes and do not consume the stage copy. Apply the same rule to the Unix materialize path and the Windows table-operand path. Refs #2589
GNU treats a numbered dup chain as one shared open file description: bash redir.c:1193 uses dup2 for <&N, so a spawned stage advances the source only by bytes it actually reads. Rubash drained a buffered source endpoint while materializing an own input binding and never replaced that bind-time drain with the child's measured consumption. Keep a duplicate handle to the carrier file, record the endpoint cursor before the stream serve, and settle base + carrier position after the child exits. Settle from both the plain external dispatcher and the external pipeline-stage funnel; command-substitution forks start with no in-flight folds. Refs #2590
GNU distinguishes a spelled /dev/fd/N input from a <&N dup inside a pipeline element: redir.c:725 redir_open performs a fresh open for the spelling on HAVE_DEV_FD builds, while redir.c:1193 dup2 shares the description for a dup. The compound-stage funnel used dup_input for both winner kinds, so brace groups and subshells continued at the donor offset.
Classify the winning fd-0 redirect with the same search order as stage_fd_alias_source. For a spelled, non-{var} Input/ReadWrite winner, try Executor::bind_fd0_fresh_alias first and retain dup_input as the fallback for endpoints that do not reopen fresh; dup winners keep the shared-description path.
Refs #2591
…eline loop Repair of af74776 (#2589), whose r1b pin the captain's central verification caught at 3/4: `cat /dev/fd/6 | wc -c` after an earlier stage partially consumed fd 6 still served the stage copy's remainder (6) instead of the origin (12). Root cause: on Unix, a redirect-free pipeline of external commands takes the concurrent spawn loop (execute_external_pipeline_concurrently), and that loop never called materialize_dev_fd_operands — its Windows twin (spawn_wait_concurrent_external_stages) and both sequential paths (pipeline_stages.rs, external_inner.rs) all do. Stages resolved a spelled operand through the ambient fd pins alone, which carry snapshot/remainder semantics. GNU's r_input is a plain open of the path (redir.c:725) — on a HAVE_DEV_FD build the kernel resolves the magic link fresh for a regular-file endpoint, so the operand serves the origin from offset 0 and the donor does not move. Port the pass into the Unix loop per stage, mirroring the Windows twin: materialize before building the stage's process, attach the operand deliveries after the ambient pins, and finish the records only after every member has been waited (an earlier finish would drop a donor entry a later stage's own operand pass still reads). The std descriptors are carved out of the records (DevOperandMaterialization::exclude_std_fd_records): fd 0/1 in this loop are the OS plumbing itself (upstream pipe, capture wiring) — real descriptors the child resolves natively — and the shell's fd-table entry 0 is the enclosing context's binding, not the stage's to consume. Verification (slot + scrubbed cargo): issue2589 stem 4/4, issue2590 stem 5/5, guards 2502 6/6, 2503 4/4, 2029 10/10, 2322 13/13, 2368 6/6, 2483 6/6; adjacent 2256 25/25, 2276 7/7, 1873 17/17, 2106 8/8. Refs #2589
…rect application seam Repair of 5b58cdd (#2591), whose three positive pins the captain's central verification caught at 3/6: `{ cat; } < /dev/fd/6 | wc -c` and the subshell twin served the donor's remainder (6) instead of a fresh open (12). Root cause: GNU applies a compound element's redirections exactly once (do_redirections in the forked element). rubash applies them twice — the stage funnel's preliminary fd-0 bind, then the body's own application inside the subshell (with_command_input_redirects → bind_command_fd0_input) — and the second application wins for the mirror readers that serve the body. That inner serve, loop_redirect_input, modeled a SPELLED `< /dev/fd/N` as a dup: it handed out the endpoint's remaining bytes and drained the donor. The comment on that branch even stated the wrong invariant ("a dup of fd N, not a filesystem path"). GNU's spelled form is r_input → redir_open (redir.c:725), a plain open the kernel resolves fresh for regular files; only the `<&N` spelling is the dup (r_duplicating_input → dup2, redir.c:1193). The funnel-side fresh bind 5b58cdd added was therefore dead on arrival — the inner application displaced it on every path (the same double application also broke plain, non-pipeline `{ cat; } < /dev/fd/6`, `( cat ) < /dev/fd/6` and `while read; done < /dev/fd/6`). Fix at the seam that actually serves: loop_redirect_input's alias branch now applies the fd_alias_reopen_path rule first (the rubash#2256 rule, same as dev_fd_operand_bytes) — an endpoint that re-opens fresh is served from its origin file and the donor is not drained; endpoints that cannot re-open (pipes, staged text) keep the shared serve. The superseded funnel fresh-bind and its stage_fd_alias_winner_is_spelled classifier are removed: one owner for the open-vs-dup distinction, at the application that wins. Verification (slot + scrubbed cargo): issue2591 stem 6/6, issue2589 stem 4/4, issue2590 stem 5/5, guards 2502 6/6, 2503 4/4, 2029 10/10, 2322 13/13, 2368 6/6, 2483 6/6; adjacent 2256 25/25, 2276 7/7, 1873 17/17, 2106 8/8. Byte-exact probes vs GNU bash 5.3.20: r5c/r5d/full-r5 shapes, dup-winner negative control (shared serve, donor drained), plain group/subshell/loop spelled serves — all match. Refs #2591
caomengxuan666
force-pushed
the
fix/2589-fd-seams
branch
from
November 2, 2026 10:51
2538567 to
9f6b0ce
Compare
caomengxuan666
marked this pull request as ready for review
November 2, 2026 10:51
This was referenced Nov 2, 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 — code-only delivery under the 2026-11-02 pace directive. Captain verifies centrally; do not merge on local results.
Refs #2589
Refs #2590
Refs #2591
Commits
af747762— [fd] /dev/fd/N 操作数在管道 stage 消费后喂副本当前字节而非 origin 重开(簇 H 残差①) #2589: serve a stage-materialized/dev/fd/Noperand from its regular-file reopen origin instead of the stage copy's remaining bytes, without consuming the copy.975eb5c3— [fd] spawned stage 链式部分 fold 按载荷全长推进源 fd 而非真实消费(#2029 缝,簇 H 残差②) #2590: replace own-input-binding bind-time drain accounting with a carrier-position fold settled after the spawned child exits, for both plain external commands and external pipeline stages.5b58cdd0— [fd] 复合组/子壳 pipeline stage 对 spelled /dev/fd/N 输入 dup 绑定而非 fresh-open(簇 H 残差⑤) #2591: distinguish spelled/dev/fd/Nfd-0 winners from<&Ndup winners for compound/subshell pipeline stages; try a fresh alias open for spelled winners and retain dup binding as fallback.GNU basis:
redir.c:601-603gates the RF_DEVFD dup emulation to builds withoutHAVE_DEV_FD;redir.c:725is the plain-open path;redir.c:1193is the dup2 path for<&N.Captain verification required (UNVERIFIED-BY-CAPTAIN)
New pins:
issue2589_dev_fd_operand_origin_reopen— 4 tests, including r1c/r1d negative controlsissue2590_spawned_stage_chain_fold— 5 tests, including drainer negative controlissue2591_compound_stage_spelled_winner— 6 tests, including dup-winner and internal-spelling negative controlsGuards:
issue2502_pipeline_alias_delivery_regressionsissue2503_born_closed_stdin_regressionsissue2029_fd_offset_fold_regressionsissue2522_*stems present at harvestissue2322_close_position_regressionsissue2368_foreign_spawn_post_wait_trunc_regressionsissue2483_stream_drainLocal compile gate only:
cargo check --all-targetsexited 0 before the test-only master rebase. No slot/scrubbed test run was performed by W16.