Repository navigation
[serve][in-place-updates][2/n] Make DEPLOY_FAILED terminal for rolling updates - #66290
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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]>
Signed-off-by: Qisheng He <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
2dc616d to
e7bf0a4
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort 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 e7bf0a4. Configure here.
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 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. |
Signed-off-by: Qisheng He <[email protected]>
There was a problem hiding this comment.
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.
Signed-off-by: Qisheng He <[email protected]>
jeffreywang88
left a comment
There was a problem hiding this comment.
one last comment :)
Signed-off-by: Qisheng He <[email protected]>
abrarsheikh
left a comment
There was a problem hiding this comment.
can you add these e2e test
- Deleting an app that is terminally failed
- Autoscaling deployment that fails a rolling update. test upscale/downscale/scale-to-zero
- 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.
- a failing rolling update on a gang of size N stops after ~`max_constructor_retry_countgang failures
- 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.
… on scaling Signed-off-by: Qisheng He <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
|
Added tests. below is their expected behavior we verify:
the app and all remaining replicas are removed, despite the terminal failure
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
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.
Count once per failed gang, not per member
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 |
Signed-off-by: Qisheng He <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
…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]>
…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]>

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_FAILEDuntil 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=0to 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:
Duplicate checks found no overlapping fix; #66267 adds complementary surge support. Claude Code assisted with implementation.