Skip to content

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

In review

Description

@vaishdho1

What happened + What you expected to happen

Description

When an app was deployed declaratively (with serve deploy or the REST API) and is then removed with serve.delete(), the app is deleted, but the saved config checkpoint (CONFIG_CHECKPOINT_KEY) still contains it. On the next controller restart, the deleted app is redeployed without any user action.

serve.delete() and serve deploy update different state:

  • serve deploy goes through ServeController.apply_config, which writes the full config to CONFIG_CHECKPOINT_KEY and then applies it.
  • serve.delete() goes through ServeController.delete_apps, which deletes the app from the application state manager and saves the application state checkpoint, but does not update CONFIG_CHECKPOINT_KEY.

When the controller recovers, _recover_state_from_checkpoint re-applies the saved config with apply_config, which recreates the deleted app.

The stale entry is not visible beforehand. serve config and deployed_app_config only list apps that are still running, so the deleted app looks gone until the controller restarts.

Impact

  • A deleted app comes back. Any controller restart, for example after a crash or a head node recovery, redeploys apps the user deleted with serve.delete().
  • Auto-rollback ([Serve][RFC] Auto-rollback for serve deploy #63016). Rolling back to the last good config would also restore an app deleted with serve.delete().

serve.shutdown() does not have this problem, because ServeController.shutdown deletes CONFIG_CHECKPOINT_KEY.

Proposed fix

Proposed fix

Treat serve.delete() on a declarative app as a change to the current config, not a new config submission.

In ServeController.delete_apps:

  1. Find the declarative apps among the requested names, using api_type. Imperative apps (serve.run) are deleted directly, as today.
  2. Remove them from the saved config. Edit CONFIG_CHECKPOINT_KEY in place and drop only those apps. Everything else is written back unchanged: the other apps, target_capacity and its direction, the deployment time and config_id. The saved config is updated before the apps are deleted, so if the controller crashes in between, recovery still deletes them.
  3. Log a warning that the app was removed from the saved config and that the user's config file should be updated too, so the next serve deploy doesn't bring it back.
  4. Docs. Update the serve.delete() docstring and the multi-app guide.

The other apps are never reapplied. Re applying the config through apply_config would also fix the restart bug, but it would reapply every remaining app: a build still in progress would restart, and a failed build would be retried, just because a different app was deleted.

Behavior after the fix

Today After the fix
Deleted declarative app after a restart Comes back Stays deleted
Saved config checkpoint Still lists the deleted app Updated without it
Other apps in the config Not touched Not touched (not re-applied, rebuilt or restarted)
Imperative apps (serve.run) Deleted directly Same
serve.delete() blocking Waits until the app is gone Same
applied_config_id Not changed by a delete Same
Rejected deletes None None

target_capacity and its direction remain unchanged.
applied_config_id. This keeps today's behavior. The ID is only set when a config is submitted through apply_config (#67458), so a delete doesn't change it. After the fix, the rebuilt config keeps the same config_id, so the ID still identifies the same submission, and the deleted app simply shows as missing from applications. Only a new serve deploy or REST PUT changes the ID, and a new config without an ID clears it, as today.

Documentation.

  • serve.delete() docstring: explain that deleting a declarative app also removes it from the saved config, that the user's config file should be updated, and that applied_config_id is unchanged.
  • ServeDeploySchema.config_id description: note that the ID is kept when serve.delete() removes apps, and only changes when a new config is submitted.
  • Any Serve guides under doc/source/serve/ that describe serve.delete() with declarative configs.

I have a working fix along these lines and will open a PR shortly.

Related

Versions / Dependencies

  • Ray: 3.0.0.dev0 (built from master at commit 7cd3cd3c0e)
  • Python: 3.11.13
  • Pydantic: 2.12
  • OS: macOS (Darwin 25.6.0)

Reproduction script

Steps to reproduce (verified on master)

app.py:

from ray import serve

@serve.deployment
class Hello:
    def __call__(self, request) -> str:
        return "hello"

app = Hello.bind()

config.yaml:

applications:
  - name: app1
    route_prefix: /app1
    import_path: app:app
    runtime_env:
      working_dir: local:///tmp/serve_delete_test
  - name: app2
    route_prefix: /app2
    import_path: app:app
    runtime_env:
      working_dir: local:///tmp/serve_delete_test
  1. ray start --head, then serve deploy config.yaml. Both apps reach RUNNING.
  2. Delete app1:
    import ray
    from ray import serve
    ray.init(address="auto", namespace="serve")
    serve.delete("app1")
    serve status now shows only app2.
  3. Restart the Serve controller:
    import ray
    from ray.serve._private.constants import SERVE_CONTROLLER_NAME, SERVE_NAMESPACE
    ray.init(address="auto", namespace=SERVE_NAMESPACE)
    controller = ray.get_actor(SERVE_CONTROLLER_NAME, namespace=SERVE_NAMESPACE)
    ray.kill(controller, no_restart=False)
  4. serve status shows app1 running again, with the same last_deployed_time_s as the original deploy.

Issue Severity

Low: It annoys or frustrates me.

Activity

  1. added
    bug
    triage
    on Nov 30, 2026
  2. PCTEJA commented on Nov 30, 2026

    @PCTEJA
    Contributor

    Thanks for the thorough write-up — the checkpoint divergence between serve deploy and serve.delete() is very clear, and the proposed fix (split by api_type, re-apply the saved config minus the deleted declarative apps through apply_config) looks like the right shape.

    I'm planning to work on the fix for this. Do you already have something locally for it, or are you already working on it? Happy to pick it up if not — I'll hold off on opening a PR until I hear back.

  3. vaishdho1 commented on Nov 30, 2026

    @vaishdho1
    ContributorAuthor

    target_capacity direction. Because the delete goes through apply_config, the direction is recalculated exactly as for a manual redeploy without the app. When target_capacity is set, the direction becomes UP because the set of apps changed. This only affects the lower bound of autoscaling deployments that set initial_replicas. I propose keeping this behavior for consistency with a manual redeploy. Does that sound reasonable?

    I have a working fix along these lines and will open a PR shortly.

    I already have a working fix locally verified. I will open the PR shortly.

  4. moved this from Todo to In progress in Ray Data OSSon Nov 30, 2026
  5. removed
    triage
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcommunity-backlogservestability

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions