Skip to content

[serve] Fix KeyError that stalls the application control loop when a deployment is removed - #66438

Merged
abrarsheikh merged 4 commits into
ray-project:masterfrom
GNITOAHC:serve/fix-autoscaling-keyerror-on-removed-deployment
Sep 24, 2026
Merged

abrarsheikh merged 4 commits into
ray-project:masterfrom
GNITOAHC:serve/fix-autoscaling-keyerror-on-removed-deployment

Conversation

@GNITOAHC

Copy link
Copy Markdown
Contributor

Description

Removing a deployment from a running application can permanently stall the controller's application control loop.

ApplicationAutoscalingState.get_decision_num_replicas iterates every registered deployment autoscaling state, but indexes the caller's deployment_to_target_num_replicas without checking membership:

for deployment_id, deployment_autoscaling_state in self._deployment_autoscaling_states.items()

Fix: skip registered deployments absent from the caller's mapping, matching the membership guards used elsewhere in the class.

Related issues

No existing issue

@GNITOAHC
GNITOAHC requested a review from a team as a code owner September 23, 2026 22:11
@GNITOAHC GNITOAHC changed the title [serve] Skip untargeted deployments when computing autoscaling decisions [serve] Fix KeyError that stalls the application control loop when a deployment is removed Sep 23, 2026

@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 a potential KeyError in the autoscaling state manager when a deployment is removed from an application but remains registered during teardown. It filters out untargeted deployments in get_decision_num_replicas by checking if the deployment ID is present in deployment_to_target_num_replicas. Additionally, comprehensive unit tests have been added to verify this behavior and ensure the control loop continues running after a deployment is removed. No review comments were provided, so there is no additional feedback.

@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Sep 24, 2026
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Sep 24, 2026
@GNITOAHC

Copy link
Copy Markdown
Contributor Author

@abrarsheikh Thanks for the review! This is green on the latest commit and all checks have passed. I don't have write access, so could you merge when you get a chance?

@abrarsheikh
abrarsheikh merged commit 6682084 into ray-project:master Sep 24, 2026
6 checks passed
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
chia7712 pushed a commit to opensource4you/readme that referenced this pull request Nov 25, 2026
fellowship: 提名 GNITOAHC (ray, 2026-11)

建議等級 2 萬

- [x] 關係人宣告:提名人與被提名者無親屬、僱傭、財務、業務合作或其他可能影響公正判斷之利害關係
- 在兩個月內自己從 Ray Serve 原始碼找到 9 個 bug 並開了 PR,其中 6 個 PR 被 Merged ([Merged PRs](https://github.com/ray-project/ray/pulls?q=is%3Apr+author%3AGNITOAHC+is%3Amerged+merged%3A%3C%3D2026-11-24))
- 開了 Gang Scheduling + Autoscaling 的 Issue 並附上 Repro Script,社群後續依此開 PR 修復,提名人則變成該 PR 的 Reviewer ([#67494](ray-project/ray#67494))
- PR Description 簡潔清楚,讓 Reviewer 清楚理解 PR 解決了什麼問題 ([#66358](ray-project/ray#66358), [#66438](ray-project/ray#66438), [#66616](ray-project/ray#66616), [#66910](ray-project/ray#66910))
- 對於 Maintainer 的 Review 會清楚了解之後回覆 ([#67923 comment](ray-project/ray#67923 (comment)), [#67210 comment](ray-project/ray#67210 (comment)), [#66438 comment](ray-project/ray#66438 (comment)))
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants