Repository navigation
WIP: executor: one evolving descriptor space for the {var} applier walk (#2612, subsumes #2607) - #2619
Merged
Conversation
caomengxuan666
added a commit
that referenced
this pull request
Nov 2, 2026
…when its redirector was open (rubash#2612) Captain verify of #2619 left one red pin: the x2 move chain's tail. After `wv 8>&9- {v}>&8` GNU leaves the caller's fd 9 closed; rubash restored it. GNU redir.c do_redirection_internal's dup/move arm adds the source's undo record — add_undo_redirect (redir_fd, r_close_this, -1) at redir.c:1175 — only when the redirector is open at the entry's walk position (the fcntl (redirector, F_GETFD, 0) != -1 test at redir.c:1173); with an inactive redirector the close has no undo record and survives undo_redirections, the restore mechanism every in-shell scope unwinds through (execute_cmd.c:5606 for functions). The compound binders in command_input_scope.rs are that shared scope machinery (function bodies, builtin dispatches and compound commands all wrap over them). Their output arm snapshotted the move source unconditionally — the phantom restore. Their input arm never snapshotted it — the mirror defect: `8<&9-` with an already-open redirector must restore the source (oracle-verified against GNU 5.3.20), and rubash left it closed. Both arms now take a MoveSourceSave policy: in-shell scopes pass GnuUndoable (snapshot iff the redirector is open at the entry's position — the live table at the arm, the list being applied in order; fds 0-2 without a table entry count as open, the process's own stdio), while the same-exe script face's segmented binds pass RestoreAlways (a fork boundary: every mutation is restored, preserving that face's prior behavior exactly). The input arm's per-entry snapshot block is factored into save_compound_numbered_input_fd so redirector and source record identical state. Pins: the failing x2 pin is unedited — it is the spec. Three sibling cells of the same rule are added with verbatim GNU 5.3.20 script-file expectations: an output move whose redirector is already open (source restored), a group-scope move with an inactive redirector (source closed), and an input move whose redirector is already open (source restored).
caomengxuan666
marked this pull request as ready for review
November 2, 2026 15:41
…ubash#2612)
GNU runs a command's redirections as ONE ordered walk over ONE
descriptor space: do_redirections (redir.c:237) applies each entry
at its position via do_redirection_internal (redir.c:790), and the
REDIR_VARASSIGN dup arm copies the descriptor as bound at its
position (the F_DUPFD/dup2 sequence, redir.c:1138-1193; a failed
redir_varassign closes the just-duplicated fd, redir.c:1161-1166).
rubash's applier iterated only the list's {var} entries and copied
dup sources from the ambient fd table, so a fixed entry earlier in
the same list that rebound the source was invisible: f 9>o1 {v}>&9
delivered the caller's old fd-9 binding at the var's slot
(rubash#2607), and the spawn row stayed red for the same reason.
The applier now maintains the walk's evolving descriptor space
(FdWalkSpace): every loop that services {var} entries records each
fixed entry's binding as the walk passes it (file entries as
replays, table-materialized bindings as slots, closes as closed),
and a {var} dup — output arm, input arm, and the /dev/fd alias
shortcut — resolves its source against that space at its position.
Undo/restore records are unchanged: the space is consulted only
while entries apply; fd_var_external_undo, fd_var_pending_closes
and fd_var_close_restore keep their shapes and consumers.
Spawn delivery needed no second change: with the applier's records
corrected, deliver_fd_var_dup's walk_opened/stamp ladder resolves
the B1 row through the list's own rebind.
Regression pins: tests/issue2612_varfd_applier_walk_regressions.rs
(audit battery S01/S05/S16/S17 x fn/builtin/group/subshell, the S02
positional control, dup/move chains, B1 spawn row; expectations
from GNU Bash 5.3.20 script-file probes; allocated descriptor
numbers deliberately unpinned — the audit's cluster-E divergence).
Refs #2612
Refs #2607
…when its redirector was open (rubash#2612) Captain verify of #2619 left one red pin: the x2 move chain's tail. After `wv 8>&9- {v}>&8` GNU leaves the caller's fd 9 closed; rubash restored it. GNU redir.c do_redirection_internal's dup/move arm adds the source's undo record — add_undo_redirect (redir_fd, r_close_this, -1) at redir.c:1175 — only when the redirector is open at the entry's walk position (the fcntl (redirector, F_GETFD, 0) != -1 test at redir.c:1173); with an inactive redirector the close has no undo record and survives undo_redirections, the restore mechanism every in-shell scope unwinds through (execute_cmd.c:5606 for functions). The compound binders in command_input_scope.rs are that shared scope machinery (function bodies, builtin dispatches and compound commands all wrap over them). Their output arm snapshotted the move source unconditionally — the phantom restore. Their input arm never snapshotted it — the mirror defect: `8<&9-` with an already-open redirector must restore the source (oracle-verified against GNU 5.3.20), and rubash left it closed. Both arms now take a MoveSourceSave policy: in-shell scopes pass GnuUndoable (snapshot iff the redirector is open at the entry's position — the live table at the arm, the list being applied in order; fds 0-2 without a table entry count as open, the process's own stdio), while the same-exe script face's segmented binds pass RestoreAlways (a fork boundary: every mutation is restored, preserving that face's prior behavior exactly). The input arm's per-entry snapshot block is factored into save_compound_numbered_input_fd so redirector and source record identical state. Pins: the failing x2 pin is unedited — it is the spec. Three sibling cells of the same rule are added with verbatim GNU 5.3.20 script-file expectations: an output move whose redirector is already open (source restored), a group-scope move with an inactive redirector (source closed), and an input move whose redirector is already open (source restored).
The trailing probe's fails before its own applies (redirections process left to right), so GNU bash 5.3.20 emits 'driver.sh: line 7: 9: Bad file descriptor' on stderr — verified byte-identical against the oracle; rubash already matched. The pin's empty-stderr expectation was the defect, not the product.
caomengxuan666
force-pushed
the
fix/2612-varfd-applier-walk
branch
from
November 2, 2026 15:49
1481e0f to
73f8c5b
Compare
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.
Refs #2612
Refs #2607
CODE-ONLY cluster delivery (W20) — captain compiles/verifies/merges centrally. Verified locally only to
cargo check --all-targets(clean); the new pin stem is UNVERIFIED-BY-CAPTAIN.The mechanism
GNU runs a command's redirections as ONE ordered walk over ONE descriptor space (redir.c:237
do_redirections; each entry applies at its position, redir.c:790do_redirection_internal; the REDIR_VARASSIGN dup arm copies the descriptor as bound at its position, redir.c:1138-1193). rubash's in-process{var}applier iterated only the list's{var}entries and copied dup sources from the AMBIENT fd table, so a fixed entry earlier in the same list that rebound the source was invisible (f 9>o1 {v}>&9delivered the caller's old fd-9 binding — #2607), and the spawn row B1 stayed red for the same reason.The applier now maintains the walk's evolving descriptor space (
FdWalkSpaceinsrc/executor/trap_exec.rs): every loop that services{var}entries records each fixed entry's binding as the walk passes it — file entries as replays of the stored entry, table-materialized bindings (injected group redirects,{var}binds, fd-alias targets) as table slots, closes as closed, heredoc/herestring and non-dup dup-targets as unmodelled (fail-closed) — and a{var}dup resolves its source against that space at its position in the output arm, the input arm, and the/dev/fdalias shortcut. Fixed dup entries record their source's at-position binding, so dup chains and move chains resolve transitively. Undo/restore records are unchanged (the space is consulted only while entries apply).Loops converted: the simple-command funnel (
apply_dynamic_fd_var_redirects, covers functions / builtins / pipeline stages / subshell faces that route through it) and the compound scope loop (with_command_input_redirects). The exec-with-operands face passes an empty space: its own loop binds fixed entries into the persistent table in list order, so the table already is the evolved space there.pin_ambient_fds_in_child's staging order (#2604) is untouched.Delivery alignment — analysis, no second change
Spawn delivery needed no edit:
deliver_fd_var_dup's ladder keys off the applier's records (the var's value, its stamped source description, the numbered records). With the applier binding the var from the list's own rebind, the B1 row (./w.sh 9>out1.txt {v}>&9 1>&10) resolves through the existing walk_opened/stamp steps. The B1 pin in the new test file adjudicates this; if it comes back red, the revocation step described in the cluster REPORT is the follow-up, as its own change.Tests
New stem:
issue2612_varfd_applier_walk_regressions— UNVERIFIED-BY-CAPTAIN. Audit battery S01/S05/S16/S17 x {fn, builtin, group, subshell}, the S02 positional control (dup-before-rebind keeps the ambient binding), dup chain, move chain, B1 spawn row (unix-only). Expectations from GNU Bash 5.3.20 script-file probes run by the cluster. Allocated descriptor NUMBERS are deliberately unpinned for the in-process faces (GNU's undo save transiently occupies the first free slot; the number is the audit's cluster-E divergence, not this issue).Guard stems for the captain's run are listed in the cluster REPORT (issue2522, issue2599, issue2255, issue2272, issue2281, issue2322, issue2368, issue2562, issue2502, issue2029).