Skip to content

[Router] NEU-869: add scoped APIs and pool metrics - #9

Merged
Yuyz0112 merged 11 commits into
neutreefrom
codex/neu-869-router-stages
Nov 12, 2026
Merged

Yuyz0112 merged 11 commits into
neutreefrom
codex/neu-869-router-stages

Conversation

@Levi080513

@Levi080513 Levi080513 commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

When backend connection pools are exhausted, Router now exposes waiting requests by workspace, endpoint, backend URL, and inference replica. The shared aiohttp client applies phase-specific transport limits, while the scoped inference APIs preserve Neutree's workspace/endpoint routing boundary.

Refs NEU-869

Changes

  • Adopt only upstream changes already merged into upstream main: startup initialization from [Bugfix][Router] Fix router startup race when using multiple replicas vllm-project/production-stack#768, Pooling from [Router] added pooling route vllm-project/production-stack#1112, and the merged multipart implementation at 7b1164d.
  • Configure the shared ClientSession/TCPConnector with per-backend capacity and startup phase timeouts. The Router uses connect, sock_connect, and sock_read settings with no total request deadline.
  • Maintain router:connection_pool_waiting through native aiohttp TraceConfig queue hooks. Backend gauges include the inference replica label, and existing incoming-request counter dimensions remain unchanged.
  • Expose Pooling, Classification, transcription, and translation only through their Neutree-scoped paths. Workspace/endpoint values select the backend and routing policy; the handlers share the existing forwarding lifecycle.
  • Preserve the existing passthrough route and discovery behavior. The Router PR does not add P/D or LoRA support.

Compatibility

  • New scoped paths are /{workspace}/{endpoint}/pooling, /{workspace}/{endpoint}/classify, /{workspace}/{endpoint}/v1/audio/transcriptions, and /{workspace}/{endpoint}/v1/audio/translations.
  • Transcription retains the existing language=en default and forwards the merged implementation's known fields. Translation preserves the original multipart body and boundary.
  • Client settings are startup configuration and require Router restart/reconciliation. Native file configuration/reload and sleep/wake remain outside this change.

Unit test

  • PYTHONPATH=src .venv/bin/python -m pytest -q: 98 passed.
  • Ruff 0.12.0 and Black checks passed.
  • Tests cover scoped selection, multipart response handling, request cancellation cleanup, sliding-window latency, queue acquisition/cancellation/timeout accounting, and replica-labelled metrics.

DB test

Not applicable; no database changes.

E2E test

  • GitHub Actions run 43011878495 built neutree/router:v1.3.0-neu869-4 from e891724554d46550e0021d8c8861f9521ce7a633; amd64 and arm64 manifests succeeded.
  • On the existing 10.255.1.136 environment, the Router Deployment reached 2/2 Ready with the new image. Scoped /v1/models and /v1/chat/completions returned 200, replica-labelled metrics were exposed, and concurrent requests produced pool-wait values that returned to zero.
  • Through the Cluster API, timeout values were temporarily set to 2/1/10, 10/1/2, and 10/1/10. Real delayed-response, pool-exhaustion, and TCP blackhole faults returned 504 at the configured phase boundaries. The Cluster was restored to 60/10/600, the temporary Pod and NetworkPolicy were deleted, and the existing inference endpoint returned 200.
  • Deployed Qwen/Qwen3-ASR-1.7B from the official model-card audio samples on a Tesla-T4 without virtualized memory. Scoped transcription returned HTTP 200 with the expected English and Chinese sample text, and scoped translation returned HTTP 200. The temporary ASR resources and API key were deleted, and neu869-router-real was restored to Running.

Checklist

  • Applicable pre-commit and local checks pass.
  • Commits include DCO Signed-off-by.
  • Router image and runtime E2E evidence are available for review.

@Levi080513 Levi080513 changed the title [Router] NEU-869: improve reliability and audio APIs [Router] NEU-869: add scoped APIs and pool metrics Nov 9, 2026
Use native aiohttp configuration and tracing, restore Kubernetes watches,
and adapt upstream audio forwarding with scoped inference routes.

Refs NEU-869

Signed-off-by: huangwei <wei.huang@smartx.com>
Withdraw unmerged fixes and unsupported P/D adapters.
Keep native timeouts, queue metrics and startup-only settings.
Trim redundant tests and extend the existing scoped audio handler.

BREAKING CHANGE: transcription uses only the scoped
/{workspace}/{endpoint}/v1/audio/transcriptions path.

Refs NEU-869

Signed-off-by: huangwei <wei.huang@smartx.com>
Use Python 3.12 annotations and equivalent timeout aliases.
Keep the existing error responses and log startup exceptions fully.

Refs NEU-869

Signed-off-by: huangwei <wei.huang@smartx.com>
Signed-off-by: huangwei <wei.huang@smartx.com>
Remove the temporary catch-all route and its discovery bypass now that scoped APIs are explicit. Keep request statistics accurate across cancellation and the latency window.
@Levi080513
Levi080513 force-pushed the codex/neu-869-router-stages branch from 653cf81 to e723c38 Compare November 11, 2026 03:38

Copilot AI 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.

🟡 Changes recommended

Active moderate and critical findings remain: the legacy transcription route contradicts the scoped contract, global pooling requests fail on Prometheus None labels, and passthrough backends can stall serial stats scraping when /metrics is unavailable.

3 open issues
What changed in this PR

This pull request adds scoped inference APIs and backend connection-pool observability to Router while centralizing aiohttp client configuration, forwarding metrics, and multipart audio handling.

Changes:

  • Adds scoped Pooling, Classification, transcription, and translation forwarding routes.
  • Configures shared aiohttp connection limits, phase-specific timeouts, and pool-wait metrics.
  • Extends replica-aware backend metrics, request-stat handling, lifecycle initialization, documentation, tests, and CI configuration.
File Description
src/​vllm_router/​utils.py Adds model types, URLs, payloads, and health-check handling for the new APIs.
src/​vllm_router/​stats/​request_stats.py Expires stale latency samples during statistics collection.
src/​vllm_router/​stats/​log_stats.py Adds inference replica labels to logged backend metrics.
src/​vllm_router/​stats/​engine_stats.py Updates backend engine metric scraping behavior.
src/​vllm_router/​services/​request_service/​request.py Adds scoped JSON and multipart forwarding with timeout and request-state handling.
src/​vllm_router/​services/​metrics_service/​forwarding.py Implements aiohttp connection-pool queue tracing and stale metric-series pruning.
src/​vllm_router/​services/​metrics_service/​__init__.py Adds inference replica labels to backend gauges while preserving existing Counter dimensions.
src/​vllm_router/​service_discovery.py Initializes event-loop-dependent discovery resources and client sessions.
src/​vllm_router/​routers/​routing_logic.py Adds QPS fallback routing for input-only requests.
src/​vllm_router/​routers/​passthrough_router.py Uses the shared aiohttp client with forwarding tracing and timeout handling.
src/​vllm_router/​routers/​metrics_router.py Exports replica-aware backend gauges and connection-pool waiting metrics.
src/​vllm_router/​routers/​main_router.py Registers scoped Pooling, Classification, transcription, and translation routes.
src/​vllm_router/​README.md Documents client configuration, metrics, and scoped APIs.
src/​vllm_router/​parsers/​parser.py Adds and validates connection-pool and timeout configuration options.
src/​vllm_router/​dynamic_config.py Carries startup-only client settings through dynamic configuration.
src/​vllm_router/​app.py Configures the shared aiohttp client during application startup and shutdown.
src/​vllm_router/​aiohttp_client.py Supports connector limits, timeout configuration, and trace configurations.
src/​tests/​test_request_stats.py Tests latency expiration and replica-labelled metrics.
src/​tests/​test_inference_api_routes.py Tests scoped forwarding, multipart behavior, health probes, responses, cancellation, and timeouts.
src/​tests/​test_forwarding_metrics.py Tests connection-pool queue accounting and stale-series pruning.
src/​tests/​test_client_config.py Tests client configuration defaults, zero values, and validation.
src/​tests/​test_aiohttp_client.py Tests shared-client configuration and lifecycle ordering.
.github/​workflows/​pre-commit.yml Pins Ruff to the validated version used by pre-commit.
.github/​workflows/​ci.yml Pins the CI Python runtime to version 3.12.

Review effort: Lite

Comment thread src/vllm_router/routers/main_router.py Resolved
Comment thread src/vllm_router/routers/main_router.py Resolved
Comment thread src/vllm_router/stats/engine_stats.py Resolved
@Levi080513
Levi080513 marked this pull request as ready for review November 11, 2026 14:30
@Levi080513
Levi080513 requested a lite review from Copilot November 11, 2026 14:34

Copilot AI 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.

🟡 Changes recommended

Two active issues remain: scoped pooling/classification can route input-only payloads incorrectly via a blocking tokenization call, and malformed JSON audio responses can incorrectly convert the backend status to 502.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve backend status when JSON response parsing fails

src/​vllm_router/​services/​request_service/​request.py:904

When the backend declares application/json but returns an empty or malformed body, backend_response.json() raises here and the handler changes the backend's status to 502. This violates the documented behavior that audio responses preserve backend status/content type (and turns, for example, a backend 422 with a malformed JSON error into a 502); return the buffered raw body with the original status/content type, or otherwise preserve the status on parse failure.

3 resolved since last review

Review effort: Lite

Comment thread src/vllm_router/app.py
sock_connect=args.sock_connect_timeout_seconds or None,
sock_read=args.sock_read_timeout_seconds or None,
)
app.state.max_connections_per_backend = args.max_connections_per_backend

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

app.state.aiohttp_timeout uses args.xxx or None, so 0 means "disabled". That matches the CLI help and the README. However, these four fields are compare=False in dynamic_config, so a hot reload silently ignores changes to them. Can we confirm that on the Neutree side, changing these values always triggers a Router restart, rather than only updating the dynamic config file?

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.

These settings are intentionally startup-only. Neutree applies them through the Router Deployment arguments, so changing them triggers a Deployment rollout and Router restart. They are excluded from in-process dynamic configuration updates by design.

selected.pod_name or "",
),
)
except asyncio.CancelledError:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In proxy_multipart_request, the except asyncio.CancelledError branch and the except Exception branch below it are identical: both call monitor.on_request_complete(..., success=False) and re-raise. They can be merged into a single except BaseException to avoid the duplication. Minor, no behavior change.

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.

asyncio.CancelledError has distinct semantics from other exceptions in Router. It indicates that the request task was cancelled, typically because the client disconnected or the Router is shutting down, rather than a backend or transport failure. Router intentionally captures it separately to record cancellation-specific cleanup and re-raise the cancellation. Other exceptions represent backend or request failures and must remain distinguishable, so these branches should not be merged into a broad BaseException handler.

@Yuyz0112
Yuyz0112 merged commit e82d9fc into neutree Nov 12, 2026
16 of 17 checks passed
@Yuyz0112
Yuyz0112 deleted the codex/neu-869-router-stages branch November 12, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants