Skip to content

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

How did you verify your code works?

@robobun
Copy link
Collaborator

robobun commented Oct 4, 2025

Updated 6:08 AM PT - Oct 6th, 2025

@Jarred-Sumner, your commit 278a3a5 has 2 failures in Build #28154 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 23235

That installs a local version of the PR into your bun-23235 executable, so you can run:

bun-23235 --bun

Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Refactors TTY handling: replaces global stdin TTY state with a thread-safe StdinTTY abstraction, updates open/close logic for TTYs and pipes with improved allocation/error handling, and rewrites Node.js TTY ReadStream/WriteStream prototypes using class-based wrappers with consolidated methods and platform-conditional behavior.

Changes

Cohort / File(s) Summary of changes
Windows TTY close flow
src/io/PipeReader.zig
In WindowsBufferedReader.closeImpl, replace direct stdin_tty comparison with Source.StdinTTY.isStdinTTY. Avoid immediate close for real stdin; for others, set tty.data and close with callback.
Source I/O and Stdin TTY abstraction
src/io/source.zig
Introduce public StdinTTY struct with atomic initialization, mutex, helpers (isStdinTTY, getStdinTTY). Update openTty to use StdinTTY for fd 0; adjust allocation/error cleanup for Tty/Pipe; comments updated; behavior otherwise preserved.
Node TTY streams prototype rewrite
src/js/node/tty.ts
Rework ReadStream/WriteStream using $toClass and Prototype objects. Add/refine methods (setRawMode, ref/unref, size ops, clear/cursor, color depth, hasColors, async iterator). Centralize exports and validations; maintain Node core bindings.

Suggested reviewers

  • nektro
  • cirospaciari

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description currently includes the required template headings but lacks any content under each section, leaving both "What does this PR do?" and "How did you verify your code works?" unanswered. Without a summary of changes or verification steps, reviewers cannot understand the intent or testing of the code. The description must be populated with details to satisfy the template requirements. Please provide a summary of the implemented changes under "What does this PR do?" and include the steps or tests performed under "How did you verify your code works?" to complete the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title clearly highlights the primary fix of a Windows memory leak in error cases for opening TTY and pipe without extraneous details. It uses concise language that accurately reflects the key change. A teammate reviewing the history can understand the main intent from the title alone.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jarred/refactor-tty-stdin-code-windows

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8d28289 and 8a0059f.

📒 Files selected for processing (3)
  • src/io/PipeReader.zig (1 hunks)
  • src/io/source.zig (2 hunks)
  • src/js/node/tty.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)

Implement debug logs in Zig using const log = bun.Output.scoped(.${SCOPE}, false); and invoking log("...", .{})

Files:

  • src/io/PipeReader.zig
  • src/io/source.zig
**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)

**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue

**/*.zig: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup

Files:

  • src/io/PipeReader.zig
  • src/io/source.zig
src/js/node/**/*.{js,ts}

📄 CodeRabbit inference engine (src/js/CLAUDE.md)

Place Node.js compatibility modules (e.g., node:fs, node:path) under node/

Files:

  • src/js/node/tty.ts
src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts}

📄 CodeRabbit inference engine (src/js/CLAUDE.md)

src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts}: Use .$call and .$apply instead of .call or .apply to avoid user tampering
Use string-literal require("...") only (no dynamic or non-literal specifiers)
Author modules as CommonJS-style with require(...) and export via export default {} (no ESM import/named exports)
Prefer JSC intrinsics and $-prefixed private APIs for performance and safety (e.g., $Array, $newArrayWithSize, $putByIdDirectPrivate, $assert, $debug)
Validate function arguments with $isCallable and throw $ERR_INVALID_ARG_TYPE for invalid callbacks
Use $isObject and throw appropriate TypeErrors for constructor/initializer inputs that must be objects

Files:

  • src/js/node/tty.ts
src/js/**/*.{js,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

src/js/**/*.{js,ts}: In built-in modules (src/js), require() must use string literals resolved at compile time
In built-in modules (src/js), use export default (converted to a return statement by the preprocessor)

Files:

  • src/js/node/tty.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Format JavaScript/TypeScript files with Prettier (bun run prettier)

Files:

  • src/js/node/tty.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format

@Jarred-Sumner Jarred-Sumner merged commit ec050e6 into main Oct 6, 2025
45 of 60 checks passed
@Jarred-Sumner Jarred-Sumner deleted the jarred/refactor-tty-stdin-code-windows branch October 6, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants