Skip to content

[docs] Document the serve.status() polling pattern for testing Serve deployments - #65868

Open
dstrodtman wants to merge 1 commit into
masterfrom
doc-910-serve-status-pattern
Open

dstrodtman wants to merge 1 commit into
masterfrom
doc-910-serve-status-pattern

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a section to the "How to write code snippets" contributor guide on how to test that a Ray Serve application actually deploys. It documents polling serve.status() until the application reaches RUNNING and raising on DEPLOY_FAILED/UNHEALTHY or timeout. An HTTP status_code == 200 check proves the endpoint answered but not that the deployment reached a healthy state, so this pattern catches deployment-lifecycle regressions the HTTP check misses.

The documented snippet uses only public modules (ray.serve, ray.serve.schema) and matches the app-name access form (next(iter(serve.status().applications.values()))) that #65381 introduces across the LLM Serve doc examples, so the guide and the examples stay consistent. It points contributors at qwen_example.py as the reference implementation.

Why this isn't a duplicate

Searched open PRs with gh pr list --search for writing-code-snippets and serve.status. #65381 would have removed the private import from the example modules themselves, but it closed without merging, and it didn't document the pattern in the contributor guide. This PR adds that guidance and uses the access form #65381 proposed. No open PR documents this pattern.

Test plan

Prose-only change under doc/. Per the docs CI routing, a change to only .md files under doc/ runs no library test steps; the Read the Docs render gate on this PR validates the build and cross-references. The Python snippet is a copyable python block, not a testcode cell, so doctest doesn't execute it.

AI assistance

Drafted with AI assistance (Claude Code). The snippet's API surface was verified against the existing qwen_example.py and #65381. The submitter reviews every changed line and confirms the RtD preview before requesting review.

@dstrodtman
dstrodtman requested review from a team as code owners September 2, 2026 16:28

@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 adds a new section to the documentation detailing how to test a Ray Serve deployment by polling serve.status() until the application reaches a RUNNING state. The review feedback points out a potential StopIteration exception if serve.status().applications is empty when the first poll runs, and provides a code suggestion to check if the applications dictionary is non-empty before accessing its values.

Comment on lines +301 to +305
while status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds:
status = next(iter(serve.status().applications.values())).status
if status in (ApplicationStatus.DEPLOY_FAILED, ApplicationStatus.UNHEALTHY):
raise AssertionError(f"Deployment failed with status: {status}")
time.sleep(1)

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 serve.run(app, blocking=False) is called, the application might not be immediately registered in the controller by the time the first poll runs. If serve.status().applications is empty, calling next(iter(...)) will raise a StopIteration exception and crash the test.

We should check if applications is non-empty before attempting to retrieve the status.

Suggested change
while status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds:
status = next(iter(serve.status().applications.values())).status
if status in (ApplicationStatus.DEPLOY_FAILED, ApplicationStatus.UNHEALTHY):
raise AssertionError(f"Deployment failed with status: {status}")
time.sleep(1)
while status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds:
apps = serve.status().applications
if apps:
status = next(iter(apps.values())).status
if status in (ApplicationStatus.DEPLOY_FAILED, ApplicationStatus.UNHEALTHY):
raise AssertionError(f"Deployment failed with status: {status}")
time.sleep(1)

@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Sep 2, 2026
@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 Sep 17, 2026
@dstrodtman dstrodtman added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Sep 21, 2026
dstrodtman added a commit that referenced this pull request Oct 29, 2026
…per-page doctest targets (#67204)

## Why are these changes needed?

Several contributor-facing CI docs fell behind the docs CI changes that
merged this month.

- **`ci.md`, "Docstring-only changes."** The section still described
`data: docstring examples` and said the examples step covers Ray Data
only. Since #67083, `doc: docstring examples` in `others.rayci.yml` runs
the changed modules' `>>>` examples for every library that a CPU
`doctest()` target covers. It runs in the light `docstringbuild` image,
which has no torch or TensorFlow, and reports examples that need those
libraries as skipped, by name. Since #67341, the label also skips every
library's test suites through `.buildkite/docs.labels.yaml`, so the
section now says that, and recommends an `@rtd-build` commit line
alongside the label so Read the Docs builds the API reference the
docstrings render into.
- **`ci.md`, broken steps and post-merge builds.** A new "Why some steps
show as broken" section says that on a PR the label rules remove the
steps a label skips, so they don't appear at all, that the scope guard
is the one label-gated step still shown as `broken` on an unlabeled PR,
and that scheduled post-merge builds don't apply label rules, so all
three label-gated steps show as `broken` there. The page also
distinguishes the two kinds of post-merge build on `master`. The build
each merge starts doesn't run the docs example tests, and the scheduled
builds that the release automation triggers run the full suite, so the
page now says "scheduled post-merge builds" wherever it means those.
- **`writing-code-snippets.md`, "How to test examples with GPUs."** It
told readers to open `doc/BUILD` and exclude their page from a
`glob(["source/**/*.rst"])` catch-all target. Neither exists: #66809 and
#67003 replaced library-wide prose targets with per-page
`doctest_each()` lists. The steps now show both cases: a doc page moves
from its library's `doctest_each` list to the GPU `doctest` rule, and a
docstring module moves from the CPU glob's `exclude` to the GPU rule. A
new short section says how a page with its first runnable example joins
CI, which the `doc_prose_doctest_targets` lint enforces.
- **`docs.md` and `writing-style.md`.** Both said CI enforces Vale. The
`documentation_style` check is out of the `lint.rayci.yml` matrix for
now, so they say the check is temporarily off.
- **`ci/ray_ci/doc/README.md`.** It described only the doc build and the
API guard. It now covers the scripts behind the `docs-example-test` and
`docstring-only` labels and `linkcheck_report.py`.
- **`doc/README.md`.** It said CI doesn't run linkcheck. The postmerge
`doc: linkcheck` step does, as a soft-fail step that never blocks.

Docs-only. No CI or behavior changes.

## Related issue number

None. Follows #66806, #66809, #66814, #67003, and #67083.

## Duplicate check

Not a duplicate. `gh pr list --repo ray-project/ray --state open`
searches for `"ci.md docstring"`, `"writing-code-snippets"`, and
`"ci/ray_ci/doc README"` return two other open PRs that touch these
files, both mine, neither covering these sections:

- #65868 adds a "How to test a Ray Serve deployment" section to
`writing-code-snippets.md` at the same insertion point as this PR's new
section, so whichever merges second needs a trivial rebase.
- #66884 updates the LLM doc paths in `ci.md`, not the docstring-only
section.

## Testing

- Every changed claim was checked against `master` at 3ae1b8b:
`.buildkite/others.rayci.yml`, `.buildkite/data.rayci.yml`,
`.buildkite/lint.rayci.yml`, `.buildkite/doc.rayci.yml`,
`doc/BUILD.bazel`, `python/ray/train/BUILD.bazel` (the GPU rule examples
are copied from the real `doctest[train-gpu]` and
`py_doctest[train-gpu]` rules), `doc/test_prose_doctest_targets.py`, and
the scripts under `ci/ray_ci/doc/`.
- `pre-commit run` on the changed files passes, including the
master-link check.
- Not run: a Sphinx build. The Read the Docs preview on this PR is the
check.

AI assistance (Claude Code) was used to find the stale text and draft
the changes. 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]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…deployments

Add a section to the code-snippets contributor guide covering how to
test that a Ray Serve application deploys, by polling serve.status()
until the application reaches RUNNING and raising on DEPLOY_FAILED,
UNHEALTHY, or timeout. An HTTP status_code == 200 check proves the
endpoint answered but not that the deployment reached a healthy state.

The snippet uses only public modules and matches the app-name access
pattern used in the LLM Serve doc examples.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the doc-910-serve-status-pattern branch from 7ce2e9c to e7c1371 Compare October 29, 2026 20:42
dstrodtman added a commit that referenced this pull request Nov 2, 2026
#67639)

## Description

Stacked on #67429, which is stacked on #67426.

#67426 tells contributors not to add new notebooks, but other
contributor docs still offer the in-tree notebook flow as a way to
publish a new example. This PR removes those instructions and keeps only
what someone needs to maintain the two notebook examples that remain.

### What this PR changes

- `doc/source/ray-contribute/publishing-examples-legacy.md`: rewrites
the page as "Maintaining an in-tree notebook example." It keeps its file
name and its `publishing-examples-legacy` label, so no redirect is
needed.
- It names the two examples that still use the flow,
`serve/tutorials/video-analysis` and
`train/examples/transformers/transformer-reinforcement-learning`. These
are the only `working_dir: //doc/...` entries in
`release/release_tests.yaml`.
- It drops the steps for publishing a new notebook: setting up a working
directory, the `content/` layout, and wiring a toctree or
`examples.yml`. Neither remaining example uses the `content/` layout.
Each one has `README.ipynb`, a `README.md` copy, and `ci/`, and
`exclude_patterns` in `conf.py` decides which file renders.
- It drops the `orphan: true` advice. `conf.py` sets `orphan` on every
page an `examples.yml` gallery links to through
`collect_example_orphans()`.
- It keeps the cell-tag guidance from #67426, the CI test, the release
test, triggering it, and the pre-merge checks, all reworded for an
existing example. The `tests.sh` sample matches what both examples run.
The trigger example uses the real test name `video_analysis_pipeline`.
- `doc/source/ray-contribute/publishing-examples.md`: replaces "Two ways
to publish an example" with a description of the template-collections
flow. It says not to publish a new example as an in-tree notebook and
links the maintenance page.
- `doc/README.md`: replaces "Adding examples as MyST Markdown Notebooks"
with "Running in-tree notebooks." It says not to add new notebooks,
points to `docs.md`, and keeps the `RUN_NOTEBOOKS` instructions, which
`conf.py` still reads as `nb_execution_mode`. It drops the paragraph
that recommended notebooks for examples and a commented-out link to a
tutorial that no longer exists.
- `doc/source/ray-contribute/writing-code-snippets.md`: "When to use
*literalinclude*" said to use it for "an end-to-end example," which
conflicts with #67426's end-to-end guide, which CI doesn't test. It now
says "a longer example" and links `writing-e2e-guide`.
- `doc/source/core/objects/object-spilling.md`: turns a `{doctest}`
block into a plain `python` block. The block has no `>>>` prompt and no
target, so it ran nothing, and it was the last `{doctest}` block on a
documentation page. #67432 missed it because it searched for `>>>`.

## Related issues

Stacked on #67429 and #67426. Follows #67432, which converted the other
page doctests.

## Additional information

### Duplicate check

I searched open PRs for `publishing-examples-legacy`, `in-tree
notebook`, `RUN_NOTEBOOKS`, `object-spilling`, `writing-code-snippets`,
and changes to `doc/README.md`. No open PR rewrites the legacy page or
the README section. #66851 also edits `object-spilling.md`, and #65868
also edits `writing-code-snippets.md`, in other hunks. `git merge-tree`
reports no conflicts with either.

### Testing

- `pre-commit run --files` on the changed files passes, including the
check that links to files on master resolve.
- `python doc/test_prose_doctest_targets.py` passes: "73 listed pages;
every runnable page is accounted for."
- `rayci test-rules` at v0.51.0, the version `.rayciversion` pins,
passes.
- `vale` on the rewritten pages: no new alerts beyond a passive-voice
flag on an unchanged sentence. The alerts in `doc/README.md` are all on
lines this PR doesn't change.
- 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]>
abrarsheikh pushed a commit that referenced this pull request Nov 5, 2026
## Description

**Stacked on #67069** (Serve advanced guides style pass), because both
edit `dev-workflow.md`. Merge #67069 first, then retarget this PR to
`master`.

Adds a "Write unit and integration tests" section to the Ray Serve
development workflow page. It follows the testing approach that Ray
Serve maintainers lay out in #44464 and its duplicate #34477:
- Keep business logic in a plain base class so you can unit test it
without Ray, and reach a deployment's underlying class through
`func_or_class`.
- Integration test by deploying with `serve.run`, then calling the app
through the returned `DeploymentHandle`
(`handle.method.remote(...).result()`) and over HTTP with `requests`.

The examples live in a new tested file,
`doc/source/serve/doc_code/testing_patterns.py`, which the existing
`source/serve/doc_code/**/*.py` glob in `doc/BUILD.bazel` already picks
up. FastAPI's `TestClient` is left out, because the issue says it's
untested with Serve. The `serve.status()` polling pattern is covered
separately by #65868 in the contributor guide.

Sources: #44464 and #34477, `python/ray/serve/deployment.py`
(`func_or_class`), `python/ray/serve/api.py` (`serve.run` returns a
`DeploymentHandle`), `python/ray/serve/handle.py`
(`DeploymentResponse.result()`).

## Related issues

Closes #44464

## Review notes

- The snippets show `from summarizer import ...`. The test file makes
that import work by registering `sys.modules["summarizer"]` outside the
include markers. Is that acceptable, or should the snippets drop the
import lines?
- The test target binds port 8000, and the serve `doc_code` targets are
tagged `exclusive`.

## Not a duplicate

`gh pr list --state open --search "44464 in:body"` returns nothing.
#65868 is related but documents a different pattern.

## Testing

- `python doc/source/serve/doc_code/testing_patterns.py` with
`ray[serve]==2.59.0`: 4 passed (`test_doubler_class`,
`test_summarize_truncates_text`, `test_summarize_with_handle`,
`test_summarize_with_http`).
- `make -C doc rtd-build`: `build succeeded.` with exit code 0 and no
Sphinx warnings.
- Vale on `dev-workflow.md`: no errors. `ruff check` on the new file:
clean.

## AI assistance

Drafted with AI assistance (Claude Code). The API usage was checked
against the Serve source and the example was run locally.

🤖 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]>

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

serve Ray Serve Related Issue unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant