Repository navigation
spawn: deleted-cwd spawn anchor + comsub ambient fd delivery + procsub settlement completion pins (Refs #3198, Refs #3201, Refs #2526) - #3234
Merged
Conversation
…26 settlement markers at shell exit Refs #3198, Refs #2526 Rework of the two captain-review points: - The deleted-cwd anchor served spawned children (fchdir) but not in-process readers: the emulated cat resolved a relative operand through session_path's string join, so `cat ../f` from a deleted cwd died at the dead path component where a spawned cat reads it fine (discrimination probe: real wc/grep/head/dd all read `../f` from the deleted inode; only the emulated cat and cp failed). external_cat's operand read now goes through the new Executor::read_session_anchored: for a relative operand whose session cwd no longer resolves, the read opens relative to the cwd anchor handle (openat) - the in-process twin of stamp_spawn_cwd's fchdir, with the same two-mode rule. Absolute operands keep the plain path open, matching GNU's ENOENT for `cat $PWD/../f` from a deleted cwd. - The 2526 settlement-completion pin asserted marker existence only after draining the shell's pipes to EOF; a detached producer inherits the stderr pipe and holds EOF off until it exits, so the assertions ran after the producer's marker touch and failed for any correct shell (GNU included). The harness now snapshots marker existence at shell exit, before either pipe is drained (pipes drain on side threads); values are the recorded GNU 5.3.20 oracle shapes.
caomengxuan666
marked this pull request as ready for review
November 10, 2026 14:28
This was referenced Nov 10, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 10, 2026
…3221) The output process-substitution spawn carries fd>=3 through the __RUBASH_FD_* env channel as inheritable dups delivered AT their stamped numbers; the child's init restores the stamped handle instead of adopting whatever descriptor sits at slot fd. Without this declaration the consumer adopted the inherited outer file at slot 3 (direct-test6: tap.log 7 lines, comsub empty, INNER-RC=1). GNU anchor: subst.c:6362 process_substitute forks the consumer at expansion time inheriting the expansion-time table, which is what the stamped handle carries. The comsub-nesting attribution half of this shape is already in master via #3132 (dollar_group_end opacity, d65441d): a span inside $(...) belongs to the comsub child, so the clone's stage machinery materializes it via this stamped spawn route. This commit carries the stamped-delivery half plus the pin that proves the combination. Verified on the Simular box. run6 (pre-rebase tree): fail-first pin 3 passed / 2 failed (cells 04/05 red); head pin 5 passed / 0 failed; probe-adopt, V1, V2, V3 all pass; direct-test6 INNER-RC=0; RUSTFLAGS="-D warnings" cargo check rc=0; fmt rc=0; marker-lint rc=0; lib head 1207 passed / 0 failed, failure name set empty. run7 (rebased head, box pid 718998): Phase A on pure master d7a3725 — pin 5/0 and probe-adopt PASS without this PR (#3132 + #3234 already fix the reduced shapes); Phase B on the head — probe-adopt, V1, V2, V3 pass, pin 5/0, direct-test6 INNER-RC=0, -D warnings/fmt/marker-lint rc=0, lib head 1230 passed / 0 failed / 4 ignored, failure names none. run8 (discrimination, 917870f binary, box pid 721997): direct-test6 INNER-RC=1 with the byte-identical leak and pin 5/0 — #3266 exonerated, and the stamped insert is what fixes the real bats shape (the reduced pin passes on master without it; the full shape is guarded by the direct-test6 box leg). Adjacent gap, out of scope: the backquote shape (out=`exec 3<&1; ...`) still fails on the head (BQ-FAIL: log non-empty) — #3132's rule covers only $-groups; GNU expects OUT hello twice, log empty. Refs #3221
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.
W-SPAWN lane: process-lifecycle family — spawn cwd stamping and comsub fd delivery, plus completion-form settlement pins.
#3198 — deleted cwd refused every external spawn (rc 127)
GNU:
cdmoves the process cwd itself (builtins/cd.defcd_builtin-> chdir) and execute_cmd.cexecute_disk_commandforks a child that inherits it; no path is re-resolved at spawn, so an unlinked cwd stays valid. Under G-02 the session cwd is a field and every spawn stamped it withCommand::current_dir(path), whose child-side chdir re-resolves the string — ENOENT once the directory is gone.Fix, by mechanism in one funnel: ShellState gains a cwd anchor (an open handle to the cwd directory, refreshed on cd and on each stamp, with a (dev, ino) freshness check). The new
stamp_spawn_cwdreplaces all 15 directcurrent_dirstamps (foreground, pipeline stages, compounds, comsub shortcut, procsub respawn, fallbacks): resolvable path → stamp by path as before; unresolvable but anchored → pre_execfchdironto the anchor inode (.is the deleted dir itself,..its real parent); unanchored → leave unstamped rather than refuse the spawn.spawn_whitelisted(respawn face) likewise skips an unresolvable cwd stamp. Pins:tests/issue3198_deleted_cwd_spawn.rs, 7 completion-form cells (outputs + exit codes, no timing thresholds).#3201 — comsub ambient fd delivery depended on body shape
Repeatability measured before fixing (N=20/10): a trivial comsub body delivered ambient fds 0/20; a non-trivial body 10/10. The split is path selection, not timing: the trivial-body shortcut spawner (
run_external_command_substitution) registered no ambient pins, while the full executor delivers them. GNU subst.c:7143command_substitutehas one fork path for every body.Fix: the shortcut spawner now registers the ambient pin set (
ambient_fd_pins_unbound, sharing theambient_fd_pins_forcore) through the existingpin_ambient_fds_in_childtransport. Sources are the fd table's own handles, so no inheritable duplicate — and no new alias — is introduced on this face. Pins:tests/issue3201_comsub_ambient_fd.rs, exact fd sets for the trivial face, presence-only for the full-executor/direct faces whose alias behaviour is a different issue's face.#2526 — settlement membership, completion-form pins
Facecheck: the headline block was adjudicated in 2026-11 as a pin-harness artifact and the bare-wait membership cells already match GNU (see the existing settlement pins on master). This PR adds
tests/issue2526_procsub_settlement_completion.rs: the same cells plus the abandoned-producer boundary, asserted only by output bytes, exit status, and marker-file existence at shell exit — no absolute time thresholds. GNU reference: jobs.c:2796wait_for_background_pids, subst.c:6479procsub_add. The Windows finish-time face stays with the Windows side per the earlier adjudication; nothing here claims it.What this PR deletes
Nothing is deleted. It adds the cwd-anchor state and one spawn-stamp funnel (replacing 15 direct stamp call sites), adds ambient pin delivery to the comsub shortcut spawner, and adds three pin files. The ambient pin transport itself and the procsub spawn-fd face are untouched.
Refs #3198
Refs #3201
Refs #2526