Skip to content

[serve] Drop dead replicas from the multiplexed model ID mapping - #66358

Merged
jeffreywang88 merged 2 commits into
ray-project:masterfrom
GNITOAHC:serve/purge-dead-replica-from-multiplex-map
Sep 22, 2026
Merged

jeffreywang88 merged 2 commits into
ray-project:masterfrom
GNITOAHC:serve/purge-dead-replica-from-multiplex-map

Conversation

@GNITOAHC

Copy link
Copy Markdown
Contributor

Description

on_replica_actor_died clears the replica set, the cached replica list and the locality sets, but it misses MultiplexMixin._multiplexed_model_id_to_replica_ids. That mapping is only rebuilt in update_replicas, so between the router noticing a replica died and the controller broadcasting a new replica set, it still points at a replica that is already gone from self._replicas.

The next request for one of that replica's models picks it anyway and blows up on the lookup in pow_2_router.py:

ERROR ... -- Unexpected error in _fulfill_pending_requests.
KeyError: Replica(id='r1', deployment='...', app='...')

_fulfill_pending_requests swallows that, so the routing task just exits and its request is never fulfilled. This drops the dead replica from the mapping too, the same way _discard_colocated_replica_ids_on_replica_actor_died already handles the locality sets.

Related issues

No existing issue.

Additional information

Tests run.

pytest python/ray/serve/tests/unit/test_pow_2_request_router.py
       python/ray/serve/tests/unit/test_router.py
       python/ray/serve/tests/unit/test_consistent_hash_router.py
       python/ray/serve/tests/unit/test_capacity_queue.py
297 passed

@GNITOAHC
GNITOAHC requested a review from a team as a code owner September 21, 2026 22:19

@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 when a replica actor dies, its replica ID is discarded from the multiplexed model ID mapping in the request router. This prevents subsequent requests for that model from raising a KeyError before the controller broadcasts the updated replica set. A unit test has been added to verify this behavior. There are no review comments, so I have no feedback to provide.

@jeffreywang88 jeffreywang88 self-assigned this Sep 21, 2026
@jeffreywang88 jeffreywang88 added the go add ONLY when ready to merge, run all tests label Sep 21, 2026
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Sep 22, 2026

@jeffreywang88 jeffreywang88 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.

Thanks for your contribution @GNITOAHC!

@jeffreywang88
jeffreywang88 merged commit a91e9d5 into ray-project:master Sep 22, 2026
7 checks passed
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
…-project#66358)

## Description

`on_replica_actor_died` clears the replica set, the cached replica list
and the locality sets, but it misses
`MultiplexMixin._multiplexed_model_id_to_replica_ids`. That mapping is
only rebuilt in `update_replicas`, so between the router noticing a
replica died and the controller broadcasting a new replica set, it still
points at a replica that is already gone from `self._replicas`.

The next request for one of that replica's models picks it anyway and
blows up on the lookup in `pow_2_router.py`:

```
ERROR ... -- Unexpected error in _fulfill_pending_requests.
KeyError: Replica(id='r1', deployment='...', app='...')
```

`_fulfill_pending_requests` swallows that, so the routing task just
exits and its request is never fulfilled. This drops the dead replica
from the mapping too, the same way
`_discard_colocated_replica_ids_on_replica_actor_died` already handles
the locality sets.


## Related issues
No existing issue.

## Additional information
Tests run.
```
pytest python/ray/serve/tests/unit/test_pow_2_request_router.py
       python/ray/serve/tests/unit/test_router.py
       python/ray/serve/tests/unit/test_consistent_hash_router.py
       python/ray/serve/tests/unit/test_capacity_queue.py
297 passed
```

Signed-off-by: GINTOAHC <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…-project#66358)

## Description

`on_replica_actor_died` clears the replica set, the cached replica list
and the locality sets, but it misses
`MultiplexMixin._multiplexed_model_id_to_replica_ids`. That mapping is
only rebuilt in `update_replicas`, so between the router noticing a
replica died and the controller broadcasting a new replica set, it still
points at a replica that is already gone from `self._replicas`.

The next request for one of that replica's models picks it anyway and
blows up on the lookup in `pow_2_router.py`:

```
ERROR ... -- Unexpected error in _fulfill_pending_requests.
KeyError: Replica(id='r1', deployment='...', app='...')
```

`_fulfill_pending_requests` swallows that, so the routing task just
exits and its request is never fulfilled. This drops the dead replica
from the mapping too, the same way
`_discard_colocated_replica_ids_on_replica_actor_died` already handles
the locality sets.


## Related issues
No existing issue.

## Additional information
Tests run.
```
pytest python/ray/serve/tests/unit/test_pow_2_request_router.py
       python/ray/serve/tests/unit/test_router.py
       python/ray/serve/tests/unit/test_consistent_hash_router.py
       python/ray/serve/tests/unit/test_capacity_queue.py
297 passed
```

Signed-off-by: GINTOAHC <[email protected]>
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