Repository navigation
[serve] Add max_request_retries to bound router retry loops - #64399
HrushiYadav wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable limit on the maximum number of times a request can be retried by the router before being dropped with a BackPressureError. It adds max_request_retries to RequestRouterConfig and implements retry tracking and limit checking in AsyncioRouter. The review feedback suggests avoiding accessing the private _deployment_config attribute of RouterMetricsManager inside _check_retry_limit by instead storing and updating _max_queued_requests directly on AsyncioRouter.
abrarsheikh
left a comment
There was a problem hiding this comment.
looks good. left some nits. please update the docs. Also, CI is failing.
|
Thanks for the review @abrarsheikh! Addressed all feedback:
|
|
please resolve comments that are addressed already, include once from bot |
|
Addressed proto serialization issue: added |
51ccde4 to
c9445e0
Compare
|
@abrarsheikh All review threads are resolved (yours + bot). The Buildkite failure is in |
|
The latest CI failure seems related to your changes. Please investigate |
|
You're right, thanks for pushing back. I dug in and the failure was my integration test, not flakiness. The test used a single always-busy replica ( I replaced it with a deterministic unit test in Pushed in 2164206. |
2164206 to
4dd41a2
Compare
|
@abrarsheikh Addressed the failing tests. Ready for another look whenever you have time, thanks! |
|
@abrarsheikh gentle nudge on this one whenever you get a chance, it's green and ready to go. no rush, thanks! |
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
Still green and ready, not stale from my side. This bounds the router retry loop with |
abrarsheikh
left a comment
There was a problem hiding this comment.
please add a e2e test
|
Thanks. I dug into how a reservation rejection actually gets triggered so the e2e exercises the retry bound rather than the queue-full or capacity-backoff paths. The catch: a rejection only happens in the optimistic-cache race window, and the cache self-corrects to the true queue length right after each rejection ( For thresholds >= 1 I don't see a way to drive repeated rejections through real routing without a fake replica, which is why the deterministic coverage sits in the unit tests (FakeRunningReplica rejecting on reserve). I can add a best-effort e2e that saturates a single replica ( |
|
with max ongoing = 1 and unlimited queue request and Send 2 requests; 1st will be blocked by the signal actor and the 2nd request will sit in the queue, incurring a backoff. The second request will deterministically fail with a backpressure error, right? |
|
Pushed changes addressing the review:
Also resolved the bot threads that were already addressed. Ready for another look, and happy to re-trigger premerge whenever. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit a7237ba. Configure here.
a7237ba to
d67fe68
Compare
|
@abrarsheikh I reverted my last push after digging into the new Bugbot finding ("Retry bound skips saturated replicas"), which turns out to be correct. Tracing it: This also runs into the "only capacity rejections count" preference: in the saturated case there is no capacity rejection to count, the request is stuck waiting inside the router backoff. How would you like to bound it? Two options I see:
Happy to implement whichever you prefer, then add an e2e test that actually terminates. |
d67fe68 to
d7c7363
Compare
|
Rebased on latest master, merge conflicts resolved. All 6 commits cherry-picked cleanly. CI should re-trigger now. @abrarsheikh |
d7c7363 to
d67fe68
Compare
|
Branch is up to date with master. @abrarsheikh — want to pick this back up? Happy to address any remaining feedback. |
|
Pushed a new commit ( Root cause: Fix:
Integration test uses your exact recipe: The existing unit test ( |
d67fe68 to
9d91f26
Compare
|
@abrarsheikh Rebased against master. Force-push: Only conflict was 9 files, +130/-1. CI should re-trigger now. |
9d91f26 to
86a1e9a
Compare
|
Following up after the Sep 26 rebase -- all checks are green. @abrarsheikh, is there anything else needed here? Happy to make changes if there is a preferred direction. |
|
there are merge conflicts and CI is failing |
Signed-off-by: Hrushikesh Yadav <[email protected]>
- Add self._max_queued_requests field initialized in __init__ - Update it in update_deployment_config alongside other config fields - Use it in _check_retry_limit instead of accessing private _metrics_manager._deployment_config attribute Signed-off-by: Hrushikesh Yadav <[email protected]>
- Move test_max_request_retries_config_validation to unit tests dir - Move inline imports to top of test_backpressure.py - Add request_router_config and max_request_retries to deployment docs Signed-off-by: Hrushikesh Yadav <[email protected]>
- Add optional int32 max_request_retries field to RequestRouterConfig proto - Using optional so unset (older controller) falls back to Pydantic default (-1) - Add proto round-trip tests for explicit values and absent field Signed-off-by: Hrushikesh Yadav <[email protected]>
… unit test The integration test in test_backpressure.py used a single always-busy replica (max_ongoing_requests=1, blocked on a signal) to try to exhaust max_request_retries. That scenario never surfaces to the retry counter: when all replicas are at capacity, the request router's internal _choose_replicas_with_backoff loop backs off and blocks until a replica frees up, so _pick_and_reserve_replica never iterates and the request just queues. The request timed out instead of raising BackPressureError. Replace it with a unit test in test_router.py that drives the actual code path ray-project#61017 fixes: a replica that repeatedly rejects reservations (_reject_reservation=True on both the initial and retry pick). With max_request_retries set, the router now raises BackPressureError once the retry budget is exhausted. The test is deterministic and fast, following the existing test_choose_replica_retries_when_reservation_rejected harness. Signed-off-by: Hrushikesh Yadav <[email protected]>
…s JSON The new max_request_retries field on RequestRouterConfig (default -1) now appears in the serialized deployment config returned by get_serve_instance_details. Both test_controller.py and test_direct_ingress.py hardcode the expected JSON and were missing the new key, so their `assert details_dict == expected_dict` failed. Add "max_request_retries": -1 to the expected request_router_config block in both. Signed-off-by: Hrushikesh Yadav <[email protected]>
86a1e9a to
d2217f1
Compare
|
@abrarsheikh -- rebased and conflicts are resolved. DCO and basic checks are passing. Could you trigger premerge when you get a chance? |
## Description This PR makes the `lint: API param coverage` step a required check by removing `soft_fail: true`. The step was added in #64788 on 2026-08-11. A comment in the step said to remove `soft_fail` "once the false-positive rate is confirmed low." This PR measures that rate from the step's CI history and fixes the four failure patterns the history turned up. While the step only warns, undocumented parameters still land on master. #65633, #66602, and #66950 all merged with the check failing. ### Warn-phase metrics These numbers come from every `premerge` build from 2026-08-11 to 2026-10-29, pulled from the Buildkite API. | | Runs | PRs | |---|--:|--:| | Completed runs of the step | 3,453 | | | Passed | 3,398 | | | Failed | 55 | 23 | | Canceled, which isn't a check outcome | 211 | | Each failure falls into one of three groups: | Failure type | PRs | Runs | Detail | |---|--:|--:|---| | Correct finding | 15 | 42 | A new parameter on a `@PublicAPI` callable has no `Args:` entry. Two of these PRs, #65823 and #65839, were stacked on #65633 before it merged and report its findings again. | | False positive | 3 | 4 | #64399 flagged the `v` argument of a pydantic `@field_validator`. #66255 flagged the private kwarg `_direct_http`. #67258 flagged an option of the `ray start` Click command, which `help=` documents. | | Infrastructure | 5 | 9 | The step printed `could not determine merge-base` and no findings. The branches of #65437 and #65809 forked 520 and 598 master commits before their builds. The step's `git fetch --depth=500` makes the full CI clone shallow, so their merge-base wasn't in the fetched history. | That's 13 spurious failures out of 3,453 runs, about 0.4%, or 13 of 55 failures. Each one would block a PR once the step is required, so this PR fixes all four patterns before removing `soft_fail`. ### Changes - **`_`-prefixed parameters:** `api_param_coverage.py` skips parameters whose names start with `_`. That's Ray's convention for private kwargs, such as `ray.put(_owner=...)`, `tune.run(_remote=...)`, and `Deployment.options(_internal=...)`. On master, 31 public callables have such parameters. - **Pydantic validators and Click commands:** The script skips callables decorated with `field_validator`, `model_validator`, `validator`, `root_validator`, `command`, or `group`. On master, this removes 59 callables from scope. All of them are Click commands, such as `ray start` and `ray job submit`, or pydantic validators on Serve config models. None of them is a Python API whose parameters a docstring documents. - **Property setters:** The script also skips callables decorated with `@<name>.setter`. A setter's `value` is documented on the property's getter, which is the docstring Sphinx renders, not in an `Args:` section of its own. - **Shallow-clone merge-base:** When `git merge-base` fails after the depth-500 fetch, `ci/lint/lint.sh` runs `git fetch --unshallow` and retries. A branch within 500 commits of the base never reaches that path. The Python check still fails closed if the base can't be resolved after that. - **Step definition:** `.buildkite/lint.rayci.yml` drops `soft_fail: true` and the warn-phase comment. The `--blocking` help text in `cmd_check_api_param_coverage.py` no longer describes a warn phase. ## Related issues Follow-up to #64788. ## Additional information ### Testing - `pytest ci/ray_ci/doc/test_api_param_coverage.py`: 40 passed. That's the 28 existing tests plus 12 new cases covering `_` params, each validator spelling, Click command forms, and property setters. The test comments name the real PR that motivated each one. - **Replay against real PRs:** I ran the master and patched versions of the check against the exact commit and base of every failing run in each of the 18 PRs with findings. Master reproduces all 18 failures. The patched check passes #64399, #66255, and #67258, and reports the same findings as master on the other 15. - **Merge-base fix:** In a local repo with 600 commits on `master` and a branch forked at commit 50, `git fetch --depth=500` followed by `git merge-base` fails, which reproduces the CI failure. With the new `lint.sh` block, it resolves the correct fork commit. A branch forked 10 commits back resolves without the fallback. - `pre-commit run` on the changed files passes, including ruff, black, shellcheck, and docstyle. ### Duplicate check `gh pr list --state open --search "param coverage"` and `--search "api_param_coverage"` return no open PR that touches this check. The script hasn't changed since #65391 on 2026-08-14. ### AI assistance I used Claude Code to pull and classify the Buildkite history, draft the changes, and run the replay. I reviewed every changed line and the classification of every failing PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Description
The router's
while Trueretry loop inroute_and_send_requestand_pick_and_reserve_replicaretries indefinitely when replicas reject requests.max_queued_requestsis only checked once at the entry gate, not during retries. Under sustained load with large payloads (~50MB), requests pile up in the retry loop causing OOM --num_queued_requestscan reach 119 whenmax_queued_requests=20.This PR adds
max_request_retriestoRequestRouterConfig:-1(unlimited) preserves backwards compatibilityBackPressureError(503) after exhausting retriesroute_and_send_request(replica rejection retry) and_pick_and_reserve_replica(capacity queue retry) are boundedRequestRouterConfig(max_request_retries=N)or env varRAY_SERVE_ROUTER_MAX_REQUEST_RETRIESRelated issues
Fixes #61017
Additional information
Files changed:
constants.py-- newRAY_SERVE_ROUTER_MAX_REQUEST_RETRIESenv var (follows existing backoff env var pattern)config.py-- newmax_request_retriesfield onRequestRouterConfigwith validator,__eq__,__hash__router.py--_check_retry_limit()helper, retry counter in both loopstest_backpressure.py-- config validation test + integration test withmax_request_retries=3Semantics:
max_request_retries=-1: unlimited (default, no behavior change)max_request_retries=0: no retries (fail on first rejection)max_request_retries=N: retry up to N times, then 503