Skip to content

fix: address PR#252 review comments + Gemini review fix (ROUTER_PORT/LANGFUSE_WEB_PORT)#254

Merged
sheepdestroyer merged 26 commits into
masterfrom
chore/learn-deployment-guidelines
Jul 11, 2026
Merged

fix: address PR#252 review comments + Gemini review fix (ROUTER_PORT/LANGFUSE_WEB_PORT)#254
sheepdestroyer merged 26 commits into
masterfrom
chore/learn-deployment-guidelines

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses all valid review comments from PR #252 (Gemini Code Assist + Sourcery), plus a fix for a Gemini review finding on PR #253.

Changes

Fix: safe_pod_teardown false timeout report (Gemini)

podman pod exists returns 0 for stopped pods too, so after a successful graceful stop the script falsely reported a timeout and force-removed. Now uses podman pod inspect --format '{{.State}}' to check actual running state.

Fix: .env key not stripped (Gemini)

line.partition("=") preserves spaces around the key. Added key = key.strip() so "KEY " doesn't fail to match in os.environ.get().

Fix: empty-string port handling (Gemini)

os.getenv('PORT', 'default') returns "" when the var is set but empty, producing broken URLs like http://127.0.0.1:. Replaced all 9 occurrences in router/main.py and 1 in litellm/entrypoint.py with os.getenv('PORT') or 'default'.

Fix: missing ROUTER_PORT and LANGFUSE_WEB_PORT env vars in pod.yaml (Gemini review on PR#253)

The router uses these for dashboard display and health checks. Without them, the dashboard always shows default ports even when custom ports are configured via .env.dev. Added both to the llm-triage-router container's environment.

Docs: README health check table

Updated valkey probes from tcpSocket to valkey-cli ping (matching the actual pod.yaml), and postgres from pg_isready -U postgres to pg_isready -U postgres -p <port>.

False positives (replied, no code change)

  • LiteLLM /ping is a valid health endpoint alongside /health/liveness
  • The or chain in entrypoint.py correctly handles empty strings
  • os.environ.setdefault is intentional: pod spec is authoritative, .env fills gaps

Files changed

  • start-stack.sh — safe_pod_teardown fix
  • litellm/entrypoint.py — key strip + empty-string port fix
  • router/main.py — empty-string port fix (9 occurrences)
  • pod.yaml — added ROUTER_PORT and LANGFUSE_WEB_PORT env vars
  • README.md — health check table update

Summary by Sourcery

Align routing stack deployment with configurable ports and images, improving dev/prod separation and fixing env/health-check issues.

New Features:

  • Add a dev wrapper script and .env.dev support to run a separate dev pod with distinct port and image configuration.
  • Introduce support for pulling a router image from GHCR as an alternative to local rebuilds.

Bug Fixes:

  • Correct safe pod teardown to avoid falsely reporting timeouts and force-removing already stopped pods.
  • Fix .env parsing so keys with trailing whitespace are recognized and do not fail env lookups.
  • Ensure services handle empty or overridden port environment variables correctly, preventing broken URLs and misreported dashboard ports.
  • Propagate ROUTER_PORT, LITELLM_PORT, LANGFUSE_WEB_PORT and related port env vars through pod.yaml so dashboard and health checks reflect actual configuration.
  • Update health checks for valkey and postgres to use the correct probe commands and ports across scripts and manifests.

Enhancements:

  • Centralize port, image, pod name and data-root configuration in start-stack.sh and use them consistently for cleanup, health checks and backup scripts.
  • Render environment-specific LiteLLM and router configs and ClickHouse port overrides into a data-root directory, decoupling runtime config from source files.
  • Refine liveness/readiness probes and routing URLs to respect configurable ports and derived proxy base URLs.
  • Make router dashboard and internal connectivity checks dynamically reflect current Valkey, LiteLLM, Langfuse and router port settings.

Documentation:

  • Update README health-check table to match the current probe mechanisms and port configurability.

boy and others added 25 commits July 11, 2026 12:18
…yments

Replaces all hardcoded port values and the pod name in pod.yaml,
start-stack.sh, litellm/config.yaml and litellm/entrypoint.py with
environment-variable-driven placeholders. A single pod.yaml now serves
both the production agent-router-pod and the development dev-router-pod.

Changes:
- pod.yaml: rewrite with *_PLACEHOLDER vars for pod name, all 13 service
  ports, and DATA_ROOT; add clickhouse-port-config volume; litellm-config
  volume now points to DATA_ROOT/litellm-rendered (rendered copy)
- start-stack.sh: load optional DEV_ENV_FILE overlay; resolve port/name
  defaults after env sourcing; add generate_clickhouse_config() and
  render_litellm_config() helpers; parameterize all agent-router-pod refs
  and hardcoded ports throughout cleanup, health-check, and minio helpers
- litellm/config.yaml: replace port 6379 / 5000 with *_PLACEHOLDER vars
  (rendered at deploy time via render_litellm_config)
- litellm/entrypoint.py: read POSTGRES_PORT / LITELLM_PORT from env
  instead of hardcoded 5432 / 4000; use setdefault to not clobber
  container-injected env vars
- .env: append production port defaults (POD_NAME, ROUTER_PORT, ...)
- .env.dev: new dev overlay (POD_NAME=dev-router-pod, +10 port offsets,
  dev.vendeuvre.lan URLs)
- start-dev.sh: thin wrapper that sets DEV_ENV_FILE + DATA_ROOT then
  delegates to start-stack.sh
- .gitignore: exclude dev-data/ (dev-stack runtime volumes)
…non-alpine valkey image

Root cause: podman play kube converts tcpSocket liveness probes into
'nc -z -v localhost <port> || exit 1' healthchecks. Alpine's BusyBox nc
does not support -z, so the healthcheck always fails. With
HealthcheckOnFailureAction=restart, this causes an infinite SIGTERM
restart loop (~every 30s).

Changes:
- valkey-cache: tcpSocket -> exec valkey-cli ping (liveness + readiness)
- valkey-lf: tcpSocket -> exec valkey-cli -a <pass> ping (liveness)
- Image: valkey:9.1.0-alpine -> valkey:9.1.0 (non-alpine has no nc,
  so no broken built-in healthcheck to conflict with)

Verified in dev: 0 SIGTERMs, 0 ECONNREFUSED, both valkey instances
healthy, Langfuse web/worker stable, chat completions 200 OK.
Sourcery review: valkey-cli ping without -p targets default 6379,
causing false negatives when VALKEY_CACHE_PORT is customized (e.g. dev=6389).
Now matches the port-aware pattern already used by valkey-lf probes.
- litellm/entrypoint.py: restore quote stripping before setdefault
  (prevents literal '"5432"' from breaking int() parsing)
- start-stack.sh: use ROUTER_IMAGE var instead of hardcoded
  ghcr.io/sheepdestroyer/llm-routing:latest in build/pull paths
- start-stack.sh: create volume dirs under DATA_ROOT instead of
  WORKDIR (fixes pod creation when DATA_ROOT != WORKDIR)
- start-stack.sh: add placeholder validation to render_litellm_config
  and chmod 644 on rendered configs for non-root container access
- scripts/backup.sh: use POD_NAME from .env instead of hardcoded
  agent-router-pod-postgres-db (fixes dev backup failures)
- router/main.py: extract _valkey_port() helper to DRY the
  VALKEY_CACHE_PORT/VALKEY_PORT fallback (3 call sites)
- router/main.py: replace hardcoded :3001 with LANGFUSE_WEB_PORT
  env var in dashboard Infrastructure Nodes display
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- scripts/backup.sh: wire POSTGRES_PORT through pg_isready -p flag
  (fixes backup failures when DB port is customized, e.g. dev=5442)
- pod.yaml: remove redundant PORT env var (LITELLM_PORT already set)
- start-stack.sh: remove undocumented --pull-latest alias
- start-stack.sh: add placeholder validation to render_router_config
  (matches existing render_litellm_config guard)
- start-stack.sh: extract deploy_fresh_pod() helper to DRY the
  repeated generate→render→deploy→setup→verify sequence (4 call sites)
- router/main.py: use LLAMA_SERVER_URL for health check instead of
  hardcoded http://127.0.0.1:8080/health
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- router/tests/test_get_redis.py: _valkey_port() now safely catches
  ValueError and returns 6379, so the old test that expected int('invalid')
  to crash inside get_redis() no longer applies. Split into two tests:
  test_valkey_port_invalid_fallback (new) and a rewritten
  test_get_redis_initialization_failure that uses aioredis.Redis
  side_effect instead.
- start-stack.sh: fix broken if/elif/else chain in first-deploy path
  (direct-applied commit had 'if' instead of 'elif', causing the
  localhost check and pull branch to run inside FULL_REBUILD mode,
  plus an extra dangling 'fi')
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ip, empty-string port handling

- safe_pod_teardown: use podman pod inspect --format '{{.State}}' instead of
  podman pod exists to distinguish running vs stopped pods (Gemini review)
- litellm/entrypoint.py: strip key after line.partition('=') to handle
  spaces around '=' in .env files (Gemini review)
- router/main.py + litellm/entrypoint.py: replace os.getenv('PORT', 'default')
  with os.getenv('PORT') or 'default' to handle empty-string env vars
  correctly, preventing broken URLs like http://127.0.0.1: (Gemini review)
- README.md: update health check table — valkey probes now use exec
  valkey-cli ping instead of tcpSocket, postgres uses pg_isready -p <port>
- Replied to false positives: LiteLLM /ping is a valid endpoint; the or
  chain in entrypoint.py correctly handles empty LITELLM_PORT
The router uses these for dashboard display and health checks.
Without them, the dashboard always shows default ports even when
custom ports are configured via .env.dev.

Reported by Gemini Code Assist review on PR#253.
@sourcery-ai

sourcery-ai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR wires environment-driven port and pod configuration through the startup scripts, pod spec, router, and LiteLLM, fixes several Gemini-found correctness issues (pod teardown, .env parsing, empty ports), and aligns health probes and docs with the actual deployment behavior, while adding a dev deployment wrapper.

Sequence diagram for deploy_fresh_pod env-driven deployment flow

sequenceDiagram
    actor Dev
    participant start_stack_sh
    participant deploy_fresh_pod
    participant podman
    participant minio_s3
    participant postgres_db
    participant litellm_gateway
    participant llm_router

    Dev->>start_stack_sh: run start-stack.sh [--pull|--full-rebuild]
    start_stack_sh->>start_stack_sh: safe_pod_teardown
    start_stack_sh->>deploy_fresh_pod: deploy_fresh_pod

    deploy_fresh_pod->>start_stack_sh: generate_clickhouse_config
    deploy_fresh_pod->>start_stack_sh: render_litellm_config
    deploy_fresh_pod->>start_stack_sh: render_router_config
    deploy_fresh_pod->>start_stack_sh: render_pod_yaml

    start_stack_sh->>podman: play kube (render_pod_yaml)
    podman-->>litellm_gateway: start with LITELLM_PORT, POSTGRES_PORT, VALKEY_CACHE_PORT
    podman-->>llm_router: start with ROUTER_PORT, LITELLM_PORT, LANGFUSE_WEB_PORT, VALKEY_CACHE_PORT
    podman-->>postgres_db: start with POSTGRES_PORT

    deploy_fresh_pod->>minio_s3: setup_minio_buckets
    deploy_fresh_pod->>start_stack_sh: verify_stack_health
    start_stack_sh->>postgres_db: pg_isready -p POSTGRES_PORT
    start_stack_sh->>litellm_gateway: GET /health/readiness on LITELLM_PORT
    start_stack_sh->>llm_router: POST /v1/chat/completions on ROUTER_PORT
    llm_router-->>Dev: triage router ready with env-driven ports
Loading

File-Level Changes

Change Details Files
Make stack startup, teardown, and deployment fully parameterized by environment (ports, pod name, data root, router image) and support a GHCR pull mode plus dev overlay.
  • Add PULL_MODE flag and --pull CLI option; distinguish pulling remote image vs local full rebuild in start-stack.sh.
  • Load optional DEV_ENV_FILE overlay and derive POD_NAME, DATA_ROOT, ROUTER_IMAGE, and all service port env vars with sensible defaults.
  • Use env-driven ports in LOCAL_BASE_URL, health checks, zombie port cleanup, MinIO bucket setup, and pod restart logic.
  • Introduce helper functions to generate ClickHouse port override config, render LiteLLM and router configs with port placeholders, and centralize fresh pod deployment.
start-stack.sh
scripts/backup.sh
router/config.yaml
litellm/config.yaml
Switch pod spec to use placeholders for pod name, ports, data paths, and image, render them from env, and improve health probes to match real services.
  • Change pod metadata name and hostPath volume paths to POD_NAME_PLACEHOLDER and DATA_ROOT_PLACEHOLDER instead of fixed WORKDIR-based values.
  • Replace hard-coded ports and URLs (Postgres, Valkey cache/LF, Langfuse web/worker, ClickHouse, MinIO, router, LiteLLM) with specific *_PORT_PLACEHOLDER and related placeholders.
  • Update probes to use valkey-cli and clickhouse-client with explicit host/port; add PGPORT, POSTGRES_PORT env and -p usage in pg_isready probes.
  • Mount rendered LiteLLM/router configs via new litellm-rendered and router-rendered volumes and add ClickHouse port override volume.
  • Derive PROXY_BASE_URL from PUBLIC_BASE_URL in the pod renderer and add raw placeholder replacement for image, pod name, data root, and ports.
pod.yaml
start-stack.sh
Fix safe pod teardown to avoid false timeout/force-remove and propagate pod name and Postgres port consistently into backup and health checks.
  • Change safe_pod_teardown to inspect pod state via podman pod inspect --format '{{.State}}' and only force-remove if still Running.
  • Parameterize podman commands (pod exists/stop/rm, postgres pg_isready, backup pg_dump) with ${POD_NAME} and POSTGRES_PORT from env or defaults.
  • Update backup.sh to source .env/.env.dev for POD_NAME/POSTGRES_PORT and to use pg_isready -p PORT in readiness checks.
start-stack.sh
scripts/backup.sh
Make router and LiteLLM respect env-driven ports and Valkey configuration, and harden .env parsing and Redis port handling.
  • Ensure .env loader strips spaces from keys and uses os.environ.setdefault so pod spec remains authoritative while .env fills gaps.
  • Change LiteLLM to wait for Postgres on POSTGRES_PORT and to start on LITELLM_PORT or PORT env vars instead of a fixed 4000.
  • Update router main to compute LITELLM_URL and LANGFUSE_HOST using LITELLM_PORT and LANGFUSE_WEB_PORT env vars, and route memory, dashboard, and health checks through these env-based ports.
  • Introduce _valkey_port() helper that prefers VALKEY_CACHE_PORT, falls back to VALKEY_PORT or 6379, and logs on invalid values; use it for Redis client creation and dashboard port display.
  • Add tests for _valkey_port invalid fallback and for get_redis failure path with aioredis.Redis raising.
  • Wire router/LiteLLM configs to use port placeholders (LITELLM_PORT_PLACEHOLDER, ROUTER_PORT_PLACEHOLDER, VALKEY_CACHE_PORT_PLACEHOLDER) so rendered configs match current env.
  • Ensure router container command sets LITELLM_PORT and VALKEY_CACHE_PORT envs before starting uvicorn.
litellm/entrypoint.py
router/main.py
router/tests/test_get_redis.py
router/config.yaml
litellm/config.yaml
pod.yaml
Align documentation and health check behavior with the updated probes and ports, and add a dev wrapper script.
  • Update README health check table to describe valkey exec probes and Postgres pg_isready with explicit -p .
  • Add start-dev.sh wrapper that sets DEV_ENV_FILE to .env.dev and delegates to start-stack.sh so dev and prod can run side by side.
  • Add .env.dev scaffold (implied by references) for dev-specific port and env overrides.
README.md
start-dev.sh
.env.dev

Possibly linked issues

  • #LHF-03: PR updates router/main.py to use env-driven ports/URLs for LiteLLM, Langfuse, Valkey and dashboard, resolving hardcoding.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next review available in: 10 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0094385b-4e30-4a94-8648-ceaf2092eebf

📥 Commits

Reviewing files that changed from the base of the PR and between 3c2296e and 7dbd041.

📒 Files selected for processing (13)
  • .env.dev
  • .gitignore
  • README.md
  • litellm/config.yaml
  • litellm/entrypoint.py
  • pod.yaml
  • router/config.yaml
  • router/main.py
  • router/tests/test_get_redis.py
  • scripts/backup.sh
  • scripts/dev-setup.sh
  • start-dev.sh
  • start-stack.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/learn-deployment-guidelines

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.

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

Hey - I've found 1 issue, and left some high level feedback:

  • There are several places now resolving ports from env (e.g., LITELLM_PORT, LANGFUSE_WEB_PORT, Valkey ports) with similar os.getenv(...) or default patterns; consider centralizing this logic into small helper functions for consistency and easier future changes.
  • The raw render_pod_yaml replacements for POD_NAME/DATA_ROOT/port placeholders in pod.yaml assume safe, unquoted values; if these can contain spaces or special characters (especially DATA_ROOT or ROUTER_IMAGE), it may be safer to either quote them in YAML or validate/sanitize them before substitution.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There are several places now resolving ports from env (e.g., LITELLM_PORT, LANGFUSE_WEB_PORT, Valkey ports) with similar `os.getenv(...) or default` patterns; consider centralizing this logic into small helper functions for consistency and easier future changes.
- The raw `render_pod_yaml` replacements for POD_NAME/DATA_ROOT/port placeholders in pod.yaml assume safe, unquoted values; if these can contain spaces or special characters (especially DATA_ROOT or ROUTER_IMAGE), it may be safer to either quote them in YAML or validate/sanitize them before substitution.

## Individual Comments

### Comment 1
<location path="start-stack.sh" line_range="659" />
<code_context>
+    "CLICKHOUSE_INTERSERVER_PORT_PLACEHOLDER",
</code_context>
<issue_to_address>
**issue (bug_risk):** Placeholder list includes CLICKHOUSE_INTERSERVER_PORT_PLACEHOLDER but it’s never substituted, which will cause render_pod_yaml to fail.

In render_pod_yaml, CLICKHOUSE_INTERSERVER_PORT_PLACEHOLDER is added to `placeholders` but is neither referenced in pod.yaml nor included in `raw_replacements`. Since the function now raises when a placeholder is missing from the YAML, this will always fail. Please either remove CLICKHOUSE_INTERSERVER_PORT_PLACEHOLDER from `placeholders`, or add it as a real placeholder in pod.yaml and include it in `raw_replacements`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread start-stack.sh

@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 introduces a development environment overlay (.env.dev, start-dev.sh) and parameterizes port assignments, pod names, and data directories across the stack's configurations and scripts to allow running a development pod alongside production. Key changes include dynamic port resolution in Python entrypoints, rendering configurations with port placeholders, and generating ClickHouse port overrides. A critical review comment points out that running both production and development pods concurrently with the same default DATA_ROOT will cause database and data corruption, and suggests isolating the development data directory.

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 .env.dev
scripts/dev-setup.sh creates a .venv with runtime deps (mirrored from
router/Dockerfile) + test deps (pytest, pytest-asyncio, anyio). Was
already referenced but never committed.
@sheepdestroyer
sheepdestroyer merged commit 6d064bb into master Jul 11, 2026
6 checks passed
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.

1 participant