Skip to content

[None][fix] catch KeyError when parsing --server_role into ServerRole - #17730

Merged
cascade812 merged 2 commits into
NVIDIA:mainfrom
lonexreb:fix/serve-role-keyerror
Sep 11, 2026
Merged

cascade812 merged 2 commits into
NVIDIA:mainfrom
lonexreb:fix/serve-role-keyerror

Conversation

@lonexreb

@lonexreb lonexreb commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

ServerRole[server_role.upper()] is an Enum name lookup, which raises KeyError for an unknown name — but the handler caught ValueError. Since --server_role is a free-form string option, an invalid value (e.g. --server_role context_server) surfaced as a raw KeyError traceback instead of the intended Invalid server role: ... Must be one of: ... message.

Change the handler to catch KeyError, matching the existing CpType parsing in the same file.

Test Plan

  • python -c "from enum import IntEnum"-level semantics: Enum[name] raises KeyError, verified.
  • trtllm-serve <model> --server_role bogus --metadata_server_config_file cfg.yaml now reports the friendly error.

Dev Engineer Review

  • Updated --server_role validation to catch KeyError from ServerRole[name].
  • Invalid role values now return the intended friendly validation message instead of a traceback.
  • The change is limited to error handling and does not change the public API.
  • No configuration or test-list changes were made.

QA Engineer Review

No test changes.

@lonexreb
lonexreb requested a review from a team as a code owner August 15, 2026 03:46
@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 00a93cef-e884-429a-8fcc-074f1769b994

📥 Commits

Reviewing files that changed from the base of the PR and between d8d7d38 and d5e2f8f.

📒 Files selected for processing (1)
  • tensorrt_llm/commands/serve.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/commands/serve.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

The server command now catches KeyError during invalid ServerRole enum lookups and preserves the existing validation error response.

Changes

Server role validation

Layer / File(s) Summary
Handle invalid server role lookups
tensorrt_llm/commands/serve.py
Server-role validation catches the KeyError raised for an invalid enum name.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to d5e2f

Invalid --server_role values now return the intended validation message rather than a traceback. No concrete current-head risk remains identified for this focused error-handling correction.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and clearly states that the fix changes exception handling for --server_role parsing.
Description check ✅ Passed The description explains the issue, the solution, and relevant test coverage. It uses a Test Plan heading instead of Test Coverage and does not include the PR Checklist, but the required technical inf…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

ServerRole[name] is an Enum name lookup, which raises KeyError for an
unknown name, but the handler caught ValueError. An invalid --server_role
therefore surfaced as a raw KeyError traceback instead of the intended
'Invalid server role: ... Must be one of: ...' message.

Signed-off-by: lonexreb <[email protected]>
@lonexreb
lonexreb force-pushed the fix/serve-role-keyerror branch from 272b103 to 7cac376 Compare August 17, 2026 02:13

@mikeiovine mikeiovine 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.

Stamp on behalf of runtime devs

@cascade812

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70807 [ run ] triggered by Bot. Commit: 7cac376 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70807 [ run ] completed with state SUCCESS. Commit: 7cac376
/LLM/main/L0_MergeRequest_PR pipeline #57990 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@cascade812

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72201 [ run ] triggered by Bot. Commit: 7cac376 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72201 [ run ] completed with state SUCCESS. Commit: 7cac376
/LLM/main/L0_MergeRequest_PR pipeline #59242 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@cascade812

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72317 [ run ] triggered by Bot. Commit: d5e2f8f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72317 [ run ] completed with state SUCCESS. Commit: d5e2f8f
/LLM/main/L0_MergeRequest_PR pipeline #59347 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@cascade812

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72522 [ run ] triggered by Bot. Commit: d5e2f8f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72522 [ run ] completed with state SUCCESS. Commit: d5e2f8f
/LLM/main/L0_MergeRequest_PR pipeline #59532 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@cascade812
cascade812 merged commit 795805f into NVIDIA:main Sep 11, 2026
10 checks passed
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.

4 participants