Skip to content

fix(metrics)+docs(ops): engine_runs query, Caddyfile capture, deploy runbook (post-incident)#1704

Open
pulzzejason wants to merge 2 commits into
mainfrom
goal/64b777fb-38cf-4101-a1b0-8df84be80427
Open

fix(metrics)+docs(ops): engine_runs query, Caddyfile capture, deploy runbook (post-incident)#1704
pulzzejason wants to merge 2 commits into
mainfrom
goal/64b777fb-38cf-4101-a1b0-8df84be80427

Conversation

@pulzzejason

Copy link
Copy Markdown
Contributor

Three small, related items hardening prod ops after the 2026-07-02 502/503 incident.

1. fix(metrics): engine_usage raw query hit a non-existent table

/api/admin/metrics ran FROM "EngineRun", but the EngineRun Prisma model is @@map("engine_runs"). So the raw query threw 42P01 relation "EngineRun" does not exist on every call — silently zeroing the engine_usage metric and logging a prisma:error each time (the endpoint is polled, e.g. by a memory-capture loop, so it spammed prod logs).

  • Fix: FROM "EngineRun"FROM engine_runs. The columns (observations, endedAt) are not @map'd, so they stay camelCase — unchanged.
  • Verified against live prod: the corrected query returns real data (318 runs this month, 1.76M input tokens) instead of erroring to 0.
  • Note added so nobody "corrects" it back to the model name.

2. ops(caddy): capture the prod Caddyfile in-repo

ops/caddy/Caddyfile — the live /etc/caddy/Caddyfile was an untracked box snowflake. Captured as source-of-truth, including the lb_try_duration 15s retry buffer applied live on 2026-07-02 (holds+retries over the pm2 reload bind-gap instead of 502/503; the single-upstream active health check was removed as counterproductive).

3. docs(runbook): docs/runbooks/prod-deploy-and-proxy.md

Documents the */15 cron deploy model (not per-push), the rsync --checksum sync, PM2 self-heal, the downtime-reduction ladder (rsync → Caddy retry → future container blue-green), common ops commands, how to update the Caddy config safely, and the 07-02 incident.

Validation

  • Typecheck clean; admin-metrics unit test passes (9); corrected query verified on live prod DB.
  • (2) and (3) are docs/config — no runtime effect; (2) documents an already-live box change.

Agent config

No agent-visible data/tools change → no PM Agent config update.

Goal: 64b777fb-38cf-4101-a1b0-8df84be80427

…ile + deploy runbook

Post 2026-07-02-incident ops hardening (3 small, related items):

1. fix(metrics): the /api/admin/metrics engine_usage raw query used FROM "EngineRun",
   but the EngineRun model is @@Map("engine_runs") — so it threw 42P01 (relation does
   not exist) on EVERY call, silently zeroing the metric AND spamming prod logs with
   prisma:error (the endpoint is polled). Fixed to FROM engine_runs (columns observations/
   endedAt are not @Map'd, so they stay camelCase — unchanged). Verified against live prod:
   the corrected query returns real data (318 runs this month) instead of erroring.

2. ops(caddy): capture the production Caddyfile in-repo (ops/caddy/Caddyfile) — it was an
   untracked box snowflake. Includes the lb_try_duration retry buffer applied live on
   2026-07-02 (holds+retries over the pm2 reload bind-gap instead of 502/503; the
   single-upstream active health check was removed as counterproductive).

3. docs(runbook): docs/runbooks/prod-deploy-and-proxy.md — documents the cron-*/15 deploy
   model, rsync --checksum sync, PM2 self-heal, the downtime-reduction ladder (rsync →
   Caddy retry → future container blue-green), common ops, and the 07-02 incident.

No agent-visible data/tools change → no PM Agent config update.

Goal: 64b777fb-38cf-4101-a1b0-8df84be80427
Live deploy on 2026-07-02 (dispatched to ship phase-1) measured the actual
deploy impact via a 1s health probe through the reload window:
- build + rsync phases: 60 consecutive 200s → phase-1 (rsync --checksum) works,
  no write-storm disruption.
- pm2 reload: ~40s outage (9 failed probes) — the single-fork Next.js cold start,
  longer than the 15s Caddy lb_try_duration, so Caddy only partially covers it.

Changes:
- cron */15 → */30: each deploy still incurs the ~40s blip, so fewer ticks = fewer
  blips (≤30 min merge→prod lag; fine with no real users). GitHub scheduled runs are
  best-effort/delayed regardless of interval, so a tighter cadence just piles up
  undeployed commits. Note added that '*/45' fires unevenly (:00/:45), not every 45m.
- runbook: correct the reload-gap description (few seconds → measured ~40s), note
  the 15s Caddy retry doesn't fully cover it, and record the zero-downtime handoff
  (SO_REUSEPORT / blue-green / container) as the real fix — NOT yet built.

Goal: 64b777fb-38cf-4101-a1b0-8df84be80427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant