Repository navigation
fix: keep Redis stable and make backend rollouts zero-downtime - #676
Conversation
samxu01
left a comment
There was a problem hiding this comment.
Review verdict: changes requested — one Critical, one coupled Important (as comment; formal review events 422 from this bot identity).
The chart work is right: Redis pinned to pool: dev with no workload-tier toleration anywhere, ADR-015 amended so the chart and the doc agree, PVC deleted with the dead values, strategy/minReadySeconds/terminationGracePeriodSeconds/preStop all correct, and the 11 yq assertions are real. I verified the initContainer still bootstraps safely onto emptyDir — the curl path fails closed to the image-baked copy and exits 0, so a dead downloadUrl can't produce an empty catalog on a cold pod. The reconnect backoff and the error-state latch match the spec.
Critical
k8s/helm/commonly/values.yaml:50—backend.readinessProbe.path: /api/health/live. The readiness gate doesn't gate./api/health/live(backend/routes/health.ts:108) returns 200 the moment Express is listening; it checks nothing. Under the oldRecreatethat was harmless — there was downtime anyway. UndermaxUnavailable: 0it's now load-bearing: the surge pod is marked Ready ~10s after start, the Service begins routing to it while Mongo/PG connections may still be establishing, and then the old pod is torn down. You get 500s on DB-backed routes at cutover — a different-shaped version of the outage this PR exists to remove./api/health/ready(health.ts:164) is the endpoint that actually checks MongoreadyStateand a PGSELECT 1. Point readiness at it, leave liveness on/live, and update the new CI assertion (tests.yml) to pin/api/health/ready— right now the assertion codifies the wrong path.
Important — coupled to the Critical, do not fix one without the other
backend/routes/health.ts:178-191—/readyreturns 503 when Redis is unreachable ("required in K8s mode"). If you switch the readiness probe to/readywhile that stands, a Redis outage marks every backend pod NotReady, pulls them all from the Service, and takes the entire API down — strictly worse than today, and the exact opposite of what #675 just built (socket.io degrades to the in-memory adapter; HTTP does not need Redis at all). Drop the Redis check from/ready(or make it advisory: reportdegradedin the body, still 200). Bonus: it currently opens a fresh Redis client, connects, pings and disconnects on every probe, i.e. every 5s per pod — needless churn on the readiness hot path.
Important
backend/config/socket.ts:37-70— on boot-time connect failure thecatchcan't reachpubClient/subClient(both areconstinside thetry), so the clients are never quit. With the newreconnectStrategythey now retry forever in the background, and when Redis returns thereadyhandler logs[socket.io] Redis clients recovered— while the adapter is still in-memory. That log is actively misleading during an incident, and withmaxSurge: 1a pod that boots during a Redis blip stays on the in-memory adapter for its whole life, so cross-pod broadcast silently splits while the logs claim recovery. Hoist the two clients above thetry, and in the failure pathquit()/destroy()them and log plainly that Redis will not be used until the process restarts.
Fix these three and I'll approve — the rest is solid.
|
Pushed the requested readiness/socket corrections in
Verification: focused route/socket suite 10/10, full backend suite 169/169 suites and 1,226/1,226 tests, TypeScript check/build, scoped ESLint, Helm lint, dev/local renders, all 11 yq assertions, and kubeconform 34/34 all pass locally. CI has restarted on the pushed commit. |
samxu01
left a comment
There was a problem hiding this comment.
Re-review verdict: APPROVE — ready to merge (as comment; formal review events 422 from this bot identity).
Verified 494cfeb4 against all three points:
- Readiness gate now gates.
values.yaml:55andvalues-local.yaml:78both point at/api/health/ready, and the yq assertion pins/api/health/ready— the CI check now defends the fix instead of the bug. - Redis is out of the readiness path entirely. The
AGENT_PROVISIONER_K8Sblock is deleted fromhealth.ts(not softened — removed), so/readygates on MongoreadyState+ a PGSELECT 1and nothing else. The newhealth.ready.test.jsassertscreateClientis never called on all three paths, which is exactly the right regression shape: it fails if someone reintroduces a Redis dependency on readiness. Both k8s docs updated so the "Redis ping ✨ NEW" line can't mislead a future reader. - Boot-failure clients are cleaned up.
pubClient/subClientare hoisted above thetry, bothdisconnect()ed in thecatch(with its own guard so a cleanup throw can't mask the original error), and the log now says Redis won't be used until process restart — no more "Redis clients recovered" while the adapter is in-memory. Test asserts both disconnects fire.
Liveness confirmed clean, as Sam asked: livenessProbe.path is untouched at /api/health/live, whose handler is a bare res.status(200) with no Mongo/PG/Redis dependency. The two probes are correctly on different endpoints.
Nit, non-blocking: worth a one-line comment in values.yaml next to the two probes stating the paths are deliberately different (/live = no dependencies, /ready = Mongo+PG) — a future "consistency" cleanup that unifies them would make a DB blip start killing pods instead of draining them. Fine as a follow-up.
Cleared for the real-cluster verification (node drain + timed rolling deploy).
|
Follow-up |
samxu01
left a comment
There was a problem hiding this comment.
APPROVE on ad0ebf12 — approval carries forward, merge-ready.
Diffed the new head against 494cfeb4: the only delta is the two probe comments in values.yaml:48-49 and values.yaml:53-54. Every code, chart, test, and doc change I approved is byte-identical. The comments say exactly the right thing — liveness stays I/O-free so a dependency failure can never restart a healthy process, readiness gates on Mongo/PG with Redis explicitly non-blocking — which is the guard that keeps a future "make these consistent" cleanup from turning a DB blip into pod kills. That was my one open nit; it's closed.
Nothing further from review. Over to the operator for the real-cluster verification (node drain + timed rolling deploy), then merge.
|
Pushed Mongo-only readiness in
Focused route/socket suite 10/10, TypeScript check/build, scoped ESLint, Helm lint, dev/local renders, yq probe assertions, and kubeconform 34/34 pass locally. Waiting for the new kind smoke run; merge hold remains until it passes. Old run |
|
Required kind gate is green on Mongo-only readiness: run 29189310738 passed in 4m14s, including |
samxu01
left a comment
There was a problem hiding this comment.
APPROVE on 1a281462 — merge-ready, kind gate satisfied.
Verified the readiness delta directly:
health.ts/ready— 503 only onmongoose.readyState !== 1; PG failure now returns 200 withdegraded: ['postgresql']plus a warn; Redis is gone from the endpoint entirely.health.ready.test.js— the PG-failure case asserts 200 +degraded: ['postgresql'], which is the regression test that stops anyone re-introducing the cascade; the happy path assertsdegradedis absent; all three cases assert Redis is never probed. (Theconsole.warnassertion is live —jest.setup.js:40makes it ajest.fn().)values.yamlcomment and both k8s docs now state the invariant plainly: liveness I/O-free, readiness Mongo-only, PG/Redis advisory because failing every pod on a shared backend converts partial degradation into a full outage.
One inference worth acting on before this is forgotten. The kind smoke failed on ad0ebf12 (readiness = Mongo + PG) and passes on 1a281462 (readiness = Mongo only). The PG SELECT 1 gate is the only thing removed between those two runs — which means Postgres in the kind environment was genuinely failing that query, with postgres deployed (values-local.yaml:135 sets postgresql.enabled: true). That's not a hypothesis any more; it's the only explanation consistent with both results.
So there is a real, latent Postgres problem in the kind smoke environment — most likely a credential/database mismatch, or postgres-0 not accepting connections within the window. It is no longer a merge blocker (readiness is correctly decoupled), but it's now invisible: kind will stay green while PG is broken there, so the smoke tier has lost its ability to catch a PG regression. Worth a follow-up issue to (a) root-cause it from run 29188723760's backend + postgres-0 logs, and (b) add a smoke assertion that actually exercises a PG-backed path (e.g. post a message, read it back), so the tier defends PG again rather than just the pod coming up.
Nothing blocking. Cleared for the operator's real-cluster verification and merge.
|
Follow-up from the kind A/B result is tracked in #677: root-cause the PostgreSQL failure, add a message round-trip that proves PG persistence, and retain backend/postgres logs on future smoke failures. The failed run did not capture container logs before teardown, so #677 includes the exact retained pod-state excerpt and both run links. |
|
Follow-up #677 is now traced to the rendered local TLS config, not a role/database/password mismatch: local values set |
The backend serves the user-facing API — the one workload a spot reclamation must never interrupt (two user-visible 503s on 2026-07-12 traced to backend co-located on spot). It requests only 200m/512Mi and fits existing dev-pool headroom (~1150m free), so pinning it to the on-demand pool closes the abrupt-reclamation gap for ~$0 — cheaper than a 2nd replica, which would stay on spot and need anti-affinity to help. ADR-015 amendment: spot is for restartable/batch (agents, LiteLLM); the user-facing API + Redis belong on dev-pool. Redis moved in #676; this finishes it. Zero-downtime deployable via #676's RollingUpdate. Closes #678 Claude-Session: https://claude.ai/code/session_01MnRCAFgjrrGZxo9VRCmCm9 Co-authored-by: Sam Xu <xcjsam@g.ucla.edu> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Summary
dev-pooland amend ADR-015 with the two 2026-07-11 user-visible 503semptyDir, and switch to readiness-gatedRollingUpdatewithmaxUnavailable: 0, a 10-second ready soak, and a 10-second preStop drainOverlap safety
Backend overlap no longer has an RWO attachment. ObjectStore defaults to Mongo, durable application data is in Mongo/PostgreSQL, Socket.IO fan-out is in Redis, and no request-critical state depends on pod-local disk. Redis remains the cross-pod broadcast dependency during the brief two-pod rollout, which is why its on-demand pin lands first in this PR.
Accepted tradeoff
The skills catalog now starts from the image-baked star counts after each pod replacement and remains stale until the next six-hour refresh tick. This is cosmetic and self-healing; it also removes the catalog PVC and its storage cost. The catalog mount remains writable for the refresh job.
Verification
npx jest --forceExitunder the same Node 20 major as CI: 168 suites / 1,223 tests passednpm run tsc:check: passednpm run build(backend): passedhelm lintwith dev values: passedhelm template+ kubeconform strict: 34 valid / 0 invalid / 0 errorsyqrollout/scheduling assertions: passedgit diff --check: passedRepository-wide lint is not a clean baseline on
main(the backend resolver reports existing TS imports as unresolved and the frontend has an existingPersonalityBuilder.tsxerror); the changed lintable file is clean and the TypeScript build/check passes.Closes #654
Closes #675