Skip to content

harness(api): add /health/ready endpoint for kubelet readinessProbe#520

Merged
korutx merged 1 commit into
trunkfrom
based/519-harness-health-ready
May 25, 2026
Merged

harness(api): add /health/ready endpoint for kubelet readinessProbe#520
korutx merged 1 commit into
trunkfrom
based/519-harness-health-ready

Conversation

@korutx

@korutx korutx commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds GET /health/ready to miot_harness.api.server so the Helm chart's readinessProbe.httpGet.path: /health/ready points at a real endpoint instead of a 404.
  • Readiness contract mirrors the lifespan boot signal: ready when Nexo isn't required (MIOT_HARNESS_NEXO_DSN unset) or when it's required and app.state.nexo_enabled is True; 503 not_ready when DSN is set but the lifespan didn't bring Nexo up (tunnel down, snapshot stale past the refuse-gate, tool registration failure).
  • Body includes nexo.required, nexo.enabled, nexo.tools, nexo.snapshot_age_minutes so operators can curl to see why a pod is not ready.

Closes #519

Test plan

  • pytest tests/api tests/test_server_lifespan.py — 14 passed, 1 skipped (pre-existing SSE skip).
  • New unit tests in tests/api/test_health.py cover: no DSN → 200, DSN set + pool fails → 503, DSN set + simulated-enabled → 200. Hermetic — create_nexo_pool mocked, no real network connect.
  • Built the image and verified live: GET /health -> 200 and GET /health/ready -> 200 {"status":"ready", "nexo":{"required":false,...}}.
  • CI green on this branch.
  • No Helm chart change needed — charts/miot-harness/values.yaml already points the readiness probe at /health/ready.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a readiness probe endpoint that reports the service's readiness status. The probe returns detailed information about required dependencies and their current state, enabling orchestration systems to determine if the service is ready to accept traffic.

Review Change Stack

The miot-harness Helm chart configures `readinessProbe.httpGet.path: /health/ready`
but the FastAPI server only exposed `/health`, so pods deployed via the chart never
became Ready. Adds a Nexo-aware readiness handler matching the chart's design:
ready when Nexo isn't required (no DSN), or when DSN is set and Nexo finished
booting; 503 when DSN is set but Nexo failed to enable (tunnel down, stale
snapshot past the refuse-gate, tool registration failure).

Closes #519

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@korutx korutx linked an issue May 25, 2026 that may be closed by this pull request
5 tasks
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new GET /health/ready endpoint is added to the FastAPI server that implements readiness based on Nexo DSN configuration and enabled state, returning HTTP 200 when ready or 503 when not ready. The response includes Nexo state details. Three hermetic test cases verify all configuration states.

Changes

Readiness probe endpoint

Layer / File(s) Summary
Readiness endpoint contract and implementation
miot-harness/src/miot_harness/api/server.py
Response imported from FastAPI; new GET /health/ready endpoint checks whether Nexo DSN is configured and enabled in app state, setting HTTP 503 when not ready, otherwise returning 200 with a JSON response that includes required, enabled, tools, and snapshot_age_minutes.
Readiness probe test coverage
miot-harness/tests/api/test_health.py
Module docstring updated to cover both /health and /health/ready; imports expanded with AsyncMock and patch; three test cases verify readiness returns 200 with no DSN configured, 503 with DSN but Nexo connection failure (mocked), and 200 with DSN and simulated enabled state via app.state after lifespan startup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • microboxlabs/modulariot#447: The fastAPI health response schema changes (adding nexo and snapshot_age_minutes to the response body) are implicitly coupled to a deploy evaluation script that validates the /health JSON payload includes those keys.

Poem

🐰 A readiness probe hops into place,
No longer lost in cyberspace!
When Nexo's up, green lights all glow,
When it's down, a 503 says "no."
The harness now knows when it's ready to go! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a /health/ready endpoint for kubelet readinessProbe functionality.
Linked Issues check ✅ Passed The pull request implements all coding requirements from issue #519: the /health/ready endpoint with Nexo-aware readiness contract, diagnostic response fields, and comprehensive unit tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the /health/ready endpoint and its tests; no unrelated modifications are present.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch based/519-harness-health-ready

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.

@korutx korutx merged commit 9f1f965 into trunk May 25, 2026
12 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.

bug(harness): readiness probe targets non-existent /health/ready endpoint

1 participant