Skip to content

[FIN-27]Fixes for the wrong status showing for gateway health - #31

Merged
ishaanbhela-ai merged 1 commit into
lending_poc/mainfrom
bug/MTE-27-fixes-gateway-healthy
Sep 24, 2026
Merged

ishaanbhela-ai merged 1 commit into
lending_poc/mainfrom
bug/MTE-27-fixes-gateway-healthy

Conversation

@JuleeGunjal

Copy link
Copy Markdown

Ticket : https://legal-ai-josh.atlassian.net/browse/FIN-27

Summary

  • Fix gateway GET /health so it reports the actual status of OCR, translation, field-mapping, and app instead of treating every HTTP 200 as healthy.
  • Downstream services often return 200 with a body like {"status":"unreachable"} or {"status":"unhealthy"}; the gateway now reads that body and normalizes "ok"/"healthy" to "healthy".
  • Fix backend container startup when the host bind-mount lacks execute permission on scripts/start-combined.sh by running it via bash, and mark the script executable in git.

Problem

GET /health always returned something like:

{"status":"healthy","services":{"ocr":"healthy","translation":"healthy","field_mapping":"healthy","app":"healthy"}}


**Changes**

gateway/main.py: add _status_from_upstream / _probe_service to map upstream health bodies and connection failures correctly; aggregate status is healthy only when all services are healthy, otherwise degraded.
Dockerfile: CMD ["bash", "scripts/start-combined.sh"] so startup does not depend on the +x bit under bind mounts.
scripts/start-combined.sh: mode 100644 → 100755 (executable).

**Test plan**

1.  docker compose up -d starts successfully (no permission denied on start-combined.sh)
2. With stack healthy + Ollama model pulled: curl -s http://localhost:8080/health shows all services healthy
3. docker compose stop ollama then recheck /health → status: degraded, translation/field_mapping not healthy (unreachable / similar)
4.  docker compose start ollama and confirm health recovers after model is available
 Spot-check namespaced routes: /ocr/health, /translation/health, /field-mapping/health, /app/health

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Guard non-object upstream JSON responses before accessing their status.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes gateway health aggregation and makes backend startup resilient to bind-mounted script permissions.

Changes:

  • Parses downstream health responses accurately.
  • Runs the startup script through Bash.
  • Marks the startup script executable.
File Summary
lending-poc/​scripts/​start-combined.sh Starts and supervises backend services.
lending-poc/​gateway/​main.py Parses and aggregates downstream health statuses.
lending-poc/​Dockerfile Invokes the startup script through Bash.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +142 to +159
if resp.status_code >= 500:
try:
body_status = resp.json().get("status")
except ValueError:
body_status = None
if isinstance(body_status, str) and body_status:
if body_status in _HEALTHY_UPSTREAM_STATUSES:
return f"unhealthy ({resp.status_code})"
return body_status
return f"unhealthy ({resp.status_code})"

if resp.status_code >= 400:
return f"unhealthy ({resp.status_code})"

try:
body_status = resp.json().get("status")
except ValueError:
body_status = None
@ishaanbhela-ai
ishaanbhela-ai merged commit b123ae5 into lending_poc/main Sep 24, 2026
1 check 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.

4 participants