Skip to content

[serve] Answer {route_prefix}/-/healthz from tracked application status - #66705

Open
dundysm wants to merge 6 commits into
ray-project:masterfrom
dundysm:serve/builtin-app-health-66509
Open

dundysm wants to merge 6 commits into
ray-project:masterfrom
dundysm:serve/builtin-app-health-66509

Conversation

@dundysm

@dundysm dundysm commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Application routes, including a user-defined /healthz, take a replica slot in _start_request. Only system /-/healthz skips admission. When max_ongoing_requests is saturated, a probe that reads app status through the ingress waits for a slot even though the app is fine, and a supervisor restarts a process that was only busy.

Following option (a) from the discussion on #66509, this adds GET {route_prefix}/-/healthz for a non-root route prefix and answers it from the application status Serve already tracks:

  • 200 when the application is RUNNING
  • 503 otherwise, with the status in the body (DEPLOYING, UNHEALTHY, DEPLOY_FAILED, DELETING, or UNKNOWN before the proxy has received statuses)
  • 503 while the proxy is draining

The request is never routed to a replica, so it does not call check_health and does not take a max_ongoing_requests slot. The controller pushes {app name: status} to the proxies over a new APPLICATION_STATUSES long poll key, only when it changes, so a probe adds no controller calls.

System /-/healthz is unchanged (proxy readiness). Ordinary application routes still count toward the limit. A route prefix of / has no separate path, because /-/healthz is already the system route.

The earlier revision called the ingress check_health on one replica; that path, and its retry/timeout handling, is removed.

Fixes #66509

cc @edoakes @abrarsheikh

Test plan

pytest python/ray/serve/tests/unit/test_proxy.py python/ray/serve/tests/unit/test_proxy_router.py \
  python/ray/serve/tests/unit/test_controller.py python/ray/serve/tests/unit/test_proxy_state.py \
  python/ray/serve/tests/unit/test_application_state.py python/ray/serve/tests/unit/test_replica_backpressure.py -q

300 passed locally. New tests cover RUNNING -> 200, each non-running status -> 503, unknown status -> 503, draining -> 503, no routing to a replica, system /-/healthz unchanged, and the controller broadcasting statuses only on change. ruff and black clean.

@dundysm
dundysm requested review from a team as code owners October 4, 2026 17:29

@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 introduces a built-in per-application health check endpoint GET {route_prefix}/-/healthz (when the route prefix is not /) that calls the ingress deployment's check_health method on a running replica. This health check bypasses request admission and does not consume a max_ongoing_requests slot, allowing saturated deployments to still respond to health probes. The feedback recommends distributing the health check load across replicas using random.choice instead of always querying the first replica to prevent hot-spotting. Additionally, it is suggested to log exception tracebacks with exc_info=True when health checks fail in both the proxy and replica to improve observability.

Comment thread python/ray/serve/_private/router.py Outdated
Comment on lines +1607 to +1611
replicas = list(self._active_request_router.curr_replicas.values())
if not replicas:
raise DeploymentUnavailableError(self.deployment_id)

await replicas[0].check_health()

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.

medium

Always querying the first replica (replicas[0]) for the application health check can lead to hot-spotting, where a single replica bears the entire load of health check requests from external load balancers. Additionally, if that specific replica is experiencing local issues or is slow, the entire application might be incorrectly marked as unhealthy. Using random.choice distributes the health check load and provides a more representative sample of the application's overall health.

        import random

        replicas = list(self._active_request_router.curr_replicas.values())
        if not replicas:
            raise DeploymentUnavailableError(self.deployment_id)

        await random.choice(replicas).check_health()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving the first replica. this probe does not take a request slot, so it is not request load. random.choice still checks only one replica, and the controller already health checks every replica.

Comment thread python/ray/serve/_private/proxy.py Outdated
Comment on lines +1145 to +1149
except Exception:
logger.warning(
"Application health check failed.",
extra={"log_to_stderr": False},
)

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.

medium

When the application health check fails, logging the exception traceback with exc_info=True is highly recommended. This provides critical context (such as connection timeouts, database errors, or internal bugs) to help operators diagnose why the health check failed.

Suggested change
except Exception:
logger.warning(
"Application health check failed.",
extra={"log_to_stderr": False},
)
except Exception:
logger.warning(
"Application health check failed.",
exc_info=True,
extra={"log_to_stderr": False},
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the traceback is now included.

Comment thread python/ray/serve/_private/replica.py Outdated
Comment on lines +3144 to +3147
except Exception:
logger.warning("Application health check failed.")
healthy = False
message = "UNHEALTHY"

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.

medium

Logging the exception traceback with exc_info=True when the replica's health check fails will greatly improve observability and make debugging much easier for operators.

Suggested change
except Exception:
logger.warning("Application health check failed.")
healthy = False
message = "UNHEALTHY"
except Exception:
logger.warning("Application health check failed.", exc_info=True)
healthy = False
message = "UNHEALTHY"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the traceback is now included.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread python/ray/serve/_private/router.py Resolved
@dundysm
dundysm force-pushed the serve/builtin-app-health-66509 branch from fe5b1cb to 59569ab Compare October 4, 2026 17:33
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Oct 4, 2026
@dundysm
dundysm force-pushed the serve/builtin-app-health-66509 branch 2 times, most recently from 49e40c0 to 4bd27ff Compare October 4, 2026 21:45

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread python/ray/serve/_private/proxy.py Resolved
@dundysm
dundysm force-pushed the serve/builtin-app-health-66509 branch from 4bd27ff to a2395ed Compare October 4, 2026 23:24
Applications with a non-root route prefix can probe
{route_prefix}/-/healthz. That path calls ingress check_health and does
not take a max_ongoing_requests slot. System /-/healthz and ordinary
application routes are unchanged.

Closes ray-project#66509

Signed-off-by: Dundy Pasupuleti <[email protected]>
@dundysm
dundysm force-pushed the serve/builtin-app-health-66509 branch from a2395ed to dc9f15b Compare October 6, 2026 19:10
@dundysm

dundysm commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@abrarsheikh @edoakes gentle ping for review when you get a chance; this is the per-app {route_prefix}/-/healthz for #66509, so an app probe doesn't wait on a max_ongoing_requests slot when the replicas are saturated. the bugbot notes are resolved in dc9f15b and microcheck is green; premerge hasn't been triggered yet. happy to change the route shape if you'd rather expose it differently.

@abrarsheikh

Copy link
Copy Markdown
Contributor

left a question #66509 (comment)

Per the discussion on ray-project#66509, the per-app health route now reports the
application status Serve already tracks (200 when RUNNING, 503 otherwise)
instead of calling check_health on an ingress replica. The controller pushes
{app name: status} to the proxies over a new APPLICATION_STATUSES long poll
key, and the proxy answers the route from that without routing to a replica.

Drops the replica-side check_health path and its retry/timeout handling.

Signed-off-by: Dundy Pasupuleti <[email protected]>
@dundysm dundysm changed the title [serve] Add a per-app health route that skips max_ongoing_requests [serve] Answer {route_prefix}/-/healthz from tracked application status Oct 18, 2026
@dundysm

dundysm commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

@abrarsheikh reworked this to follow (a) per the thread on #66509: {route_prefix}/-/healthz is now answered by the proxy from the application status serve already tracks (200 when RUNNING, 503 otherwise, with the status in the body), never routed to a replica and no check_health call. the controller pushes app statuses to the proxies over long poll only when they change, so probes add no controller calls. the replica-side path and its retry/timeout handling are gone (3dc61c3). if you would rather not add a route at all, happy to switch this to docs only.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread python/ray/serve/_private/proxy.py Outdated
message = HEALTHY_MESSAGE
else:
healthy = False
message = status.value if status is not None else "UNKNOWN"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probes fail during rolling updates

High Severity

{route_prefix}/-/healthz is healthy only when application status is RUNNING, so it returns 503 for DEPLOYING. A config update puts deployments in UPDATING and the app back into DEPLOYING even while old replicas still serve. Load-balancer and Kubernetes probes pointed at this path then fail for the whole rollout and can take serving backends out of rotation.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3dc61c3. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. fixed in 7cc7f23: the proxy now remembers apps that reached RUNNING, so a config update (RUNNING back to DEPLOYING while old replicas serve) keeps {route_prefix}/-/healthz at 200. a first deploy, DEPLOY_FAILED, UNHEALTHY and DELETING still return 503, and DELETING resets it. added a unit test for the update path and updated the docs.

A config update moves a RUNNING app back to DEPLOYING while its existing
replicas keep serving, so reporting 503 for every DEPLOYING app would fail
probes for the whole rollout. The proxy now remembers which apps reached
RUNNING and answers 200 for those while they are DEPLOYING. A first deploy,
DEPLOY_FAILED, UNHEALTHY, and DELETING still report 503.

Also fixes import order flagged by the ruff isort hook.

Signed-off-by: Dundy Pasupuleti <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

The proxy used to remember which apps had reached RUNNING to keep
{route_prefix}/-/healthz at 200 during an in-place update. A proxy that
starts or restarts mid-update never saw RUNNING, so it returned 503 while
the old replicas were still serving.

The controller now broadcasts (status, serving) per app, where serving is
RUNNING, or DEPLOYING while the ingress deployment has running replicas.
It is derived from live replica state, so every proxy agrees and nothing
is lost on a proxy restart.

Signed-off-by: Dundy Pasupuleti <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 94ca62c. Configure here.

Comment thread python/ray/serve/_private/controller.py Resolved
A declarative rebuild clears the app's target ingress until the build
task finishes, while the old deployments keep serving. The controller
treated a missing ingress as not serving, so {route_prefix}/-/healthz
returned 503 for a healthy app during the build.

Fall back to the endpoint the proxies are still routing the app to
when the target ingress is unset. A first deploy has no endpoint yet
and still reports not serving.

Also fix the mypy union-attr error on the status message in the proxy.

Signed-off-by: Dundy Pasupuleti <[email protected]>
@dundysm

dundysm commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

hi @abrarsheikh, i addressed the bugbot points and the probe timeout. the remaining microcheck failure was an npm 504 during a lint job, so it may just need a rerun. could you take another look?

@dundysm

dundysm commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

fyi the red microcheck is lint: dashboard_format, which failed on an npm mirror 504 (registry.npmmirror.com gateway timeout) while installing npm. this pr doesn't touch dashboard files, so a retry should clear it.

dstrodtman added a commit that referenced this pull request Oct 29, 2026
…blocks (#67432)

## Description

Converts the last `>>>` doctest examples on documentation pages, so
`>>>` examples remain only in docstrings and on the two pages that teach
the docstring format. #67429 changes the contributor guidance to match.
This PR is independent of that stack and targets `master`.

Before this PR, seven pages under `doc/source/` had `>>>` prompts. Two
of them teach the docstring format and stay as they are:
`ray-contribute/writing-code-snippets.md` and
`ray-contribute/getting-involved.md`. This PR converts the other five:

| Page | Before | After | Test coverage |
|---|---|---|---|
| `data/working-with-tensors.md` | Three `{doctest}` blocks |
`{testcode}` and `{testoutput}` blocks | Unchanged. The `dtype` and
shape checks still run. The two per-image shapes the doctest skipped are
now a `+MOCK` sample. |
| `ray-references/glossary.md` | One `{doctest}` block with `+SKIP` on
every line | `{testcode}` and `{testoutput}` | Gained. The block used to
run nothing and now runs. The expected output is unchanged, because Ray
produces it exactly. |
| `serve/advanced-guides/multi-app-container.md` | `>>>` prompts in a
`python` fence, with every request skipped | Plain `python` and `text`
blocks | None before or after. The requests need the containerized Serve
apps running. The doctest only ran `import requests` and two string
assignments. |
| `core/tasks/nested-tasks.md` | REPL transcript in a `bash` block |
Plain `python` and `text` blocks | None before or after. The page's
`doc_code/` script is tested. |
| `serve/production-guide/fault-tolerance.md` | Interactive `$ python` /
`>>>` transcripts | Plain `python` blocks, with `text` blocks for output
| None before or after. These steps kill actors on a live cluster. |

### Test wiring

- `doc/BUILD.bazel`:
- Removes the Serve `doctest_each` call. Its only file was
`multi-app-container.md`, which no longer has a runnable example, so the
target would pass without testing anything.
- Drops the comment explaining why `nested-tasks.md` isn't listed, since
the page no longer has anything runnable to explain.
- The glossary and tensors entries stay, because both pages still have
runnable examples.
- `doc/test_prose_doctest_targets.py`: removes `nested-tasks.md` and
`fault-tolerance.md` from `UNTESTED`. Neither page has a runnable
example now. The two docstring-teaching pages stay exempt.

No `.buildkite/test.rules.txt` change. All prose routes to `doc_example`
whether or not a doctest target names the page, and the existing routing
cases for these pages still hold.

This PR edits `doc/BUILD.bazel`, so premerge runs every library's docs
example step. The glossary target is tagged `team:none`, which runs only
post-merge or with `docs-example-test`, so this PR carries that label
too.

## Related issues

Companion to #67429, which reserves `>>>` doctest-style examples for
docstrings in the contributor guide.

## Additional information

### Duplicate check

I searched open PRs for each converted page and for `doctest` in titles.
#66705 edits `fault-tolerance.md` around line 53, far from these hunks.
Draft #66851 appends a line to `nested-tasks.md` after these hunks.
Neither converts these examples. The docstring conversion PRs (#67238,
#66745, #67237) touch `python/`, not pages.

### Testing

I reproduced the CI doctest runner locally: Ray 2.59.0, Python 3.11,
`pytest==7.4.4`, `ray-project/pytest-sphinx@c1ab2b33`, the Ray Data
`doctest_pytest_plugin.py`, and the macro's `--doctest-modules
--doctest-glob='*.md' -c NO_PYTEST_CONFIG` arguments.

- `working-with-tensors.md`: passes before (2 items: the doctest blocks
and the testcode blocks) and after (1 item). A copy with a wrong
expected shape fails with `Expected (32, 28, 99) / Got (32, 28, 28)`, so
the new assertions are live.
- `glossary.md`: before, 1 skipped. After, 1 passed. A copy with a wrong
expected value fails.
- `python doc/test_prose_doctest_targets.py`: "73 listed pages; every
runnable page is accounted for."
- `pre-commit run --files` on the changed files passes, including
buildifier and buildifier-lint.
- `vale` on each changed page: no new alerts compared with `master`.
- After this PR, `git grep -l '^\s*>>> '` over `doc/source/*.md` and
`*.rst` returns only the two pages that teach the docstring format.
- The Read the Docs preview covers rendering.

This PR was prepared with AI assistance (Claude Code). I reviewed every
changed line.

🤖 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]>
…h-66509

Signed-off-by: Dundy Pasupuleti <[email protected]>

# Conflicts:
#	python/ray/serve/tests/unit/test_controller.py
@dundysm

dundysm commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@eicherseiji could you take a look when you have time? this answers {route_prefix}/-/healthz from the app status serve already tracks, per the direction on #66509; ci is green on 255820a

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 27, 2026

This branch has not been deployed

No deployments
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 serve Ray Serve Related Issue stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Serve] Allow app-defined health routes to bypass max_ongoing_requests

2 participants