Skip to content

[Serve] Persist declarative app deletions across controller restarts - #68664

Open
vaishdho1 wants to merge 4 commits into
ray-project:masterfrom
vaishdho1:vaish-serve-delete-declarative-config
Open

vaishdho1 wants to merge 4 commits into
ray-project:masterfrom
vaishdho1:vaish-serve-delete-declarative-config

Conversation

@vaishdho1

Copy link
Copy Markdown
Contributor

Description

serve.delete() on an app deployed from a declarative config (serve deploy or the REST API) deletes the app, but leaves it in the config the controller saves. When the controller restarts, it re-applies that saved config and the deleted app comes back.
This PR removes a deleted declarative app from the saved config as well.

  • Only the deleted apps' entries are removed, the rest of the config and all other apps stay as they were.
  • The saved config is updated before the apps are deleted, so a controller crash in between still ends with the apps deleted. - A warning tells the user to also remove the app from the config file, or the next serve deploy brings it back.
  • Imperative apps (serve.run) aren't affected.

Related issues

Fixes #68660

Additional information

An alternate method to fix this was passing the config without the deleted app to apply_config, which would treat the delete as a new deploy of every other app. Some issues behind why this approach was not prefferred was:

  • Apps that are still building or failed to build would rebuild, `
  • target_capacityscaling could change direction, and every app'slast_deployed_time_s` would reset.
    Editing the saved config in place avoids this.

@vaishdho1
vaishdho1 requested review from a team as code owners November 30, 2026 07:13

@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 ensures that deleting a declarative application via serve.delete() also removes it from the controller's saved config checkpoint, preventing it from being redeployed upon a controller restart. Documentation and unit tests have been added to support this behavior. A critical review comment points out a bug where pre-filtering application names by their current APIType can prevent the cleanup of the saved config checkpoint if a declarative app was previously overwritten by an imperative one; it is recommended to pass all names directly to the checkpoint removal method instead.

Comment thread python/ray/serve/_private/controller.py Resolved
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Nov 30, 2026
@abrarsheikh

Copy link
Copy Markdown
Contributor

I reviewed this PR. The core approach is sound — the config checkpoint is only written by apply_config, so pruning it in delete_apps isn't undone anywhere else, the crash-window behavior checks out, and the old 4-vs-5-field tuple layouts unpack safely with *_. No blocking issues; a handful of nits below.

1. delete_apps consumes its names argument twice (controller.py ~2083). _remove_apps_from_config_checkpoint iterates names, then the delete_app loop iterates it again. With a non-list iterable, apps get pruned from the config checkpoint but the delete loop sees an exhausted iterator, so the apps keep running — the checkpoint then disagrees with reality permanently. Duplicate names also make del config_checkpoints_dict[name] raise KeyError on the second occurrence. Both are latent today (all callers pass de-duplicated lists through Ray remote), but normalizing once at the top — names = list(dict.fromkeys(names)) — closes both holes.

2. logger.warning on a success path (~2088). A routine, user-initiated serve.delete of a declarative app now emits a WARNING on every success. Teams that alert on controller WARNING lines get paged for normal usage — this looks like an info.

3. No error isolation around the KV-store pruning (~2079). delete_apps calls _remove_apps_from_config_checkpoint before any delete_app, so a GCS hiccup or unreadable checkpoint now fails serve.delete for every app — including imperative serve.run apps that were never in the config checkpoint and previously didn't touch it. Consider catching, logging, and proceeding with the state deletion.

4. applied_config_id goes stale after an out-of-band delete (~2051). After serve.delete, the controller keeps reporting the deleted-from config as applied (the new test asserts it stays "c1"). For config-hash-based reconcilers like KubeRay RayService, the operator sees "in-sync" and never re-PUTs, so the deleted app never comes back. If that's intended, worth stating explicitly; otherwise clear or annotate _applied_config_id when apps are pruned.

5. Missing edge-case test: deleting the last remaining app. The new tests cover deleting one of two declarative apps. Deleting the only app leaves a zero-application checkpoint, which on controller restart goes through _read_config_checkpoint → ServeDeploySchema(applications=[]) → apply_config rewriting an empty config. A variant that deletes the sole app, restarts the controller, and asserts clean serve status output (no residual applied_config_id) would cover this recovery path.

6. Docs wording (multi-app.md ~204). "If you delete an application from the config with serve.delete()" reads as if serve.delete() edits the config, and "remove it from the config file too" assumes a local file. Suggest: "If you delete an application with serve.delete(), Serve removes it from the saved copy of the declarative config — update the submitted config (file or REST payload) if you want it to come back."

🤖 Generated with Claude Code

Signed-off-by: Vaishnavi Panchavati <[email protected]>
@vaishdho1

Copy link
Copy Markdown
Contributor Author

Thanks for the review.
Addressed the comments. Below are a few points

3. No error isolation around the KV-store pruning (~2079). delete_apps calls _remove_apps_from_config_checkpoint before any delete_app, so a GCS hiccup or unreadable checkpoint now fails serve.delete for every app — including imperative serve.run apps that were never in the config checkpoint and previously didn't touch it. Consider catching, logging, and proceeding with the state deletion.

This is intentional here. Catching and continuing would bring back the issue this PR is trying to solve. The fail happens before anything changes so this is safe. The user can just retry serve.delete(). GCS was already required here since ApplicationStateManager.save_checkpoint() writes to the same KV store.

4. applied_config_id goes stale after an out-of-band delete (~2051). After serve.delete, the controller keeps reporting the deleted-from config as applied (the new test asserts it stays "c1"). For config-hash-based reconcilers like KubeRay RayService, the operator sees "in-sync" and never re-PUTs, so the deleted app never comes back. If that's intended, worth stating explicitly; otherwise clear or annotate _applied_config_id when apps are pruned.

Yes, this is intended. With KubeRay, the spec is the source of truth, so removing an app means editing the spec. KubeRay doesn't read applied_config_id either, so I've left it as is and added a comment explaining why.

Addressed the rest:

  1. delete_apps now deduplicates names once at the top.
  2. The log is now info instead of warning.
  3. Extended the restart test to delete the last app and restart again.
  4. Reworded the docs.

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 serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Serve] App deleted with serve.delete() is redeployed after a controller restart

2 participants