Repository navigation
Conversation
At the end of a pipe or a file, a line that is still in the line editor is submitted the way Enter submits it. A failed read and a terminal on stdin submit nothing.
|
Updated 1:56 PM PT - Oct 21st, 2026
✅ @robobun, your commit 8692289d3f3efd2a38207d80ea337ac31691998e passed in 🧪 To try this PR locally: bunx bun-pr 46126That installs a local version of the PR into your bun-46126 --bun |
|
Status Reproduced on Linux x64 with the released build (1.4.3) and with a release build of main (c1df64b):
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe REPL now distinguishes confirmed stdin EOF from read errors. For non-TTY input, it processes a non-empty final line when stdin reaches EOF. Tests cover EOF handling and terminal hang-up. ChangesREPL stdin EOF handling
Suggested reviewers: Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
|
Overlap note: #46248 changes the same loop. It reads a stdin that is not a raw terminal as lines of text, and it includes the end-of-input rule of this PR and its 11 tests. The failed-read test is skipped on Windows there, because the read after |
fs.closeSync(0) does nothing on Windows, so the read of stdin does not fail there and the last line runs.
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline finding, two things I checked on this push and ruled out: the synthesized Enter cannot spin at EOF, since every path through handle_enter (editor mode, dot-command, incomplete code, evaluation) either clears line_editor or sets running = false, so the next None from read_key takes the leave-and-break arm; and stdin_at_eof cannot be stale, because read_key returns None only via read_byte, which writes the flag on both of its None arms.
Extended reasoning...
The second push only adds a Windows skip to the failed-read test; the Rust change in src/runtime/cli/repl.rs is unchanged from the previously reviewed version. No security-sensitive surface is touched. The note records two concrete concerns examined from the diff and ruled out, in addition to the inline test-coverage finding.
Still open from earlier reviews (1):
- Unresolved: 1 minor or pre-existing.
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
LGTM. The two points from my earlier reviews are addressed by the latest commits: the failed-read test is now gated on Windows with the no-op closeSync(0) named, and the new repl | cat line-mode test gives Linux coverage for the !Output::is_stdin_tty() clause (raw mode is only set when both stdin and stdout are ttys, so Ctrl+D there is a real 0-byte read). The one inline note is pre-existing .editor behavior the description already lists as out of scope.
Extended reasoning...
The diff adds a stdin_at_eof flag set by read_byte and a loop arm in run_with_vm that synthesizes Key::Enter for a non-empty line at a clean, non-tty EOF, plus eleven tests in repl.test.ts. It touches no security-sensitive surface. Every handle_enter path either clears the line editor or sets running = false, so the synthesized Enter cannot loop, and bun_sys maps Windows BROKEN_PIPE/HANDLE_EOF to Ok(0) so the ungated piped tests hold there too. The change is about twenty lines of Rust with clear intent, the path has no CODEOWNER, and the only remaining finding is a pre-existing gap the author already documents.
Still open from earlier reviews (1):
- Unresolved: 1 minor or pre-existing.
Problem
bun repldrops the last line of piped input when it has no newline.echo -n 'console.log(1)' | bun replprints nothing and exits 0.run_with_vm(src/runtime/cli/repl.rs:2346) leaves. The line inline_editor.bufferis lost.Fix
Enter.node -iandbun --interactivedo the same. A failed read or a terminal on stdin submits nothing.test/js/bun/repl/repl.test.ts, 12 new tests, 8 fail without the fix. The file passes 141 of 141.Background
read_bytereturnsNoneat the end of stdin and after a failed read.stdin_at_eoftells them apart.handle_entercall at the end of input. The second call site stops its inlining: +12 instructions perEnter.Downsides
node -i..editorinput with noCtrl+Dat its end, and a terminal in line mode (bun repl | cat).Notes
Origin. A fuzz run on the REPL's stdin found it. There is no GitHub issue. The end-of-input arm is unchanged since the first native REPL (#26304, Bun 1.3.10).
Repro. Each input has no final newline.
mainis a release build of c1df64b.bun --interactive1+1222console.log("one"),console.log("two")oneone,twoone,twoone,twoif (true) {,console.log("two"),}twotwotwofoo(The rule. An input with no final newline behaves as the same input with one. That covers a dot-command as the last line, a line of spaces (prints
undefined, asEnteron it does), and a line that does not parse (prints its SyntaxError). Nothing is evaluated twice: after the synthesizedEnterthe line editor is empty, and the next read returns the end of input again.What does not change. Every input that ends with a newline. The 28 inputs of the existing piped tests give the same stdout, stderr, exit code and history file on both builds.
Lines that nobody submitted (release build of this PR)
VMIN=0,bun repl | cat): 0 of 5 runs.Measurements. Release builds of c1df64b and of this PR, one toolchain, Linux x64. Instructions are
instructions:ufromperf_event_open, as the slope between N and 2N keys, minimum of 3 runs, spread 0.03%.Enteron an empty line: 365.05 to 347.13.Enterin.editormode: 468.23 to 434.45. An evaluated1+1: 64.6k and 64.4k, inside the run-to-run spread of 0.5k. The loop head compiles to fewer instructions with thematch:Repl::run_with_vmgoes from 3,443 to 3,250 instructions.read_byte: 40 to 42 instructions. The two new ones are the stores on the two arms that returnNone, after the syscall.mi_*entry points, 200 lines): equal for an emptyEnter, an.editorline and an evaluated line.1+1\nis 26, 18, 110 on both.1+1goes from 26, 14, 105 to 27, 18, 110. The extra read is the second read of the end of input. A 1000-line script that ends with a newline: 84, 3015, 6995 on both.replmodule has 35 symbols in both builds, 38,982 and 38,411 bytes..textof the whole binary: -512 bytes.Relation to open PRs
.editormode) and repl: keep the line on Down with no newer entry, reset the history cursor at every line start #46084 (Down and the history cursor): a trial merge with each is clean, source and tests. Until repl: clear the typed line on Ctrl+C in every mode, evaluate it on Ctrl+D in editor mode #46083 merges, a half line that Ctrl+D leaves at the prompt runs at the end of piped input.stdin_at_eof.EAGAINfor every synchronous reader of stdin, the REPL included. It changes the read call inread_byte. The source merges with this change, the test file conflicts.For a maintainer to decide
.editorinput that ends with noCtrl+Don a pipe is still dropped. Node has no.editorwithout a terminal.Ctrl+Dtwice, is still dropped. A first draft handled it with apollfor a hang-up. A read timeout on a non-canonical terminal then ran a half-typed line, so that arm is not here. The end of input on a terminal is also not sticky: after a synthesizedEnterthe next read waits for more keys.Tests. The 8 tests that fail without the fix: five last lines with no newline, the transcript of a last line that leaves a call open, the clean-end half of the failed-read test, and the history file. The 4 that pass on both builds pin what must stay: empty stdin, no newline after
.exit, a terminal that goes away, andCtrl+Dtwice on a terminal in line mode. The line-mode test pins the terminal check on Linux: it fails on a build with the check removed. A hang-up on Linux fails the read, so the hang-up test reaches the check only where a hang-up reads as 0 bytes.Platforms. Nothing was run on macOS or Windows locally. The failed-read test is skipped on Windows:
fs.closeSync(0)does nothing there (libuv keeps fds 0 to 2 open), so no read fails. The other piped tests are not gated. The pty tests are in the existingdescribe.todoIf(isWindows)block.