Skip to content

feat(router): expose virtual model running details - #5397

Open
m199369309 wants to merge 2 commits into
xorbitsai:mainfrom
m199369309:feat/router-virtual-model-details
Open

feat(router): expose virtual model running details#5397
m199369309 wants to merge 2 commits into
xorbitsai:mainfrom
m199369309:feat/router-virtual-model-details

Conversation

@m199369309

Copy link
Copy Markdown
Collaborator

Summary

  • expose Token Router virtual models through the Running Model detail contract
  • declare virtual models as chat-capable and identify their virtual model type
  • include sanitized runtime, backend, status, and deployment summaries
  • normalize sparse legacy and typed Router configurations without mutating persistence
  • route GET /v1/models/{model_uid} through the unified running-model descriptor

Dependency

Validation

  • pytest -q xinference/api/tests/test_token_router_dispatch.py xinference/api/tests/test_token_router_api.py
  • pre-commit run --files xinference/core/supervisor.py xinference/api/restful_api.py xinference/api/tests/test_token_router_dispatch.py xinference/api/tests/test_token_router_api.py

@XprobeBot XprobeBot added this to the v3.x milestone Aug 20, 2026

@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 refactors how token router configurations are handled and described in the supervisor, introducing a schema-complete normalization for UI-facing responses and adding support for describing both virtual and physical running models. It also includes comprehensive test coverage for these changes. The review feedback suggests several defensive programming improvements in xinference/core/supervisor.py to prevent potential runtime exceptions, such as using the robust _safe_public_int helper to parse the configuration revision safely and using .get() instead of direct bracket access to avoid potential KeyErrors when retrieving router and virtual model UIDs.

Comment on lines +5089 to +5096
if not (
instance.get("online")
and instance.get("status") == "ready"
and not instance.get("config_error")
and acked_revision >= int(config.get("revision", 0))
and isinstance(endpoint, str)
and endpoint.startswith(("http://", "https://"))
):

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.

high

If config.get("revision") is None or a non-integer string, calling int() directly on it will raise a TypeError or ValueError, crashing the health check. Use the robust self._safe_public_int helper to safely parse the revision value with a fallback default.

Suggested change
if not (
instance.get("online")
and instance.get("status") == "ready"
and not instance.get("config_error")
and acked_revision >= int(config.get("revision", 0))
and isinstance(endpoint, str)
and endpoint.startswith(("http://", "https://"))
):
if not (
instance.get("online")
and instance.get("status") == "ready"
and not instance.get("config_error")
and acked_revision >= self._safe_public_int(config.get("revision"), 0)
and isinstance(endpoint, str)
and endpoint.startswith(("http://", "https://"))
):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in bedc100. The config revision is parsed with _safe_public_int, and invalid revisions now fail closed so no runtime is considered ready. Added regression coverage for None and non-integer revisions.

Comment thread xinference/core/supervisor.py Outdated
self, config: Dict[str, Any]
) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]], List[Dict[str, Any]]]:
"""Return all, effectively ready, and controllably ready Runtimes."""
instances = self._token_router_registry.list(config["router_uid"])

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.

medium

To prevent potential KeyError exceptions if config is missing the router_uid key, use .get() to retrieve it defensively.

Suggested change
instances = self._token_router_registry.list(config["router_uid"])
instances = self._token_router_registry.list(config.get("router_uid"))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in bedc100. router_uid is validated before querying the registry. We intentionally return an empty instance list for a missing/invalid UID because RouterRuntimeRegistry.list(None) returns all Router instances and would cause cross-Router state leakage. Added a regression test for this case.

Comment thread xinference/core/supervisor.py Outdated
Comment on lines +5289 to +5296
return {
"model_name": config["virtual_model_uid"],
"model_type": config.get("model_type", "LLM"),
"model_engine": "token_router",
"model_ability": ["chat"],
"model_kind": "virtual",
"virtual_model_type": "token_router",
"router_uid": config["router_uid"],

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.

medium

To adhere to defensive programming practices and prevent potential KeyError exceptions if the keys are missing from config, use .get() instead of direct bracket access for virtual_model_uid and router_uid.

Suggested change
return {
"model_name": config["virtual_model_uid"],
"model_type": config.get("model_type", "LLM"),
"model_engine": "token_router",
"model_ability": ["chat"],
"model_kind": "virtual",
"virtual_model_type": "token_router",
"router_uid": config["router_uid"],
return {
"model_name": config.get("virtual_model_uid"),
"model_type": config.get("model_type", "LLM"),
"model_engine": "token_router",
"model_ability": ["chat"],
"model_kind": "virtual",
"virtual_model_type": "token_router",
"router_uid": config.get("router_uid"),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in bedc100. Missing or non-string virtual_model_uid and router_uid values are now rendered as empty strings instead of raising KeyError, preserving stable public response types. Added regression coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants