Alerts that fix themselves

HCAA Reporting · planned and built Oct 30, 2026 (migration 408). The list of every automatic fix is on Admin → Alerts that fix themselves. Figures below are from live Supabase on Oct 30 (last 30 days).

In one minute

  • Every alert keeps telling you what broke. Each email gains a section: What was fixed automatically, What Claude did, or Waiting for your approval (with the review link).
  • Layer 1, code only, no Claude: widen the retries and catch-ups that already exist (Oct 3, migration 208) to cover more failure types and more alerts.
  • Layer 2, a Claude session: only when Layer 1 can't fix it. Supabase starts one cloud Claude session through Anthropic's routine API, passing the alert details. It applies database fixes and puts website fixes on the review link. Production still needs your phrase.
  • Guardrails: one session per failure per day, at most 2 tries per failure, a daily cap, an off switch, and every fix listed on the Reporting site.
Alerts / watchdogs found
7
Alarm emails, last 30 days
59
Failed calls, last 30 days
49 / 3,736
From scheduled jobs
≈10

Most of the 59 emails came from test runs (now filtered by migration 407) and 17 "still broken" repeats from SendJim, which you canceled on Oct 20.

What exists today

AlertWatchesTells youFixes itself today?Plan
Edge-call alarm (every 10 min)Scheduled jobs and buttons that fail, plus 10 "must have run by" checks (Twist posts, AI Voice email…)Email; repeats every 4 h; all-clearPartly
Retries outages and timeouts at 1/3/10 min, re-runs missed jobs, ignores "reply lost, data OK"
Layer 1 + Layer 2
Sync health (6:30 AM daily)32 data sources: failed, stale or bad rowsEmail when amber or redNoRe-run stale syncs at 6:00 before the email; Layer 2 if still red
Jobber schedule watchdog (mornings)Visit data older than 12 hNothing (silent)Yes
Re-runs the schedule sync
Log its fixes in the new list
Security monitor (daily)CM Locator database permissions, users, MFAEmail on any findingNoLayer 2 diagnoses and reports only. Security changes always wait for you
QuickBooks token lockOne token refresh at a timeNothingYes
203 refreshes, 0 races in 30 days
No change
Helcim ACH void / returned (hourly)Customer payments voided or returnedEmail per paymentBusiness noticeNo change (not a system failure)
Field app feedbackCraftsman feedbackEmail to you and MaxBusiness noticeNo change

Also business notices, unchanged: compliance reminders, booked-without-assessment, AI Voice daily, bank charges, EMC "ready to post". The Outlook email syncs stay as Cowork tasks, as already settled.

Gaps found while taking stock

GapLast 30 daysProposed
Jobber webhook token refresh fails, and nothing alerts on it75 errors (68 × 503, 7 × 401)Retry 503s in code; add to sync health; 401 → Layer 2
Network errors and "Throttled" from Jobber are classed as our own errors, so they are never retried3Treat as temporary and retry with backoff
SendJim nightly fetch still scheduled after the Oct 20 cancel17 repeat emailsTurn off its schedule and "must have run" check your OK
eLocal and Project Quote GitHub workflows still scheduled (retired Sep 3)not checkedTurn off their schedules your OK
Security monitor isn't in sync health, so if it stops running nobody hears—Add it
Leftover Oct 3 test row (zz-retry-test)—Delete

How a failure flows

1 · DetectSame alarms as today. Migration 407's rule stays: only scheduled jobs, dispatches and buttons are judged.
2 · Layer 1: code repairRetry, catch-up, re-run a stale sync, refresh a token. No Claude, no cost. Logged.
3 · EmailIf fixed: "Fixed automatically: what was done". If not: the alert as today, plus "Claude is looking at it".
4 · Layer 2: Claude sessionDiagnoses. Applies database fixes. Puts website fixes on the review link.
5 · Follow-up email"What Claude did" or "Waiting for your approval" with the review link. Logged.

Layer 1: automatic repairs in code (no Claude)

  1. Classify more failures as temporary. Network errors reaching a vendor, 429 / "Throttled", and 546 resource limits join outages and timeouts in the existing 1, 3 and 10 minute retries. Errors from our own code are still never retried, as you decided on Oct 3.
  2. Sync health heals before it emails. At 6:00 AM, each amber or red source that has a known job gets one re-run. The 6:30 email then shows what was re-run and whether it's green now. Mailbox and 2FA sources are skipped, because a re-run can't fix them.
  3. Jobber webhook token: retry 503s on refresh, and add the webhook to sync health.
  4. Every automatic repair is written to one list: retries, catch-ups, watchdog re-runs and "reply lost, data OK". Today these are scattered across three logs.
  5. Alert emails gain the "What was fixed automatically" section.

Layer 2: a Claude session for failures that need diagnosis

How it starts, fully in the cloud: one new scheduled task, "HCAA alert fixer", with no schedule of its own. It has an API trigger: Anthropic's routine API (POST /v1/claude_code/routines/{id}/fire) starts a session and passes the alert text. A small Supabase function calls it, with the trigger's token kept in the Supabase vault. This uses your Claude plan, not API credits.

When it fires: a scheduled job that is still failing after Layer 1 has finished, or one that failed in a way code shouldn't guess at (a vendor page changed, 401 / login, bad data, a code error). Test and one-off calls never fire it.

What the session may do (your Oct 30 rules):

  • Database: migrations, data repairs, cron changes, re-runs. It applies these itself and logs them. It tells you when money, payroll, QuickBooks, customer-facing data or a business decision is involved, or when it deletes data.
  • Website: branch → PR → merge to main → refresh the review link → email you the link. It never deploys to production.
  • Never: production deploys, security or permission changes, anything that sends to customers, Outlook or 2FA logins. These become "Waiting for your approval".

Last 30 days, this would have started about 3–8 sessions: SendJim export failing (session expired), Valpak returning a web page instead of data, the EMC split not adding up, and the Jobber webhook 401s. This is an estimate from those failure counts.

Guardrails

RuleSetting
Same failure (job + error type)At most 1 session per 24 h, 2 in total; then "Needs you"
Sessions per day, all failures5 confirm
Start requestLogged before sending and never re-sent. The API has no duplicate protection, and every resend starts another session.
Off switchOne setting turns Layer 2 off; Layer 1 keeps running
Anthropic's own limits30 starts/hour per task, 100/hour per account. We stay far below.

The fix list on the Reporting site: Admin → Sync gains Automatic fixes, showing when, which alert, Layer 1 or 2, what was done, the result, a review link, and whether it's waiting for you.

Not changing

  • Production deploys still need "push to live", "deploy to production" or "deploy to prod".
  • Migration 407: only cron:, dispatch: and button: callers and expected jobs alarm.
  • The Oct 3 retry rules, and qb-*, WebPunch and SendJim staying out of catch-ups.
  • The Outlook email syncs stay Cowork tasks.

Tim's decisions (Oct 30, 2026)

QuestionDecision
Edge function code fixesApply, then tell. Wait for Tim only when payroll, QuickBooks or customers are involved.
Claude sessions per day5
Trigger tokenClaude creates it on claude.ai through Chrome and saves it straight into the Supabase vault.
CleanupSendJim fetch and its check turned off (canceled Oct 20); Oct 3 test row deleted. eLocal and Project Quote workflows left as they are.
Sync Status tableFull browser width, so it doesn't need a side scroll.

What is built (Oct 30, 2026)

  • Wider retries: rate limits, worker limits and vendor network errors are now retried at 1, 3 and 10 minutes, like outages.
  • 6:00 AM re-run: every amber or red sync that is safe to re-run is re-run once before the 6:30 check; the email shows the result.
  • Jobber request webhook: token refresh now retries and re-reads the token, and the webhook is watched by sync health. The security monitor now alarms if it doesn't run by 7:30 AM.
  • Claude sessions: the "HCAA alert fixer" cloud task, started by the alarms through Anthropic's routine API, with the guardrails above. It reports back with a "What Claude did" or "Waiting for your approval" email.
  • Emails: edge-call alarm v5 and sync-health check v5 have "What Claude is doing" and "What was fixed automatically" sections.
  • Record: Admin → Alerts that fix themselves lists every fix, with an off switch for Claude fixes.

Files: migrations/408_self_healing_alerts.sql (rollback: ROLLBACK_408_self_healing_alerts.sql), supabase/functions/edge-call-alarm, sync-health-alert, auto-fix-notify, jobber-request-webhook. Original plan: claude_reports/Alerts_Self_Healing_Plan_2026-10-30.html.