Skip to content

feat(python): add --enable-mesh support to Python bindings - #775

Merged
slin1237 merged 3 commits into
mainfrom
slin/python-mesh-args
Mar 16, 2026
Merged

slin1237 merged 3 commits into
mainfrom
slin/python-mesh-args

Conversation

@slin1237

@slin1237 slin1237 commented Mar 16, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds --enable-mesh and related mesh server CLI args to the Python bindings
  • The Rust binary supported mesh but the Python entrypoint (used in Docker images) did not, causing crashes when users passed --enable-mesh

Closes #773

What changed

  • bindings/python/Cargo.toml: Added smg-mesh and rand workspace dependencies
  • bindings/python/src/lib.rs: Added enable_mesh, mesh_server_name, mesh_host, mesh_port, mesh_peer_urls fields to Router struct. Builds MeshServerConfig when enable_mesh is true (same logic as main.rs).
  • bindings/python/src/smg/router_args.py: Added mesh fields to RouterArgs dataclass and CLI argparse group (--enable-mesh, --mesh-server-name, --mesh-host, --mesh-port, --mesh-peer-urls)

New CLI args

Arg Default Description
--enable-mesh false Enable mesh server for HA multi-router coordination
--mesh-server-name auto-generated Mesh server name
--mesh-host 0.0.0.0 Mesh server bind address
--mesh-port 39527 Mesh server port
--mesh-peer-urls [] Peer mesh addresses to join (host:port)

Test plan

  • cargo check -p smg-python compiles clean
  • smg launch --enable-mesh no longer errors with "unrecognized arguments"
  • smg launch --enable-mesh --mesh-port 40000 --mesh-peer-urls 10.0.0.2:39527 passes args correctly

Summary by CodeRabbit

  • New Features

    • Mesh networking support added to the Python router, toggleable via five new CLI options: enable mesh, server name, host, port, and peer URLs; router startup now accepts and validates mesh configuration.
  • Chores

    • Python bindings workspace updated to include additional mesh-related dependencies.

What changed:
- bindings/python/Cargo.toml: add smg-mesh and rand workspace deps
- bindings/python/src/lib.rs: add enable_mesh, mesh_server_name,
  mesh_host, mesh_port, mesh_peer_urls fields to Router struct.
  Build MeshServerConfig when enable_mesh is true (matching main.rs
  logic) instead of hardcoding None.
- bindings/python/src/smg/router_args.py: add mesh fields to RouterArgs
  dataclass and --enable-mesh, --mesh-server-name, --mesh-host,
  --mesh-port, --mesh-peer-urls to argparse CLI args.

Why: the Python entrypoint (used in Docker images) lacked mesh server
support, causing --enable-mesh to fail with "unrecognized arguments".
The Rust binary had this support but the Python bindings did not.

Closes #773

Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@github-actions github-actions Bot added python-bindings Python bindings changes dependencies Dependency updates labels Mar 16, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces comprehensive support for mesh networking within the Python bindings. It addresses a previous limitation where the Python entrypoint lacked the necessary configuration and argument parsing for mesh server functionality, which led to crashes. By adding the required CLI arguments and integrating the underlying Rust mesh logic, this change enables Python-based deployments to leverage multi-router coordination for enhanced high availability.

Highlights

  • Mesh Server Support: Added --enable-mesh and related CLI arguments to the Python bindings, allowing the Python entrypoint to properly configure and utilize the mesh server for high-availability.
  • Dependency Integration: Integrated smg-mesh and rand crates into the Python Rust binding's Cargo.toml to support mesh server functionality.
  • Router Configuration: Extended the Router struct in lib.rs with new fields for mesh server configuration and implemented the logic to build MeshServerConfig based on these parameters.
  • CLI Argument Exposure: Exposed new mesh-related configuration options (--enable-mesh, --mesh-server-name, --mesh-host, --mesh-port, --mesh-peer-urls) through the RouterArgs dataclass and CLI argparse group in router_args.py.
Changelog
  • bindings/python/Cargo.toml
    • Added smg-mesh dependency to enable mesh server functionality.
    • Added rand dependency for generating random mesh server names.
  • bindings/python/src/lib.rs
    • Extended the Router struct with new fields for mesh server configuration: enable_mesh, mesh_server_name, mesh_host, mesh_port, and mesh_peer_urls.
    • Updated the Router constructor to accept and initialize these new mesh-related parameters.
    • Implemented logic within the Router to construct a MeshServerConfig when enable_mesh is true, including auto-generating a server name if not explicitly provided.
  • bindings/python/src/smg/router_args.py
    • Added mesh server configuration fields (enable_mesh, mesh_server_name, mesh_host, mesh_port, mesh_peer_urls) to the RouterArgs dataclass.
    • Integrated new CLI arguments for mesh server configuration into the add_cli_args method, complete with default values and help descriptions.
Activity
  • Closed issue [Bug]: --enable-mesh does not work in smg docker image #773, resolving the problem of --enable-mesh causing crashes in Python bindings.
  • Verified that cargo check -p smg-python compiles cleanly after the changes.
  • Confirmed that smg launch --enable-mesh no longer produces 'unrecognized arguments' errors.
  • Validated that complex mesh arguments like smg launch --enable-mesh --mesh-port 40000 --mesh-peer-urls 10.0.0.2:39527 are correctly parsed and passed.
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 Mar 16, 2026 •

Copy link
Copy Markdown

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: dd1f968b-aaf8-4d7d-953b-0c83c069776c

📥 Commits

Reviewing files that changed from the base of the PR and between b3498eb and 7a8044a.

📒 Files selected for processing (1)
  • bindings/python/src/lib.rs

📝 Walkthrough

Walkthrough

Adds mesh networking support to the Python bindings: workspace dependencies for smg-mesh and rand and five mesh configuration fields (enable_mesh, mesh_server_name, mesh_host, mesh_port, mesh_peer_urls) wired from CLI dataclass through the Router constructor into runtime MeshServerConfig construction.

Changes

Cohort / File(s) Summary
Dependency Management
bindings/python/Cargo.toml
Added workspace-scoped dependencies: smg-mesh and rand.
Core Router Implementation
bindings/python/src/lib.rs
Added public Router fields for mesh config; extended Router::new signature; conditional logic to construct and attach MeshServerConfig (self_name, self_addr, init_peer) when enable_mesh is true, with validation and errors on invalid addresses/URLs.
CLI Configuration
bindings/python/src/smg/router_args.py
Added mesh fields to RouterArgs dataclass with defaults and added CLI arguments (--enable-mesh, --mesh-server-name, --mesh-host, --mesh-port, --mesh-peer-urls) grouped under a Mesh Server section.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as RouterArgs
  participant PyRouter as Router (Python)
  participant Runtime as Runtime Server
  participant Mesh as MeshServerConfig

  User->>CLI: pass --enable-mesh + mesh args
  CLI->>PyRouter: instantiate Router with mesh params
  PyRouter->>PyRouter: validate peer URLs and host:port
  alt enable_mesh == true
    PyRouter->>Mesh: build MeshServerConfig (self_name, self_addr, init_peer)
    PyRouter->>Runtime: attach MeshServerConfig
  else
    PyRouter->>Runtime: no mesh config
  end
  Runtime->>Runtime: start server with/without mesh
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • CatherineSue
  • key4ng
  • gongwei-130

Poem

🐰
I hop through args and stitch a seam,
From CLI whispers to mesh-born dream,
Peers find paths where bytes now stream,
A tiny flag, a bounding leap,
I guard the code while others sleep.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding mesh CLI support to Python bindings, which directly addresses the issue of --enable-mesh not being recognized.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #773: adds mesh CLI arguments to router_args.py, expands Router struct with mesh fields, constructs MeshServerConfig in startup flow, and wires mesh configuration through to the Rust backend.
Out of Scope Changes check ✅ Passed All changes are within scope of issue #773: adding mesh dependencies, Router struct fields, CLI arguments, and MeshServerConfig construction. No unrelated modifications detected.
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 (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/python-mesh-args
📝 Coding Plan
  • Generate coding plan for human review comments

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

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

Copy link
Copy Markdown

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: 2ea6daf73b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bindings/python/src/lib.rs Outdated

@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 adds support for mesh networking to the Python bindings, exposing the existing Rust functionality through CLI arguments. The changes in Cargo.toml, lib.rs, and router_args.py are well-aligned with this goal. No specific code review comments were kept after filtering based on repository rules.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindings/python/src/lib.rs`:
- Around line 1121-1142: When enable_mesh is true the current mesh_server_config
block silently returns None on parse failures; change it to return a Result and
propagate explicit errors instead of disabling mesh: validate parsing of
format!("{}:{}", self.mesh_host, self.mesh_port) and, if it fails, return an Err
with a clear message referencing mesh_host/mesh_port; also validate each entry
of self.mesh_peer_urls by attempting url.parse::<SocketAddr>() and return an Err
if any peer URL is malformed; update the construction of
smg_mesh::MeshServerConfig (self_name, self_addr, init_peer, mtls_config) to be
created on successful parsing and propagate errors up from the function that
currently builds mesh_server_config (use the same function names/fields
enable_mesh, mesh_server_config, mesh_host, mesh_port, mesh_peer_urls, and
smg_mesh::MeshServerConfig).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 71589ef1-6d68-49bb-bc01-287fdeac345e

📥 Commits

Reviewing files that changed from the base of the PR and between eae871e and 2ea6daf.

📒 Files selected for processing (3)
  • bindings/python/Cargo.toml
  • bindings/python/src/lib.rs
  • bindings/python/src/smg/router_args.py

Comment thread bindings/python/src/lib.rs
…y disabling

What changed:
- bindings/python/src/lib.rs: when --enable-mesh is set, return explicit
  PyValueError if mesh_host:mesh_port fails to parse as SocketAddr or if
  a mesh peer URL is malformed. Previously these were silently converted
  to None, disabling mesh without any signal to the user.

Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@slin1237
slin1237 force-pushed the slin/python-mesh-args branch from bfeea85 to b3498eb Compare March 16, 2026 20:07

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

Copy link
Copy Markdown

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: b3498eb4ab

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bindings/python/src/lib.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindings/python/src/lib.rs`:
- Around line 1129-1150: The code currently uses self.mesh_peer_urls.first() and
therefore ignores additional entries; either reject multiple peers or pass them
through—if only a single seed peer is supported, add a guard that checks
self.mesh_peer_urls.len() > 1 and return a pyo3::exceptions::PyValueError naming
the offending list (use the same style as the existing errors), otherwise change
the parsing to map all entries into Vec<std::net::SocketAddr> and set
MeshServerConfig::init_peer accordingly; locate the fix around the
mesh_peer_urls parsing and where MeshServerConfig { init_peer, ... } is
constructed and update the error path or the type plumbing for init_peer to
avoid silently discarding entries.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a5d17f80-74d6-41ce-9c44-2531e9ae391c

📥 Commits

Reviewing files that changed from the base of the PR and between 2ea6daf and b3498eb.

📒 Files selected for processing (1)
  • bindings/python/src/lib.rs

Comment thread bindings/python/src/lib.rs
What changed:
- bindings/python/src/lib.rs: move error formatting into the map
  closure where the URL is already bound, avoiding a redundant
  .first().unwrap() that clippy flagged.

Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@slin1237
slin1237 merged commit 7b5d1dc into main Mar 16, 2026
27 of 28 checks passed
@slin1237
slin1237 deleted the slin/python-mesh-args branch March 16, 2026 21:29
smfirmin pushed a commit to smfirmin/smg that referenced this pull request Mar 20, 2026
smfirmin pushed a commit to smfirmin/smg that referenced this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Dependency updates python-bindings Python bindings changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: --enable-mesh does not work in smg docker image

1 participant