chore: robust URL resolution, consolidated domain defaults, and generalized runbook (PR #244 fixes)#246
Conversation
…tions in AGENTS.md
…vironment variable
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… single x570.vendeuvre.lan domain
…leak / TLS bypass
…up false failures
…al_host/port resolution, fix agy startup SSH commands
…uccess endpoints, nohup stdin redirect)
…add fallbacks, avoid duplicate variables)
…PLACEHOLDER, HOME_PLACEHOLDER, and RUN_USER_PLACEHOLDER
…g subpath if missing
…tilizing PUBLIC_BASE_URL
…ack URLs, and generalize AGENTS.md runbook
Reviewer's GuideCentralizes external URL resolution and routing domain configuration, adds safer validation and fallbacks for dashboard links, exports derived base URLs into the pod, and generalizes production/runbook documentation while re-enabling a local model in LiteLLM. Sequence diagram for dashboard URL resolution with resolve_external_urlssequenceDiagram
actor User
participant FastAPIApp
participant get_dashboard
participant resolve_external_urls
User->>FastAPIApp: HTTP_GET_/dashboard
FastAPIApp->>get_dashboard: route_handler
get_dashboard->>resolve_external_urls: resolve_external_urls(request)
resolve_external_urls-->>get_dashboard: langfuse_url, litellm_url, llama_url
get_dashboard-->>User: HTMLResponse_with_dynamic_links
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
Next review available in: 33 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?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 reviews. How do review 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 refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ 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 |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="router/main.py" line_range="3133-3134" />
<code_context>
+ f"{external_scheme}://{external_netloc}/llm-routing/litellm/ui",
+ f"{external_scheme}://{external_netloc}/llm-routing/llama/"
+ )
+ elif is_valid_base:
+ netloc = request.url.netloc if re.match(r"^[a-zA-Z0-9.-]+(?::\d+)?$", request.url.netloc) else "localhost"
+ base = f"{external_scheme}://{netloc}"
+ return (
</code_context>
<issue_to_address>
**issue:** Netloc validation here still rejects IPv6 and some proxy-style netlocs, undermining the earlier relaxed handling.
The earlier `resolve_external_urls` branch relaxes validation via `urlparse`, allowing IPv6 literals and proxy-style netlocs. Here, `^[a-zA-Z0-9.-]+(?::\d+)?$` rejects valid values like `[::1]:5000`, forcing an incorrect fallback to `localhost`. To keep behavior consistent and avoid breaking proxied/IPv6 deployments, consider parsing `request.url.netloc` with `urlparse` and only falling back when the parsed hostname is missing or invalid.
</issue_to_address>
### Comment 2
<location path="router/main.py" line_range="3142-3151" />
<code_context>
+ f"{base}/llm-routing/llama/"
+ )
+ else:
+ # Local development fallback: derive ports and paths dynamically from configuration constants
+ parsed_lf = urlparse(LANGFUSE_HOST)
+ parsed_ll = urlparse(LITELLM_URL)
+ parsed_lm = urlparse(LLAMA_SERVER_URL)
+
+ lf_port = f":{parsed_lf.port}" if parsed_lf.port else ""
+ ll_port = f":{parsed_ll.port}" if parsed_ll.port else ""
+ lm_port = f":{parsed_lm.port}" if parsed_lm.port else ""
+
+ lf_path = parsed_lf.path
+ ll_path = parsed_ll.path or "/ui"
+ if not ll_path.endswith("/ui") and not ll_path.endswith("/ui/"):
+ ll_path = ll_path.rstrip("/") + "/ui"
+ lm_path = parsed_lm.path
+
+ return (
+ f"http://{external_host}{lf_port}{lf_path}",
+ f"http://{external_host}{ll_port}{ll_path}",
+ f"http://{external_host}{lm_port}{lm_path}"
+ )
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Local fallback hardcodes `http` and ignores the original schemes, which can break HTTPS dev setups.
In the local-dev fallback, all three URLs are forced to `http://{external_host}...`, even if `LANGFUSE_HOST`, `LITELLM_URL`, or `LLAMA_SERVER_URL` use HTTPS or another scheme. This can cause mixed-content errors or break setups where services only listen on HTTPS. Please derive the scheme from `parsed_lf`, `parsed_ll`, and `parsed_lm` (defaulting to `http` when absent) instead of hardcoding `http`.
Suggested implementation:
```python
else:
# Local development fallback: derive schemes, ports, and paths dynamically from configuration constants
parsed_lf = urlparse(LANGFUSE_HOST)
parsed_ll = urlparse(LITELLM_URL)
parsed_lm = urlparse(LLAMA_SERVER_URL)
lf_scheme = parsed_lf.scheme or "http"
ll_scheme = parsed_ll.scheme or "http"
lm_scheme = parsed_lm.scheme or "http"
lf_port = f":{parsed_lf.port}" if parsed_lf.port else ""
ll_port = f":{parsed_ll.port}" if parsed_ll.port else ""
lm_port = f":{parsed_lm.port}" if parsed_lm.port else ""
lf_path = parsed_lf.path or ""
ll_path = parsed_ll.path or "/ui"
if not ll_path.endswith("/ui") and not ll_path.endswith("/ui/"):
ll_path = ll_path.rstrip("/") + "/ui"
lm_path = parsed_lm.path or ""
return (
f"{lf_scheme}://{external_host}{lf_port}{lf_path}",
f"{ll_scheme}://{external_host}{ll_port}{ll_path}",
f"{lm_scheme}://{external_host}{lm_port}{lm_path}"
)
```
If the surrounding code assumes non-empty paths, you may want to normalize `lf_path` and `lm_path` (e.g., ensure they start with `/`) based on how `LANGFUSE_HOST`, `LITELLM_URL`, and `LLAMA_SERVER_URL` are typically configured elsewhere in the codebase.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic URL resolution for Langfuse, LiteLLM, and Llama.cpp in the router dashboard, replacing hardcoded local paths and hostnames with environment-driven placeholders across configurations, scripts, and documentation. It also re-enables the local Qwen model on a new port, updates the free models roster, and adds a production deployment checklist. The review feedback highlights a duplicate import of urlparse and recommends improving IPv6 compatibility in the new URL resolution logic by allowing colons in the host validation regex and wrapping IPv6 addresses in square brackets for fallback URLs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if not isinstance(external_host, str) or not re.match(r"^[a-zA-Z0-9.-]+$", external_host): | ||
| logger.warning( | ||
| "Unexpected external_host %r, falling back to request.base_url.hostname (%r)", | ||
| external_host, | ||
| request.base_url.hostname, | ||
| ) | ||
| external_host = request.base_url.hostname or "localhost" |
There was a problem hiding this comment.
The regular expression r"^[a-zA-Z0-9.-]+$" used for sanity-checking external_host does not allow colons (:), which causes valid IPv6 addresses (e.g., ::1) to fail the check and trigger a warning, even though IPv6 support is intended.
| if not isinstance(external_host, str) or not re.match(r"^[a-zA-Z0-9.-]+$", external_host): | |
| logger.warning( | |
| "Unexpected external_host %r, falling back to request.base_url.hostname (%r)", | |
| external_host, | |
| request.base_url.hostname, | |
| ) | |
| external_host = request.base_url.hostname or "localhost" | |
| if not isinstance(external_host, str) or not re.match(r"^[a-zA-Z0-9.-:]+$", external_host): | |
| logger.warning( | |
| "Unexpected external_host %r, falling back to request.base_url.hostname (%r)", | |
| external_host, | |
| request.base_url.hostname, | |
| ) | |
| external_host = request.base_url.hostname or "localhost" |
| return ( | ||
| f"http://{external_host}{lf_port}{lf_path}", | ||
| f"http://{external_host}{ll_port}{ll_path}", | ||
| f"http://{external_host}{lm_port}{lm_path}" | ||
| ) |
There was a problem hiding this comment.
When formatting fallback URLs for local development, if external_host is an IPv6 address (containing colons), it must be enclosed in square brackets (e.g., [::1]) to produce syntactically valid URLs.
| return ( | |
| f"http://{external_host}{lf_port}{lf_path}", | |
| f"http://{external_host}{ll_port}{ll_path}", | |
| f"http://{external_host}{lm_port}{lm_path}" | |
| ) | |
| host_formatted = f"[{external_host}]" if ":" in external_host else external_host | |
| return ( | |
| f"http://{host_formatted}{lf_port}{lf_path}", | |
| f"http://{host_formatted}{ll_port}{ll_path}", | |
| f"http://{host_formatted}{lm_port}{lm_path}" | |
| ) |
| from typing import Dict, Optional, Union | ||
| from urllib.parse import urlparse |
There was a problem hiding this comment.
…tibility in external URL resolution and local fallback formatting
|
|
||
| # Basic sanity-check on external_host, but don't over-restrict valid hostnames; | ||
| # fall back to the request base URL rather than silently forcing localhost. | ||
| if not isinstance(external_host, str) or not re.match(r"^[a-zA-Z0-9.-:]+$", external_host): |
This PR resolves review comments from PR #244, introduces robust URL resolution safety, consolidates routing domain config, and refactors local port-independent fallbacks.
Key Changes
get_dashboardinto a small, testable utility functionresolve_external_urls(request: Request) -> tuple[str, str, str]inrouter/main.py.PUBLIC_BASE_URL(passed directly to thellm-triage-routercontainer) as the primary source of truth, fallbacking toBASEURL/BASE_URL/request.base_urlsecurely to prevent configuration drift between shell scripts and Python.resolve_external_urlsinrouter/main.pyto support reverse proxy netlocs, IPv6, and IDN punycodes.llm-triage-routerlogger.ROUTING_DOMAINvariable (default:vendeuvre.lan), exporting and passing it directly to the container inpod.yaml.start-stack.shleveragingROUTING_DOMAIN.LANGFUSE_HOST,LITELLM_URL, andLLAMA_SERVER_URLviaurlparseinstead of hardcoding ports..agents/AGENTS.mdto replace host-specific paths and user names (boy,/mnt/DATA/boy/...,x570.vendeuvre.lan) with clean, generic variables (<prod-host>,<prod-home>,<prod-domain>), ensuring portability.Summary by Sourcery
Centralize and harden external URL resolution for the dashboard while aligning deployment and routing configuration around portable, environment-driven base URLs and domains.
Enhancements:
Documentation: