Repository navigation
[serve][in-place-updates][3/n] Restore code defaults when config overrides are removed - #66266
Conversation
0614b71 to
4d0b129
Compare
9b49a9d to
7c670ce
Compare
b7ede56 to
d8d7a30
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces an AppBuild dataclass to cache original application build results in ApplicationState, ensuring that removing configuration overrides correctly restores values defined in the code. It updates the controller to track and report this capability via restores_unset_config_options and includes comprehensive unit and integration tests to verify the rollback behavior. The review identified a critical issue regarding potential in-memory mutation of cached build results during configuration overrides, suggesting the use of copy.deepcopy to prevent corruption of the cached state.
2dc616d to
e7bf0a4
Compare
97418a5 to
28fe00c
Compare
A config for an already built code version was overridden onto the previously overridden deployment infos, so an option a later config stopped setting kept its previous override instead of returning to its code-defined value. Re-applying a sparse config after an update that had added a failing `ray_actor_options.runtime_env` was therefore a replica-level no-op and the deployment stayed DEPLOY_FAILED: rollback by re-applying the previous config only worked for options that config set explicitly. `ApplicationTargetState` now keeps the build (`AppBuild`: the code-defined deployment infos and the serialized classes overrides may reference) and the fast path overrides onto it, so removed overrides return to their code-defined values. The build is checkpointed and restored across a controller restart. A target state recovered from a checkpoint written before the build was kept has none: the next config for the same code rebuilds the application once instead of overriding the accumulated infos, so removed overrides are restored on any application once this version runs. An older Ray image keeps the accumulating behavior. Tests: unit tests for a removed override returning to the code-defined value, a sparse rollback after a controller restart, and a checkpoint without a build rebuilding on the next config; integration test (with and without a controller restart) that a sparse config re-applied after a failing added override restores the decorator-defined `max_ongoing_requests`, reuses the surviving replica and serves again. Signed-off-by: Qisheng He <[email protected]>
28fe00c to
ec1aeea
Compare
A checkpoint is only ever read by the Ray version that wrote it, so the target state never lacks build results when code_version is set. Read the field directly on recovery and assert the invariant instead of rebuilding. Signed-off-by: Qisheng He <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces the AppBuild dataclass to store original application build results before config overrides, allowing code-defined defaults to be restored when overrides are removed. It also adds a restores_unset_config_options field to the ServeInstanceDetails schema to indicate this capability. Feedback on the changes identifies a potential AssertionError when recovering from older checkpoints where self._target_state.build is None and a new config is applied with the same code_version. To resolve this, it is suggested to check that self._target_state.build is not None in the if condition, allowing a graceful fallback to the rebuild path.
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 d0dd41f. Configure here.
…oval Add the e2e cases requested in review: a config that keeps one override while dropping another, removing autoscaling_config, and two deployments whose overrides are removed independently, including dropping one from the deployments list. The sparse rollback test now keeps traffic flowing from before the failing update through the optional controller restart and asserts every response is 200. Move TestConfigOverridesFromBuild above the __main__ guard so it runs under bazel. The controller gains a testing hook exposing whether the autoscaler still tracks a deployment; the chain fixture sets distinct decorator values so the multi-deployment test can tell which deployment reverted. Signed-off-by: qishengxhe <[email protected]>
…nd in-place updates The controller cannot import an application-level autoscaling policy that lives only in the application's runtime_env, so the build task cloudpickles it and returns the bytes, which the target state and checkpoint carry as `serialized_application_autoscaling_policy_def`. Two `_set_target_state` callers never forwarded the field: `recover_target_state_from_checkpoint` and the same-code-version branch of `apply_app_config`. The policy was still registered from the checkpoint's bytes on that first recovery, so nothing failed immediately, but the new target state held None and the next checkpoint persisted it. The recovery after a second controller restart, or the first restart after an in-place update, then built `AutoscalingPolicy` without bytes, imported the policy by path inside the controller, and raised ModuleNotFoundError out of ServeController.__init__, leaving the controller in a crash loop. Forward the field at both call sites. A same-code-version update cannot change the policy module, so the previous target state's bytes remain correct. The unit test uses a policy path that is not importable in the test process to mirror a runtime_env-only module. Signed-off-by: qishengxhe <[email protected]>
|
Also fixes a pre-existing bug on master that Abrar found: |
| # the build rather than the previous target restores the values in | ||
| # code for options the new config no longer sets. | ||
| build = self._target_state.build | ||
| assert build is not None |
There was a problem hiding this comment.
Should we take the rebuild branch when build is None instead of asserting, since a checkpoint written before this PR (e.g. GCS FT on Redis across a Ray upgrade) hits this during __init__ recovery and kills the controller permanently?
There was a problem hiding this comment.
I learnt that we never restore the checkpoints written by an old cluster into a new cluster, so a checkpoint is only read by the ray version that wrote it. Also during a startup recovery, controller init goes through recover_target_state_from_checkpoint. this assert sits in apply_app_config which is never invoked by controller init.
There was a problem hiding this comment.
Oh but wouldn't controller init reach this through _recover_state_from_checkpoint -> apply_config -> apply_app_config? Also how do we know checkpoints from an old cluster won't get written into a new cluster on OSS setups?
There was a problem hiding this comment.
You're right about the path :) controller init does reach apply_app_config .
On the second point, I double-checked. it's possible that on OSS someone pins RAY_external_storage_namespace to restore checkpoints across clusters / ray versions,but that's unsupported: KubeRay's docs recommend against it since the new cluster reads the old cluster's serve status from Redis and the operator flips traffic too early (doc link). and cross-version checkpoints already fail earlier in the same init: required fields like external_scaler_enabled and serialized_application_autoscaling_policy_def have no default and would and raise AttributeError for an older checkpoint before we get to this assert. so we should be good.
The AppBuild return value was documented on _determine_app_status, which returns a 2-tuple. Move it to _reconcile_build_app_task, which returns it. Signed-off-by: qishengxhe <[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
Problem:
An in-place update applies a new config to an existing application. When the code version is unchanged, Serve called
override_deployment_infowith the previous target state's deployment infos as the base.This breaks rollback after a failed in-place update. For example, an update adds a ray_actor_options.runtime_env that prevents replicas from starting. Reapplying the last healthy config should remove that override, but Serve keeps it and the deployment stays DEPLOY_FAILED.
Fix:
Serve now stores the original build results and uses them as the base for each config. Removing an override restores the value defined in code, so reapplying the last healthy config can undo settings introduced by a failed update.

The build results survive controller restarts. Applications recovered from older checkpoints rebuild once on their next config update.
Backward Compatibility:
ServeInstanceDetails reports
restores_unset_config_options=Truewhen supported. The control plane can use this field to determine whether automatic rollback is supported for an in-place update. Older versions omit the field, so no Ray version check is needed.Alternatives:
Option A (Chosen in this PR): store the original build alongside the effective deployment infos
Keep the untouched build output in
buildand apply same-version config updates to it, rather than to the previous result.deployment_infosreaders stay unchanged.DeploymentInfoOption B: rebuild when config keys or deployments are removed
Compare the old and new configs in
apply_app_configand use the existing rebuild path on removal, even when the code version matches. Only removals require a rebuild because overrides replace top-level keys wholesale.Option C: store only the build and config; derive effective infos
Replace stored
deployment_infoswith a memoized result ofoverride_deployment_info(build, config)._set_target_state. Imperative apps need separate handling, and memoization must avoid recomputing on every controller tick.Tests
Covers removed overrides, older checkpoints, and capability reporting. The rollback test sends continuous traffic through the failed update, optional controller restart, and rollback, asserting no request failures and reuse of the surviving replica.
The three integration cases passed in an isolated Linux container using this PR’s Serve code. Formatting and lint checks passed.
Duplicate checks found no overlapping fix. Claude Code assisted with implementation.