leonida: a closed stdout or stderr drops the line instead of panicking (one write per line) #3447
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!3447
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/run-stdout-closed"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Change
A closed stdout or stderr (a parent that stopped reading, a pipe closed early, a console gone) made
leonidapanic on the nextprintln!/eprintln!and exit with 101. The 167println!/eprintln!ofapps/leonidanow go throughsay!/say_err!(apps/leonida/src/out.rs), which drop the line when the stream is gone instead of panicking.Stringand sent with a singlewrite_all, so another writer cannot cut a line in two (measured:write_fmtmade 5 to 6 writes per line). Output is byte for byte the same asprintln!. Cost: oneStringper line; none of the call sites is in a per-frame loop.writeln!calls that already handle a write error on purpose (warm.rs, exit 1) are unchanged.println!/eprintln!left inapps/leonida/src(those inbuild.rsare cargo instructions).Tests
cargo test -p leonida --locked: 58 passed, 0 failed (rerun by the reviewer side too).cargo clippy -p leonida --locked --all-targets: no diagnostic.check_no_game_data.pyon the touched files: pass.apps/leonida/tests/closed_stdout.rs(Windows only,#![cfg(windows)]): runs aleonidacommand with stdout bound to a file opened read-only; without the change the child panics and exits 101 (checked by putting an.unwrap()back for one try). On Linux std turns that case (EBADF) into Ok, so the test proves nothing there; a closed pipe (EPIPE) still reachesprintln!on Linux and is handled by the same macros.AI-assisted
Written with Freebuff (its "ultra" mode; the tool does not say which underlying model it runs), driven by Moon. Reviewed twice by separate Claude Opus 5.5 reviewer instances (Claude Code): accepted, the two requested changes (single write, Windows-only test) are in. Commit history kept as written; one early commit message still has the wrong Linux note, fixed in the next commit, so a squash merge is planned.
🤖 PR opened with Claude Code
Two review points. `out::line_to` wrote the text with `write_fmt` and then wrote the newline with a second call, so the text and its newline were two writes. It now does one `write_fmt` of `"{args}\n"`: the same text, one write. `tests/closed_stdout.rs` only proves anything on Windows: on Linux, `std` treats a failed write to stdout as success (a read-only descriptor gives `EBADF`, a closed pipe `EPIPE`, and `Stdout::write` returns the buffer's length either way), so `println!` would not panic and the command would end with 0 whether or not the fix is in place. The file is `#![cfg(windows)]`, with the reason in its doc comment. `cargo test -p leonida --locked`: 58 passed, 0 failed. `cargo clippy -p leonida --locked --all-targets`: no findings. With `line_to` made to panic again, both tests fail: the unit test at `out.rs:19`, and `census` ends with 101. AI-assisted (Freebuff, Buffy)The doc comment on `line_to` said `write_fmt` writes a piece per literal and per argument plus one for the newline. A counting `Write` says: a line with three literals and two arguments takes 5 writes through `write_fmt`, the merged `"{args}\n"` form also takes 5 (the newline joins the last literal), and the buffer with one `write_all` takes 1. The comment now states the rule without the off-by-one story. No behaviour change. `cargo test -p leonida --locked`: 58 passed, 0 failed. `cargo clippy -p leonida --locked --all-targets`: no findings. AI-assisted (Freebuff, Buffy)Merging (squash). Not a rendering change. Branch updated with main
93db515363; the merged tree (326f1d15) is the one tested locally:cargo test --locked -p leonida-gpu -p leonida -p leonida-hleall passed, 0 failed;tests/test_d3d12_switches.pyOK. Reviewed twice by separate reviewer instances (accepted). Thanks to Freebuff and Moon. AI-assisted (Claude Opus 5.5 for the review and merge).