Repository navigation
WIP: materialize heredoc Text endpoints for spawn delivery (ambient + own-list dup faces) - #2303
Merged
Merged
Conversation
rubash#2292: a heredoc / here-string Text binding was invisible to every machinery that hands descriptors to a child, on two layers of one mechanism. Ambient bindings (group / function / script / exec faces): the binding lives in the fd table as a Text endpoint with no OS handle, and the ambient spawn delivery (the __RUBASH_FD_* stamp and ambient_fd_pins_for) only carries handle-backed endpoints, so a foreign grandchild inherited nothing at the slot and read EBADF. GNU's forked child inherits the descriptor here_document_to_fd created (redir.c:423) because do_redirections (redir.c:237) runs in every fork. New deliver_ambient_text_endpoints pass in the shared delivery segment materializes ambient Text endpoints into carrier files (the #2272 {var} trick), skipping every slot the command's own list, its own heredoc_redirects, or a {var} binding owns — the skip is what preserves the 2026-09-29 owner-tag rationale documented on ambient_fd_pins_for. Own-list bindings (the widened Discovery B face, e.g. `cat 3<<EOF <<EOF2 <&3`): a heredoc entry recorded no ordered fd effect in the reject gate and was kind-skipped by the fd-0 dup replay, so a later `<&N` dup of the heredoc's fd in the same list was rejected `N: Bad file descriptor`. The gate now records the heredoc / here-string binding at its list position (here_document_to_fd, redir.c:423; dup2 onto the redirector at redir.c:1065-1072), and own_input_binding_before materializes the winning heredoc body through the position-exact ordinal correlation (materialize_async_stdin_body, now returning the carrier path) and stashes it as the own binding, so the spawn stamps one description at N and the dup shares it. Pins: tests/issue2292_ambient_text_spawn_delivery_regressions.rs — compound faces (group/function/script/exec/pipeline stage), here-string faces, File and plain-heredoc controls, the Discovery B dup cells (dup-to-stdin, superseded dup, dup-before-bind negative control, builtin face), and the exec-ambient overlap cells (no clobber in either direction). Expectations byte-verified against GNU bash 5.3.20 with foreign-observer probes; the pins themselves are pending the collector's scrubbed-fd batch (compile rationing: cargo check only locally). Refs #2292
… bind
The pin's sibling bind was a same-fd heredoc inside the group
(`{ cmd 3<<INNER >/dev/null; cmd; } 3<<OUTER`). Collector-batch
adjudication (oracle-first, GNU bash 5.3.20 + script-file probes
adj/q1-q7 in the cluster workdir) showed that shape adjudicates
the pre-existing nested-heredoc body-correlation defect filed as
rubash#2305, not #2292's spawn-delivery mechanism: the two bodies
cross (first command served OUTER, second INNER), the pure
in-process face loses the ambient body as well, and a File bind
at the same slot behaves correctly on both shells.
GNU ground: redir.c:237 do_redirections is the single ordered
walk; with RX_UNDOABLE it records an undo list (redir.c:229-236,
undo via execute_cmd.c:526 undo_partial_redirects) so a sibling's
scoped redirects restore the group's binding intact, and each
heredoc's body travels with its own redirect node (redir.c:423
here_document_to_fd). The pin's expectation (second command reads
outer-body) is GNU's; only the trigger belonged to #2305.
The pin now binds the sibling's fd 3 to a file, preserving the
#2292 property under test (a redirect-less second command
inherits the group's ambient Text binding after a sibling's
scoped same-slot bind/restore), with a comment recording the
excluded heredoc variant and its owner. Full issue2292 target:
18/18 under the scrubbed-fd runner; issue2235 control 11/11
(single-threaded; parallel runs flake under VM load on a pin this
diff does not touch — see cluster REPORT-ADDENDUM.md).
Refs #2292
caomengxuan666
marked this pull request as ready for review
October 31, 2026 01:06
This was referenced Oct 31, 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: fix for #2292 (ambient heredoc Text endpoints not materialized for spawned grandchildren), as widened by collector adjudication to all faces including the plain exterior-command face of Discovery B.
One mechanism, two layers — a heredoc / here-string Text binding was invisible to the machinery that hands descriptors to a child:
Ambient bindings (group / function / script /
execfaces): the binding sits in the fd table as a Text endpoint with no OS handle; the ambient stamp +ambient_fd_pins_foronly carry handle-backed endpoints, so a foreign grandchild read EBADF. Fix:deliver_ambient_text_endpointsin the shared delivery segment (apply_external_fd_delivery) materializes ambient Text endpoints into carrier files (the {fd} 变量形重定向在 spawn 投递面全 kind 缺失(外部子进程拿不到 fd_var 绑定) #2272 {var} trick), skipping every slot the command's own list, its ownheredoc_redirects, or a {var} binding owns — the skip preserves the 2026-09-29 owner-tag rationale. GNU basis:here_document_to_fd(redir.c:423) +do_redirections(redir.c:237) in every fork (execute_cmd.c:2620 for pipeline elements).Own-list bindings (Discovery B:
cat 3<<EOF <<EOF2 <&3→3: Bad file descriptor): a heredoc entry recorded no ordered fd effect inreject_invalid_redirectsand was kind-skipped by the fd-0 dup replay (own_input_binding_before). Fix: the gate records the heredoc / here-string binding at its list position (redir.c:423; dup2 at redir.c:1065-1072), and the replay materializes the winning body via the position-exact ordinal correlation (materialize_async_stdin_body, now returning the carrier path) and stashes it as the own binding.Pins:
tests/issue2292_ambient_text_spawn_delivery_regressions.rs(17 pins) — compound faces, here-string faces, controls, the B dup cells (incl. the GNU-matching dup-before-bind negative control and the builtin face), and theexec-ambient overlap cells. Expectations byte-verified against GNU bash 5.3.20 with foreign-observer (python3) probes.Verification status (compile rationing):
cargo check+cargo check --test issue2292_ambient_text_spawn_delivery_regressionsgreen locally; per-file rustfmt applied; LF clean. Pins NOT run locally — pending the collector's scrubbed-fd batch. Known residuals (see the cluster REPORT.md): concurrent pipeline spawners are pins-only (no carrier lifetime) so ambient Text stays undelivered there; the compound-nested heredoc overlap ({ cmd 3<<INNER; } 3<<OUTER) is a separate pre-existing body-correlation divergence (fails on in-process faces too) and is deliberately not pinned here.Refs #2292