Skip to content

[serve][in-place-updates][2/n] Make DEPLOY_FAILED terminal for rolling updates - #66290

Merged
abrarsheikh merged 11 commits into
masterfrom
serve/inplace-2-terminal-deploy-failed
Sep 23, 2026
Merged

abrarsheikh merged 11 commits into
masterfrom
serve/inplace-2-terminal-deploy-failed

Conversation

@qishengxhe

@qishengxhe qishengxhe commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A failing rolling update can keep replacing healthy old replicas until none remain. This change stops the update at the existing startup failure threshold, including failures from new replicas that start but then fail health checks. Gang health failures count once per affected gang; healthy siblings stopped for a gang restart do not consume retries.

The deployment stays DEPLOY_FAILED until a deploy changes the target. This state survives a controller restart, including when actor or placement-group creation reaches the failure threshold during scheduling. The terminal flag is set when the threshold is reached, and checkpoint changes are collected after scheduling failures are processed.

Surviving replicas keep serving, but a small deployment can still lose all old replicas before reaching the threshold. Set RAY_SERVE_STOP_FAILED_ROLLING_UPDATES=0 to disable this behavior.

Tests

Coverage includes startup and health failures, gang failure accounting, controller recovery, autoscaling, the environment setting, stale constructor-error cleanup, and successful recovery after a changed deploy. Actor-creation and placement-group-creation regression cases both failed before the checkpoint fix and pass afterward; they recover directly from the threshold-reaching tick's checkpoint and verify the rollout remains stopped.

Ran locally in the Python 3.11 environment:

python -m pytest python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/unit/test_application_state.py -q
400 passed

python -m pytest python/ray/serve/tests/test_deploy_app_2.py -q -k 'keeps_serving_from_old_replicas or flapping_rolling_update or survives_controller_restart'
4 passed, 24 deselected

pre-commit run --files python/ray/serve/_private/deployment_state.py python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/test_deploy_app_2.py python/ray/serve/tests/BUILD.bazel
Passed

Duplicate checks found no overlapping fix; #66267 adds complementary surge support. Claude Code assisted with implementation.

@qishengxhe qishengxhe added go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue labels Sep 18, 2026
@qishengxhe
qishengxhe added this pull request to stack #66293 September 18, 2026 19:51
@qishengxhe
qishengxhe marked this pull request as ready for review September 18, 2026 21:15
@qishengxhe
qishengxhe requested a review from a team as a code owner September 18, 2026 21:15

@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 a mechanism to halt rolling updates in Ray Serve when a startup failure threshold is reached, preserving surviving replicas of the previous version until a new deployment is triggered. This behavior is managed by a new environment variable, RAY_SERVE_STOP_FAILED_ROLLING_UPDATES, and tracked via rolling_update and terminally_failed states that persist across controller restarts and autoscaling. The review feedback highlights two important improvement opportunities: resetting self._replica_constructor_error_msg and self._replica_constructor_retry_counter upon a new deployment, and clearing self._replica_constructor_error_msg when transitioning to a HEALTHY state, to prevent stale error details from leaking into subsequent updates.

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

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

probably worth considering a behavior similar to k8s to ensure zero availability drop ( https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#failed-deployment). k8s keeps v2 as the desired version, retries it, and prevents further v1 scale-down according to maxUnavailable. I'm worried about the possible availability drop during updates. @abrarsheikh wdyt?

Comment thread python/ray/serve/tests/BUILD.bazel Resolved
A rolling update whose new version kept failing was only terminal (no more
replacements, no more old replicas replaced) while no replica of the new
version had ever started. Once one had, the update retried forever and kept
consuming old replicas; startup failures counted but health-check failures
did not; and a controller restart or an autoscale-up that raised the
threshold resumed the retries.

`DeploymentTargetState` now carries two checkpointed fields: `rolling_update`
(the `deploy()` that set the version found replicas of another version;
cleared when the deployment reaches HEALTHY) and `terminally_failed` (sticky
until the next `deploy()`). During a rolling update the existing startup
failure threshold is evaluated independently of how many new replicas are
RUNNING, health-check failures of new-version replicas count toward it, and
once reached the deployment is DEPLOY_FAILED straight from the flag:
`_check_and_stop_outdated_version_replicas` stops no more old replicas and
`_get_upscale_replicas` starts no replacements. Both fields are carried
through count-only target-state reconstructions (autoscaling, num_replicas,
target_capacity), old checkpoints load with defaults, and the manager writes
a checkpoint when either field changes so the state survives a controller
restart while the retry counter restarts from zero as today.

Fresh deploys and scale-from-zero are unchanged (no marker). Kill switch:
RAY_SERVE_STOP_FAILED_ROLLING_UPDATES=0 restores the previous behavior.

Tests: unit tests for constructor failures, health-check failures, terminal
failure while some new replicas run, autoscale-up staying terminal, the two
restart cases (converged: marker cleared and steady-state rules apply;
failed: DEPLOY_FAILED and both guards restored with a zero counter), the
kill switch and old-checkpoint loading. Integration tests with traffic for a
flapping new version (rollout stops consuming old replicas) and for a
controller restart after a terminal failure (no replica is retried); both
fail without this change.

Signed-off-by: Qisheng He <[email protected]>
@qishengxhe
qishengxhe force-pushed the serve/inplace-2-terminal-deploy-failed branch from 2dc616d to e7bf0a4 Compare September 21, 2026 18:53
@qishengxhe
qishengxhe requested review from a team as code owners September 21, 2026 18:53

@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 using default effort 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 e7bf0a4. Configure here.

@qishengxhe
qishengxhe marked this pull request as draft September 21, 2026 19:04
@qishengxhe
qishengxhe removed request for a team September 21, 2026 19:05
@qishengxhe
qishengxhe removed the request for review from a team September 21, 2026 19:05
@qishengxhe
qishengxhe removed this pull request from stack #66293 September 21, 2026 19:13
@qishengxhe
qishengxhe changed the base branch from serve/inplace-1-keep-replicas-routable to master September 21, 2026 19:14
@qishengxhe

Copy link
Copy Markdown
Contributor Author

probably worth considering a behavior similar to k8s to ensure zero availability drop ( https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#failed-deployment). k8s keeps v2 as the desired version, retries it, and prevents further v1 scale-down according to maxUnavailable. I'm worried about the possible availability drop during updates. @abrarsheikh wdyt?

agreed that availability during updates matters. Today the batch size (20% by default) of our rolling in-place updates limits concurrent replacement, so it's equivalent to maxUnavailable.

This PR addresses an existing failure mode where new replicas start and then fail health checks, but the rollout keeps consuming healthy old replicas. This PR stops the rollout at the failure threshold and preserves that state across controller restarts.

On the other side, the control plane should detect the replica failure status and trigger automatic rollback on the serve cluster to the last stable version.

Separately #66267 adds surge support so replacements can start on new replicas before old replicas stop.

@qishengxhe
qishengxhe marked this pull request as ready for review September 21, 2026 21:07

@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 a mechanism to stop failed rolling updates at the startup failure threshold (including health check failures) in Ray Serve, preserving surviving replicas of the previous version until a new deployment changes the target. It adds tracking flags (rolling_update, terminally_failed) to DeploymentTargetState that survive controller restarts, along with comprehensive tests. The review feedback identifies two critical issues with the newly introduced _replica_constructor_error_msg attribute: first, it is not initialized in __init__, which could lead to an AttributeError upon controller restart; second, it is not updated in record_replica_startup_failure, which would cause the failure message to display None instead of the actual error. Both comments provide actionable code suggestions to resolve these issues.

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

one last comment :)

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

can you add these e2e test

  1. Deleting an app that is terminally failed
  2. Autoscaling deployment that fails a rolling update. test upscale/downscale/scale-to-zero
  3. Lightweight num_replicas change while terminally failed. operator sees DEPLOY_FAILED, edits num_replicas in the config and re-applies, hoping to force progress. That goes through the lightweight-update path and must not reset the flags and resume eating old replicas.
  4. a failing rolling update on a gang of size N stops after ~`max_constructor_retry_countgang failures
  5. deploy a new version whose actor creation genuinely fails (runtime_env with a nonexistent pip package, or an invalid ray_actor_options resource), drive to DEPLOY_FAILED, kill the controller, assert it stays failed with old replicas intact.

@qishengxhe

Copy link
Copy Markdown
Contributor Author

Added tests. below is their expected behavior we verify:

  1. Deleting an app that is terminally failed

the app and all remaining replicas are removed, despite the terminal failure

  1. Autoscaling deployment that fails a rolling update. test upscale/downscale/scale-to-zero

Upscaling cannot start new replicas. Downscaling, including to 0, remains allowed while status stays DEPLOY_FAILED. At 0, requests fail with DeploymentUnavailableError. A corrected deploy restores service

  1. Lightweight num_replicas change while terminally failed. operator sees DEPLOY_FAILED, edits num_replicas in the config and re-applies, hoping to force progress. That goes through the lightweight-update path and must not reset the flags and resume eating old replicas.

Preserves the terminal flags and failure counter. It cannot resume the failed rollout. Reducing the count can still remove replicas. Changing the target version allows recovery.

  1. a failing rolling update on a gang of size N stops after ~`max_constructor_retry_count_gang_ failures

Count once per failed gang, not per member

  1. deploy a new version whose actor creation genuinely fails (runtime_env with a nonexistent pip package, or an invalid ray_actor_options resource), drive to DEPLOY_FAILED, kill the controller, assert it stays failed with old replicas intact.

a nonexistent pip package causes a real runtime-env setup failure. After reaching terminal failure, restarting the controller preserves DEPLOY_FAILED and the surviving old replica PIDs, without retrying the failed version

@abrarsheikh
abrarsheikh merged commit 18bfedf into master Sep 23, 2026
6 checks passed
@abrarsheikh
abrarsheikh deleted the serve/inplace-2-terminal-deploy-failed branch September 23, 2026 18:02
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…g updates (ray-project#66290)

## Summary

A failing rolling update can keep replacing healthy old replicas until
none remain. This change stops the update at the existing startup
failure threshold, including failures from new replicas that start but
then fail health checks. Gang health failures count once per affected
gang; healthy siblings stopped for a gang restart do not consume
retries.

The deployment stays `DEPLOY_FAILED` until a deploy changes the target.
This state survives a controller restart, including when actor or
placement-group creation reaches the failure threshold during
scheduling. The terminal flag is set when the threshold is reached, and
checkpoint changes are collected after scheduling failures are
processed.

Surviving replicas keep serving, but a small deployment can still lose
all old replicas before reaching the threshold. Set
`RAY_SERVE_STOP_FAILED_ROLLING_UPDATES=0` to disable this behavior.

## Tests

Coverage includes startup and health failures, gang failure accounting,
controller recovery, autoscaling, the environment setting, stale
constructor-error cleanup, and successful recovery after a changed
deploy. Actor-creation and placement-group-creation regression cases
both failed before the checkpoint fix and pass afterward; they recover
directly from the threshold-reaching tick's checkpoint and verify the
rollout remains stopped.

Ran locally in the Python 3.11 environment:

```text
python -m pytest python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/unit/test_application_state.py -q
400 passed

python -m pytest python/ray/serve/tests/test_deploy_app_2.py -q -k 'keeps_serving_from_old_replicas or flapping_rolling_update or survives_controller_restart'
4 passed, 24 deselected

pre-commit run --files python/ray/serve/_private/deployment_state.py python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/test_deploy_app_2.py python/ray/serve/tests/BUILD.bazel
Passed
```

Duplicate checks found no overlapping fix; ray-project#66267 adds complementary
surge support. Claude Code assisted with implementation.

---------

Signed-off-by: Qisheng He <[email protected]>
sai-miduthuri pushed a commit that referenced this pull request Oct 16, 2026
…rcent` for start-before-stop rolling updates (#66267) (#67094)

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:

- `_private/deployment_state.py`, `tests/unit/test_deployment_state.py`:
#66243.
- `schema.py`, `tests/BUILD.bazel`, `tests/test_controller.py`,
`tests/test_direct_ingress.py`: #66339 and #66940.

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](https://claude.com/claude-code)

Signed-off-by: Qisheng He <[email protected]>
Signed-off-by: qishengxhe <[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.

3 participants