Repository navigation
fix(executor): pipeline bad substitution reports once and discards the element (Refs #3499) - #3761
Merged
Merged
Conversation
…e element (Refs #3499) GNU reports one diagnostic per bad element and discards it (DISCARD, status 1, no output); rubash reported one per bad word, ran the element with the failure's empty product, and leaked the verdict latch into the next command: - one-shot print budget (`bad_substitution_reported`) for the diagnostic; the verdict latch still sets at every site. - the verdict joins the DISCARD latch family, so spec nets decline and the stage wrapper harvests (empty, 1) instead of leaking. - external stages never spawn on a failed argv, and a failed word's arguments are dropped whole (a pre-failure `file` in `rm file ${-x}` must not reach the command). - the driver's routing walk skips a bad-substitution discard, so the element's redirects are not materialized there. Known limitation: a discarded element's own output redirect still creates/truncates its target - the stage redirect preflight opens the target before the word expansion that detects the failure (an unopenable target also swallows the diagnostic outright). Fixing that needs the preflight to move after expansion; same pre-existing divergence for the `${x?word}` gate.
Member
|
Thank you for the PR — received and queued for captain review. Per the owner's rule, external PRs are reviewed by the captain first; this is intake triage, not a merge decision. CI checked by name (main run 43805456889, canary run 43805456921):
Two things flagged for the captain's review:
No action needed from you right now — CI is watched and the captain will review. |
Member
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:无 |
This was referenced Nov 16, 2026
Member
|
【WIN-AGENT-AUDIT】s2 批次汇总(S 审计波 s2,10 个 PR 全部有处置)
要点:
|
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.
Fixes #3499
GNU reports one diagnostic per bad element and discards it (DISCARD, status 1, no output). Rubash reported one diagnostic per bad word, ran the element with the failure's empty product, and leaked the verdict latch into the next command.
Root cause: the
parameter_bad_substitutionverdict latch was set at each bad-substitution diagnostic site but the pipeline stage path never handled it —execute_pipeline_stage_inner's adjudication didn't check it, the stage wrapper's DISCARD latch family didn't include it, and the speculative concurrent specs didn't decline on it. The latch then leaked to the next command (silently discarded, fatal under POSIX mode /set -e), and external members ran with the failure's empty product (a""argv reachedcatas a filename; a live-piped producer's bytes escaped the wrapper's string harvest through the real pipe).What changed (13 files, +629/-68):
src/shell/state.rs,src/executor/init.rs: new one-shot print budgetbad_substitution_reported, riding every boundary the verdict rides (Clone, snapshot/restore, comsub clears, verdict consumers, prompt save/restore).src/executor/expand_word.rs,parameter_words.rs,embedded_parameters.rs: all 7 expansion-time print sites guarded by the budget; the verdict still sets at every site.src/executor/pipeline_exec.rs: verdict joins the DISCARD latch family (8-tuple); both spec nets decline on it; the wrapper harvests a set verdict to(empty, 1)(discarding the doomed run's captured stderr too) and flags the discard so the routing walk doesn't materialize the element's redirects; arg-word expansion drops all arguments when a word newly sets the verdict.src/executor/pipeline_stages.rs: external stages never spawn on a failed argv; tail-word expansion drops all arguments the same way.src/executor/mod.rs,command_substitution.rs: newpipeline_stage_bad_substitution_discardedflag for the routing skip.tests/issue3499_bad_substitution_pipeline_discard.rs: 7 regression tests (issue shapes, latch leak, pipeline positions, later-words-never-expand, ERR trap + errexit, POSIX containment, discarded-element side effects).Verification (Simular box, GNU bash 5.2.21 oracle):
/bin/echo, two bad elements, assignment-only element, later-words side effects, ERR trap + errexit, POSIX mode, DEBUG-trap-forced sequential path, comsub +2>&1diagnostic routing.cargo test --lib: 1249 passed, 0 failed, 4 ignored. 15 neighbor suites (bad-substitution / pipeline expansion / discard / redirect): 134 passed, 0 failed.cargo fmt --checkandgit diff --checkclean.Known limitation: a discarded element's own output redirect still creates/truncates its target — the stage redirect preflight opens the target before the word expansion that detects the failure (an unopenable target also swallows the bad-substitution diagnostic outright). Fixing that needs the preflight to move after expansion; the same pre-existing divergence exists for the
${x?word}gate. The driver's routing walk already skips a bad-substitution discard.No new ledger API item is added (both new fields are internal executor/shell state), so the canary ledger comparison should be unaffected by this PR.