Skip to content

[cherry-pick][2.60.0][serve][in-place-updates][4/n] Add max_surge_percent for start-before-stop rolling updates (#66267) - #67094

Merged
sai-miduthuri merged 1 commit into
ray-project:releases/2.60.0from
qishengxhe:cherry-pick-66267-2.60.0
Oct 16, 2026
Merged

sai-miduthuri merged 1 commit into
ray-project:releases/2.60.0from
qishengxhe:cherry-pick-66267-2.60.0

Conversation

@qishengxhe

Copy link
Copy Markdown
Contributor

Cherry-pick of #66267 (master commit 9491664) onto releases/2.60.0.

Why

The first three PRs of the in-place-updates series (#66252, #66290, #66266) are already on releases/2.60.0. This picks the fourth, which adds max_surge_percent for start-before-stop rolling updates, so 2.60.0 ships the complete series.

Cherry-pick details

git cherry-pick -x conflicted in one file, python/ray/serve/tests/unit/test_deployment_state.py. The conflict was positional only: on master, #66243 (push-based replica health) had appended TestPushedHealthEndToEnd and related tests to the end of that file, and #66267 inserts TestMaxSurge right before them. This branch doesn't have #66243, so git couldn't anchor the hunk and offered the #66243 tests as part of the incoming side. Resolved by inserting only the PR's TestMaxSurge block (plus its defaultdict import) before the __main__ guard. The added and removed lines in each of the 17 files are identical to the master commit's diff.

After the pick, 11 of the 17 files are byte-identical to master at 9491664. The other 6 differ only by master commits that aren't on this branch and that #66267 doesn't depend on:

No commit on releases/2.60.0 after the branch cut touched any of these files.

Not a duplicate: no PR against releases/2.60.0 references #66267.

Testing

Run on this branch with the Serve protobuf regenerated from the branch's serve.proto (the pick adds the max_surge_percent field).

python -m pytest python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/unit/test_config.py python/ray/serve/tests/unit/test_deployment_class.py python/ray/serve/tests/unit/test_schema.py
3530 passed, 12 skipped
python -m pytest python/ray/serve/tests/test_deploy_app_3.py python/ray/serve/tests/test_deploy_app_2.py -k surge
13 passed, 41 deselected in 282s

pre-commit run --files <changed files> passed.

AI assistance was used to prepare this cherry-pick.

🤖 Generated with Claude Code

…re-stop rolling updates (ray-project#66267)

Draft for discussion of the rollout behavior raised in ray-project#63016.

Rolling updates currently stop old replicas before starting
replacements, temporarily reducing capacity.

This adds `max_surge_percent` to start replacements first. Old replicas
stop in batches once enough replacements are running to maintain the
target count. If capacity is unavailable, replacements wait while old
replicas keep serving.

The default is `0`, preserving existing behavior. Gang deployments round
the allowance up to whole gangs. During a terminally failed surge
update, reducing the replica count is deferred until a deploy changes
the target.
<img width="1497" height="1185" alt="image"
src="https://github.com/user-attachments/assets/d4d6dcbb-c93a-4a35-87c9-fb9fbf491a98"
/>

Example usage:
in YAML
```
name: surge-demo
image_uri: anyscale/ray:nightly-py311   # needs a Ray with ray-project#66267
working_dir: .
applications:
  - name: app
    import_path: serve_app:app
    deployments:
      - name: Model
        num_replicas: 4
        max_surge_percent: 50          # up to 2 extra replicas during a restart
        graceful_shutdown_timeout_s: 60
```
or via decorator:
```
from ray import serve
from starlette.requests import Request

@serve.deployment(num_replicas=4, max_surge_percent=50)
class Model:
    def __init__(self, version: str = "v1"):
        self.version = version

    async def __call__(self, request: Request) -> str:
        return f"hello from {self.version}"

app = Model.bind()

```

Added end-to-end tests covering surge rolling updates:
- Startup failures, rollback reusing original replicas, and successful
surge replacement while preserving capacity and serving traffic, with
and without a controller restart.
- Independent surge rollouts and rollbacks across multiple applications.
- Surge with autoscaling, graceful request draining, scale-to-zero, and
recovery after a failed deployment.
- Whole-gang surge replacement, failure handling, and rollback.
- Replica-count increases and decreases during surge rollouts.
- Health-check failures stopping a surge rollout, followed by rollback
preserving surviving old replicas.
- Insufficient capacity leaving surge replacements pending while old
replicas keep serving.

```text
python -m pytest python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/unit/test_config.py python/ray/serve/tests/unit/test_deployment_class.py
python -m pytest python/ray/serve/tests/test_deploy_app_2.py -k surge_rolling_update
```

Duplicate checks found no overlapping implementation. Claude Code
assisted with implementation.

---------

Signed-off-by: Qisheng He <[email protected]>
Signed-off-by: qishengxhe <[email protected]>
(cherry picked from commit 9491664)
Signed-off-by: qishengxhe <[email protected]>
@qishengxhe
qishengxhe requested review from a team as code owners October 15, 2026 21:59
@qishengxhe qishengxhe added the serve Ray Serve Related Issue label Oct 15, 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 the max_surge_percent configuration option for Ray Serve deployments, allowing extra replicas to be started during a rolling update before old replicas are stopped. This ensures that capacity is maintained and traffic is served continuously during updates. The changes include updates to the deployment configuration, state management logic to handle surge rollouts, documentation, and comprehensive unit and integration tests. Since there are no review comments, I have no feedback to provide.

@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

Reviewed by Cursor Bugbot for commit 947e832. Configure here.


// Extra replicas allowed during a rolling restart, as a percentage of the
// target count. Defaults to 0, which stops old replicas before starting new ones.
int32 max_surge_percent = 25;

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/ray-core/internals/rpc-fault-tolerance.rst

Fix in Cursor Fix in Web

Triggered by project rule: Bugbot Rules

Reviewed by Cursor Bugbot for commit 947e832. Configure here.

@qishengxhe qishengxhe added the go add ONLY when ready to merge, run all tests label Oct 15, 2026
@sai-miduthuri
sai-miduthuri enabled auto-merge (squash) October 15, 2026 22:27
@sai-miduthuri
sai-miduthuri merged commit 77010ab into ray-project:releases/2.60.0 Oct 16, 2026
6 of 7 checks passed
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.

2 participants