Skip to content

fix(cli): honor port 0 in checkPortAvailable#1304

Open
ChunkyMonkey11 wants to merge 4 commits intoNVIDIA:mainfrom
ChunkyMonkey11:fix/preflight-port-zero
Open

fix(cli): honor port 0 in checkPortAvailable#1304
ChunkyMonkey11 wants to merge 4 commits intoNVIDIA:mainfrom
ChunkyMonkey11:fix/preflight-port-zero

Conversation

@ChunkyMonkey11
Copy link
Copy Markdown

@ChunkyMonkey11 ChunkyMonkey11 commented Apr 2, 2026

Summary

This PR fixes a bug in CLI preflight port handling by preserving port = 0 instead of incorrectly defaulting it to 18789.
In Node.js networking, 0 is a valid value that asks the OS to assign a temporary available port.
The fix changes null/default logic to keep valid explicit inputs while still applying the default when no port is provided.

Changes

  • Updated checkPortAvailable in src/lib/preflight.ts:
    • Before: const p = port || 18789;
    • After: const p = port ?? 18789;
  • This preserves:
    • undefined/null -> default 18789
    • 0 -> stays 0 (valid OS-assigned temporary available port request)
    • any explicit non-null value -> unchanged
  • No CLI command surface changes.
  • No docs changes required.

Type of Change

  • Code change for a new feature, bug fix, or refactor.
  • Code change with doc updates.
  • Doc only. Prose changes without code sample modifications.
  • Doc only. Includes code sample changes.

Testing

  • npx prek run --all-files passes (or equivalently make check).
  • npm test passes.
  • make docs builds without warnings. (for doc-only changes)

Checklist

General

Code Changes

  • Formatters applied — npx prek run --all-files auto-fixes formatting (or make format for targeted runs).
  • Tests added or updated for new or changed behavior.
  • No secrets, API keys, or credentials committed.
  • Doc pages updated for any user-facing behavior changes (new commands, changed defaults, new features, bug fixes that contradict existing docs).

Doc Changes

  • Follows the style guide. Try running the update-docs agent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docs catch up the docs for the new changes I made in this PR."
  • New pages include SPDX license header and frontmatter, if creating a new page.
  • Cross-references and links verified.

Signed-off-by: Revant Patel revant.h.patel@gmail.com

Summary by CodeRabbit

  • Bug Fixes
    • Corrected port configuration handling to properly respect explicitly set values instead of defaulting to the standard port.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

The checkPortAvailable() function in src/lib/preflight.ts was updated to use nullish-coalescing (??) instead of logical-or (||) when defaulting the port parameter. This preserves an explicitly provided port value of 0 instead of replacing it with the default port 18789.

Changes

Cohort / File(s) Summary
Port defaulting logic
src/lib/preflight.ts
Changed port parameter handling from logical-or to nullish-coalescing operator to preserve explicit port value of 0 instead of replacing it with the default.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through code so small,
One operator fixes all!
From \|\| to ?? it goes,
Port zero now survives the flows! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: using nullish coalescing to preserve port 0 instead of replacing it with the default 18789.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@ChunkyMonkey11
Copy link
Copy Markdown
Author

@cv I fixed the PR issue and this should be good now. Updated the PR body sign-off format, and checks are now passing on my side (npx prek run --all-files, npm test, make docs). Please take another look when you have a moment.

@cv cv enabled auto-merge (squash) April 2, 2026 21:53
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