Skip to content

fix(proxy): serve dashboard routes from flat Next.js exports without restructuring - #35751

Open
davesheffer wants to merge 1 commit into
BerriAI:mainfrom
davesheffer:litellm_ui_html_fallback_serve
Open

davesheffer wants to merge 1 commit into
BerriAI:mainfrom
davesheffer:litellm_ui_html_fallback_serve

Conversation

@davesheffer

@davesheffer davesheffer commented Aug 4, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Direct navigation to /ui/chat and other UI sub-routes returns 404
  • Startup restructure needs a writable filesystem, so read-only deployments stay broken

How it solves it:

  • /ui mount serves the sibling <route>.html when <route>/index.html is missing
  • Both export layouts now work as-is, with zero disk writes at startup

Relevant issues

Fixes #24037

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests) — all green except osv-scan, which is the pre-existing cryptography CVE failure that has been red on every branch since 2026-08-03 and is fixed by fix(deps): bump cryptography to 49.0.0 to clear osv-flagged CVEs #35759; it is unrelated to this PR
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

The failing deployment shape from the issue is a UI bundle in the pre-trailingSlash layout (chat.html next to an index-less chat/ RSC data directory) served from a location where the startup restructure cannot run, which is what a read-only pod filesystem looks like in practice. To reproduce it locally I copied litellm/proxy/_experimental/out, moved each route's index.html back to a sibling <route>.html, and dropped a .litellm_ui_ready marker so startup skips the restructure, exactly like a read-only filesystem would

Both runs start the proxy the same way and hit it with plain curl:

LITELLM_UI_PATH=/path/to/flat_ui litellm --config config.yaml --port 4000
for route in chat logs models-and-endpoints api-keys usage; do
  printf "GET /ui/%s -> " "$route"
  curl -sS -o /dev/null -w "%{http_code} (final: %{url_effective})\n" -L "http://localhost:4000/ui/$route"
done

Before, at a625d1e:

GET /ui/chat -> 404 (final: http://localhost:4000/ui/chat)
GET /ui/logs -> 404 (final: http://localhost:4000/ui/logs)

curl -i http://localhost:4000/ui/chat returns HTTP/1.1 404 Not Found with the Next.js <title>404: This page could not be found.</title> page, which is exactly what users report in #24037

After, at 6257a6c:

GET /ui/chat -> 200 (final: http://localhost:4000/ui/chat/)
GET /ui/logs -> 200 (final: http://localhost:4000/ui/logs/)
GET /ui/models-and-endpoints -> 200 (final: http://localhost:4000/ui/models-and-endpoints/)
GET /ui/api-keys -> 200 (final: http://localhost:4000/ui/api-keys/)
GET /ui/usage -> 200 (final: http://localhost:4000/ui/usage/)

$ curl -sS -L http://localhost:4000/ui/chat | grep -o "<title>[^<]*</title>"
<title>LiteLLM Dashboard</title>

After serving, flat_ui/chat/ still has no index.html and chat.html is still at the top level, confirming the proxy wrote nothing to the bundle

Type

🐛 Bug Fix

Changes

StaticFiles(html=True) resolves /ui/chat by matching the chat/ directory first and looking for chat/index.html; the sibling chat.html is never tried, so the request 404s. The existing compensation moves files around at startup (_restructure_ui_html_files), but it only runs when the UI directory is writable, so read-only deployments serving a flat bundle keep failing, as reported on the issue as recently as v1.90.0

This PR adds UiStaticFiles in litellm/proxy/common_utils/ui_static_files.py, a StaticFiles subclass that falls back at lookup time: when a lookup misses, it retries <route>/index.html as <route>.html, and a plain extensionless miss as <route>.html. The /ui mount in proxy_server.py now uses it. Restructured bundles resolve on the first lookup and never reach the fallback, flat bundles resolve on the retry, and nothing is written to disk either way

Tests in tests/test_litellm/proxy/common_utils/test_ui_static_files.py cover the flat layout with and without the shadowing directory, the restructured layout, the guarantee that serving writes nothing to disk, plain asset files, and unknown routes still returning 404. The flat-layout cases fail against vanilla StaticFiles, so a regression of #24037 fails the suite

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

…restructuring

Next.js exports built without trailingSlash emit chat.html plus an
index-less chat/ data directory. StaticFiles(html=True) matches the
directory first, looks for chat/index.html, and 404s direct navigation
to /ui/chat. The startup restructure that compensates for this needs a
writable filesystem, so read-only deployments keep returning 404.

Resolve the fallback at lookup time instead: when <route>/index.html is
missing, serve the sibling <route>.html. Both export layouts now work
as-is with zero writes to disk at startup.

Fixes BerriAI#24037
@CLAassistant

CLAassistant commented Aug 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a Starlette static-file subclass that serves flat Next.js route exports without startup filesystem writes and switches the dashboard mount to use it

  • Retries missing <route>/index.html lookups as sibling <route>.html files
  • Preserves ordinary static assets and already restructured route exports
  • Adds regression coverage for flat, shadowed, restructured, unknown, and read-only-style layouts

Confidence Score: 5/5

The PR appears safe to merge; the fallback preserves standard static-file behavior while resolving flat dashboard exports

Starlette’s directory-index lookup reaches the new fallback for index-less route directories, and every retry still passes through the framework’s normal path-resolution and containment checks

Important Files Changed

Filename Overview
litellm/proxy/common_utils/ui_static_files.py Adds a contained lookup fallback for flat Next.js HTML exports while preserving Starlette’s standard resolution and path protections
litellm/proxy/proxy_server.py Replaces the /ui static mount with the specialized subclass without changing startup restructuring behavior
tests/test_litellm/proxy/common_utils/test_ui_static_files.py Provides focused regression coverage for both export layouts, shadowing directories, assets, missing routes, and the no-write requirement

Reviews (1): Last reviewed commit: "fix(proxy): serve dashboard routes from ..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing davesheffer:litellm_ui_html_fallback_serve (6257a6c) with litellm_internal_staging (956d517)

Open in CodSpeed

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:38
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 15:18
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 15:18

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /ui/chat returns 404 — Next.js static export missing index.html in chat/ directory

3 participants