Skip to content

Extract hardcoded microservice endpoint bindings#47

Merged
sheepdestroyer merged 3 commits into
masterfrom
fix/hardcoded-endpoints-739998213933189672
Jun 24, 2026
Merged

Extract hardcoded microservice endpoint bindings#47
sheepdestroyer merged 3 commits into
masterfrom
fix/hardcoded-endpoints-739998213933189672

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Extracted hardcoded LiteLLM, Llama.cpp, Langfuse, Valkey, and Agy daemon endpoints into environment variables with safe fallback constants. Updated router/main.py and router/agy_proxy.py to use these configurable parameters. Fixed an unrelated indentation error in router/main.py.

Fixes #43


PR created automatically by Jules for task 739998213933189672 started by @sheepdestroyer

Summary by CodeRabbit

  • Bug Fixes

    • Router and dashboard connections now use configured service URLs instead of hardcoded localhost addresses.
    • Health checks and startup readiness now follow the same environment-based endpoints, improving reliability in different deployments.
    • The AGY proxy now builds its run endpoint from a configurable base URL, with trailing slashes handled automatically.
  • New Features

    • Dashboard links and service port display now reflect the configured infrastructure endpoints, making environment setup easier to verify.

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @sheepdestroyer, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 51 minutes and 23 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e958d1a-caaa-4c28-9bbb-73df54e17a25

📥 Commits

Reviewing files that changed from the base of the PR and between 3d09707 and 1fd14b9.

📒 Files selected for processing (2)
  • router/agy_proxy.py
  • router/main.py
📝 Walkthrough

Walkthrough

Hardcoded 127.0.0.1 endpoint URLs for LiteLLM, Llama-server, Langfuse, Valkey, and the agy daemon are replaced with environment-variable-sourced constants (LITELLM_URL, LLAMA_SERVER_URL, LANGFUSE_URL, VALKEY_HOST/VALKEY_PORT, AGY_DAEMON_URL). All call sites, health checks, proxy routes, and dashboard UI elements are updated to use these derived values.

Changes

Environment-driven URL configuration

Layer / File(s) Summary
Global URL constants and port helpers
router/agy_proxy.py, router/main.py
Adds AGY_DAEMON_URL in agy_proxy.py and LITELLM_URL, LLAMA_SERVER_URL, LANGFUSE_URL, VALKEY_HOST/PORT constants plus port-extraction helpers in main.py, all normalised with rstrip("/") and localhost defaults.
Service client initialization
router/main.py
Valkey/Redis lazy client construction switches to derived VALKEY_HOST/VALKEY_PORT; Langfuse client construction receives LANGFUSE_URL as host.
Routing, proxy, and API call sites
router/agy_proxy.py, router/main.py
Replaces all hardcoded localhost URLs in router_api_base, LiteLLM admin calls (adaptive roster sync, Ollama DB registration), LiteLLM readiness polling, agy daemon /run URL (non-streaming and streaming), llama.cpp metrics fetches, and /v1/memory//v1/models proxy routes.
Dashboard health checks and UI
router/main.py
Health-check probes use configured URLs/ports for all four services; llamacpp metrics object added to dashboard data payload and rendering; Langfuse observability button, infrastructure port display nodes, and Quick Console Links updated from localhost to config-driven values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 No more 127.0.0.1 in my hutch,
Each service now answers to os.getenv and such.
LiteLLM, Llama, Langfuse, Valkey too —
Just set your env vars and they'll find their way through.
The hardcodes are gone, replaced with a shrug,
One rstrip and default — a tidy little hug. 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning router/agy_proxy.py adds Agy daemon URL configuration, which is not part of linked issue #43. Move the Agy daemon endpoint extraction to a separate issue or PR, or link it explicitly if it is intended scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: extracting hardcoded endpoint bindings into configurable values.
Linked Issues check ✅ Passed The main.py changes replace the hardcoded LiteLLM, Llama.cpp, and Langfuse URLs in the locations called out by #43.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hardcoded-endpoints-739998213933189672

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the codebase to externalize hardcoded service URLs and ports (such as LiteLLM, Llama-Server, Langfuse, Valkey, and AGY Daemon) into environment variables. Feedback on these changes highlights potential startup crashes if VALKEY_PORT is misconfigured as a non-integer, and suggests stripping trailing slashes from the configured URLs to prevent double-slash routing issues. Additionally, it is recommended to pre-calculate port suffixes at the module level to avoid fragile inline string splitting within the HTML dashboard templates.

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.

Comment thread router/main.py Outdated
Comment on lines +22 to +27
# Global Configuration from Environment
LITELLM_URL = os.getenv("LITELLM_ADMIN_URL", "http://127.0.0.1:4000")
LLAMA_SERVER_URL = os.getenv("LLAMA_SERVER_URL", "http://127.0.0.1:8080")
LANGFUSE_URL = os.getenv("LANGFUSE_URL", "http://127.0.0.1:3001")
VALKEY_HOST = os.getenv("VALKEY_HOST", "127.0.0.1")
VALKEY_PORT = int(os.getenv("VALKEY_PORT", "6379"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Parsing VALKEY_PORT directly as int at the module level without error handling can cause the application to crash on startup if the environment variable is misconfigured (e.g., set to an empty string or a non-numeric value). Previously, this parsing was safely wrapped in a try-except block inside get_redis(). Additionally, stripping trailing slashes from the configured URLs prevents potential double-slash issues when constructing API endpoints, and we can pre-calculate the port suffixes using urllib.parse.urlparse to avoid fragile string splitting in the HTML template.

from urllib.parse import urlparse

# Global Configuration from Environment
LITELLM_URL = os.getenv("LITELLM_ADMIN_URL", "http://127.0.0.1:4000").rstrip("/")
LLAMA_SERVER_URL = os.getenv("LLAMA_SERVER_URL", "http://127.0.0.1:8080").rstrip("/")
LANGFUSE_URL = os.getenv("LANGFUSE_URL", "http://127.0.0.1:3001").rstrip("/")
VALKEY_HOST = os.getenv("VALKEY_HOST", "127.0.0.1")

def _get_valkey_port() -> int:
    try:
        return int(os.getenv("VALKEY_PORT", "6379"))
    except ValueError:
        return 6379

VALKEY_PORT = _get_valkey_port()

def _get_port_suffix(url: str) -> str:
    try:
        port = urlparse(url).port
        return f":{port}" if port else ""
    except Exception:
        return ""

LITELLM_PORT = _get_port_suffix(LITELLM_URL)
LLAMA_SERVER_PORT = _get_port_suffix(LLAMA_SERVER_URL)
LANGFUSE_PORT = _get_port_suffix(LANGFUSE_URL)

Comment thread router/main.py Outdated
<div class="service-info">
<span class="service-name">LiteLLM Proxy</span>
<span class="service-port">:4000</span>
<span class="service-port">{':' + LITELLM_URL.split(':')[-1] if LITELLM_URL.count(':') > 1 else ''}</span>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using {LITELLM_PORT} pre-calculated at the module level is much cleaner and avoids fragile inline string splitting, which fails on IPv6 addresses or URLs with paths.

Suggested change
<span class="service-port">{':' + LITELLM_URL.split(':')[-1] if LITELLM_URL.count(':') > 1 else ''}</span>
<span class="service-port">{LITELLM_PORT}</span>

Comment thread router/main.py Outdated
<div class="service-info">
<span class="service-name">Llama-Server</span>
<span class="service-port">:8080</span>
<span class="service-port">{':' + LLAMA_SERVER_URL.split(':')[-1] if LLAMA_SERVER_URL.count(':') > 1 else ''}</span>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using {LLAMA_SERVER_PORT} pre-calculated at the module level is much cleaner and avoids fragile inline string splitting, which fails on IPv6 addresses or URLs with paths.

Suggested change
<span class="service-port">{':' + LLAMA_SERVER_URL.split(':')[-1] if LLAMA_SERVER_URL.count(':') > 1 else ''}</span>
<span class="service-port">{LLAMA_SERVER_PORT}</span>

Comment thread router/main.py Outdated
<div class="service-info">
<span class="service-name">Langfuse Traces</span>
<span class="service-port">:3001</span>
<span class="service-port">{':' + LANGFUSE_URL.split(':')[-1] if LANGFUSE_URL.count(':') > 1 else ''}</span>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using {LANGFUSE_PORT} pre-calculated at the module level is much cleaner and avoids fragile inline string splitting, which fails on IPv6 addresses or URLs with paths.

Suggested change
<span class="service-port">{':' + LANGFUSE_URL.split(':')[-1] if LANGFUSE_URL.count(':') > 1 else ''}</span>
<span class="service-port">{LANGFUSE_PORT}</span>

Comment thread router/agy_proxy.py Outdated

logger = logging.getLogger("agy-proxy")

AGY_DAEMON_URL = os.getenv("AGY_DAEMON_URL", "http://127.0.0.1:5005")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Strip trailing slashes from AGY_DAEMON_URL to prevent double slashes (e.g., //run) when constructing API endpoints, which can cause routing issues or 404 errors on some web servers.

Suggested change
AGY_DAEMON_URL = os.getenv("AGY_DAEMON_URL", "http://127.0.0.1:5005")
AGY_DAEMON_URL = os.getenv("AGY_DAEMON_URL", "http://127.0.0.1:5005").rstrip("/")

google-labs-jules Bot and others added 2 commits June 24, 2026 17:28
…bles

Extracted core target URLs for LiteLLM, Llama.cpp, Langfuse, Valkey, and Agy daemon into environment variables with safe fallback constants in `router/main.py` and `router/agy_proxy.py`. This improves deployment agility across varied network environments.

- Defined `LITELLM_URL`, `LLAMA_SERVER_URL`, `LANGFUSE_URL`, `VALKEY_HOST`, and `VALKEY_PORT` in `router/main.py`.
- Defined `AGY_DAEMON_URL` in `router/agy_proxy.py`.
- Updated health checks, proxy logic, and dashboard UI to use these constants.
- Fixed a minor indentation error in `detect_active_tool`.

Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
@sheepdestroyer
sheepdestroyer force-pushed the fix/hardcoded-endpoints-739998213933189672 branch from 5037d71 to 3d09707 Compare June 24, 2026 15:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@router/agy_proxy.py`:
- Line 46: The AGY_DAEMON_URL fallback handling in the module-level assignment
is bypassed when the env var is present but empty, causing requests in the proxy
flow to be built incorrectly. Update the AGY_DAEMON_URL initialization so the
default URL is used not only when the variable is missing, but also when it is
set to an empty string, and keep the existing rstrip("/") behavior. Use the
AGY_DAEMON_URL symbol in router/agy_proxy.py as the location to fix.

In `@router/main.py`:
- Around line 45-49: The environment variable initialization in router/main.py
currently uses os.getenv(..., default), which still accepts empty strings and
can leave LITELLM_URL, LLAMA_SERVER_URL, LANGFUSE_URL, or VALKEY_HOST blank.
Update the startup config handling around these constants so empty values are
treated the same as unset values and the intended safe defaults are applied. Use
the existing symbols LITELLM_URL, LLAMA_SERVER_URL, LANGFUSE_URL, and
VALKEY_HOST to centralize the fallback logic before any readiness or proxy code
consumes them.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4db56b88-adc3-4def-8fc6-506605c4d2ec

📥 Commits

Reviewing files that changed from the base of the PR and between 559382a and 3d09707.

📒 Files selected for processing (2)
  • router/agy_proxy.py
  • router/main.py

Comment thread router/agy_proxy.py Outdated
Comment thread router/main.py Outdated
@sheepdestroyer
sheepdestroyer merged commit eaf476a into master Jun 24, 2026
6 checks passed
@sheepdestroyer
sheepdestroyer deleted the fix/hardcoded-endpoints-739998213933189672 branch June 24, 2026 15:54
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.

[LHF-03] Hardcoded Microservice Endpoint Bindings

1 participant