fix(chainlit): serve source downloads from standalone Chainlit app (Ray Serve mode)#578
Conversation
In Ray Serve mode the API and Chainlit run on separate ports (the API via
`serve.run`, Chainlit via its own `uvicorn.run` on `chainlit_port`). Source
previews rewrite their file download links to the browser origin — which in
that topology is the Chainlit host, not the API host. But the standalone
Chainlit app (`chainlit_api.app`) only mounted the Chainlit UI, so the
authorized `/static/{extract_id}` download route was absent there and every
PDF/image/audio source preview 404'd.
Mount `download_router` on the standalone Chainlit app so the rewritten
links resolve. The route reuses the same `AuthMiddleware` (cookie in OIDC
mode — cookies aren't port-scoped, so the session cookie set by the API is
sent to the Chainlit port too — and `?token=` in token mode) and resolves
its services from the container the middleware initializes. The mounted
(`/chainlit`) deployment is unaffected: the UI shares the API origin, which
already serves this route.
Adds a regression test asserting the standalone app exposes the route.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 26 minutes and 11 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Follow-up to a review finding on #568 (F9). In Ray Serve mode, source-document previews (PDFs/images/audio) fail to load in the Chainlit chat UI.
Why it's broken
In Ray Serve mode the API and Chainlit run on separate ports:
download_routermounted) viaserve.run(OpenRagAPI.bind(), route_prefix="/")onray.serve.port,uvicorn.run(chainlit_app, port=ray.serve.chainlit_port)— wherechainlit_appischainlit_api.app._format_sources(app_front.py) rewrites each file URL from the internal base URL to the browser origin (get_external_url(), derived from theReferer). In separate-port mode that origin is the Chainlit host, butchainlit_api.pyonly mounted the Chainlit UI — so/static/{extract_id}didn't exist there and every source preview 404'd.The default mounted
/chainlitdeployment is fine because the UI and API share one origin (the API already serves the route).Change
openrag/chainlit_api.py: mountdownload_routeron the standalone Chainlit FastAPI app.AuthMiddlewareruns here. In OIDC mode theopenrag_sessioncookie is sent to the Chainlit port too (cookies aren't port-scoped), and in token mode the preview link carries?token=. The route resolves its services from the container the middleware initializes onapp.state.container.tests/unit/test_chainlit_api_download.py: regression test asserting the standalone app exposesdownload_sourceat/static/{extract_id}(would fail before this change).Verification
uv run pytest tests/unit/test_chainlit_api_download.py tests/unit/test_chainlit_api_auth.py tests/unit/api/routers/user/test_download.py→ all passruff checkclean; layer-import guard OK🤖 Generated with Claude Code