Skip to content

fix(serve): harden CLI arg filtering and config error handling - #483

Merged
slin1237 merged 1 commit into
mainfrom
slin/cli-fixup
Feb 20, 2026
Merged

slin1237 merged 1 commit into
mainfrom
slin/cli-fixup

Conversation

@slin1237

@slin1237 slin1237 commented Feb 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes bugs and hardens error handling in the serve CLI introduced by #460.

Refs: #460

What changed

bindings/python/src/smg/serve.py:

  • _filter_backend_args: Split on = before matching against filter list so --key=value syntax is correctly filtered (previously only --key value worked)
  • _get_tp_size: File I/O and YAML parse errors now propagate instead of being silently caught by a broad except Exception. Missing/malformed --config files fail loudly instead of silently using tp=1
  • _filter_backend_args docstring: Fixed incorrect reference to "vLLM's grpc_server"
  • VllmWorkerLauncher docstring: Removed stale "(gRPC mode only)" since HTTP mode is now supported

bindings/python/tests/test_serve.py:

  • Added TestFilterBackendArgs class (5 tests) covering --key value, --key=value, multiple keys, empty args, and no-filter cases
  • Added test_get_tp_size_from_config_malformed_yaml_raises — verifies yaml.YAMLError propagation
  • Updated test_get_tp_size_from_config_read_fails_raises — expects FileNotFoundError instead of silent fallback
  • Updated test_get_tp_size_from_config_empty_or_no_keys_returns_default — verifies warning message content
  • Removed stray print(cmd) debug statement

Why

  1. --key=value bug: If a user passed --model=/tmp/model, the filter compared the whole string against "--model" — no match. The arg leaked through unfiltered, causing duplicate --model in the worker command.

  2. Silent tp=1 fallback: The old code caught all exceptions from config parsing and fell back to tp_size=1. A missing config file or malformed YAML would silently launch workers with wrong GPU allocation — potentially causing OOM or wasting resources.

Test plan

  • python3 -m pytest bindings/python/tests/test_serve.py -v — 101 passed

Summary by CodeRabbit

  • Bug Fixes

    • Improved configuration argument parsing to handle multiple command-line formats robustly.
    • Enhanced error handling for configuration file operations, ensuring errors are properly reported instead of being silently handled.
  • Documentation

    • Updated worker launcher documentation for clarity.

- Fix _filter_backend_args to handle --key=value syntax by splitting on
  '=' before matching against filter list. Previously only exact string
  match worked, so --model=/tmp/m would not be filtered when --model was
  in the filter list, causing duplicate args in worker commands.
- Fix _get_tp_size to let FileNotFoundError and yaml.YAMLError propagate
  instead of catching all exceptions and silently falling back to tp=1.
  A missing or malformed --config file is a real misconfiguration that
  should fail loudly, not silently launch with wrong GPU allocation.
- Fix VllmWorkerLauncher docstring that still said "gRPC mode only"
  after HTTP mode support was added.
- Fix _filter_backend_args docstring that incorrectly referenced vLLM.
- Remove stray print(cmd) left in test_build_command.
- Add TestFilterBackendArgs covering --key value, --key=value, multiple
  keys, empty args, and no-filter-args cases.
- Add test for malformed YAML config raising yaml.YAMLError.
- Update config error test to expect FileNotFoundError propagation.
- Update missing-keys test to verify warning message content.

Signed-off-by: Simo Lin <simo.lin@oracle.com>
@github-actions github-actions Bot added python-bindings Python bindings changes tests Test changes labels Feb 20, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @slin1237, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical issues in the serve CLI by refining argument parsing and hardening configuration file error handling. The changes ensure that command-line arguments are correctly filtered regardless of their syntax and that errors during configuration file processing are no longer silently suppressed. This significantly improves the robustness and reliability of the worker launcher, preventing silent failures, incorrect resource allocation, and providing clearer diagnostics for misconfigurations.

Highlights

  • Improved CLI Argument Parsing: The _filter_backend_args function was enhanced to correctly parse and filter command-line arguments provided in both --key value and --key=value formats, preventing arguments from being unintentionally passed through.
  • Hardened Configuration Error Handling: Error handling in the _get_tp_size function for reading configuration files was strengthened. File I/O errors (like FileNotFoundError) and YAML parsing errors (yaml.YAMLError) now propagate instead of being silently caught, ensuring misconfigurations are caught early.
  • Enhanced Test Coverage: New unit tests were introduced for the _filter_backend_args function to validate its behavior with different argument syntaxes. Existing tests for _get_tp_size were updated to confirm the new error propagation for invalid or missing configuration files.
  • Docstring Refinements: Docstrings were updated to accurately reflect the functionality of the argument filtering mechanism and to remove stale information regarding gRPC-only mode for the VllmWorkerLauncher.
Changelog
  • bindings/python/src/smg/serve.py
    • Updated _filter_backend_args to correctly parse and filter arguments using both --key value and --key=value syntax.
    • Modified _get_tp_size to remove broad exception handling, allowing FileNotFoundError and yaml.YAMLError to propagate when reading configuration files.
    • Revised the docstring for _filter_backend_args to accurately describe its function.
    • Removed "(gRPC mode only)" from the VllmWorkerLauncher docstring.
  • bindings/python/tests/test_serve.py
    • Added a new test class TestFilterBackendArgs with five tests to validate the _filter_backend_args function's behavior across various argument formats.
    • Updated test_get_tp_size_from_config_read_fails_raises to assert that FileNotFoundError is raised for non-existent config files.
    • Added test_get_tp_size_from_config_malformed_yaml_raises to verify yaml.YAMLError propagation for invalid YAML.
    • Adjusted test_get_tp_size_from_config_empty_or_no_keys_returns_default to specifically check the warning message content.
    • Removed a debug print(cmd) statement.
Activity
  • The author, slin1237, initiated this pull request to fix bugs and harden error handling in the serve CLI, referencing a previous PR (feat: smg serve pass through engine args to engine #460).
  • New unit tests were added to cover argument filtering logic and configuration file error propagation.
  • Existing tests were updated to align with the new error handling behavior.
  • The test plan included running pytest for the bindings/python/tests/test_serve.py module, which passed all 101 tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@coderabbitai

coderabbitai Bot commented Feb 20, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This PR enhances argument filtering logic and error handling in the vLLM worker launcher configuration. Changes include more robust filtering of launcher-set arguments supporting both --key value and --key=value formats, updated docstrings, and improved exception propagation for tensor parallel configuration parsing instead of silently logging warnings.

Changes

Cohort / File(s) Summary
Argument Filtering Enhancement
bindings/python/src/smg/serve.py
Refactored _filter_backend_args to robustly handle both --key value and --key=value argument formats, with clearer key matching logic.
Error Handling & Configuration
bindings/python/src/smg/serve.py
Modified TrtllmWorkerLauncher._get_tp_size to propagate FileNotFoundError and yaml.YAMLError instead of silently catching them; added explicit raises documentation. Defaults to 1 with warning only when config exists but lacks tensor parallel size keys.
Documentation Updates
bindings/python/src/smg/serve.py
Updated VllmWorkerLauncher docstring to remove explicit gRPC limitation, making it more general.
Test Coverage
bindings/python/tests/test_serve.py
Added TestFilterBackendArgs class with comprehensive tests for filtering both argument formats; removed stray print statements; updated tensor parallel configuration tests to verify error propagation and warning messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

python-bindings, tests

Suggested reviewers

  • CatherineSue
  • key4ng

Poem

🐰 A filter refined with care and grace,
Parsing arguments in their proper place,
Errors now echo instead of hide,
With warnings as gentle as morning tide,
Tests bloom bright as Easter morning light! 🌸

🚥 Pre-merge checks | ✅ 2 | ❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(serve): harden CLI arg filtering and config error handling' accurately and concisely summarizes the main changes: fixes to CLI argument filtering and improvements to error handling in config processing.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch slin/cli-fixup

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request provides good improvements to the serve CLI. It fixes a bug in argument filtering to correctly handle --key=value syntax and hardens error handling for config file parsing by propagating errors instead of silently failing. The accompanying test changes are thorough and correctly verify the new behavior. I have one suggestion to further harden the argument filtering logic to make it more robust against future changes.

Comment thread bindings/python/src/smg/serve.py
@slin1237
slin1237 merged commit c953342 into main Feb 20, 2026
20 checks passed
@slin1237
slin1237 deleted the slin/cli-fixup branch February 20, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python-bindings Python bindings changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant