Skip to content

[None][fix] validate trtllm-serve --port with ValueError not assert#16260

Open
lonexreb wants to merge 2 commits into
NVIDIA:mainfrom
lonexreb:fix/serve-port-validation
Open

[None][fix] validate trtllm-serve --port with ValueError not assert#16260
lonexreb wants to merge 2 commits into
NVIDIA:mainfrom
lonexreb:fix/serve-port-validation

Conversation

@lonexreb

@lonexreb lonexreb commented Jul 10, 2026

Copy link
Copy Markdown

Description

launch_server (tensorrt_llm/commands/serve.py) guarded the trtllm-serve --port CLI argument with:

assert port > 0 or disagg_cluster_config is not None, "Port must be specified ..."

Using assert on user input means an AssertionError (not a clear error), and under python -O the check is stripped entirely — so --port 0 without a disagg config silently binds an ephemeral port instead of erroring. Behavior should not depend on the -O flag.

Change

Replace the assert with an explicit raise ValueError.

Test

New CPU-only unit test in tests/unittest/llmapi/apps/test_serve_port_validation.py: launch_server with port=0 and no disagg config raises ValueError (the check runs before any bind/model load).

Summary by CodeRabbit

  • Bug Fixes
    • Improved server startup validation when no valid port or cluster configuration is provided.
    • Startup now reports a clear ValueError message instead of relying on an assertion.
  • Tests
    • Added coverage to verify invalid port values are rejected before server binding or model loading.

@lonexreb lonexreb requested a review from a team as a code owner July 10, 2026 23:44
@lonexreb lonexreb requested a review from JunyiXu-nv July 10, 2026 23:44
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

launch_server now performs always-on validation for missing or non-positive ports and raises a descriptive ValueError. A pytest regression test verifies this behavior when no disaggregated cluster configuration is provided.

Changes

Serve port validation

Layer / File(s) Summary
Runtime validation and regression coverage
tensorrt_llm/commands/serve.py, tests/unittest/llmapi/apps/test_serve_port_validation.py
launch_server replaces the assertion with an explicit ValueError check, and the new test verifies rejection of port=0 with the expected message.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change and follows the repository's [None][fix] template.
Description check ✅ Passed The description clearly explains the problem, change, and test, but omits the PR checklist and full template sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/commands/serve.py`:
- Around line 290-293: Move the port validation in the serve command before the
socket.getaddrinfo(host, port, ...) call so invalid negative ports raise the
intended ValueError. Preserve the existing rule that port must be greater than
zero unless disagg_cluster_config is provided, while allowing port == 0 only
with that configuration.

In `@tests/unittest/llmapi/apps/test_serve_port_validation.py`:
- Around line 20-30: Expand
test_launch_server_rejects_nonpositive_port_without_disagg to cover both port=0
and port=-1 using parametrization, and mock or spy on the server socket bind
operation to assert bind() is never called when validation fails. Preserve the
ValueError assertion and existing launch_server inputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c31e2072-7296-421c-867c-0eeb27d649df

📥 Commits

Reviewing files that changed from the base of the PR and between b4e7808 and c852d1a.

📒 Files selected for processing (2)
  • tensorrt_llm/commands/serve.py
  • tests/unittest/llmapi/apps/test_serve_port_validation.py

Comment thread tensorrt_llm/commands/serve.py
Comment thread tests/unittest/llmapi/apps/test_serve_port_validation.py Outdated
@lonexreb

Copy link
Copy Markdown
Author

Addressed in 26826eb: parametrized over port 0 and -1 (mocking socket so getaddrinfo doesn't fail first on -1) and assert bind() is never called when validation fails.

@JunyiXu-nv JunyiXu-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes are small and good! But we want to hold this PR for a while before this one #15815 get merged. So that we can add the test into the cpu only test stage to make it covered by CI.

lonexreb added 2 commits July 14, 2026 10:51
launch_server guarded the --port CLI argument with an assert, which raises
AssertionError and, under python -O, is stripped entirely (silently binding
an ephemeral port). Raise a ValueError instead.

Signed-off-by: lonexreb <reach2shubhankar@gmail.com>
Parametrize over port 0 and -1 (mock socket so getaddrinfo does not fail
first for -1) and assert bind() is never called when validation fails.

Signed-off-by: lonexreb <reach2shubhankar@gmail.com>
@JunyiXu-nv JunyiXu-nv force-pushed the fix/serve-port-validation branch from 26826eb to 18de818 Compare July 14, 2026 02:51

@JunyiXu-nv JunyiXu-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @lonexreb , could you please add the test into tests/integration/test_lists/test-db/l0_cpu_x86.yml? And then we can run CI and merge this PR. Thanks!

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