Skip to content

test(host): pin the closed-stdout contract across every non-interactive execution shape (closes #286) - #289

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/286-pipe-close-exit
Oct 13, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/286-pipe-close-exit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #286.

Root cause (verified locally, RED reproduced)

#286 reported host_contract::closed_stdout_pipe_does_not_print_broken_pipe_error red on 0830c78: after the stdout reader leaves, niu never exits and stderr floods with niu: line 1: Broken pipe — one engine diagnostic per failed write, forever, because Windows has no SIGPIPE to kill an unbounded producer and the host had no convergence of its own (the engine's rubash#455 semantics correctly treat a closed-output write as the hitting command's failure and continue the list; on an infinite loop that degenerates into per-iteration spam).

The behavior fix is already on master: the piped-stdout pump (src/piped_stdout.rs, #245/#256, commit 11c1612, which landed after 0830c78) interposes one wrapper pipe between every process stdout writer and the real downstream, and on the first failed downstream write reports ONCE and exits status 1. Reproduced the RED for the record on a detached 0830c78 worktree (same spam, 3.79s FAILED), and master is GREEN (0.7s).

What this PR adds

The -c builtin-loop and yes shapes were already pinned by tests/broken_stdout_pipe.rs (#256's suite) and host_contract.rs. What nothing yet guarded were the execution shapes #286's report implies but no test covered. New tests/issue286_pipe_close_exit.rs pins all of them, deadline-bounded (a hang fails the test):

  1. script FILE producer loop (niu loop.sh)
  2. stdin SCRIPT producer loop (bare niu, script on stdin)
  3. EXTERNAL child as the unbounded producer (cmd /c echo per iteration — the inherited-wrapper-handle path)
  4. stderr also gone when the pump reports (the diagnostic write must not wedge the exit)

Contract pinned per shape: exit by itself, rubash#455-shaped status 1, no raw OS broken-pipe text ("Broken pipe" / "os error 232" / 管道正在被关闭), exactly ONE diagnostic.

GNU anchoring

WSL oracle: bash -c 'while true; do echo x; done' | head -c 16 — bash dies promptly via SIGPIPE with zero stderr bytes. niu's vendored adaptation keeps the prompt termination and the errno silence, deliberately spending one descriptive diagnostic plus status 1 instead of signal death (rubash#455 semantics ownership note in tests/broken_stdout_pipe.rs). Vendored-rubash side unchanged (#455 execute_cmd/trap semantics respected).

Test evidence

Merge-order note

#284/#287 (paste/typeahead, repl.rs + typeahead_guard.rs) is landing first per plan; this PR touches only tests/issue286_pipe_close_exit.rs — no file overlap. If master moves, rebase is trivial and I'll refresh.

…ve execution shape (closes #286)

The #286 failure (host_contract::closed_stdout_pipe... red on 0830c78:
niu never exits after the stdout reader leaves and spams 'niu: line 1:
Broken pipe' per failed write) is already fixed on master by the
piped-stdout pump (#245/#256): one diagnostic, status 1, prompt exit.
Reproduced locally for the record - the pin file below is RED on
0830c78 (3 of 4 shapes hang past the deadline) and GREEN on master.

What was still unpinned after #256 were the execution shapes #286's
report implies but nothing guarded: a script FILE producer loop, a
stdin-script producer loop, an EXTERNAL child as the unbounded
producer (the inherited-handle path), and stderr being gone too when
the pump reports. All four now carry the deadline-bounded contract:
exit by itself, rubash#455-shaped status 1, no raw OS broken-pipe
text, exactly one diagnostic.

GNU oracle (WSL bash): the same producer under 'bash | head -c 16'
dies promptly via SIGPIPE with zero stderr bytes; niu's vendored
adaptation keeps the prompt termination and the errno silence,
spending one descriptive diagnostic plus status 1 instead of signal
death - deliberate, per the rubash#455 semantics ownership note in
tests/broken_stdout_pipe.rs.
@caomengxuan666
caomengxuan666 merged commit 0957ad9 into master Oct 13, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/286-pipe-close-exit branch October 13, 2026 02:30
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.

[P2] stdout 管道关闭后 niu 不退出且 Broken pipe 刷屏(host_contract 红,100% 复现)

1 participant