Skip to content

[Serve] [1/N] Add RolloutSupervisor core logic - auto-rollback feature - #63382

Open
vaishdho1 wants to merge 10 commits into
ray-project:masterfrom
vaishdho1:serve-auto-rollback-core-logic
Open

vaishdho1 wants to merge 10 commits into
ray-project:masterfrom
vaishdho1:serve-auto-rollback-core-logic

Conversation

@vaishdho1

Copy link
Copy Markdown
Contributor

Description

This is the first PR towards implementing auto-rollback for serve deploy (#63016). It Implements the core RolloutSupervisor state machine logic along with unit tests to test its behavior.

Changes

  • common.py: Add RolloutState enum and ConfigSnapshot dataclass.
  • rollout_supervisor.py(new) : Entire state machine logic for the Rollout supervisor
  • test_rollout_supervisor.py (new): Unit tests covering all state transitions.

Related issues

Related to #63016

Follow up

The next PR is Controller integration and checkpoint persistence

@vaishdho1
vaishdho1 requested a review from a team as a code owner May 15, 2026 22:36

@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 RolloutSupervisor to manage automatic rollbacks for Ray Serve deployments, supported by new RolloutState and ConfigSnapshot definitions and a unit test suite. The reviewer identified a critical logic error in the application status check where the DEPLOYING status was incorrectly prioritized over DEPLOY_FAILED, potentially delaying rollbacks. Other feedback included correcting type hints for optional configuration attributes and fixing a typo in a test function name.

Comment on lines +56 to +65
for app_name in self._current_config.config_dict:
if app_name not in app_statuses:
return ApplicationStatus.DEPLOYING
status = app_statuses[app_name].status
if status == ApplicationStatus.DEPLOY_FAILED:
return ApplicationStatus.DEPLOY_FAILED
if status == ApplicationStatus.DEPLOYING:
atleast_one_deploying = True
elif status == ApplicationStatus.UNHEALTHY:
atleast_one_unhealthy = True

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.

high

The current implementation of _check_apps_status returns ApplicationStatus.DEPLOYING immediately if an application is not found in app_statuses. This violates the precedence rules defined in the docstring, where DEPLOY_FAILED should take priority. If one application has already failed but another is not yet present in the status manager, the supervisor will incorrectly report DEPLOYING and delay the rollback process. The loop should continue checking for failures even if an app is missing.

Suggested change
for app_name in self._current_config.config_dict:
if app_name not in app_statuses:
return ApplicationStatus.DEPLOYING
status = app_statuses[app_name].status
if status == ApplicationStatus.DEPLOY_FAILED:
return ApplicationStatus.DEPLOY_FAILED
if status == ApplicationStatus.DEPLOYING:
atleast_one_deploying = True
elif status == ApplicationStatus.UNHEALTHY:
atleast_one_unhealthy = True
for app_name in self._current_config.config_dict:
if app_name not in app_statuses:
atleast_one_deploying = True
continue
status = app_statuses[app_name].status
if status == ApplicationStatus.DEPLOY_FAILED:
return ApplicationStatus.DEPLOY_FAILED
if status == ApplicationStatus.DEPLOYING:
atleast_one_deploying = True
elif status == ApplicationStatus.UNHEALTHY:
atleast_one_unhealthy = True

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This condition will never be touched in the actual flow. apply_app_configs guarantees all apps exist before update() runs.
Removed in 5451521

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.

right, but still good to be defensive here right?

@vaishdho1 vaishdho1 Jun 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If an app in config_dict isn't in app_statuses, it means apply_app_configs never created its state, which shouldn't happen in the current flow. We can still add a defensive check here and treat it as DEPLOY_FAILED since we can only recover from this scenario by rolling back if that is possible.
Added in 7cd3cd3

@vaishdho1 vaishdho1 changed the title [Serve] [1/N] Add RolloutSupervisor core logic - Auto-rollback feature [Serve] [1/N] Add RolloutSupervisor core logic - auto-rollback feature May 15, 2026
return ApplicationStatus.DEPLOYING
if atleast_one_unhealthy:
return ApplicationStatus.UNHEALTHY
return ApplicationStatus.RUNNING

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unhandled app statuses silently treated as RUNNING

Medium Severity

_check_apps_status only explicitly handles DEPLOY_FAILED, DEPLOYING, and UNHEALTHY, causing any other ApplicationStatus value — including DELETING and NOT_STARTED — to silently fall through and be counted as RUNNING. The real ApplicationState._determine_app_status can return DELETING for apps that exist in _application_states. If an app in the current config happens to have one of these unhandled statuses, _check_apps_status returns RUNNING, and update() would incorrectly promote the config to _last_good_config and transition to IDLE. This also isn't future-proof — any new ApplicationStatus variant added to the enum would be silently treated as healthy.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f6e8b8e. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The supervisor only sees apps that were just submitted via apply_app_configs, and those apps can only be in DEPLOYING, RUNNING, UNHEALTHY, or DEPLOY_FAILED states. The other states are not touched during its watching state.

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.

will update not be called on every controller loop? if it is being called on every loop then it is possible to get app status with DELETING no?

@vaishdho1 vaishdho1 Jun 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is an interesting case. An app in _current_config can only reach DELETING if someone calls the imperative serve.delete() on it. In the declarative flow, removing an app means submitting a new config without it, apply_app_configs handles deletion via set difference and updates _current_config in the same call, so _check_apps_status never sees it.

Hitting DELETING here would require mixing imperative and declarative APIs. There's no guard preventing that today, so it could still happen accidentally. There are a couple of options to prevent this:

  • Add a guard in controller.delete_apps() that rejects calls targeting declaratively managed apps.
  • Internally translate the imperative delete into a new config without that app and route it through apply_app_configs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Following up on this. The supervisor now handles DELETING and missing apps explicitly instead of treating them as RUNNING. If an app in the current config was deleted outside the config, the supervisor goes back to IDLE without promoting the config, and real failures still trigger a rollback. The updated state diagram is on the RFC #63016 (comment)

For serve.delete() on declarative apps, I have opened a separate issue #68660 with the second fix, since the deleted app also comes back after a controller restart. The fix will go in it own PR

@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels May 16, 2026
@vaishdho1

Copy link
Copy Markdown
Contributor Author

@abrarsheikh Could you review this PR?

@harshit-anyscale harshit-anyscale added the go add ONLY when ready to merge, run all tests label Jun 10, 2026
@harshit-anyscale

Copy link
Copy Markdown
Contributor

@vaishdho1 premerge tests have been failing, can you PTAL?

@vaishdho1

Copy link
Copy Markdown
Contributor Author

@harshit-anyscale This is a windows build failure in the CI environment. I retried it after pushing the latest changes, but its the same failure again.

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

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit a9d0b29. Configure here.

elif self._state == RolloutState.ROLLING_BACK:
# Rollback succeeded.
self._state = RolloutState.ROLLED_BACK
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Premature rollback completion

High Severity

When a deploy fails, update() sets ROLLING_BACK and points _current_config at _last_good_config before the controller reapplies that snapshot. The next update() then runs _check_apps_status() only over last-good app names, so statuses from the failed rollout (still RUNNING, DEPLOY_FAILED, or DELETING) can be misread as rollback success or immediate ROLLBACK_FAILED.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a9d0b29. Configure here.

@vaishdho1 vaishdho1 Jun 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not a problem here. The next PR which connects the controller to the rollout supervisor logic makes it clear.
The controller 's run_control_loop_step implements the following steps:

  • calls supervisor.update() detects failure, sets ROLLING_BACK, swaps _current_config to _last_good_config, returns True
  • Controller immediately calls apply_config() on the application state manager
  • apply_app_configs() always resets every app in the rollback config to DEPLOYING

In the next tick, when the supervisor runs _check_apps_status(), all last-good apps are already at DEPLOYING after reconciliation.

Comment on lines +56 to +65
for app_name in self._current_config.config_dict:
if app_name not in app_statuses:
return ApplicationStatus.DEPLOYING
status = app_statuses[app_name].status
if status == ApplicationStatus.DEPLOY_FAILED:
return ApplicationStatus.DEPLOY_FAILED
if status == ApplicationStatus.DEPLOYING:
atleast_one_deploying = True
elif status == ApplicationStatus.UNHEALTHY:
atleast_one_unhealthy = True

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.

right, but still good to be defensive here right?

return ApplicationStatus.DEPLOYING
if atleast_one_unhealthy:
return ApplicationStatus.UNHEALTHY
return ApplicationStatus.RUNNING

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.

will update not be called on every controller loop? if it is being called on every loop then it is possible to get app status with DELETING no?

return ApplicationStatus.UNHEALTHY
return ApplicationStatus.RUNNING

def update(self) -> bool:

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.

maybe a future addition but how do we want to handle stuck (ApplicationStatus.DEPLOYING, ApplicationStatus.UNHEALTHY), should we have a timeout feature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Handling stuck states inside the rollout supervisor or even at controller level is not going to be accurate. It doesn't have enough context to make the right call. The deployment state manager is where the actual logic lives, so that's where the decision on how long to wait should be made. In the current flow it just waits forever.
For this we need to analyze how to change the flow for DEPLOYING and UNHEALTHY states which are stuck and decide on when to escalate this.
This needs its own exploration and design work. I can check that and file it separately.

We can keep the supervisor to just react on the signal that it receives, to keep this simple.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jun 30, 2026
@abrarsheikh

Copy link
Copy Markdown
Contributor

unstale, will review

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Jul 1, 2026
@vaishdho1

Copy link
Copy Markdown
Contributor Author

@abrarsheikh Could you review this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants