Skip to content

[docs] Drop private-module import from LLM Serve doc examples - #65381

Closed
dstrodtman wants to merge 1 commit into
ray-project:masterfrom
dstrodtman:doc-1479-serve-default-app-name
Closed

dstrodtman wants to merge 1 commit into
ray-project:masterfrom
dstrodtman:doc-1479-serve-default-app-name

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Description

The 13 LLM Serve documentation examples under doc/source/llm/doc_code/serve/ each imported SERVE_DEFAULT_APP_NAME from ray.serve._private.constants so their CI polling loop could look up the deployed application by name:

from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
...
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status

These files are executed by CI, so this couples the doc build to a private Serve module. It also buys nothing: every one of the 13 calls serve.run(app) exactly once with no name=, so there is exactly one application and the loop never needs to name it.

This replaces the keyed lookup with the single application's status:

status = next(iter(serve.status().applications.values())).status

No published example content changes. Every edited line sits outside the literalinclude marker regions these files expose to the docs, so the rendered pages are byte-identical. Three of the files (custom_vllm_yaml_config_example.py, direct_streaming_yaml_config_example.py, llm_yaml_config_example.py) aren't referenced by any doc page at all and exist purely as CI tests.

Related issues

Related to #58624, which covers the separate ray.serve._private.common.DeploymentID case in doc/source/serve/doc_code/autoscaling_policy.py. That one needs a symbol relocated and is not addressed here.

Additional information

Part of a broader pass removing private-module imports from executed documentation examples. This is the mechanical subset: one repeated pattern, no public API change, no rendered-doc change.

black and ruff report the same findings on these files before and after this change (5 files black would reformat, 20 ruff errors), all pre-existing and inside published example regions, so this PR leaves them alone. Note that doc/source/ is excluded from the repo's pre-commit hooks, so those tools were run directly rather than via pre-commit.

The 13 LLM Serve documentation examples under doc/source/llm/doc_code/serve
imported SERVE_DEFAULT_APP_NAME from ray.serve._private.constants to look up
the deployed application in their CI polling loop.

These files are executed by CI, so the import couples the doc build to a
private Serve module for no benefit: each example deploys exactly one
unnamed application, so the polling loop can read that application directly
without naming it.

Replace the keyed lookup with the single application's status. No published
example content changes -- every edited line sits outside the literalinclude
marker regions, so the rendered docs are byte-identical.

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested review from a team as code owners August 11, 2026 18: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 removes the usage of the private constant SERVE_DEFAULT_APP_NAME across multiple Ray Serve example scripts, replacing it with dynamically fetching the status of the first application using next(iter(serve.status().applications.values())).status. The reviewer pointed out a potential issue where serve.status().applications could be empty during startup, which would cause next(iter(...)) to raise a StopIteration exception and crash the script. They recommended using next(iter(...), None) to handle empty applications gracefully.

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

    app_status = next(iter(serve.status().applications.values()), None)
    status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

    app_status = next(iter(serve.status().applications.values()), None)
    status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
status = next(iter(serve.status().applications.values())).status

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

If serve.status().applications is empty (for example, during initial startup or if there is a slight delay in application registration), calling next(iter(...)) will raise a StopIteration exception and crash the script. Using next(iter(...), None) handles the empty case gracefully by returning None instead of raising an exception.

Suggested change
status = next(iter(serve.status().applications.values())).status
app_status = next(iter(serve.status().applications.values()), None)
status = app_status.status if app_status else None

@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Aug 11, 2026
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue docs An issue or change related to documentation labels Aug 11, 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 Aug 28, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation go add ONLY when ready to merge, run all tests 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.

2 participants