fix(runtime): deliver JS process stdout/stderr to a redirected fd (pipe/file) - #1967
Conversation
…pe/file) Guest process.stdout/process.stderr (and console.log/error) wrote via the _log/_error bridge globals, which append to the process's *captured* output and bypass kernel fd 1/2. So any redirection was silently dropped: 'node -e ... | cat' produced empty output (wc -c saw 0 bytes) and 'node -e ... > file' wrote nothing, while fs.writeSync(1, ...) — which goes through the kernel fd — worked. Confirmed pre-existing on 0.2.20-rc.1. Route _stdout/_stderr through the existing _kernelStdioWriteRaw bridge (__kernel_stdio_write -> write_process_stdout/stderr on kernel fd 1/2), the same path WASM stages use, so redirection and pipes are honored. Falls back to _log/_error only when the kernel bridge is unavailable (e.g. browser). Top-level captured output is unchanged (the sidecar drains fd 1). Verified: process.stdout|cat, console.log|cat, node|wc -c (6 bytes), node>file, console.error 2>&1|cat all deliver output; top-level node output and the #1959 pipelines are unaffected. Note: the symmetric stdin-stream gap (process.stdin does not emit 'data' from a piped fd 0, though fs.readSync(0) works) is a separate follow-up.
Collaborator
Author
|
Stack for rivet-dev/agentos
Get stack: change rsnpzpss |
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.
Guest process.stdout/process.stderr (and console.log/error) wrote via the _log/_error bridge globals, which append to the process's captured output and bypass kernel fd 1/2. So any redirection was silently dropped: 'node -e ... | cat' produced empty output (wc -c saw 0 bytes) and 'node -e ... > file' wrote nothing, while fs.writeSync(1, ...) — which goes through the kernel fd — worked. Confirmed pre-existing on 0.2.20-rc.1.
Route _stdout/_stderr through the existing _kernelStdioWriteRaw bridge (__kernel_stdio_write -> write_process_stdout/stderr on kernel fd 1/2), the same path WASM stages use, so redirection and pipes are honored. Falls back to _log/_error only when the kernel bridge is unavailable (e.g. browser). Top-level captured output is unchanged (the sidecar drains fd 1).
Verified: process.stdout|cat, console.log|cat, node|wc -c (6 bytes), node>file, console.error 2>&1|cat all deliver output; top-level node output and the #1959 pipelines are unaffected. Note: the symmetric stdin-stream gap (process.stdin does not emit 'data' from a piped fd 0, though fs.readSync(0) works) is a separate follow-up.