Skip to content

fix: bind uvicorn to Railway's dynamic $PORT (prod deploy healthcheck failure)#319

Merged
DevanshuNEU merged 1 commit into
OpenCodeIntel:mainfrom
DevanshuNEU:fix/railway-dynamic-port-bind
Jun 11, 2026
Merged

fix: bind uvicorn to Railway's dynamic $PORT (prod deploy healthcheck failure)#319
DevanshuNEU merged 1 commit into
OpenCodeIntel:mainfrom
DevanshuNEU:fix/railway-dynamic-port-bind

Conversation

@DevanshuNEU

@DevanshuNEU DevanshuNEU commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Problem

Production backend (api.opencodeintel.com) was returning 502 Application failed to respond on every route. The browser surfaced it as a CORS error (no Access-Control-Allow-Origin), but the API was simply not reachable: no healthy Railway replica.

Root cause

The Railway deploy was failing at the healthcheck step, not at boot. Deploy logs show the app starts fine (Uvicorn running on http://0.0.0.0:8000, Application startup complete), but /health returns "service unavailable" on all 11 attempts.

backend/Dockerfile hardcoded --port 8000. Railway assigns a dynamic $PORT and runs its platform healthcheck (healthcheckPath: /health in railway.json) against that port. Nothing listens there, so the healthcheck never passes and the deploy is rejected.

This was a latent bug: healthcheckPath was added to railway.json after the last good deploy (#293), so #293 served fine on 8000 with no healthcheck enforcing reachability. Every deploy since (#316, #318) hit this and failed silently for days; prod only stayed up on the stale #293 image until that replica was replaced.

Fix

Bind uvicorn to ${PORT:-8000} (fallback preserves local/docker-compose), and make the internal Docker healthcheck read the same port. exec keeps uvicorn as PID 1 for graceful SIGTERM shutdown.

CMD exec uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000} --proxy-headers

Note for reviewer / on merge

This fix unblocks the deploy pipeline, so merging it will deploy the backend changes from #316 (durable repo-state) and #318 (eval harness) to prod for the first time — they were merged to main but never actually shipped because of this bug. Both passed CI/CodeRabbit; flagging so the first green deploy is expected to carry that code.

Testing

  • ${PORT:-8000} expansion verified (set -> dynamic port, unset -> 8000).
  • Real validation is the next Railway deploy's healthcheck passing.

Summary by CodeRabbit

  • Chores
    • Updated backend container configuration to support dynamic port assignment, enabling the service to adapt to hosting platforms that dynamically allocate ports at runtime. This ensures reliable operation across different deployment environments.

Railway assigns a dynamic $PORT and runs its healthcheck against it. The
Dockerfile hardcoded --port 8000, so every deploy after healthcheckPath was
added to railway.json failed with "service unavailable" on /health. OpenCodeIntel#316 and
OpenCodeIntel#318 have both been stuck for days; prod only survived on the pre-healthcheck
OpenCodeIntel#293 image until that replica was knocked out. Bind ${PORT:-8000} (fallback for
local/compose) and make the internal healthcheck read the same port.
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 61f93919-10c8-4db4-ba0e-d67c753522c3

📥 Commits

Reviewing files that changed from the base of the PR and between 022ef14 and 1ce41ee.

📒 Files selected for processing (1)
  • backend/Dockerfile

📝 Walkthrough

Walkthrough

The pull request modifies backend/Dockerfile to support Railway's dynamic runtime port assignment. The healthcheck now queries http://localhost:$PORT/health instead of hardcoding port 8000, and the startup command uses shell-expanded ${PORT:-8000} to bind uvicorn to the provided port environment variable with 8000 as fallback.

Changes

Dynamic Port Support

Layer / File(s) Summary
Healthcheck and startup command for runtime port binding
backend/Dockerfile
Healthcheck probes use the $PORT environment variable with 8000 fallback; startup command changed to shell form with proper variable expansion for --port ${PORT:-8000} binding instead of hardcoded port configuration.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related PRs

  • OpenCodeIntel/opencodeintel#310: Both PRs address Railway port/healthcheck boot behavior by adjusting how uvicorn binds to the correct $PORT and passes the /health probe on startup.

Poem

🐰 A port that shifts with the Railway wind,
No hardcoded eight-thou will pin us in,
The health check hops, the startup flies,
Dynamic binding—how the server thrives! 🚂✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: binding uvicorn to Railway's dynamic $PORT environment variable to fix a production deployment healthcheck failure. It is specific, concise, and accurately reflects the core problem being solved.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
opencodeintel Ignored Ignored Preview Jun 11, 2026 9:04pm

@DevanshuNEU DevanshuNEU merged commit 8afb4e5 into OpenCodeIntel:main Jun 11, 2026
8 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