Repository navigation
feat(api): add GET /health/ready readiness probe for PostgreSQL and KV/Redis - #202
Conversation
…V/Redis Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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"); |
There was a problem hiding this comment.
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 👍 / 👎.
| await Promise.race([ | ||
| run(), | ||
| new Promise<never>((_, reject) => { | ||
| timer = setTimeout(() => reject(new Error("timeout")), PROBE_TIMEOUT_MS); | ||
| }), |
There was a problem hiding this comment.
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 👍 / 👎.
| initialDelaySeconds: 10 | ||
| periodSeconds: 15 |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Thanks for contributing, has some minor issues. Will get them fixed from my end!
- 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)
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 runsSELECT 1on PostgreSQL and reads a key from the KV store (Redis on Node, Workers KV on Cloudflare), each with a 2 second timeout. It returns200when both answer, and503with{ status: "unhealthy", timestamp, checks: { database, kv } }when one fails or times out.GET /healthis unchanged and still touches no dependency, so it stays the liveness probe.The probes live in
createSharedApiDeps(deps.health), which bothapps/nodeandapps/workeralready call with their owndbandkv, so the two runtimes share one implementation instead of two copies. On Node the KV read is a RedisGETof a missing key rather than a literalPING; on Workers it is a KVgetof__health_check__. I did not add thequeuecheck from the issue's example body, since the Done When list asks for the database and KV only.The response carries only
ok,timeoutorunreachableper 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.ymlnow checks/health/ready(timeout 5s, start_period 10s), anddocs/docker.mdx,docs/nodejs.mdxanddocs/operations.mdxdescribe 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.tsand 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
createSharedApiDepsitself (queryRows(db, "SELECT 1")andkv.get) is read but not executed by a test. No Cloudflare Workers runtime run either.Type of change
How Has This Been Tested?
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 astimeout, no probes wired, and/healthnot calling any probe. It passes with the change; with the/health/readyroute 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 runnpm testagainst a database or the integration suite.Checklist: