Skip to content

[Serve][LLM] Lazily import RouterApplication to fix the docs build - #67741

Merged
dstrodtman merged 1 commit into
masterfrom
djs-261103-fix-serve-llm-docs-import
Nov 3, 2026
Merged

dstrodtman merged 1 commit into
masterfrom
djs-261103-fix-serve-llm-docs-import

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Why are these changes needed?

The Ray docs build on master has failed on every commit since #66519 merged. Sphinx aborts during autosummary setup with no module named ray.serve.llm (for example, RtD build 4665012). That message masks the real import error:

ray/serve/llm/__init__.py
 -> ingress/builder.py           from ...router_application import RouterApplication  (module level, added in #66519)
 -> ingress/router_application.py from ...ingress.router import (...)
 -> ingress/router.py:75         @serve.ingress(router_app)
 -> serve/api.py:446             isinstance(app, (FastAPI, APIRouter))
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

The docs build mocks fastapi (doc/source/api_mock_imports.py), so FastAPI isn't a real type there. builder.py already avoids this by importing LLMRouter lazily inside _build_openai_ingress_request_router. The new top-level RouterApplication import pulled router.py back in at import time.

This PR moves the RouterApplication import into build_openai_router_app, the only place that uses it. #66519 changed nothing under doc/, so its RtD previews were skipped by the doc-change guard and the break first showed up on master. The commit carries an @rtd-build line so this PR builds a preview.

Duplicate check

I searched open PRs for RouterApplication, serve llm import docs, and the #66519 author's open PRs, and found nothing that addresses this break.

Testing

  • Reproduced the failure by importing ray.serve.llm from source with Sphinx's sphinx.ext.autodoc.mock.mock() active over the docs mock list, in a venv built from doc/requirements-doc.lock.txt. The import fails at dec986ce ([Serve][LLM][3/5] Add multi-application OpenAI routing #66519) with the traceback above, succeeds at its parent c2adf94c, and succeeds with this change.
  • I didn't run the Serve LLM unit tests locally. Premerge CI covers test_builder_openai_router_app.py and the router tests, and the RtD preview on this PR confirms the docs build.

AI assistance

Claude Code helped diagnose the build failure and draft this change. I reviewed the change and the analysis.

🤖 Generated with Claude Code

builder.py imported RouterApplication at module level. router_application
imports router, whose module-level @serve.ingress(FastAPI()) raises a
TypeError when fastapi is mocked, as it is in the Sphinx docs build. That
broke `import ray.serve.llm` and failed every master docs build since #66519.

Import RouterApplication inside build_openai_router_app, matching the
existing lazy LLMRouter import in _build_openai_ingress_request_router.

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested a review from a team as a code owner November 3, 2026 14:00

@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 moves the import of RouterApplication from the module level to a lazy import inside the build_openai_router_app function. This prevents import failures when fastapi is mocked, such as during documentation builds, which previously broke import ray.serve.llm. There are no review comments, and I have no additional feedback to provide.

@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Nov 3, 2026
@dstrodtman
dstrodtman merged commit daf6c86 into master Nov 3, 2026
7 checks passed
@dstrodtman
dstrodtman deleted the djs-261103-fix-serve-llm-docs-import branch November 3, 2026 16:16
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants