Skip to content

fix(executor): staged pipeline input keeps a shared cursor for bounded reads (Refs #2779) - #3694

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2779-staged-input-cursor
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2779-staged-input-cursor

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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 the FUNCTION_STDIN text mirror, and mapfile -n's bounded pull took the slurp arm — stdin_string_for_command_mut parks FUNCTION_STDIN_OFFSET at 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 — lseek ESPIPE 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.c do_piping).

mapfile_record_source resolves the staged mirror to a new MapfilePullSource::StagedText arm (incremental raw-byte pull, like the pipe/handle arms), and mapfile_source_sync — now the single consume point for the bounded and callback paths — folds origin + taken back into FUNCTION_STDIN_OFFSET (idempotent across the callback path's per-record syncs).

Legs

  • cargo test --test issue2779_pipeline_brace_group_staged_input under WSL: 8/8.
  • GNU 5.3.20 script-file probes: byte-for-byte match on mapfile-n1+cat, mapfile+read+cat chain, unbounded-mapfile guard.
  • GNU cites: builtins/mapfile.def:162-166, execute_cmd.c do_piping.

Generated with Devin

…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>
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