Repository navigation
fix(io): flush buffered output before IO.exit - #1519
Merged
Merged
Conversation
Lorenzobattistela
approved these changes
Oct 13, 2026
Merged
viridale
added a commit
to viridale/bend-cli
that referenced
this pull request
Oct 20, 2026
Records lessons from commits since 9f7b840 that AGENTS.md lacked: planting bugs against a new law; the kernel's missing eta and tab_cons; ctorarms.py and charsplit.py for heads a wildcard arm refined; chk-expected.tsv rows and CI cases for files reaching run.bend; #ifdef CID guards in .c effects; consing then reversing over List.append; Bool.or and Bool.and as eager; FID names from the harness path and _C closures; peerbench.sh; test_tools.py; where the minimum Bend is pinned; e2e's build/ inputs. Updates what changed: PROOF.bend takes ~40 s and --verdict ~3 min; native IO.exit on 2.0.37 exits with its code, not 141, after a print to a closed pipe (checked today), so run.bend keeps Sys.exit until bendlang/bend#1519 ships; kernel.sh retires with bendlang/bend#1536; 1.0 waits on bendlang/bend#1466, as the README now says.
viridale
added a commit
to viridale/bend-cli
that referenced
this pull request
Oct 21, 2026
run.bend declared its own Sys.exit because Base's IO.exit, natively, skipped the checked stdout flush: with stdout a closed pipe, `pkg run exit 3` exited 3 where every other write ends the process by SIGPIPE. bendlang/bend#1519, in Bend 2.0.38, flushes before the exit, so Run.exit now calls IO.exit, and sys.c and sys.js keep only Sys.isatty and Sys.columns. exit_when, exit, finish, ended and stepped no longer rely on foreign code, so run.bend and its importers list only Sys.isatty, Sys.columns, host and main; CI's expected output and tools/chk-expected.tsv follow. The README's platform note and AGENTS.md's IO.exit rule say so, and tests/host.bend's header no longer claims to test an unreached effect. A new CI step runs `pkg run exit 3`, native and under Bun, into a closed pipe and requires status 141. With io_sync removed from the old Sys.exit, the native build exits 3 there instead. Checked on Bend 2.0.38, macOS arm64: - tools/chk.sh: 20 ok, 0 with errors; CI's source-module check passes - bend tests/e2e.bend: 121 runs passed - Closed stdout: 141 native and under Bun; with stdout open, both exit 3 - Example apps native and under Bun, the TTY smoke test, the benchmark's equal stdout at one thread and all cores, and tests/complete/run.sh bash zsh fish man: pass - No law, proof or benchmark imports run.bend. Co-Authored-By: Claude <[email protected]>
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.
Problem and fix
Native
IO.print("buffered")followed byIO.exit(0)can report success even when stdout's reader has closed. The short output stays buffered, and libc's implicit exit flush bypasses Bend's stream-error handling.Call the existing
io_sync()after exit-code validation and before nativeexit. This applies the accepted stream-error policy: EPIPE terminates quietly by SIGPIPE; other flush failures use the existing diagnostic/status 1. This intentionally changes the exit status when earlier buffered output fails. Healthy output, requested exit codes, quiet exit behavior and invalid-code validation remain intact.Blast radius
Four files: one added line in
bend2/comp.tsand an extension to the existingtests/io/stream_epipe.{bend,c,js}regression. The native Halt/Exit branch shares the flush; Halt already flushes through its error writer. No Base API, parser, device runtime, main-result semantics, gate or cap changes.Regression evidence
The existing native pipe/fork fixture now resumes its first child into checked
IO.printfollowed byIO.exit(7). It reportsexit: 7on main andexit: 141with the fix, including under a PTY; removing only the flush restores the failure. Existing stdout/stderr cases remain. The JS twin continues to check its synchronous writer, which encounters EPIPE before exit.Checks
git diff --checkpasses.Validation limits
Local execution used macOS arm64, Bun 1.3.11, Node 26.8.2 and clang 23.1.3. Linux, Windows, GPU paths, installed compiled CLI and full cluster test/perf/ping/safe gates were not run; the cluster hostname is unavailable locally.
Node's
stderr_failurefixture has the same pre-existingerrno 2versusNo such file or directoryoutput mismatch on main and this branch. Node stream_epipe was skipped because its existing twin requires bun:ffi; exit_status has no native twin.--check-onlyrejects these two foreign fixtures identically on main and this branch; their normal build and execution lanes pass.