Repository navigation
Convert stdio to TypeScript - #8120
Conversation
Writes to the stdio file descriptors through node:fs are line-buffered and logged through globalThis.console.log by StdioFile in C++. With the TS_STDIO autogate enabled, that is done by node-internal:internal_fs_stdio instead, which node:fs calls for fds 0-2 before reaching native code. The C++ implementation is retained for rollback. FileSystemModule gains tsStdio(), which reports the autogate, and stdioPrefix(), since the configured logging prefixes are not otherwise visible to TypeScript. fs-stdio-test.js runs under a C++ cell and a TypeScript cell, each asserting which implementation it runs, and the stdio golden-output tests gain @all-autogates variants. With the autogate enabled, behaviour matches the C++ implementation, except that a partial line flushed outside a request is logged (StdioFile drops it) and no warning is logged to the server when console.log is missing. Neither changes the API surface exposed to Workers.
There was a problem hiding this comment.
Superseded by the review of
2bff94a2.
This review, of 40543edb
💬 Approved with comments — The gated TypeScript port matches the C++ stdio behaviour on the paths checked. The remaining points are INFO-level: missing tests for two call sites, no warning when console.log is missing, and a small change in behaviour for closed stdio fds.
Findings: 3 info
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 3 info
The port matches C++ on the main paths; three INFO-level gaps.
Recommendation: 💬 Optional Nits
- [INFO] With the gate on, the stdio branches in writeFileSync and callback writeFile have no test; only writeSync/writevSync is exercised. (
src/node/internal/internal_fs_sync.ts:823) - [INFO] The TypeScript path drops output without a message when console.log is missing, where the C++ path logs a warning. (
src/node/internal/internal_fs_stdio.ts:68) - [INFO] isStdioFd bypasses the virtual file system's fd table, so with the gate on a write to fd 1 or 2 after fs.closeSync() succeeds instead of failing. The pull request description does not list this change. (
src/node/internal/internal_fs_stdio.ts:92)
View full review
On the paths checked, the TypeScript StdioStream matches the C++ StdioFile behaviour:
- line splitting;
- the 4 KiB tail kept for a partial line;
- the 16 KiB cap on each write;
- prefix formatting;
- safe re-entrancy, because
#pendingis cleared beforeconsole.logruns.
Three minor points:
-
Tests for the new call sites.
fs-stdio-test.jsonly exerciseswriteSync, which goes throughwritevSync. These branches have no test under either configuration:writeFileSync(1, ...)(internal_fs_sync.ts:823);- callback
writeFile(1, ...)(internal_fs_callback.ts:1351-1354); - a test where
console.logwrites back intowriteSync, which would lock in the re-entrancy handling.
-
Missing
console.log.internal_fs_stdio.ts:65-68returns without a message whenconsoleorconsole.logis missing or not a function. The C++ path logs a warning in this case, so a deleted or replacedconsole.logis harder to diagnose with the gate on. -
Closed stdio fds.
isStdioFdreturns true for fds 0–2 before the virtual file system is consulted, sowriteSync(1, ...)afterfs.closeSync(1)now succeeds where the C++ path would fail on the closed fd. This is an edge case and it is behind the autogate. The description says only partial-line flushing changes, though, so it should either be listed there or the TypeScript path should respect closed fds.
✅ All other checks passed
🔒 Security: ✅ LGTM
No exploitable issues:
- Only fds 0–2 are routed to the new path.
- Buffers are capped and copied.
- The prefix comes from the isolate, not from user input.
- Only data the caller wrote to stdout or stderr is logged, as the C++ path already did.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 40543edb
writeFileSync, appendFileSync and callback writeFile reach stdio through their own branches in node:fs, separate from writeSync's.
There was a problem hiding this comment.
💬 Approved with comments — The new writeFileToStdio test closes the earlier test-coverage gap. Two INFO notes from the last review still apply to code that has not changed: no warning when console.log is missing, and writes to closed stdio fds succeeding with the gate on.
Findings: 2 info
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
The earlier test-coverage note is resolved. Two INFO notes on unchanged code remain.
Recommendation: 💬 Optional Nits
- [INFO] When console.log is missing or not a function, the TypeScript path drops output without any message. The C++ path logs a warning in that case. (
src/node/internal/internal_fs_stdio.ts:68) - [INFO] isStdioFd does not check the virtual file system's fd table, so with the gate on a write to fd 1 or 2 after fs.closeSync() succeeds instead of failing. The pull request description does not list this change. (
src/node/internal/internal_fs_stdio.ts:92)
View full review
🔄 Since last review: 1 finding resolved, 2 preserved, 0 new
Resolved: The new writeFileToStdio test (fs-stdio-test.js) covers writeFileSync(1, ...), appendFileSync(2, ...) and callback writeFile(1, ...). It runs under both the C++ and the TypeScript configuration, so the stdio branches in internal_fs_sync.ts and internal_fs_callback.ts are now tested.
Still open (INFO):
internal_fs_stdio.ts:64-68:#logreturns without any message whenconsoleorconsole.logis missing or not a function. The C++ path logs a warning in that case, so with the gate on, a deleted or replacedconsole.logis harder to diagnose.internal_fs_stdio.ts:91-93:isStdioFdreturns true for fds 0-2 without checking the virtual file system's fd table. With the gate on,writeSync(1, ...)afterfs.closeSync(1)therefore succeeds, where the C++ path fails. The pull request description lists partial-line flushing as the only behaviour change, so either add this change there or make the TypeScript path respect closed fds.
✅ All other checks passed
🔒 Security: ✅ LGTM
Only fds 0–2 are routed to the new path, and only behind the TS_STDIO autogate. Each write is capped at 16 KiB, and a partial line keeps at most 4 KiB. The prefix comes from the isolate, not from user input. The logged data is the caller's own stdout/stderr output, which the C++ path already logged.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 2bff94a2
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8120 +/- ##
==========================================
- Coverage 68.45% 68.31% -0.15%
==========================================
Files 726 726
Lines 189225 189675 +450
Branches 29668 29675 +7
==========================================
+ Hits 129543 129583 +40
- Misses 42307 42717 +410
Partials 17375 17375 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Part of a broader effort to reduce C++ JSG. Writes to stdout/stderr through
node:fsandprocess.stdout/stderrare line-buffered and logged throughconsole.logby C++ that calls back into JavaScript for every line. That logic is JS-shaped, so this moves it to TypeScript (node-internal:internal_fs_stdio).Following #8105, the TypeScript implementation is behind a new
TS_STDIOautogate, and the C++ one stays in place for rollback.fs-stdio-test.jsruns under a C++ test configuration and a TypeScript one, each asserting which implementation it ran. The stdio golden-output tests also run with all autogates on.With the gate on, output is the same except a partial line flushed outside a request is now logged rather than dropped, and no server-side warning is logged when
console.logis missing. No API surface changes.