mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-28 01:49:00 +09:00
## Why A "Karaoke Backend - Service Unavailable" uptime alert fired at 06:06 UTC on 2026-08-22 and auto-recovered ~1m41s later. Investigation showed it was a **routine Cloud Run instance recycle** on `--min-instances 1`: the single warm instance (up ~9.6h) was reaped at 06:01:53, leaving a ~80s gap with no origin, so Cloudflare failed the health check from all 6 checker regions at once. No crash/OOM — a self-healing platform recycle. (Full write-up: `docs/archive/2026-08-22-health-check-alert-noise-and-graceful-degradation.md`.) We're deliberately keeping `--min-instances 1` for cost, so this addresses the two things we *can* control: alert noise, and how the UI behaves during such a blip. ## What **1. Soften the uptime alert** (`infrastructure/modules/monitoring.py`) - Condition `duration` 60s → **300s**: a sub-5-min self-healing recycle no longer pages; a sustained hard-down still fires (~5–6 min). Incident documented in-code. **2. Graceful frontend degradation** - `lib/api.ts` — new **`apiFetch`** wrapping every backend call: non-aborting 2.5s "reconnecting" hint, hard-timeout backstop, **safe retries (GET only — never replays a mutation)**, transient-status detection (502/503/504 + Cloudflare 52x), GCS/third-party passthrough. Throws a typed `BackendUnavailableError`. - `lib/backend-status.ts` — framework-agnostic connectivity store (`online | reconnecting | unavailable`); escalates to `unavailable` on a 10s clock, clears to `online` on any success. - `components/backend-status-banner.tsx` — one reassuring app-wide banner (mounted under `[locale]`, covers landing + logged-in dashboard + review screens), **i18n across all 33 locales**. `/admin/*` intentionally excluded. Copy reassures that in-flight renders are unaffected. During a real recycle the dashboard's own polling drives the banner and it self-heals when the backend returns — no refresh needed. ## Testing - New unit tests: `__tests__/backend-status.test.ts`, `__tests__/api-fetch.test.ts` (GET retry→10s escalation, transient 503, transparent recovery, non-GET never retried, `Request`-input method/signal, GCS passthrough, caller-abort passthrough). Updated `completeJobUpload` assertion. - Full suite green: **1130 passing**. - Banner verified visually locally (reconnecting + unavailable, en + es). - Local CodeRabbit review: 5 findings (1 major, 4 minor) all addressed; cycle 2 clean. ## Deploy notes - Infra change: `pulumi up` run locally before merge to avoid IaC drift (Pulumi CI re-runs as no-op). @coderabbitai ignore --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>