Skip to content

WIP: fix(executor): keep the spawn capture record across a route decline (niubash#729) - #2264

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/729-command-pipeline
Oct 30, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/729-command-pipeline

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP — collector: batch-run the executor::external_route lib tests and the probes before merge (author ran cargo check + cargo check --tests only, per the rationing regime).

What

Refs unixwin/niubash#729 — command perl -e 'print "X\n"' | wc -c prints 0 in niubash (works in the rubash binary and in GNU): a non-final command <external> pipeline stage loses its stdout.

Attribution: engine (rubash), route seam — not the niu host

niubash registers its FFI route provider unconditionally (declining every call while its switch is off); the rubash binary registers none. The stage re-dispatch (command → execute_external_inner) prepares a capture-bound spawn plan whose fd 1 is the stage capture, then consults the route. On Declined, try_external_route unconditionally spent external_stdio_outcome — the record that owns the capture pipe's reader and keys the prepared spawn's capture drain. The spawn that followed wrote into a pipe nobody routed into the capture, so the stage produced nothing. With no provider registered, the consult exits at its first gate before touching the record — hence niu-only. The spend also contradicts the fn's documented contract ("a decline leaves every piece of spawn state exactly as the preparation left it"). Defect verified present at the issue's engine rev c31b357 and at master.

Adjacent but different from #2255 (a stage's own redirects not applied): this is capture routing after redirect application, in the route seam.

Fix

Spend the record only on the Handled outcomes (Completed/Cancelled — no spawn follows). On Declined, the prepared spawn owns it: spawn_external_process consumes it on every success path and drops it on the spawn-error path, so nothing leaks into the next command.

GNU anchor: execute_cmd.c:2620 / :6373 — every pipeline element's fd 1 is the pipeline; a command prefix changes nothing about the wiring.

Pins

issue729_declining_provider_keeps_command_stage_output in the existing route harness, with a new DeclineRecorded mock behavior (records the consult, then declines — non-vacuity): command dd as first stage, middle stage, and command -p dd, each byte-identical to the no-provider baseline. The Decline × active-capture cell was previously untested (decline battery = file redirects only; capture battery = claiming provider).

Full evidence chain: workdir REPORT.md (fix-729-command-pipeline) — niu picks this up on its next rubash pin bump; no niu code change.

…niubash#729)

try_external_route spent the spawn plan's capture outcome record
unconditionally after a route consult — including on Declined.
When the plan bound fd 1 to the active capture (the realization a
`command <external>` builtin pipeline stage produces: its
re-dispatch runs in-process under the stage capture), the record
owns the capture pipe's reader and keys the prepared spawn's
capture drain, so a declining provider silently disarmed the
spawn: the child wrote into a pipe nobody routed into the
capture and the stage produced no output (`command perl ... |
wc -c` printed 0 in niubash, which registers its FFI provider
unconditionally and declines while its switch is off; the
provider-less rubash binary exits the consult at the
no-provider gate and was never affected).

Spend the record only on the Handled outcomes, where the route
consumed the call and no spawn follows. On a decline the
prepared spawn owns it: spawn_external_process consumes it on
every success path and drops it on the spawn-error path, so
nothing leaks into the next command. This restores the fn's
documented contract: a decline leaves every piece of spawn
state exactly as the preparation left it.

GNU: execute_cmd.c:2620 (execute_in_subshell hands each
pipeline element the pipe fds) and execute_cmd.c:6373
(do_piping) — every element's fd 1 is the pipeline; a `command`
prefix changes nothing about the wiring.

Regression pin: issue729_declining_provider_keeps_command_stage_output
(new DeclineRecorded mock behavior; first / middle / `command -p`
stages asserted byte-identical to the no-provider baseline). The
Decline x active-capture cell was previously untested: the
decline battery used file redirects only, and the capture
battery a claiming provider.

Refs unixwin/niubash#729
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 17:22
@caomengxuan666
caomengxuan666 merged commit 22532c8 into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/729-command-pipeline branch November 2, 2026 01:10
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