Skip to content

[serve] Avoid rolling replicas for no-op config overrides - #63034

Merged
abrarsheikh merged 7 commits into
ray-project:masterfrom
harshit-anyscale:harshit-codex/serve-default-num-replicas-no-roll
May 12, 2026
Merged

abrarsheikh merged 7 commits into
ray-project:masterfrom
harshit-anyscale:harshit-codex/serve-default-num-replicas-no-roll

Conversation

@harshit-anyscale

@harshit-anyscale harshit-anyscale commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Avoid materializing an empty runtime_env while applying declarative deployment overrides.
  • Preserve replica actor options when a YAML config lists a deployment without changing actor runtime options.
  • Add unit and CLI regression coverage to ensure no-op YAML deployment overrides do not roll replicas.

Root Cause

Before this change, the declarative config override path ran the runtime env merge for every deployment listed in the YAML deployments section. Even a deployment entry that only named the deployment, with no runtime env changes, could cause override_runtime_envs_except_env_vars({}, {}) to produce runtime_env: {"env_vars": {}}.

That extra empty runtime env was written into ray_actor_options, changing the deployment version actor-options hash and causing Serve to roll replicas even though the effective actor configuration did not change.

Testing

Tested locally:

  • python -m py_compile python/ray/serve/_private/application_state.py python/ray/serve/tests/unit/test_application_state.py python/ray/serve/tests/test_cli.py
  • git diff --check -- python/ray/serve/_private/application_state.py python/ray/serve/tests/unit/test_application_state.py python/ray/serve/tests/test_cli.py
  • Commit hooks also ran successfully, including ruff, black, pydoclint, import-order checks, and related linters.

@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 prevents unnecessary rolling updates in Ray Serve by avoiding the materialization of empty runtime_env dictionaries in actor options, which ensures the configuration hash remains unchanged when no environment overrides are present. It also introduces integration and unit tests to verify that explicitly setting the default number of replicas does not trigger a restart. Feedback was provided to improve the robustness of temporary file cleanup within the test suite.

Comment thread python/ray/serve/tests/test_cli.py Resolved
@harshit-anyscale harshit-anyscale added the go add ONLY when ready to merge, run all tests label Apr 30, 2026
@harshit-anyscale harshit-anyscale self-assigned this Apr 30, 2026
@harshit-anyscale harshit-anyscale changed the title [serve] Avoid rolling replicas for default num_replicas override [serve] Avoid rolling replicas for no-op config overrides Apr 30, 2026
@harshit-anyscale
harshit-anyscale marked this pull request as ready for review April 30, 2026 13:28
@harshit-anyscale
harshit-anyscale requested a review from a team as a code owner April 30, 2026 13:28
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Apr 30, 2026
@abrarsheikh
abrarsheikh merged commit 772329a into ray-project:master May 12, 2026
3 checks passed
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
…t#63034)

## Summary
- Avoid materializing an empty `runtime_env` while applying declarative
deployment overrides.
- Preserve replica actor options when a YAML config lists a deployment
without changing actor runtime options.
- Add unit and CLI regression coverage to ensure no-op YAML deployment
overrides do not roll replicas.

## Root Cause
Before this change, the declarative config override path ran the runtime
env merge for every deployment listed in the YAML `deployments` section.
Even a deployment entry that only named the deployment, with no runtime
env changes, could cause `override_runtime_envs_except_env_vars({}, {})`
to produce `runtime_env: {"env_vars": {}}`.

That extra empty runtime env was written into `ray_actor_options`,
changing the deployment version actor-options hash and causing Serve to
roll replicas even though the effective actor configuration did not
change.

## Testing
Tested locally:
- `python -m py_compile python/ray/serve/_private/application_state.py
python/ray/serve/tests/unit/test_application_state.py
python/ray/serve/tests/test_cli.py`
- `git diff --check -- python/ray/serve/_private/application_state.py
python/ray/serve/tests/unit/test_application_state.py
python/ray/serve/tests/test_cli.py`
- Commit hooks also ran successfully, including ruff, black, pydoclint,
import-order checks, and related linters.

---------

Signed-off-by: harshit <[email protected]>
alexandrplashchinsky pushed a commit to alexandrplashchinsky/ray-alex that referenced this pull request May 29, 2026
…t#63034)

## Summary
- Avoid materializing an empty `runtime_env` while applying declarative
deployment overrides.
- Preserve replica actor options when a YAML config lists a deployment
without changing actor runtime options.
- Add unit and CLI regression coverage to ensure no-op YAML deployment
overrides do not roll replicas.

## Root Cause
Before this change, the declarative config override path ran the runtime
env merge for every deployment listed in the YAML `deployments` section.
Even a deployment entry that only named the deployment, with no runtime
env changes, could cause `override_runtime_envs_except_env_vars({}, {})`
to produce `runtime_env: {"env_vars": {}}`.

That extra empty runtime env was written into `ray_actor_options`,
changing the deployment version actor-options hash and causing Serve to
roll replicas even though the effective actor configuration did not
change.

## Testing
Tested locally:
- `python -m py_compile python/ray/serve/_private/application_state.py
python/ray/serve/tests/unit/test_application_state.py
python/ray/serve/tests/test_cli.py`
- `git diff --check -- python/ray/serve/_private/application_state.py
python/ray/serve/tests/unit/test_application_state.py
python/ray/serve/tests/test_cli.py`
- Commit hooks also ran successfully, including ruff, black, pydoclint,
import-order checks, and related linters.

---------

Signed-off-by: harshit <[email protected]>
Signed-off-by: Alexandr Plashchinsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants