Repository navigation
[serve] Push-based replica health: controller-side receive path - #66243
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a replica-pushed self-health mechanism in Ray Serve to short-circuit active pull probes, reducing controller overhead. It implements a ReplicaHealthPushRegistry to manage pushed health reports and integrates it into the controller and deployment state management, along with comprehensive unit tests. The review feedback highlights two key areas for improvement: first, a bug in check_health where discarding an in-flight probe as stale incorrectly clears the health check failure status set by a newer push, which can be resolved by preserving and restoring the previous status; second, a defensive programming improvement in record_pushed_health to prevent delayed older pushes from overwriting newer stashed pushes when multiple updates arrive before a reconcile sweep.
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 fe54a4d. Configure here.
64158e1 to
2d98b0a
Compare
8b1a0b0 to
55be1ce
Compare
abrarsheikh
left a comment
There was a problem hiding this comment.
how are consecutive failure counts honored in push based health checks?
Move the push vs. probe logic into its own small class, and test that class directly.
Right now this logic lives inside ActorReplicaWrapper, mixed in with Ray calls. That's why the tests build the wrapper with __new__, set private fields by hand, monkeypatch ray.get, and add + 1e-3 to avoid clock ties.
Instead, add a small class, something like PushedHealthTracker. Each replica wrapper owns one. It makes no Ray calls and takes a timer (timer: TimerBase = Timer()), the same way proxy_state.py does.
It needs three methods:
record(report): save the newest pushshould_defer_probe(): return whether the newest push is still fresh enough to skip a proberesolve(probe_response, probe_started_at): return the result to act on — the probe result, a result based on the push, or nothing
ActorReplicaWrapper.check_health then calls resolve(...) once before the existing if/elif chain, and the chain itself doesn't change.
With this, the tests get much simpler. Build the tracker with a MockTimer, move time forward with timer.advance(), and check what resolve() returns. No Ray, no mocks, and no private fields.
On top of that, add a couple of end-to-end tests through mock_deployment_state_manager, similar to the existing health-check tests:
- Fresh healthy pushes mean no probe is sent.
- N unhealthy pushes move the replica to
STOPPING.
Replica keeps failure counts now and sends them in the reports. The Controller mirrors them.
Done
Done
Adding |
Adds the registry the controller records pushed replica self-health into, and the arbitration that lets a fresh push stand in for a pull probe: a probe is deferred while the newest observation is inside 1.5x the health-check period, and two watermarks keep a push and an in-flight probe from overwriting each other's verdict. An actor crash stays authoritative either way. Inert on its own. No replica pushes yet, so the registry stays empty, every replica is probed exactly as before, and the pull path is unchanged. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
…allers Makes record_pushed_health self-contained: it now keeps the newer of the stashed and incoming observations rather than relying on the registry's ordering guard. Unreachable through today's only caller, but the later PRs in this stack add producers upstream of that funnel. Also restores the rationale for clearing the failure flag while keeping the latency sample when a stale in-flight probe is discarded. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
…resh The deferral gate only consulted the last APPLIED push, but a push that a resolving probe beat to the tick stays stashed and unconsumed. With a probe outstanding longer than the health-check period -- a timeout, the case at scale -- the gate then armed a fresh probe against health already in hand. Take the newer of the applied and stashed arrival times instead. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
…failures Two push/probe arbitration tests read time.time() twice and relied on the second read being strictly greater, which is what the stale-probe drop is gated on. On Windows time.time() resolves to the ~15.6ms system timer tick, so the two reads tie, the drop never fires, and both tests fail there instead of pinning the arbitration they describe. Pin the two instants explicitly. Mirror the pushed consecutive-failure count with a max() against the count the controller already holds. The absolute assignment let a push arriving mid-failure-run lower a probe-derived count, moving a failing replica further from eviction than the pull-only path would have. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
test_apply_pushed_health_hands_off_to_wrapper asserted only that the wrapper was called, never with what. Since _apply_pushed_health forwards the registry entry as a bare splat, swapping the two floats was silent, and it would have fed replica-clock in as received_at, the exact skew the field exists to avoid. Assert the arguments, and cover the DeploymentReplica hop, which had no direct test. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
The age-based prune only runs when the registry holds more than _PRUNE_THRESHOLD entries, so a fleet that never crosses 65536 distinct replica ids keeps every dead replica's entry for the life of the controller. The terminal reap already evicts four sibling per-replica maps with the unique id in hand, so evict here too and leave the prune as the backstop for ids that stop pushing without a stop event. A review bot read this as an unbounded leak. It is not: the size gate is a level trigger, so once the registry crosses the threshold it re-prunes every _PRUNE_MIN_INTERVAL_S and the ceiling carries no uptime term (measured 12.4 MiB at the threshold). The real cost is retention time below the threshold, and that nothing reclaims once pushes stop, which a prune reachable only from record() cannot fix. MockReplicaActorWrapper gained record_pushed_health, without which no deployment-state-level test could exercise the push-apply path at all. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
…ence A crashed replica is invisible while a pushed result is still fresh, because ACTOR_CRASHED only ever comes from an outstanding probe ref and the window delays arming one. At 1.5x the health-check period that made crash detection slower than pull probing alone: ~15s against ~11s at the default period. The window is keyed on the push cadence, which is twice the probe cadence, so 0.75x is enough to never probe a replica whose pushes are arriving. Detection is then ~7.5s, better than before pushes existed. Pinned with absolute values rather than by calling the function under test, so changing the factor has to be deliberate. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
The registry stored a four-field tuple, so every reader had to decode prev[0] and v[1] against a comment. A NamedTuple names them at the call site, and the same shape on the replica wrapper gets it too. Unpacking and the splat into record_pushed_health are unchanged; only the index accesses move to attributes. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
A replica counts an unhealthy self-check once per health-check period but heartbeats on every eval, so the same count reaches the controller twice. Each arrival was consumed as a fresh APP_FAILURE and advanced the controller's count, reaching the threshold in about half the configured time and replacing replicas with flaky checks sooner than intended. The controller now advances only when the replica's reported count actually increases. A count that genuinely advances still mirrors as before, so a push stream starting mid-failure-run cannot lower what the controller already probed. The watermark that makes this work is cleared wherever the failure counter resets. Without that, a replica's next failure after recovering reports count 1 again, matches the stale watermark, and has its strike dropped, so a fail-recover-fail cycle would never reach the threshold. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
check_health decided between a pushed result and a pull probe inline, mixed in with the Ray calls around it, so the tests had to build the wrapper with __new__, set five private fields by hand, monkeypatch ray.get, and nudge timestamps apart to avoid clock ties. That decision now lives in PushedHealthTracker: record a push, say whether one is fresh enough to skip a probe, and resolve what a tick should act on. It makes no Ray calls and takes a timer the way proxy_state does, so its 15 tests drive it directly with a MockTimer and no mocks. check_health calls resolve() once and the if/elif chain below it is unchanged. Pushed health also lived in two places: a registry keyed by replica id, copied onto the replica every tick. The controller now routes a push through the manager to the replica that owns it, which writes it to that replica's tracker, so the result lives in one place. ReplicaID is (unique_id, deployment_id), so the existing per-deployment index answers the lookup without a new one. This drops the registry, its pruning, the per-tick hand-off, the discard on replica stop, and the optional constructor argument that only existed for tests. One behaviour change: a push for a replica the controller does not track is now dropped rather than held. That matters while the controller rebuilds state after a restart; the pull probe covers those replicas once they exist. Probe-only members are named for the probe: _probe_ref, _probe_started_at, _resolve_active_probe, _should_start_new_probe. Members both modes write keep their names, since calling them probe would be wrong. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
The heartbeat now sends the full ReplicaID, matching ReplicaMetricReport, so the controller indexes straight into the owning deployment instead of asking every deployment in turn whether the replica is theirs. The deployment also stops rebuilding an id it was already given. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
…er tests The controller now takes the replica's count as given rather than deriving a value for its own increment to land on. Reconstructing it was what forced the repeat detection, since the second heartbeat of a period reports the same count; copying makes a repeat simply the same count. It also drops a strike the old arithmetic added when a replica reported fewer failures than the controller had already probed. The tracker stamps arrival from its own clock, so received_at no longer travels through four layers that only forwarded it. One test was injecting that stamp to fake a stale push and now has to record the push before the probe, which is what it meant all along. Ten wrapper-driven tests duplicated TestPushedHealthTracker and are gone, with test_deployment_replica_forwards_pushed_health. The rest stay: conftest patches ActorReplicaWrapper out of mock_deployment_state_manager, so nothing else reaches the probe gate, the failure chain or the metrics flags. The freshness window is a plain function and is tested as one. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
b92f42c to
540a42c
Compare
…ts to three The replica always sends its consecutive-failure count, so the Optional and the branch that handled its absence were unreachable. The count is required through the chain now and _mirror_failures is a plain copy. The wrapper suite keeps only what the wrapper itself does and the tracker cannot reach: a fresh push stopping a probe from starting, a pushed count reaching the threshold, and the metrics flag on a pushed verdict. The seven that re-tested should_defer_probe, the count copy and the unchanged SUCCEEDED branch are gone, along with the ray.get patching they needed. The wrapper is built through its real constructor and driven by a MockTimer rather than the wall clock. Co-Authored-By: Claude <[email protected]> Signed-off-by: john.taylor <[email protected]>
…project#66243) The controller health-checks every replica by firing `check_health.remote()` on a timer. At scale that probe is pure overhead: the `.remote()` submit alone is ~465 µs and GIL-bound, and at 8k replicas it accounts for essentially all of the deployment-state update time. This PR lands the receive half of replacing that probe with a push. It adds nothing to the hot path and changes no behavior on its own — there is no sender yet, so the registry stays empty, `_apply_pushed_health` is a no-op, and every replica is probed exactly as before. It is reviewable against master in isolation, which is why it goes first. **What it adds** - `ReplicaHealthPushRegistry` — latest self-health per replica id, written by the controller ingest path and read by the reconcile sweep. Out-of-order reports are rejected on `checked_at`; pruning is rate-limited so the O(N) rebuild cannot thrash ingest at the scale it serves. - `Controller.record_replica_health(replica_unique_id, checked_at, healthy, consecutive_failures)` — the whole payload. Absolute state, not a delta, so a dropped push costs nothing. - Probe deferral: `_should_start_new_health_check` returns False while the newest observation is inside `max(1.5 × health_check_period_s, 1.0)`, anchored to **arrival** so a slow reconcile cannot stretch the window. - Push/probe arbitration in `check_health`, with two watermarks: a probe already in flight when a newer push is applied is discarded, and a push that arrived before the last applied probe is dropped. `ACTOR_CRASHED` is exempt from both — a crash is authoritative and a dead replica pushes nothing. **Clocks.** `checked_at` is replica-clock and used only for ordering and dedupe; every freshness decision uses the controller-clock arrival time, so replica clock skew cannot widen a window. **Testing.** 17 new unit tests. Verified by mutation: each of seven independent removals — probe deferral, freshness window, failure-count mirroring, both watermarks, push dedupe, registry ordering guard — is caught by at least one test. Full `test_deployment_state.py` 275 passed against a 258-test baseline, with `test_controller.py`, `test_application_state.py` and `test_deployment_rank_manager.py` unchanged. --------- Signed-off-by: john.taylor <[email protected]> Co-authored-by: Claude <[email protected]>
…rcent` for start-before-stop rolling updates (#66267) (#67094) Cherry-pick of #66267 (master commit 9491664) onto `releases/2.60.0`. ## Why The first three PRs of the in-place-updates series (#66252, #66290, #66266) are already on `releases/2.60.0`. This picks the fourth, which adds `max_surge_percent` for start-before-stop rolling updates, so 2.60.0 ships the complete series. ## Cherry-pick details `git cherry-pick -x` conflicted in one file, `python/ray/serve/tests/unit/test_deployment_state.py`. The conflict was positional only: on master, #66243 (push-based replica health) had appended `TestPushedHealthEndToEnd` and related tests to the end of that file, and #66267 inserts `TestMaxSurge` right before them. This branch doesn't have #66243, so git couldn't anchor the hunk and offered the #66243 tests as part of the incoming side. Resolved by inserting only the PR's `TestMaxSurge` block (plus its `defaultdict` import) before the `__main__` guard. The added and removed lines in each of the 17 files are identical to the master commit's diff. After the pick, 11 of the 17 files are byte-identical to master at 9491664. The other 6 differ only by master commits that aren't on this branch and that #66267 doesn't depend on: - `_private/deployment_state.py`, `tests/unit/test_deployment_state.py`: #66243. - `schema.py`, `tests/BUILD.bazel`, `tests/test_controller.py`, `tests/test_direct_ingress.py`: #66339 and #66940. No commit on `releases/2.60.0` after the branch cut touched any of these files. Not a duplicate: no PR against `releases/2.60.0` references #66267. ## Testing Run on this branch with the Serve protobuf regenerated from the branch's `serve.proto` (the pick adds the `max_surge_percent` field). ``` python -m pytest python/ray/serve/tests/unit/test_deployment_state.py python/ray/serve/tests/unit/test_config.py python/ray/serve/tests/unit/test_deployment_class.py python/ray/serve/tests/unit/test_schema.py 3530 passed, 12 skipped ``` ``` python -m pytest python/ray/serve/tests/test_deploy_app_3.py python/ray/serve/tests/test_deploy_app_2.py -k surge 13 passed, 41 deselected in 282s ``` `pre-commit run --files <changed files>` passed. AI assistance was used to prepare this cherry-pick. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Qisheng He <[email protected]> Signed-off-by: qishengxhe <[email protected]>

The controller health-checks every replica by firing
check_health.remote()on atimer. At scale that probe is pure overhead: the
.remote()submit alone is~465 µs and GIL-bound, and at 8k replicas it accounts for essentially all of the
deployment-state update time.
This PR lands the receive half of replacing that probe with a push. It adds
nothing to the hot path and changes no behavior on its own — there is no sender
yet, so the registry stays empty,
_apply_pushed_healthis a no-op, and everyreplica is probed exactly as before. It is reviewable against master in
isolation, which is why it goes first.
What it adds
ReplicaHealthPushRegistry— latest self-health per replica id, written by thecontroller ingest path and read by the reconcile sweep. Out-of-order reports are
rejected on
checked_at; pruning is rate-limited so the O(N) rebuild cannotthrash ingest at the scale it serves.
Controller.record_replica_health(replica_unique_id, checked_at, healthy, consecutive_failures)— the whole payload. Absolute state, not a delta, so adropped push costs nothing.
_should_start_new_health_checkreturns False while the newestobservation is inside
max(1.5 × health_check_period_s, 1.0), anchored toarrival so a slow reconcile cannot stretch the window.
check_health, with two watermarks: a probe already inflight when a newer push is applied is discarded, and a push that arrived before
the last applied probe is dropped.
ACTOR_CRASHEDis exempt from both — a crashis authoritative and a dead replica pushes nothing.
Clocks.
checked_atis replica-clock and used only for ordering and dedupe;every freshness decision uses the controller-clock arrival time, so replica clock
skew cannot widen a window.
Testing. 17 new unit tests. Verified by mutation: each of seven independent
removals — probe deferral, freshness window, failure-count mirroring, both
watermarks, push dedupe, registry ordering guard — is caught by at least one test.
Full
test_deployment_state.py275 passed against a 258-test baseline, withtest_controller.py,test_application_state.pyandtest_deployment_rank_manager.pyunchanged.