Repository navigation
Conversation
…direct
The Request/Response branch in Builtin::init_redirections computed
is_file_blob as !needs_to_read_file(), the opposite of its sibling
direct-Blob branch. As a result, for a builtin command like echo:
echo hi > ${new Response(Bun.file(path))} threw 'immutable blob'
echo hi > ${new Response(new Blob([..]))} succeeded with exit 0
and discarded the output
Fixing the guard alone is not enough: a file-backed body that passes
the guard was stored as BuiltinIO::Blob, and write_no_io_to treats
that variant as a no-op, so output would still be silently dropped.
The same silent discard also affected echo > ${Bun.file(fd)}.
Both the Response/Request and bare-Blob JsBuf branches now go through
a shared setup_blob_redirect helper. A file-backed blob has its
path/fd extracted and is opened via the same IOReader/IOWriter path as
a > filename redirect (factored into open_file_redirect); an in-memory
blob is rejected for stdout/stderr and kept for stdin.
|
Warning Review limit reached
Next review available in: 3 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Comment |
|
Updated 7:15 PM PT - Jul 23rd, 2026
❌ @robobun, your commit 9d0d364 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 35318That installs a local version of the PR into your bun-35318 --bun |
|
No open issues found that this PR would fix. 🤖 Generated with Claude Code |
Match open_file_redirect and the interpreter root stdout/stderr: a pipe/FIFO/socket fd now takes the pollable IOWriter path instead of the synchronous do_file_write loop.
setup_blob_redirect routes file-backed blobs to BuiltinIO::Fd and rejects in-memory blobs for stdout/stderr, so the Blob output variant is never constructed. Its write_no_io_to arm returned Ok(buf.len()) without writing, which is exactly the silent-drop this change removes; deleting the variant turns that into a compile-time guarantee. BuiltinInput::Blob stays for in-memory stdin.
|
Diff is green: |
There was a problem hiding this comment.
No new findings — both earlier nits (fd-arm is_pollable probe, toBe on the exact error string) are confirmed addressed. Deferring to a human because this reworks native fd ownership / IOWriter lifecycle in the builtin redirect path rather than being a mechanical fix.
What was reviewed:
open_file_redirectis a pure hoist of the Atom-arm body; behavior for> pathis unchanged.setup_blob_redirectpath/fd extraction: path bytes are cloned and the fd isshell_dup'd beforedrop(blob), so no borrow into freed store; the dup'd fd is owned byIOWriter/IOReaderand closed on Drop.BuiltinIO::Blobhas no remaining references after removal (greppedsrc/).body.use_()now runs before the immutable-blob guard, so a rejectedResponsebody is consumed before the throw — benign since the operation fails either way.
Extended reasoning...
Overview
The PR fixes an inverted needs_to_read_file() predicate in Builtin::init_redirections's Request/Response body branch, then goes further: it hoists the Atom-redirect open logic into open_file_redirect, adds setup_blob_redirect to unify the bare-Blob and Request/Response arms, routes file-backed blobs through real IOReader/IOWriter (path via open_file_redirect, fd via shell_dup + is_pollable probe), and deletes the now-unreachable BuiltinIO::Blob output variant whose write_no_io_to arm silently discarded writes. interpreter.rs only promotes is_pollable to pub. Five subprocess-spawning tests are added under bunshell.test.ts.
Security risks
None identified. Inputs are user-owned JS Blob/Response objects; paths come from Bun.file(path) and go through the same shell_openat/open_for_writing_impl machinery the > filename atom redirect already uses; fds are dup'd so the writer owns a private handle it can close.
Level of scrutiny
Medium-high. This is native Rust touching fd ownership, IOWriter lifecycle, and Blob Drop ordering — exactly the class REVIEW.md's memory-safety section flags ("who frees this, when, on which paths"). The hoist looks byte-identical, the new helper's Drop ordering checks out, and Stdio::extract_blob (the subprocess-spawn analogue the PR cites) does the same pathlike unpacking. But it is not a one-line polarity flip: it removes an enum variant, changes when body.use_() fires relative to the guard, and introduces a new IOWriter construction site. That's enough moving parts in native I/O code to warrant a human pass rather than bot approval.
Other factors
Two prior review rounds from me raised nits (hardcoded pollable on the fd arm; toContain vs toBe); both were fixed in follow-up commits and are visible in the current diff. The bug hunt on the latest revision found nothing. Tests use tempDir, bunEnv, test.concurrent, drain both pipes, and the PR description reports the USE_SYSTEM_BUN=1 fail / bun bd pass split. I grepped src/ for BuiltinIO::Blob — no remaining references, so the variant removal is complete.
|
Closing this PR because it has been inactive for more than 90 days. |
What does this PR do?
Builtin::init_redirectionsguards a> ${jsvalue}stdout/stderr redirect against in-memory Blob bodies with:needs_to_read_file()is true for file-backed blobs, sois_file_blobwas true for in-memory bodies and false for file-backed ones, the opposite of the sibling direct-Blob branch. Sinceechoalways runs as a builtin:Fixing the predicate alone isn't sufficient: a file-backed body that passes the guard was stored as
BuiltinIO::Blob(..), andwrite_no_io_totreated that variant asOk(buf.len())(a no-op), so output would still be silently dropped. The same silent drop also affectedecho hi > ${Bun.file(fd)}(fd-backed blobs reach the JsBuf arm because only path-backedBun.fileis inlined as a path string byhandle_template_value).Fix
The Request/Response and bare-Blob JsBuf branches now share one
setup_blob_redirecthelper:store.data.File.pathlikeextracted and is opened through the sameIOReader/IOWriterpath that anAtom(> filename) redirect already uses (hoisted intoopen_file_redirect); an fd-backed blob isshell_dup'd so the writer owns a private fd, and the dup'd fd is probed withis_pollable()so a pipe/socket/tty takes the async writer pathBuiltinInput::BlobThis mirrors what
Stdio::extract_blobalready does for the spawned-subprocess path inCmd::init_subproc_redirections.The
BuiltinIO::Bloboutput variant is no longer constructed anywhere and has been removed so the silent-drop arm cannot reappear;BuiltinInput::Blobstays for in-memory stdin.Related
Locked/Used/Errorbody check just before this branch; that PR does not touch the polarity and its addedcheck_body_for_redirectcall sits cleanly above the newbody.use_()line.Yield::failed()throw; the new tests spawn a subprocess per case so they do not depend on that fix.setup_blob_redirectalso routes< ${Response(Bun.file(p))}stdin throughIOReader(previously it delivered empty bytes viashared_view()on a file store). This is only observable via builtincat(Windows, or POSIX withBUN_ENABLE_EXPERIMENTAL_SHELL_BUILTINS=1), where builtincat < filehas a separate pre-existing issue on POSIX; left out of this PR's test coverage.How did you verify your code works?
Added to
test/js/bun/shell/bunshell.test.tsunderredirect builtin stdout to Blob / Response body:echo > ${new Response(Bun.file(path))}writeshello\nto the fileecho > ${new Response(new Blob([..]))},${new Response("..")},${new Blob([..])}each reject with the exact "immutable blob" messageecho > ${Bun.file(fd)}writes to the fd (and the user's fd stays open)no test proof · iteration 0 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/js/bun/shell/bunshell.test.ts