Skip to content

fix(python): add router arg fallback disable flag#1072

Open
gongwei-130 wants to merge 4 commits intomainfrom
wei/disable-router-args-fallback
Open

fix(python): add router arg fallback disable flag#1072
gongwei-130 wants to merge 4 commits intomainfrom
wei/disable-router-args-fallback

Conversation

@gongwei-130
Copy link
Copy Markdown
Collaborator

@gongwei-130 gongwei-130 commented Apr 9, 2026

Summary

  • add --router-disable-arg-fallback for smg serve
  • when enabled, router args only come from explicit --router-* flags
  • keep existing behavior unchanged unless this flag is set

Why this is needed

In HTTP mode, --tool-call-parser and --reasoning-parser are meant for the backend engine. But SMG router could pick them up via argument fallback, which can cause parser-related errors. This flag lets us prevent router fallback so backend-only parser flags stay backend-only.

Testing

  • added unit tests for prefixed arg fallback default behavior
  • added unit tests for disabling fallback
  • added parse test to ensure --router-disable-arg-fallback is accepted in smg serve

Summary by CodeRabbit

  • New Features

    • Added a CLI flag --router-disable-arg-fallback that, when enabled, prevents router-specific settings from inheriting unset values from backend configuration.
  • Tests

    • Added tests ensuring the new flag is parsed correctly and that router argument fields do or do not fall back to backend values depending on the flag.

Signed-off-by: gongwei-130 <weigong28@gmail.com>
@github-actions github-actions bot added python-bindings Python bindings changes tests Test changes labels Apr 9, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: afed6766-4460-46de-bf2c-a814aa54ffb8

📥 Commits

Reviewing files that changed from the base of the PR and between da9d8b9 and 96c5e15.

📒 Files selected for processing (1)
  • bindings/python/src/smg/router_args.py

📝 Walkthrough

Walkthrough

This PR adds an optional CLI flag --router-disable-arg-fallback (registered when use_router_prefix=True) and changes RouterArgs parsing so unprefixed backend-style CLI values are only copied into router-prefixed fields when that flag is false.

Changes

Cohort / File(s) Summary
Router Arguments Implementation
bindings/python/src/smg/router_args.py
Adds conditional CLI option --router-disable-arg-fallback (when use_router_prefix=True) and updates RouterArgs.from_cli_args to respect disable_arg_fallback, preventing unprefixed→prefixed fallback when true.
Tests
bindings/python/tests/test_arg_parser.py, bindings/python/tests/test_serve.py
Adds unit tests: two tests verifying fallback behavior with use_router_prefix=True for enabled/disabled router_disable_arg_fallback, and one test ensuring parse_serve_args parses --router-disable-arg-fallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • CatherineSue
  • key4ng
  • slin1237

Poem

🐰 A toggle to tame the fallback fray,
No more shall unprefixed values stray,
When disable_arg_fallback says "nay,"
Only explicit router flags hold sway,
The router hops on, clean and gay! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a flag to disable router argument fallback behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wei/disable-router-args-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea8ee2ee66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1128 to +1132
elif (
not disable_arg_fallback
and attr.name in cli_args_dict
and cli_args_dict[attr.name] not in (None, "")
):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve serve host/port fallback when disabling arg fallback

With --router-disable-arg-fallback, this branch blocks all unprefixed values, but serve builds router args with use_router_prefix=True and exclude_host_port=True, so router host/port can only come from unprefixed --host/--port. In that mode, enabling the new flag makes the router ignore the configured serve endpoint and silently fall back to RouterArgs defaults (0.0.0.0:30000), which can bind the gateway to the wrong address/port. Keep host/port fallback (or provide prefixed host/port args) when this flag is set.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

makes sense

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

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 introduces a new --router-disable-arg-fallback CLI argument, allowing users to explicitly disable the fallback mechanism where router arguments would otherwise inherit values from non-prefixed backend arguments. The changes include adding the argument definition, modifying the argument parsing logic to incorporate this new flag, and adding comprehensive unit tests to validate both the default fallback behavior and the disabled fallback behavior. Feedback from the review suggests minor improvements for code clarity and conciseness, such as removing a redundant bool() cast and simplifying SimpleNamespace initializations in the tests.

I am having trouble creating individual review comments. Click here to see my feedback.

bindings/python/src/smg/router_args.py (1115-1117)

medium

The bool() cast is redundant here. The action="store_true" in argparse ensures that the value of router_disable_arg_fallback in the namespace is already a boolean (True if the flag is present, False otherwise). You can simplify this by removing the bool() call.

        disable_arg_fallback = cli_args_dict.get(f"{prefix}disable_arg_fallback", False)

bindings/python/tests/test_arg_parser.py (411-425)

medium

The SimpleNamespace object is initialized with many attributes that are not relevant to this test case, making the test verbose and harder to read. You can simplify it by only including the attributes that are actually used to test the fallback logic (router_model_path, model_path, router_tokenizer_path, tokenizer_path, and router_disable_arg_fallback). The from_cli_args method is robust enough to handle missing attributes in the namespace.

        args = SimpleNamespace(
            router_model_path=None,
            router_disable_arg_fallback=False,
            model_path="backend/model",
            router_tokenizer_path=None,
            tokenizer_path="backend/tokenizer",
        )

bindings/python/tests/test_arg_parser.py (434-448)

medium

Similar to the test above, the SimpleNamespace object here is initialized with many attributes that are not relevant to this test case. This makes the test verbose and harder to read. You can simplify it by only including the attributes that are actually used to test disabling the fallback logic.

        args = SimpleNamespace(
            router_model_path=None,
            router_disable_arg_fallback=True,
            model_path="backend/model",
            router_tokenizer_path=None,
            tokenizer_path="backend/tokenizer",
        )

Signed-off-by: gongwei-130 <weigong28@gmail.com>
@gongwei-130 gongwei-130 changed the title python: add router arg fallback disable flag fix(python): add router arg fallback disable flag Apr 9, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96c5e15e09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1133 to +1135
not disable_arg_fallback
and attr.name in cli_args_dict
and cli_args_dict[attr.name] not in (None, "")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep host/port fallback when router fallback is disabled

Disabling fallback here also drops host/port inheritance even though smg serve/launch_server register router args with exclude_host_port=True (bindings/python/src/smg/serve.py lines 540/554 and bindings/python/src/smg/launch_server.py line 161), so the router has no --router-host/--router-port source. With --router-disable-arg-fallback, RouterArgs.from_cli_args no longer reads unprefixed --host/--port, and the router silently reverts to dataclass defaults (0.0.0.0:30000) instead of the serve endpoint requested via CLI, which can bind the gateway to the wrong address/port.

Useful? React with 👍 / 👎.

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.

2 participants