Repository navigation
Description
What happened + What you expected to happen
Observed behavior
With two idle replicas, max_ongoing_requests=1, and a warm queue-length cache, the FIFO router can assign both pending requests to the same replica before the first request is sent. A cache hit lets the routing task continue after the first assignment. The next selection can still see a queue length of zero for that replica because the sending coroutine has yet to call on_send_request().
HTTP proxy confirmation
In a separate instrumented Python HTTP proxy test with real replica actors, both requests in each burst were queued before routing began, and tied candidates were considered in a fixed order. In all ten two-request bursts, the original router assigned both requests to the same replica before the first send. The proxy made 30 dispatch attempts and received 10 replica-side rejections. In each burst, the rejected dispatch was retried on the other idle replica. All 20 client requests returned HTTP 200.
Expected behavior
When two requests are pending and both one-slot replicas initially appear idle, the second selection should account for the first assignment. With the fixed candidate order in the standalone reproducer, the expected assignments are replica A followed by replica B.
Versions / Dependencies
- Ray
3.0.0.dev0from commitc1b9e408aa1cc6d1ac07947e8364d3199fd558b1. - Standalone script and Python HTTP proxy test on Linux x86_64 (WSL2), CPython 3.12.13, using the official nightly wheel for the commit above.
- The same HTTP proxy behavior reproduced with real replica actors on native Linux RISC-V (
riscv64), openEuler 24.03 LTS-SP3, CPython 3.11.6.
Reproduction script
Save the snippet as reproduce_fifo.py and run the commands on Linux x86_64 with Python 3.12. The standalone script isolates replica selection using the installed Serve router and two simulated replicas. Both start with a cached queue length of zero, and the script fixes the candidate order for ties. After each assignment, it calls the real router's on_send_request() to model the sender's queue-length cache update. The output shows which replicas were selected. Actual dispatches, replica-side rejections, and retries were observed in the separate HTTP proxy test above. The script runs in a single Python process.
python3.12 -m venv .venv
source .venv/bin/activate
commit=c1b9e408aa1cc6d1ac07947e8364d3199fd558b1
wheel=ray-3.0.0.dev0-cp312-cp312-manylinux2014_x86_64.whl
python -m pip install "ray[serve] @ https://s3-us-west-2.amazonaws.com/ray-wheels/master/$commit/$wheel"
python reproduce_fifo.pyimport asyncio
from types import SimpleNamespace
from ray.serve._private.common import (
DeploymentHandleSource,
DeploymentID,
ReplicaID,
RequestMetadata,
)
from ray.serve._private.request_router import PendingRequest, PowerOfTwoChoicesRequestRouter
async def main():
deployment = DeploymentID(name="fifo-repro")
router = PowerOfTwoChoicesRequestRouter(
deployment_id=deployment,
handle_source=DeploymentHandleSource.REPLICA,
use_replica_queue_len_cache=True,
)
async def queue_len(*, deadline_s):
return 0
replicas = [
SimpleNamespace(replica_id=ReplicaID(name, deployment), max_ongoing_requests=1,
multiplexed_model_ids=[], get_queue_len=queue_len)
for name in ("A", "B")
]
router.update_replicas(replicas)
while any(router.replica_queue_len_cache.get(r.replica_id) != 0 for r in replicas):
await asyncio.sleep(0)
async def fixed_candidate_order(*, candidate_replicas, pending_request):
return [replicas]
router.choose_replicas = fixed_candidate_order
async def route_and_send(request_id):
metadata = RequestMetadata(request_id=request_id, internal_request_id=request_id)
replica = await router._choose_replica_for_request(PendingRequest([], {}, metadata))
router.on_send_request(replica.replica_id)
return replica.replica_id.unique_id
assignments = await asyncio.gather(route_and_send("r0"), route_and_send("r1"))
print(f"Assignments: {', '.join(assignments)}", flush=True)
assert assignments == ["A", "B"], "Both requests selected the same cached replica"
asyncio.run(asyncio.wait_for(main(), timeout=10))On the original wheel the script exits with status 1 and prints these lines in its output and traceback.
Assignments: A, A
AssertionError: Both requests selected the same cached replica
The expected output is Assignments: A, B, followed by exit status 0.
Issue Severity
Low. It annoys or frustrates me.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Wali05 commentedon Dec 4, 2026
I'd like to take this. The cause is in
_fulfill_pending_requests: when the cache is hit, the selection never yields, so the next pending request is routed beforeon_send_request()bumps the cached queue length for the first one. I'd reserve the slot in the cache at the moment a request is assigned to a replica, and make the send path stop adding it a second time, plus a regression test along the lines of the repro here.Behaviour for the non-cached path and for probing stays the same, and a cancelled assignment releases the slot so the count can't drift. Ok if I pick this up?