Repository navigation
fix(executor): staged pipeline input keeps a shared cursor for bounded reads (Refs #2779) - #3694
Merged
Merged
Conversation
…d reads (Refs #2779) A pipeline stage's brace-group/subshell stdin is staged on the FUNCTION_STDIN text mirror with a FUNCTION_STDIN_OFFSET cursor, not a real handle. mapfile -n's bounded pull still took the slurp arm — stdin_string_for_command_mut parks the offset at end — so the whole staged remainder was consumed and the next reader of the same stage input saw EOF (`printf 'l1\nl2\nl3\n' | { mapfile -n1; cat; }` lost l2/l3). GNU's bounded read never over-consumes: for a pipe descriptor zgetline switches to unbuffered record reads (builtins/mapfile.def read_array:162-166, lseek ESPIPE), and for a seekable source the post-read lseek rewinds past the buffered surplus — both leave the tail on the shared fd. mapfile_record_source now resolves the staged mirror to a new MapfilePullSource::StagedText arm when the command's fd 0 is the shared mirror (function_stdin_is_command_source, no own stdin body): the pull is incremental in the raw-byte domain like the existing pipe/handle arms, and mapfile_source_sync — replacing the bare sync_offset calls at the bounded and callback consumers — publishes `origin + taken` back into FUNCTION_STDIN_OFFSET. The cursor write is idempotent across the callback path's per-record syncs because taken is cumulative from source creation. GNU: execute_cmd.c do_piping (the stage's fd 0 is one shared pipe for every command in the group), builtins/mapfile.def:162-166. tests/issue2779_pipeline_brace_group_staged_input.rs (unix-only): 8/8 under WSL. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Nov 15, 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.
Summary
tests/issue2779_pipeline_brace_group_staged_input.rs(unix-only) was fully red: a pipeline stage's brace-group/subshell stdin is staged on theFUNCTION_STDINtext mirror, andmapfile -n's bounded pull took the slurp arm —stdin_string_for_command_mutparksFUNCTION_STDIN_OFFSETat end — so the whole shared remainder was drained and the next reader saw EOF (printf 'l1\nl2\nl3\n' | { mapfile -n1; cat; }lost l2/l3).GNU never over-consumes a bounded read:
builtins/mapfile.def:162-166—lseekESPIPE on a pipe switches zgetline to unbuffered record reads; a seekable source is rewound to the consumed boundary. The stage's fd 0 is one shared pipe for every group command (execute_cmd.cdo_piping).mapfile_record_sourceresolves the staged mirror to a newMapfilePullSource::StagedTextarm (incremental raw-byte pull, like the pipe/handle arms), andmapfile_source_sync— now the single consume point for the bounded and callback paths — foldsorigin + takenback intoFUNCTION_STDIN_OFFSET(idempotent across the callback path's per-record syncs).Legs
cargo test --test issue2779_pipeline_brace_group_staged_inputunder WSL: 8/8.builtins/mapfile.def:162-166,execute_cmd.cdo_piping.Generated with Devin