Repository navigation
[Serve][1/5] Add private router-application role - #66506
Conversation
Add an internal, application-wide role, `Application._as_router_application()`, for applications whose ingress chooses which replica of which other application serves a request. HAProxy will consume the role in a follow-up; this change only carries it from the application to the target group. The role marks the application's existing ingress. No router deployment is added. It flows through BuiltApplication, DeploymentArgs and DeploymentInfo (new `router_application` proto fields), ApplicationState, and the HTTP TargetGroup (`is_router_application`). gRPC target groups never carry it. The marker is read from the target state rather than running replicas, so a router application scaled to zero keeps it. Otherwise HAProxy would stop treating the application as a router and return its routing decisions to clients as responses. Validation: - requires HAProxy; - cannot be combined with `_with_ingress_request_router()`: both choose the replica for requests to the application; - requires a route prefix, checked for `serve.run` in the client and for config deploys after route-prefix overrides. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Celina Yang <[email protected]>
…oups Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Celina Yang <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Celina Yang <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
b9e7c59 to
489f175
Compare
…-1-serve-role Signed-off-by: Celina Yang <[email protected]>
Replace Application._as_router_application() with a private class decorator. Being a router application depends on what the class returns, so the marker lives on the class (like @serve.multiplexed) and build_app reads it from the ingress. The wire format is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Celina Yang <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces support for application-level router applications in Ray Serve, allowing an ingress deployment to be marked with @serve._router_application so that HAProxy can route requests directly to specific replicas. It updates deployment info, application state, controller target groups, and protobuf schemas to propagate and validate this metadata. The review feedback highlights several potential AttributeError issues during rolling upgrades when deserializing older DeploymentInfo objects that lack the new router_application attribute, suggesting the use of getattr with a default value. Additionally, a missing import of ServeControllerClient in a test helper was identified.
Signed-off-by: Seiji Eicher <[email protected]>
f556d7a to
a5b5822
Compare
Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]> # Conflicts: # python/ray/serve/_private/build_app.py # python/ray/serve/tests/unit/test_application_state.py
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e560b2a. Configure here.
| double target_capacity = 8; | ||
| TargetCapacityDirection target_capacity_direction = 9; | ||
| bool ingress_request_router = 10; | ||
| bool router_application = 11; |
There was a problem hiding this comment.
Proto change needs fault-tolerance review
Low Severity
.proto files.
Please review the RPC fault-tolerance & idempotency standards guide here:
https://github.com/ray-project/ray/tree/master/doc/source/core/internals/rpc-fault-tolerance.md
Additional Locations (1)
Triggered by project rule: Bugbot Rules
Reviewed by Cursor Bugbot for commit e560b2a. Configure here.
#66507) ## Why this is needed PR #66506 marks router applications and publishes that role to HAProxy. This PR implements the private HAProxy protocol that lets a router application choose a replica in another Serve application while preserving the direct model-to-client streaming path. ## Summary For a request whose longest-prefix match is a router application, HAProxy: 1. Holds the original client request and sends a separate `POST /internal/route` control request to a router replica. The control request carries the original method, prefix-stripped path and query, selected headers including Authorization, request ID, session ID, and buffered body. 2. Accepts either a routing decision or a router-owned response. 3. Validates the selected application and full replica ID against its current target configuration. 4. Rewrites the router prefix to the target application's route prefix. 5. Pins the original request to the selected replica with forced persistence, so connection failure cannot redispatch it to a different replica. 6. Streams the target replica's response directly to the client. The Lua response path is bypassed after a successful routing decision. A routing decision has this private shape: ```json {"application": "llm-model-qwen", "replica_id": "SERVE_REPLICA::..."} ``` A router-owned response contains `X-Serve-Router-Direct-Response: 1`. HAProxy strips that private marker and hop-by-hop headers while preserving end-to-end headers, status, and body. Chunked router responses are decoded before forwarding or parsing. Unmarked non-2xx responses are returned as errors. Decision parsing supports escaped JSON strings and rejects unknown applications, unknown replicas, malformed decisions, unavailable replicas, and router failures with a fail-closed `503`. Ordinary applications and the existing ingress request router path retain their previous behavior. ## Test plan - `RAY_SERVE_ENABLE_HA_PROXY=1 python -m pytest -q python/ray/serve/tests/test_haproxy_router_application.py` - Coverage includes POST and non-POST methods, query forwarding, route-prefix rewriting, escaped names, CORS preflight metadata, direct responses and headers, chunked responses, malformed decisions, unavailable replicas, router failures, and scale-to-zero router fallback. - Pinned Black 22.10.0 and pre-commit checks on changed files. --------- Signed-off-by: Celina Yang <[email protected]> Signed-off-by: Seiji Eicher <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Seiji Eicher <[email protected]>


Why this is needed
Multi-model direct streaming deploys each model as an independent Serve application and places one router application at the shared OpenAI route prefix. HAProxy needs a private application-level marker to distinguish that router from an ordinary application.
Summary
@serve._router_applicationclass decorator.@serve.ingress, regardless of decorator order.Falsewhen older deployment information is restored during an upgrade.This is private Serve infrastructure. It does not add a general public router-application API.
Test plan
@serve.ingress, validation, and deployment-argument propagation intest_build_app.py.test_application_state.py.test_controller_direct_ingress.py.