Skip to content

[Serve][1/5] Add private router-application role - #66506

Merged
elliot-barn merged 17 commits into
masterfrom
celina/router-app-1-serve-role
Oct 20, 2026
Merged

elliot-barn merged 17 commits into
masterfrom
celina/router-app-1-serve-role

Conversation

@celinaky

@celinaky celinaky commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Add the private @serve._router_application class decorator.
  • Detect the marker through the class MRO so it survives the wrapper subclass created by @serve.ingress, regardless of decorator order.
  • Propagate the role through application build metadata, deployment arguments and information, controller state, and HTTP target groups.
  • Reject router applications when HAProxy is disabled, the route prefix is missing, or an ingress request router is also attached.
  • Preserve the currently serving ingress name and router role while a declarative replacement is building. This prevents HAProxy from temporarily treating a live router as an ordinary application and returning an internal routing decision to a client.
  • Clear or replace the retained metadata when the application is deleted or a completed replacement is installed.
  • Default the new persisted field to False when 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

  • Decorator ordering, inheritance through @serve.ingress, validation, and deployment-argument propagation in test_build_app.py.
  • Declarative rolling replacement, deletion, and target-state restoration in test_application_state.py.
  • Controller target-group propagation in test_controller_direct_ingress.py.
  • Pre-commit and Buildkite checks.

@celinaky celinaky changed the title [Serve] [1/4] [Serve][1/4] Sep 26, 2026
@celinaky
celinaky added this pull request to stack #66518 September 27, 2026 16:35
@celinaky celinaky added the go add ONLY when ready to merge, run all tests label Sep 28, 2026
@celinaky celinaky changed the title [Serve][1/4] [Serve][1/4] Add flag indicating a router application to HAProxy Sep 29, 2026
@celinaky celinaky changed the title [Serve][1/4] Add flag indicating a router application to HAProxy [Serve][1/4] Add private router-application role Oct 1, 2026
celinaky and others added 12 commits October 4, 2026 23:10
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]>
@celinaky
celinaky force-pushed the celina/router-app-1-serve-role branch from b9e7c59 to 489f175 Compare October 5, 2026 00:19
celinaky and others added 2 commits October 5, 2026 17:00
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]>
@eicherseiji
eicherseiji marked this pull request as ready for review October 7, 2026 20:50
@eicherseiji
eicherseiji requested a review from a team as a code owner October 7, 2026 20:50
@eicherseiji eicherseiji self-assigned this Oct 7, 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 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.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread src/ray/protobuf/serve.proto Resolved
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Oct 8, 2026
@eicherseiji
eicherseiji force-pushed the celina/router-app-1-serve-role branch from f556d7a to a5b5822 Compare October 13, 2026 21:43

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread src/ray/protobuf/serve.proto Resolved
@eicherseiji eicherseiji changed the title [Serve][1/4] Add private router-application role [Serve][1/5] Add private router-application role Oct 15, 2026
@eicherseiji eicherseiji changed the title [Serve][1/5] Add private router-application role [Serve][1/4] Add private router-application role Oct 15, 2026
@eicherseiji
eicherseiji removed this pull request from stack #66518 October 15, 2026 18:58
@eicherseiji
eicherseiji added this pull request to stack #67088 October 15, 2026 18:58
Signed-off-by: Seiji Eicher <[email protected]>

# Conflicts:
#	python/ray/serve/_private/build_app.py
#	python/ray/serve/tests/unit/test_application_state.py

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Proto change needs fault-tolerance review

Low Severity

⚠️ This PR modifies one or more .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)
Fix in Cursor Fix in Web

Triggered by project rule: Bugbot Rules

Reviewed by Cursor Bugbot for commit e560b2a. Configure here.

@elliot-barn
elliot-barn merged commit ef74918 into master Oct 20, 2026
5 of 6 checks passed
@elliot-barn
elliot-barn deleted the celina/router-app-1-serve-role branch October 20, 2026 20:59
@eicherseiji eicherseiji changed the title [Serve][1/4] Add private router-application role [Serve][1/5] Add private router-application role Oct 20, 2026
eicherseiji added a commit that referenced this pull request Oct 21, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants