← Back to Pull requests

fix(api): describe the selected replica before inference #6114

Closed
unknown closed this pull request without merging on Nov 15, 2026 05:31 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 15:39 UTC
Author

An ordinary inference request can select healthy replica 1 while replica 0 is recovering, then fail before inference: healthy selected replica blocked by metadata lookup against recovering replica.

At 13bb1570, unkeyed selection uses the scheduler, but describe_model defaults to the first active replica. Completions and image edits omit the selected UID; chat supplies it only for keyed requests.

Pass the selected actor UID to the metadata lookup in all three handlers. The existing keyed scaling fallback, replica selection policy, and request/response schemas are preserved.

| Request, with healthy replica 1 selected | Before | After |
| --- | --- | --- |
| Unkeyed chat or completion | Metadata lookup fails against recovering replica 0 | Describe replica 1 and serve the request |
| Keyed chat control | Describe replica 1 and serve the request | Same behavior |
| Image edit | Metadata lookup fails against recovering replica 0 | Describe replica 1 and retain the existing image conversion behavior |

Deterministic regressions exercise the real supervisor selection and description methods with two stub workers. LLM cases cover streaming and non-streaming chat/completions plus keyed chat controls. Image cases retain RGB/RGBA conversion and option assertions. Supporting fixtures now expose byte actor UIDs matching production refs, including ordinary replicas and the P/D router, and accept the selected-replica keyword.

The shared REST paths cover supported chat/completion operations for Transformers, vLLM, SGLang, llama.cpp, MLX, and TRT-LLM, and supported image-edit operations for diffusers, transformers, vLLM, and SGLang. The metadata lookup precedes the streaming branches and both image-to-image and inpainting dispatch. Local and supervisor/worker deployments use the same supervisor methods; sharded models retain their first-worker lookup.

P/D keeps its existing worker-metadata lookup because the supervisor ignores the selected router UID for P/D models. Token Router proxy paths are unchanged. Audio, embeddings, rerank, Responses, and Anthropic messages do not perform this post-selection supervisor metadata lookup. Realtime performs its lookup before replica selection for model-type authorization and is outside this change. General unkeyed failover and P/D metadata availability remain outside the scope of this fix.

VALIDATION:

The current branch head is 6fa1fd15. The Linux runs used an identical Git tree. The follow-up changes only the two remaining test modules; production code and assertions are unchanged.

  • On Windows Python 3.10.20 and 3.14.6, offline runs passed 376 distinct tests per version: 152 core REST tests, all 28 non-streaming request-abort tests, and 196 tests across the five other changed modules. Fifteen core REST cases across thirteen functions requiring model launches or downloaded weights were excluded. The saved CI failure set was rerun separately: all 122 core REST cases and 19 abort cases passed on each Python version, without teardown errors.

  • On Ubuntu 24.04.5, all seven changed test modules produced 378 passed, 7 failed, 6 skipped in each configuration: Python 3.12.3 with Transformers 5.23.0, Python 3.12.3 with the Transformers 4.57.6 CI pin, and Python 3.10.22.

  • A separate Linux Python 3.12 comparison ran the full xinference/core/tests/test_restful_api.py and xinference/api/tests/test_non_streaming_request_abort.py suites on base 13bb1570 and the tree matching 6fa1fd15. Both produced 182 passed, 7 failed, 6 skipped, with identical failure sets. All seven failures are in core REST: test_events, test_lang_chain, test_launch_model_async, test_launch_model_by_version, test_openai, test_restful_api, and test_restful_api_with_request_limits. Their model launches fail because xllamacpp cannot be imported in that environment, causing downstream response or polling failures. They fail on base as well. Upstream CI installs xllamacpp; the local Linux results are not a claim that upstream CI is already green.

  • Linux Python 3.12 consumer coverage passes: 300 tests spanning Anthropic messages, Responses, authentication, model catalog/recommendation, request overhead, metrics, Token Router, cache salt, and benchmarks.

  • The Linux pre-commit run passes for the changed files and the additional checked types.py and engine_family.py files.

  • The original Windows regression check against base 13bb1570 produced four failing unkeyed LLM cases, five failing image cases, and two passing keyed controls on Python 3.10.20 and 3.14.6. All eleven passed with the fix. The original Linux fail-before run also failed as expected.

  • Windows formatting, lint, typing, whitespace, and local test-platform coverage checks pass. Those environments use xoscar 0.11.2, below the declared 0.12.2 minimum; their Ruff version is 0.17.3 rather than the configured 0.15.22.
  • The seven changed test modules are test_llm_request_abort.py, test_qwen_image21_edits.py, test_cache_salt.py, test_model_recommendation.py, test_token_router_dispatch.py, and test_non_streaming_request_abort.py under xinference/api/tests/, plus xinference/core/tests/test_restful_api.py.

    Windows focused runs used python -m pytest -p no:cacheprovider -o addopts="" --timeout=300 -vv, one file at a time with a temporary XINFERENCE_HOME. The base regression selectors were -k test_llm_describes_selected_replica and -k test_image_edits_alpha_depends_on_model_name.

    Validation uses stub workers and model actors. Real-engine inference, GPU/model-weight runs, and the full repository suite were not run.

    AI disclosure: this was prepared with AI assistance (Claude Opus 5.5 and Claude Sonnet 5.5).

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01JfvcPZyKcKQUG9fQGYfRMw

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Jackmeson1 Review duration: 831m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #6114"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%