Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ COPY . .
# Convert Windows line endings to Unix and make executable
RUN sed -i 's/\r$//' docker/build_admin_ui.sh && chmod +x docker/build_admin_ui.sh && ./docker/build_admin_ui.sh

# Pre-restructure UI: move root-level {page}.html → {page}/index.html so
# Starlette StaticFiles can serve extensionless routes (e.g. /ui/chat).
# Must run before building the wheel since the out/ dir is included in the package.
RUN cd litellm/proxy/_experimental/out && \
for html_file in *.html; do \
if [ "$html_file" != "index.html" ] && [ "$html_file" != "404.html" ] && [ -f "$html_file" ]; then \
folder_name="${html_file%.html}" && \
mkdir -p "$folder_name" && \
mv "$html_file" "$folder_name/index.html"; \
fi; \
done && \
touch .litellm_ui_ready
Comment on lines +30 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Silent partial restructure with marker file written

If any individual mv operation fails (e.g. a pre-existing {page}/index.html conflicts, or a filesystem error occurs), the for loop continues because shell for loops do not propagate inner command failures to the outer flow. The final touch .litellm_ui_ready then still executes, marking the UI as fully restructured even if some HTML files were not moved.

At runtime _is_ui_pre_restructured() sees the marker file and returns True early, skipping the Python fallback, so the unprocessed route will still 404.

Consider adding set -e at the top of the RUN or using || exit 1 after the move to ensure the build fails loudly rather than silently producing a partial result:

Suggested change
RUN cd litellm/proxy/_experimental/out && \
for html_file in *.html; do \
if [ "$html_file" != "index.html" ] && [ "$html_file" != "404.html" ] && [ -f "$html_file" ]; then \
folder_name="${html_file%.html}" && \
mkdir -p "$folder_name" && \
mv "$html_file" "$folder_name/index.html"; \
fi; \
done && \
touch .litellm_ui_ready
RUN set -e && cd litellm/proxy/_experimental/out && \
for html_file in *.html; do \
if [ "$html_file" != "index.html" ] && [ "$html_file" != "404.html" ] && [ -f "$html_file" ]; then \
folder_name="${html_file%.html}" && \
mkdir -p "$folder_name" && \
mv "$html_file" "$folder_name/index.html"; \
fi; \
done && \
touch .litellm_ui_ready


# Build the package
RUN rm -rf dist/* && python -m build

Expand Down
22 changes: 21 additions & 1 deletion litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,27 @@ def _is_ui_pre_restructured(ui_dir: str) -> bool:
if entry.is_dir() and not entry.name.startswith("_"):
index_path = os.path.join(entry.path, "index.html")
if os.path.exists(index_path):
# Found at least one restructured route - this proves the pattern
# Found at least one restructured route.
# Also verify no root-level .html files still need restructuring.
# Next.js static export may generate both pre-restructured pages
# (e.g. login/index.html) and new pages as root-level .html files
# (e.g. chat.html), causing the heuristic to fire prematurely.
try:
orphaned = [
e.name
for e in os.scandir(ui_dir)
if e.is_file()
and e.name.endswith(".html")
and e.name not in ("index.html", "404.html")
]
except (PermissionError, OSError):
orphaned = []
if orphaned:
verbose_proxy_logger.debug(
f"Found un-restructured HTML files at root: {orphaned}. "
f"Restructuring needed despite existing {entry.name}/index.html."
)
return False
Comment on lines +1212 to +1227
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant directory scan on every matched entry

The inner os.scandir(ui_dir) is launched inside the outer for entry in os.scandir(ui_dir) loop, effectively scanning the same directory twice. In the current implementation the function always returns on the first matching entry, so the double-scan is harmless, but it is an implicit invariant that future readers may not notice.

Consider hoisting the orphan check outside the loop so it is only performed once after confirming at least one restructured directory exists:

restructured_found = None
for entry in os.scandir(ui_dir):
    if entry.is_dir() and not entry.name.startswith("_"):
        index_path = os.path.join(entry.path, "index.html")
        if os.path.exists(index_path):
            restructured_found = entry.name
            break

if restructured_found:
    try:
        orphaned = [
            e.name
            for e in os.scandir(ui_dir)
            if e.is_file()
            and e.name.endswith(".html")
            and e.name not in ("index.html", "404.html")
        ]
    except (PermissionError, OSError):
        orphaned = []
    if orphaned:
        verbose_proxy_logger.debug(...)
        return False
    verbose_proxy_logger.debug(...)
    return True

verbose_proxy_logger.debug(
f"Detected restructured UI via pattern: found {entry.name}/index.html"
)
Expand Down
Loading