Skip to content

feat(server): add GET /api/ready PostgreSQL readiness probe - #360

Closed
Sahilkumar-r wants to merge 1 commit into
BaaRai:mainfrom
Sahilkumar-r:feat/326-api-ready-probe
Closed

Sahilkumar-r wants to merge 1 commit into
BaaRai:mainfrom
Sahilkumar-r:feat/326-api-ready-probe

Conversation

@Sahilkumar-r

Copy link
Copy Markdown

Closes #326

Problem

/api/health reports HTTP liveness without checking PostgreSQL. Operators and orchestrators need to distinguish a running process from one whose database is unavailable.

Fix

Add GET /api/ready:

  • Returns HTTP 200 {"ready":true} when PostgreSQL is reachable, 503 {"ready":false} otherwise, with no connection details or raw errors.
  • No LLM calls, scans, database writes, or migrations.
  • /api/health and its route are unchanged.
  • Unauthenticated, like /api/health (added to the same requireAuth exemption).

Per the discussion on the issue: the PostgreSQL ping is cached for 1 second, and a request landing while a ping is already in flight waits for that ping instead of starting a new one, so a burst of probes can't queue one ping per request. readyCache in server/ready.go holds this.

Tests

server/ready_test.go: cache reuse within the TTL, re-ping after TTL expiry, 20 concurrent callers deduped into exactly one ping, and the handler's response/body when no database is configured.

Verification

In a container (Go 1.26, GOPROXY pointed at a mirror since storage.googleapis.com was unreachable from my sandbox): go build ./... succeeds, the 4 new tests pass, and go vet ./server/... is clean. The full server package suite passes except TestHealthSyncDropsStaleWrite, a pre-existing timing flake unrelated to this change — confirmed by running it 5x in isolation on this branch (all pass) and on an unpatched clone (all pass); it only showed up once, inside the full suite run. Not run: a real PostgreSQL-reachable path for /api/ready (would need a live Postgres instance), and gofmt/go vet on the rest of the repo beyond server/.

AI disclosure

This change, its tests and this description were written by Claude Code (Claude Sonnet 5) for @Sahilkumar-r, and verified by running the checks above.

🤖 Generated with Claude Code

/api/health reports process liveness only. Add /api/ready so operators
and orchestrators can distinguish a running process from one whose
PostgreSQL connection is down: HTTP 200 {"ready":true} when reachable,
503 {"ready":false} otherwise. No connection details or raw errors are
exposed, and the route makes no LLM calls, scans, writes or migrations.

The PostgreSQL ping result is cached for one second and concurrent
requests that land while a ping is in flight wait for that ping instead
of starting their own, so a burst of probes cannot queue one ping per
request. /api/health, its route and existing authentication elsewhere
are unchanged; /api/ready is exempt from auth like /api/health.

Closes BaaRai#326

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@BaaRai

BaaRai commented Nov 19, 2026

Copy link
Copy Markdown
Owner

The readiness probe landed in #363, which adds the route/auth, outage, timeout and cancellation tests the issue asked for. Thanks for the cache design; closing this one to keep a single probe.

@BaaRai BaaRai closed this Nov 19, 2026
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.

Add a separate PostgreSQL-backed readiness probe

2 participants