Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8668e52
feat(web): extract lazy Zoekt gRPC client into a shared module
Harsh23Kashyap Jul 24, 2026
8e90c6f
feat(web): add /api/health/ready endpoint with dependency health checks
Harsh23Kashyap Jul 24, 2026
0f04b34
test(web): cover /api/health/ready healthy and degraded paths
Harsh23Kashyap Jul 24, 2026
e29ed6b
docs(health): document liveness vs readiness split
Harsh23Kashyap Jul 24, 2026
375f2dd
chore: changelog entry for /api/health/ready
Harsh23Kashyap Jul 24, 2026
2a47d11
fix(web): only cache successful Zoekt client builds
Harsh23Kashyap Jul 26, 2026
7a4ddc5
fix(web): bound the readiness route by its own timeout
Harsh23Kashyap Jul 26, 2026
56e336b
test(web): cover unhandled-rejection suppression in readiness probe
Harsh23Kashyap Jul 26, 2026
3b1ebe9
chore: changelog link to PR #1507 instead of issue #1506
Harsh23Kashyap Jul 26, 2026
f5193ae
fix(web): Zoekt readiness probe uses empty List options (max_wall_tim…
Harsh23Kashyap Jul 26, 2026
3335633
feat(web): add ?strict=true mode to /api/health/ready
Harsh23Kashyap Jul 26, 2026
8ff1624
test(web): cover strict mode and invalid-param paths in readiness probe
Harsh23Kashyap Jul 26, 2026
a238ee3
docs(health): document the ?strict=true readiness mode
Harsh23Kashyap Jul 26, 2026
6166565
chore: changelog entry for ?strict=true readiness mode
Harsh23Kashyap Jul 26, 2026
aed1a21
style(web): tighten comments and pull a repeated test type alias
Harsh23Kashyap Jul 26, 2026
3fa3c63
fix(web): handle undefined Zoekt List response in the readiness probe
Harsh23Kashyap Jul 26, 2026
a92eceb
fix(web): set 500MB gRPC message size limits on the readiness probe Z…
Harsh23Kashyap Jul 26, 2026
4ef628d
fix(web): do not leak upstream error details on the unauthenticated r…
Harsh23Kashyap Jul 26, 2026
2b8b833
docs(navigation): drop the duplicate GET /api/health entry from docs.…
Harsh23Kashyap Jul 26, 2026
44e43bf
chore: link the changelog entry to PR #1512 instead of issue #1511
Harsh23Kashyap Jul 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Added a `GET /api/health/ready` endpoint that returns per-dependency health (Postgres, Redis, Zoekt) for use as a Kubernetes `readinessProbe` or load-balancer health check. The existing `GET /api/health` endpoint is unchanged and remains the liveness probe. [#1507](https://github.com/sourcebot-dev/sourcebot/pull/1507)
- Added a `?strict=true` query parameter to `GET /api/health/ready`. When set, the endpoint reports `503 / status: "degraded"` and `zoekt.status: "empty"` if the Zoekt shard set contains no indexed repositories, distinguishing "Zoekt is unreachable" from "Zoekt is up but the instance is not yet useful" for orchestrators. Default behavior is unchanged. [#1512](https://github.com/sourcebot-dev/sourcebot/pull/1512)

### Changed
- Vulnerability triage now keeps Linear issues synchronized with current security findings.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
"icon": "server",
"pages": [
"GET /api/version",
"GET /api/health"
"docs/api-reference/health"
]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
]
Expand Down
130 changes: 130 additions & 0 deletions docs/docs/api-reference/health.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: "Health Endpoints"
description: "Liveness and readiness probes for orchestrators and monitoring systems."
---

Sourcebot exposes two public health endpoints that follow the standard Kubernetes liveness / readiness split. Both are unauthenticated and return no user data.

## Liveness: `GET /api/health`

Returns `200 OK` with `{ "status": "ok" }` whenever the Next.js process is running and able to handle a request. Does not touch the database, Redis, or Zoekt. Use this for Kubernetes `livenessProbe` or Docker Compose `healthcheck.test`. A failing liveness probe means the process must be restarted.

```bash
curl -fsS https://sourcebot.example.com/api/health
# {"status":"ok"}
```

## Readiness: `GET /api/health/ready`

Returns `200 OK` with `{"status":"ok", "checks":{...}}` when Postgres, Redis, and Zoekt are all reachable. Returns `503 Service Unavailable` with `{"status":"degraded", "checks":{...}}` if any dependency is unreachable. Each check runs in parallel with a 2-second per-check timeout, so the worst-case request time is bounded even when a dependency hangs.

Use this for Kubernetes `readinessProbe` or a load balancer health check. A failing readiness probe means the pod should be removed from the load-balancer rotation but not restarted.

### Strict mode

Add `?strict=true` to require the Zoekt shard set to be non-empty as well. The default mode only confirms the dependencies are reachable; strict mode confirms the instance can actually serve a search that returns results. A freshly-started instance, or one whose connection sync has silently failed, returns `503` until at least one repository is indexed.

```bash
curl -fsS 'https://sourcebot.example.com/api/health/ready?strict=true' | jq .status
# "ok" Postgres, Redis, and Zoekt (with at least one indexed repo) are healthy
# "degraded" Something failed, see `checks` for which
```

The response always includes a top-level `strict` field so the operator can confirm the mode that was applied:

```json
{
"status": "degraded",
"strict": true,
"checks": {
"postgres": { "status": "ok", "latencyMs": 3 },
"redis": { "status": "ok", "latencyMs": 1 },
"zoekt": { "status": "empty", "latencyMs": 18, "error": "no repositories indexed (strict mode)" }
}
}
```

The Zoekt check distinguishes the two failure modes in its `status` field:
- `error`. The gRPC call itself failed (Zoekt unreachable, timeout, etc.).
- `empty`. Strict mode is on and the shard set is empty. The dependency is healthy; the instance is just not yet useful.

### Response shape

```json
{
"status": "ok",
"strict": false,
"checks": {
"postgres": { "status": "ok", "latencyMs": 3 },
"redis": { "status": "ok", "latencyMs": 1 },
"zoekt": { "status": "ok", "latencyMs": 12 }
}
}
```

When degraded, each failed check carries an `error` field with the underlying message:

```json
{
"status": "degraded",
"strict": false,
"checks": {
"postgres": { "status": "ok", "latencyMs": 4 },
"redis": { "status": "ok", "latencyMs": 1 },
"zoekt": { "status": "error", "latencyMs": 2003, "error": "zoekt check timed out after 2000ms" }
}
}
```

| Check | What it probes |
|-------|---------------|
| `postgres` | `SELECT 1` via Prisma |
| `redis` | `PING` (rejects non-`PONG` responses) |
| `zoekt` | Empty `List` RPC (proves the gRPC channel is alive; bounded by the 2s per-check timeout) |

### Example probes

<Tabs>
<Tab title="Docker Compose">
```yaml
services:
sourcebot:
image: sourcebot/sourcebot:latest
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/health"]
interval: 30s
timeout: 5s
retries: 3
# For dependency-aware probes, point the orchestrator at /api/health/ready
# instead. Sourcebot's example compose file does this via a sidecar.
```
</Tab>
<Tab title="Kubernetes">
```yaml
livenessProbe:
httpGet:
path: /api/health
port: 3000
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /api/health/ready
port: 3000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
# For deployments that should not receive traffic until the shard set
# is non-empty, switch to the strict readiness probe:
# path: /api/health/ready?strict=true
```
</Tab>
</Tabs>

<Note>
The readiness probe hits the database on every call. On large deployments with many pods, a high-frequency probe interval (sub-5s) can produce noticeable background load. A 10s interval with `failureThreshold: 3` is a good starting point.
</Note>
Loading