Skip to content

feat(api): add GET /health/ready readiness probe for PostgreSQL and KV/Redis - #202

Merged
devarshishimpi merged 2 commits into
devarshishimpi:mainfrom
MaxonT:contrib/173-auto
Nov 29, 2026
Merged

devarshishimpi merged 2 commits into
devarshishimpi:mainfrom
MaxonT:contrib/173-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Hey there, I think this change covers the issue, but please check my reading of it.

Description

Adds GET /health/ready, a readiness probe that runs SELECT 1 on PostgreSQL and reads a key from the KV store (Redis on Node, Workers KV on Cloudflare), each with a 2 second timeout. It returns 200 when both answer, and 503 with { status: "unhealthy", timestamp, checks: { database, kv } } when one fails or times out. GET /health is unchanged and still touches no dependency, so it stays the liveness probe.

The probes live in createSharedApiDeps (deps.health), which both apps/node and apps/worker already call with their own db and kv, so the two runtimes share one implementation instead of two copies. On Node the KV read is a Redis GET of a missing key rather than a literal PING; on Workers it is a KV get of __health_check__. I did not add the queue check from the issue's example body, since the Done When list asks for the database and KV only.

The response carries only ok, timeout or unreachable per check. The raw error can contain a host or connection string, so the log gets only the error name and code. Health paths are also skipped by the request-logging middleware, as the implementation notes ask.

docker-compose.yml now checks /health/ready (timeout 5s, start_period 10s), and docs/docker.mdx, docs/nodejs.mdx and docs/operations.mdx describe both endpoints with the Kubernetes probe example. Note that with this compose check a container whose database or Redis is down is reported unhealthy, which anything that restarts unhealthy containers will act on.

Fixes #173

Thanks for the issue: pointing at packages/api/src/router.ts and listing the liveness versus readiness split made it quick to place.

Not verified: I did not run the endpoint against a real PostgreSQL, Redis or Cloudflare KV, and the tests inject fake probes, so createSharedApiDeps itself (queryRows(db, "SELECT 1") and kv.get) is read but not executed by a test. No Cloudflare Workers runtime run either.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Chore (refactoring, dependency updates, etc.)

How Has This Been Tested?

  • Unit Tests: new test/health-ready.spec.ts (6 tests) covers healthy, one dependency down (and that no secret or host from the error reaches the body), all down, a hanging probe reported as timeout, no probes wired, and /health not calling any probe. It passes with the change; with the /health/ready route mount removed, 5 of the 6 fail.
  • npm run lint: clean.
  • npm run typecheck: 22 errors, the same 22 as on the base commit (worker and test files, none in the touched files).
  • npx vitest run (whole suite): 84 failed, 465 passed; the same 20 files fail on the base commit without my change. I did not inspect each failure; the suite has Postgres-dependent tests and I had no Postgres running. I did not run npm test against a database or the integration suite.
  • Integration Tests (not run)
  • Manual Dashboard Verification (not applicable)
  • Manual GitHub Webhook Verification (not applicable)

Checklist:

  • I have starred Codra on GitHub
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes (the Postgres-dependent failures above also occur without my change)
  • I have signed the CLA

…V/Redis

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T11:38:43.949971Z 1515305 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codra-app-personal codra-app-personal Bot 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.

Codra Review

✅ Nothing to flag. Reviewed 10 files (264 changed lines) and found no issues worth raising.

Note

1 candidate did not survive the evidence and claim gates — see the dashboard for what was dropped and why.

Reviewed commit: 880ff07cf5

ℹ️ About Codra in GitHub

Your team has set up Codra to review pull requests in this repo. Reviews are triggered when you:

  • Open a pull request for review
  • Mark a draft as ready

Every review posts a summary here. A clean pass also gets a 👍 on the pull request itself.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 880ff07cf5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

authz: p.authz,
health: {
database: async () => {
await queryRows(p.db, "SELECT 1");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bypass Hyperdrive caching when probing PostgreSQL

In Workers deployments with Hyperdrive query caching enabled, this constant SELECT 1 is cacheable. The Workers factory supplies the Hyperdrive binding here (apps/worker/src/api-deps.ts:12), so a previously successful probe can keep reporting the database as healthy after origin PostgreSQL becomes unreachable, until the cached result expires. The HTTP response's Cache-Control: no-store does not bypass Hyperdrive's SQL cache. Use an uncached database check so readiness actually tests the origin connection.

Useful? React with 👍 / 👎.

Comment on lines +12 to +16
await Promise.race([
run(),
new Promise<never>((_, reject) => {
timer = setTimeout(() => reject(new Error("timeout")), PROBE_TIMEOUT_MS);
}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound outstanding dependency operations after a timeout

During a Redis outage on Node, this race times out the HTTP waiter but does not stop the underlying GET. RedisKVAdapter.get() directly uses the shared ioredis client, which is configured with maxRetriesPerRequest: null in apps/node/src/index.ts:38–39, so commands can remain queued indefinitely after these responses return. Every subsequent readiness poll adds another command, causing unbounded retained work during a prolonged outage and a backlog on reconnection. Make probe operations fail fast without entering the offline queue, or bound/coalesce outstanding probes rather than only timing out their waiters.

Useful? React with 👍 / 👎.

Comment thread docs/docker.mdx
Comment on lines +178 to +179
initialDelaySeconds: 10
periodSeconds: 15

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Give the Kubernetes probe enough time to finish

When a healthy dependency responds in 1–2 seconds, this example fails readiness even though the handler ultimately returns 200: Kubernetes defaults an omitted timeoutSeconds to 1, while the endpoint allows each check two seconds. Users copying this configuration can therefore keep healthy pods unready. Set an explicit probe timeout above the handler's two-second deadline, such as timeoutSeconds: 3.

Useful? React with 👍 / 👎.

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>

@codra-app-personal codra-app-personal Bot 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.

Codra Review

✅ Nothing to flag. Reviewed 10 files (264 changed lines) and found no issues worth raising.

Note

1 candidate did not survive the evidence and claim gates — see the dashboard for what was dropped and why.

Reviewed commit: 151530558b

ℹ️ About Codra in GitHub

Your team has set up Codra to review pull requests in this repo. Reviews are triggered when you:

  • Open a pull request for review
  • Mark a draft as ready

Every review posts a summary here. A clean pass also gets a 👍 on the pull request itself.

@devarshishimpi devarshishimpi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for contributing, has some minor issues. Will get them fixed from my end!

@devarshishimpi
devarshishimpi merged commit 89e0eb7 into devarshishimpi:main Nov 29, 2026
6 checks passed
devarshishimpi added a commit that referenced this pull request Nov 29, 2026
- core(review): deduplicate diff cache helper, cache empty diffs via != null, validate commit SHAs, and add PR-context JSDoc note (#181 / PR #203)

- api/node/worker: bypass Hyperdrive SQL caching via SELECT clock_timestamp(), fail fast on disconnected Redis via PING_REDIS, coalesce in-flight probes, suppress late rejections, preserve logger requestId on health probe warnings, and add adapter wiring tests + K8s timeoutSeconds docs (#173 / PR #202)

- models/schema: guard non-finite/negative thinkingBudget, exclude o1-mini/o1-preview from reasoning_effort, simplify Zod schema, and consolidate OpenAI tests with real schema parsing (#177 / PR #201)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a Deep Health Check Endpoint for Dependencies

2 participants