Skip to content

[serve] Deflake test_deploy_app_3 - #67165

Merged
jeffreywang88 merged 6 commits into
ray-project:masterfrom
johntaylor-cell:serve-deploy-app3-deflake
Oct 20, 2026
Merged

jeffreywang88 merged 6 commits into
ray-project:masterfrom
johntaylor-cell:serve-deploy-app3-deflake

Conversation

@johntaylor-cell

@johntaylor-cell johntaylor-cell commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

test_deploy_app_3 (added in #66267) flakes on the HAProxy, gRPC and flaky-tests shards. One commit per cause:

  • Two waits read replica counts and pids in separate calls, so a replica changing state in between could pass for the state they wait for. They now read one snapshot, as [Serve] Fix race in test_flapping_rolling_update_stops_consuming_old_replicas #67163 does for the same race in test_deploy_app_2.
  • The HAProxy shard's 0.01s drain lets a stopping replica close connections HAProxy still uses. The traffic tests whose replicas stop during a rollout now use the 5s drain test_deploy_app_2 already uses; the gang test is left out, since gang replicas are force-stopped.
  • Under direct ingress, a request moving from the handle to a replica can briefly count twice, which raised the autoscaling target in test_surge_rolling_update_follows_autoscaling_mid_rollout. A 2s upscale delay filters it.
  • Two waits that ran close to their limit under load get more room.

Tested with pytest python/ray/serve/tests/test_deploy_app_3.py under the default and HAProxy shard environments with CPU stressors: 13 of 13 in each at the final commit.

johntaylor-cell and others added 4 commits October 19, 2026 17:48
…shot

Two predicates read the replica counts from serve.status() and the running pids from the instance details, two calls a few dozen milliseconds apart, so a transition between the calls could combine into a state that never existed.

check_stalled waits for the capacity-blocked stall: three running and two starting, with one new replica among the running. Those are also the counts just before the first replacement comes up, when all three running replicas are still old. When the controller ticked between the two calls, the counts from before that transition and the pids from after it made the stall while an old replica was still STOPPING; the test moved on, and its "still stalled" check then saw STOPPING and failed. Under load it failed this way in 2 of 6 runs on its own.

In test_surge_rolling_update_stops_after_health_check_failures, a replacement that was already starting when the update stopped still starts, passes its first health check, then fails and stops. Read just before that stop, the counts were all RUNNING; read just after, the pids were all old, so check_settled passed while the replacement was STOPPING, and the next check, which counts every replica for 5s, failed. This happened once in the HAProxy runs.

Both now read states and pids from one instance-details snapshot, which includes STOPPING replicas. The file's other predicates that mix the two calls either read the state after the point they wait for, or have no strict check after them.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
…er than an HAProxy reload

Seven of the eight tests that assert every request returns 200 through a rolling update ran with the HAProxy shard's 0.01s RAY_SERVE_DIRECT_INGRESS_MIN_DRAINING_PERIOD_S. A stopping replica then closes HAProxy's pooled connections before the reload that stops routing to it lands, and the request HAProxy writes into a closing connection fails; test_surge_rolling_update_with_one_replica failed this way with a RemoteProtocolError under load. test_surge_rolling_update_with_num_replicas_change already gave its replicas 5s for this reason.

Six of the seven now deploy through _drained_config, which adds the INGRESS_DRAIN_ENV that test_deploy_app_2 already uses to every version they deploy and keeps each version's own environment, so every transition is still a restart or a lightweight change exactly as before. The shared constant also replaces the local copy in test_surge_rolling_update_with_num_replicas_change. test_gang_surge_rolling_update_and_rollback stays undrained: Serve force-stops gang replicas about 0.1s into their stop, so a drain only keeps them accepting requests until the kill, and with it the test failed 3 of 3 HAProxy runs. Without direct ingress the setting has no effect.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
… the autoscaling target

Under direct ingress the replica reports its running requests and the handle its queued ones, each sampled every 0.1s in its own process, so a request moving from the handle to the replica can be counted by both for up to one sample. The autoscaler averages only from the point every source has reported, so just after the first replica of test_surge_rolling_update_follows_autoscaling_mid_rollout starts, that overlap is a large share of its window. In every failing run it read 1.02 to 1.15 ongoing requests 0.2s after the replica started and, with upscale_delay_s 0, raised the target to 2 as v2 rolled out. The surge started two replacements and does not stop a starting replacement when the target falls back to 1, so the test saw {RUNNING: 1, STARTING: 2} until it timed out.

A 2s upscale delay outlasts the 1s look-back window a double count can stay in, so only sustained load raises the target. Scaling up from zero skips the delay, so the first replica still starts at once. Under the HAProxy shard's environment with one CPU stressor, the test failed 4 of 15 runs on its own without the delay and none of 15 with it; run after the lightweight-change test, 4 of 12 failed without it, whether or not that test drained, and none of 6 with it.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
In the file's runs under load, the waits on the 10s default that succeeded took under 2s, except two. test_surge_rolling_update_with_deployment_actors' surge check took 5.9 to 7.0s, since v2 rebuilds the app and starts its deployment actor before any replacement, and the controller restart in test_surge_rolling_update_keeps_capacity_and_replaces[True] took up to 4.7s. They now wait up to 30s and 20s.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
@johntaylor-cell
johntaylor-cell requested a review from a team as a code owner October 19, 2026 18:29
@johntaylor-cell johntaylor-cell self-assigned this Oct 19, 2026
@johntaylor-cell johntaylor-cell added serve Ray Serve Related Issue go add ONLY when ready to merge, run all tests labels Oct 19, 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 updates test_deploy_app_3.py to use INGRESS_DRAIN_ENV across several tests, introduces helper functions _drained and _drained_config to inject this environment, and refactors replica state checks to use a single snapshot of deployment details to prevent race conditions during state transitions. Feedback on these changes suggests using or {} instead of .get(..., {}) to safely handle None values in deployment configurations, and utilizing ReplicaState enum members directly rather than redundant wrapping or string comparisons when asserting replica states.

johntaylor-cell and others added 2 commits October 19, 2026 18:49
ReplicaDetails.state is already a ReplicaState, so the snapshot predicates take its value directly. The counts stay keyed by value, so they print and compare like the _replica_states() dicts the rest of the file asserts on.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
test_surge_rolling_update_stops_after_health_check_failures now waits up to 120s for the update to stop. The update stops after three failed replacements and the surge starts two at a time, so the wait spans two rounds of replica startup, and one soak run under heavy load used up the 60s.

The controller-restart wait in test_surge_rolling_update_keeps_capacity_and_replaces goes back to its default timeout. Its predicate blocks in ray.get until the restarted controller answers, and wait_for_condition checks its deadline only between calls, so the 20s set in e216f2c never applied: a 12s restart passes a 10s wait.

test_surge_rolling_update_with_num_replicas_change deploys through _drained_config like the other traffic tests. It used to pass INGRESS_DRAIN_ENV to every _env_override, which replaces the environment, so a new version could drop the drain by leaving it out. The deployed configs are unchanged.

test_surge_replacements_wait_for_capacity is undrained again. None of its replicas stops while traffic runs, so the drain only added 5s to its teardown on the HAProxy shard.

_drained_config takes the one deployment every caller passes, and its docstring says what it is for.

At this commit the whole file passed under the HAProxy shard's environment with one CPU stressor and under the default environment with two, and the num_replicas and capacity tests passed three more HAProxy runs, with the replica logs showing the 5s drain in the first and the shard's 0.01s in the second.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
@jeffreywang88
jeffreywang88 merged commit b2ca380 into ray-project:master Oct 20, 2026
6 checks passed
jeffreywang88 added a commit that referenced this pull request Oct 20, 2026
…nscaling, and deletion (#67172)

## Description
Gracefully drain gang replicas independently, then kill all members in
one controller tick after completion or timeout.

- Graceful termination: node drains, migration, rollouts, downscaling,
and deletion.
- Forceful termination: health check failures.

Fixes the gang request-loss issue explicitly excluded from #67165.

## Approach
Each replica runs the existing graceful shutdown independently. A
controller
[barrier](https://github.com/ray-project/ray/compare/gang-drain?expand=1#diff-c4c2583a4c2f3a3c87ada6faebd0b2dfef404e165df133a11195be5d65fcb387R5964)
waits for every stopping gang member to finish or time out, then kills
them in the same tick.

## Validation

- Real HTTP requests survive gang rollout and rollback;
`test_gang_surge_rolling_update_and_rollback` fails before the fix.
- Rollout, surge, downscale, deletion, and migration wait for the whole
gang.
- Placement groups stay allocated until termination.
- Timeouts and checkpoint recovery still work.
- Deployments converge to healthy capacity or complete deletion.

## Related issues
> Link related issues: "Fixes #1234", "Closes #1234", or "Related to
#1234".

## Additional information
> Optional: Add implementation details, API changes, usage examples,
screenshots, etc.

---------

Signed-off-by: Jeffrey Wang <[email protected]>
qishengxhe pushed a commit to qishengxhe/ray that referenced this pull request Oct 26, 2026
…7165)

`test_deploy_app_3` (added in ray-project#66267) flakes on the HAProxy, gRPC and
flaky-tests shards. One commit per cause:

- Two waits read replica counts and pids in separate calls, so a replica
changing state in between could pass for the state they wait for. They
now read one snapshot, as ray-project#67163 does for the same race in
`test_deploy_app_2`.
- The HAProxy shard's 0.01s drain lets a stopping replica close
connections HAProxy still uses. The traffic tests whose replicas stop
during a rollout now use the 5s drain `test_deploy_app_2` already uses;
the gang test is left out, since gang replicas are force-stopped.
- Under direct ingress, a request moving from the handle to a replica
can briefly count twice, which raised the autoscaling target in
`test_surge_rolling_update_follows_autoscaling_mid_rollout`. A 2s
upscale delay filters it.
- Two waits that ran close to their limit under load get more room.

Tested with `pytest python/ray/serve/tests/test_deploy_app_3.py` under
the default and HAProxy shard environments with CPU stressors: 13 of 13
in each at the final commit.

---------

Signed-off-by: john.taylor <[email protected]>
Co-authored-by: Claude <[email protected]>
(cherry picked from commit b2ca380)
Signed-off-by: qishengxhe <[email protected]>
elliot-barn pushed a commit that referenced this pull request Oct 26, 2026
…, a longer ingress drain for the traffic tests, and a Windows timeout (#66492) (#67439)

Cherry-pick of #66492 ([serve] Deflake test_deploy_app_2 - wait budgets,
a longer ingress drain for the traffic tests, and a Windows timeout)
onto `releases/2.60.0`. Master commit `09cc6ec807`.

Applied cleanly with `git cherry-pick -x`. Test-only changes:
`BUILD.bazel`, `test_config_files/fail_on_flag.py`,
`test_deploy_app_2.py`.

Needed on the release branch because #67165 (cherry-pick in #67438)
imports `INGRESS_DRAIN_ENV`, which this change adds. Split into its own
PR so each squash on the release branch maps to one master commit.

No other backport PR for this change targets `releases/2.60.0`.
`pre-commit run --files` on the touched files passes. Relying on CI for
the test runs.

AI assistance was used to prepare this cherry-pick.

Signed-off-by: qishengxhe <[email protected]>
Co-authored-by: johntaylor-cell <[email protected]>
elliot-barn pushed a commit that referenced this pull request Oct 26, 2026
Cherry-pick of #67165 ([serve] Deflake test_deploy_app_3) onto
`releases/2.60.0`. Master commit `b2ca380473`.

Applied cleanly with `git cherry-pick -x`. Test-only change:
`test_deploy_app_3.py`.

Depends on #67439 (cherry-pick of #66492), which adds the
`INGRESS_DRAIN_ENV` fixture constant this test imports. Stacked on that
PR so this diff shows only #67165; merge #67439 first, then retarget
this PR to `releases/2.60.0`.

No other backport PR for this change targets `releases/2.60.0`.
`pre-commit run --files` on the touched file passes. Relying on CI for
the test runs.

AI assistance was used to prepare this cherry-pick.

Signed-off-by: john.taylor <[email protected]>
Signed-off-by: qishengxhe <[email protected]>
Co-authored-by: johntaylor-cell <[email protected]>
Co-authored-by: Claude <[email protected]>
elliot-barn added a commit that referenced this pull request Oct 26, 2026
Cherry-pick of #67165 onto `releases/2.60.0`.

Original PR: #67165 (merged on master as b2ca380). This cherry-pick
was first made as #67438. That PR was stacked on the #66492 cherry-pick
branch and merged into it after #67439 had already landed, so it never
reached `releases/2.60.0`. This PR applies the same commit (c4840ed)
directly onto `releases/2.60.0`. It replaces #67441, which was opened
from the stacked branch and showed the already-landed #66492 changes
alongside this one.

## Change

`python/ray/serve/tests/test_deploy_app_3.py` only, +59/-41, identical
to #67165 and #67438. The cherry-pick applied cleanly.

From #67165: `test_deploy_app_3` flakes on the HAProxy, gRPC and
flaky-tests shards. The fix:
- waits read replica counts and pids from one snapshot;
- traffic tests whose replicas stop during a rollout use the 5s HAProxy
drain;
- handles the direct-ingress request-count race.

## Testing

Test-only change, verified on master in #67165. This PR's premerge runs
the Serve test shards against `releases/2.60.0`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: john.taylor <[email protected]>
Signed-off-by: qishengxhe <[email protected]>
Co-authored-by: qishengxhe <[email protected]>
Co-authored-by: johntaylor-cell <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants