Skip to content

fix(chainlit): serve source downloads from standalone Chainlit app (Ray Serve mode)#578

Closed
Ahmath-Gadji wants to merge 1 commit into
forward-port/main-to-hexagonalfrom
fix/ray-serve-source-download
Closed

fix(chainlit): serve source downloads from standalone Chainlit app (Ray Serve mode)#578
Ahmath-Gadji wants to merge 1 commit into
forward-port/main-to-hexagonalfrom
fix/ray-serve-source-download

Conversation

@Ahmath-Gadji

Copy link
Copy Markdown
Collaborator

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:

  • the API (with download_router mounted) via serve.run(OpenRagAPI.bind(), route_prefix="/") on ray.serve.port,
  • Chainlit via its own uvicorn.run(chainlit_app, port=ray.serve.chainlit_port) — where chainlit_app is chainlit_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 the Referer). In separate-port mode that origin is the Chainlit host, but chainlit_api.py only mounted the Chainlit UI — so /static/{extract_id} didn't exist there and every source preview 404'd.

The default mounted /chainlit deployment is fine because the UI and API share one origin (the API already serves the route).

Change

  • openrag/chainlit_api.py: mount download_router on the standalone Chainlit FastAPI app.
    • Auth is unchanged: the same AuthMiddleware runs here. In OIDC mode the openrag_session cookie 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 on app.state.container.
  • tests/unit/test_chainlit_api_download.py: regression test asserting the standalone app exposes download_source at /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 pass
  • ruff check clean; layer-import guard OK

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Ahmath-Gadji, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fb4c9173-e543-4eeb-aa49-e0a9e747091b

📥 Commits

Reviewing files that changed from the base of the PR and between e717a12 and 1e7af0f.

📒 Files selected for processing (2)
  • openrag/chainlit_api.py
  • tests/unit/test_chainlit_api_download.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ray-serve-source-download

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Ahmath-Gadji

Copy link
Copy Markdown
Collaborator Author

Folded directly into #568 as commit 18050a2 on forward-port/main-to-hexagonal (this PR's base), since it's a follow-up to #568's F9 finding and belongs in that branch. Closing — no separate PR needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants