🤖 Autopilot: Structured Health Check Endpoint#87
Merged
Conversation
…/metrics)
- GET /api/health (unauthenticated): returns {status, uptime_seconds, version}
- GET /api/health (authenticated): returns full component breakdown (db, gateway, agents, queue, research, costs)
- GET /api/health/metrics: Prometheus text exposition format for scraping
- Middleware updated to bypass auth for /api/health routes
- Core logic in src/lib/health.ts with separate component checks
- DB: integrity_check, user_version, page_count*page_size for size
- Gateway: checks OpenClaw client isConnected()
- Agents: active/total counts + health state aggregation
- Queue: task status breakdown (assigned, in_progress, queued, testing, verification)
- Research: per-product latest cycle phase and freshness
- Costs: per-cap utilization percentage from existing cost_caps
- Unit tests for summary, detail, and Prometheus formatting
Task: db22214b-b5b3-4a0c-8e24-60f4d3e27755
- Remove .mc-workspace.json, .tmp/db-backups/*, db-backups/* from repo - Add db-backups/, .tmp/, .mc-workspace.json to .gitignore - Fix checkResearch() query: MAX(id) on UUIDs doesn't give latest cycle, use MAX(started_at) instead - Remove dead code block in checkGateway() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Integrity check already proves DB is accessible. Derive writable from integrity_check result instead of a separate SELECT 1. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was built
Structured health check endpoints for Mission Control, enabling integration with monitoring tools (UptimeRobot, Grafana, Prometheus).
Endpoints
GET /api/health{status, uptime_seconds, version}GET /api/healthGET /api/health/metricsComponent checks (authenticated detail)
PRAGMA integrity_check(1),user_version,page_count * page_sizefor size, writable testisConnected()statusagent_healthassigned,in_progress,queued,testing,verification)cost_capstablePrometheus metrics exposed
autensa_up,autensa_uptime_seconds,autensa_db_ok,autensa_db_size_bytes,autensa_db_schema_version,autensa_gateway_connected,autensa_agents_active,autensa_agents_total,autensa_queue_assigned,autensa_queue_in_progress,autensa_queue_total_pending,autensa_cost_utilization_pct{product_id,cap_type},autensa_research_last_cycle_age_seconds{product_id}Research backing
Research recommended "Add health check endpoint (/api/health) that reports gateway connectivity, database status, active agent count, and queue depth for monitoring." This is standard infrastructure that was missing from Mission Control.
Technical approach
/api/healthand/api/health/metricsadded to middleware exclusion list (same pattern as/api/webhooks/)Date.now()captured at import timeRisks / trade-offs
PRAGMA integrity_check(1)checks only one page — fast but not a full scan (intentional for performance)current_spend_usdbeing kept up to date by the cost tracking systemFiles changed
src/lib/health.tssrc/app/api/health/route.tssrc/app/api/health/metrics/route.tssrc/middleware.ts/api/healthroutessrc/lib/health.test.tsTesting
next buildsucceeds — both routes compiledTask ID: db22214b-b5b3-4a0c-8e24-60f4d3e27755