Skip to content

WIP: design+fix: ambient Text endpoints for concurrent pipeline spawners (#2308) - #2331

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2308-concurrent-text
Oct 31, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2308-concurrent-text

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2308. Design + fix, ready for harvest review (cluster REPORT in the workdir has the full design, probe tables and run ledger).

Design (one paragraph)

Three resources, three owners: the carrier file already lives long enough (registered in procsub_adhoc_carriers, unlinked at finish_process_substitutions — after every pipeline stage is reaped); the parent-side inheritable dup must live from materialization until that stage's spawn() resolves (the sequential face's apply_external_fd_delivery contract); the actual gap was that the concurrent spawn loops never ran the Text pass at all — attach_ambient_fd_pins can only carry handle-backed endpoints, and a heredoc body has no handle. GNU ground: the body is materialized once (redir.c:423 here_document_to_fd) and every forked pipeline element inherits the descriptor (redir.c:237 do_redirections; execute_cmd.c:2620 execute_pipeline). The fix is contained in the current spawner architecture — no #2234-class carrier rework is needed.

What changed

  • external_inner.rs: new attach_ambient_text_delivery — runs the existing deliver_ambient_text_endpoints verbatim (same slot selection/skip rules), registers its pins as an additional pre_exec closure, returns the parent-side dups.
  • pipeline_exec.rs: all four concurrent spawn loops (spawn_wait_concurrent_external_stages, run_shell_writer_pipeline, execute_external_prefix_streaming_tail, non-Windows execute_external_pipeline_concurrently) call it beside attach_ambient_fd_pins and close the dups right after their spawn resolves. On Windows the concurrent faces gain the env-stamp channel the sequential face already had.
  • tests/issue2308_concurrent_text_delivery_regressions.rs: 8 pins (one-reader stage, group-wrapped pipeline, two stages on one heredoc, stage+grandchild, writer-pipeline consumer, mixed File+Text ambient on one stage, last-stage reader, prefix + brace-group tail).

Per-stage snapshot carriers are the standing #2272/#2292 delivery model (a child's reads don't advance the parent's offset); GNU's concurrent readers of one shared description race on the offset, so no deterministic behavior depends on sharing one carrier.

Verification (scrubbed-fd batches, CARGO_BUILD_JOBS=1)

  • Probes vs GNU bash 5.3.20: pre-fix every concurrent face read EBADF and lost the body; post-fix all shapes byte-match GNU.
  • New pins 8/8; controls issue2292 18/18, issue2235 11/11; lib 985/985; regression 221 passed + exactly the 6 stock local reds.
  • cargo check clean; rustfmt clean on touched files.
  • The issue2305 control (16 pins) doesn't exist on master yet (its target lives on PR WIP: fix(parser+executor): heredoc bodies stay with their own redirect node under compounds (#2305) #2313's branch) — left for the composed batch at harvest.

Residual found (separate bug, not this PR)

A rubash child inheriting two or more ambient heredoc carriers gets them crossed in its startup restore (its fd 3 serves the last carrier's body; parent delivery itself is proven correct via a foreign python3 witness). Reproduces with no pipeline at all on the sequential face, and this diff can't reach that path (additive-only in external_inner.rs) — pre-existing on master. Full evidence + reproducers in the cluster REPORT (residual R1), ready to file separately.

GNU materializes a heredoc body once (redir.c:423
here_document_to_fd) and every forked pipeline element inherits the
descriptor through the same do_redirections walk (redir.c:237;
execute_cmd.c:2620 execute_pipeline). #2292 taught the sequential
spawn faces to materialize ambient Text endpoints, but the
concurrent pipeline spawn loops only registered the handle-backed
ambient pins (attach_ambient_fd_pins) — a Text endpoint has no
handle to pin, no env stamp was made and no carrier materialized,
so a stage spawned in the concurrent burst read EBADF on every
ambient heredoc descriptor.

New attach_ambient_text_delivery (external_inner.rs) runs the
existing deliver_ambient_text_endpoints pass for a hand-built stage
process — same slot selection and skip rules, no second copy —
registers its pins as an additional pre_exec closure, and returns
the parent-side duplicates. All four concurrent spawn loops in
pipeline_exec.rs (spawn_wait_concurrent_external_stages,
run_shell_writer_pipeline, execute_external_prefix_streaming_tail,
the non-Windows execute_external_pipeline_concurrently) call it
beside attach_ambient_fd_pins and close the dups once their spawn
resolves — the apply_external_fd_delivery lifetime contract. The
carrier files keep living in procsub_adhoc_carriers until
finish_process_substitutions, after every stage of the pipeline
has been reaped; the only per-stage artifact is the dup, whose
required lifetime is exactly the one spawn.

Pins: tests/issue2308_concurrent_text_delivery_regressions.rs (8 —
one-reader stage, group-wrapped pipeline, two stages on one
heredoc, stage+grandchild, writer-pipeline consumer, mixed
File+Text ambient, last-stage reader, prefix + brace-group tail).
Controls: issue2292 18/18, issue2235 11/11, lib 985/985,
regression 221 passed + the 6 stock local reds.

Refs #2308
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 08:25
@caomengxuan666
caomengxuan666 merged commit 9561d6d into master Oct 31, 2026
13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2308-concurrent-text branch November 2, 2026 01:09
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