Skip to content

feat(watchdog): active recovery for stopped workers (#4723)#4724

Merged
bokelley merged 2 commits into
mainfrom
bokelley/fly-worker-comment-correction
May 18, 2026
Merged

feat(watchdog): active recovery for stopped workers (#4723)#4724
bokelley merged 2 commits into
mainfrom
bokelley/fly-worker-comment-correction

Conversation

@bokelley

@bokelley bokelley commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Watchdog now actively recovers a stopped worker via the Fly Machines API, closing the gap behind today's 04:31 UTC alert (issue #4723).

Root cause

PR #3374 added [[services]] with auto_start_machines = true + min_machines_running = 1 for the worker process group, claiming this would prevent rolling deploys from leaving workers stopped. Per Fly docs, those flags are only enforced via fly-proxy, and a [[services]] block without [[services.ports]] isn't routed through fly-proxy — so both settings are inert. The watchdog from PR #4358 observed the failure but couldn't recover it.

Today's incident: v2738 rolling deploy. Worker 6832693c334dd8 event log: pending(launch) → created(launch) → stopped(update) — no start event. Watchdog tripped at 3 misses (~180s); manual fly machine start was required.

Fix

On probe failure the watchdog calls GET /v1/apps/{app}/machines, filters to fly_process_group == worker && state == stopped, and issues POST /v1/apps/{app}/machines/{id}/start for each. Recovered machines surface as successful probes on the next tick. If start didn't help (real crashloop), the failure streak still climbs and the alert fires at threshold as before.

Recovery requires FLY_API_TOKEN secret on the app. Without it the watchdog gracefully degrades — behavior matches PR #4358 exactly. Failures during the recovery call are logged at warn (not error, so they don't re-route to #admin-errors and stack on top of the real alert).

Setup

After merge, mint and set the token (one time):

fly tokens create deploy -a adcp-docs --expiry 8760h | xargs -I{} fly secrets set FLY_API_TOKEN={} -a adcp-docs

Until that secret is set, the watchdog behaves identically to today.

Test plan

  • 9 vitest cases — original 5 plus 4 new for the recovery path (starts stopped worker, skips when none stopped, still alerts when recovery doesn't help, skips without token)
  • Typecheck clean
  • Verify in prod: next deploy where the worker happens to be left stopped should self-heal within one watchdog tick; alert should NOT fire

Refs

🤖 Generated with Claude Code

bokelley and others added 2 commits May 18, 2026 05:39
The fly.toml block for the worker process group claimed that adding
`auto_start_machines = true` + `min_machines_running = 1` opted workers
into Fly's autostart lifecycle. It does not — per Fly docs, those flags
are enforced through fly-proxy, and a `[[services]]` block without
`[[services.ports]]` doesn't get fly-proxy routing. The settings are
inert; the block still earns its keep by attaching the http_check.

The actual recovery gap (rolling deploys can leave the worker `stopped`
with no automatic restart) is tracked in #4723.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PR #3374's `auto_start_machines = true` + `min_machines_running = 1` on
the worker `[[services]]` block are inert without a `[[services.ports]]`
entry — Fly only enforces those flags via fly-proxy, and a service with
no ports isn't routed through fly-proxy. Rolling deploys that leave the
worker `stopped` had no recovery path; the watchdog from PR #4358
observed the failure but couldn't act on it. Today's 04:31 UTC alert
required a manual `fly machine start`.

On probe failure the watchdog now calls the Fly Machines API, finds any
worker machines in `stopped` state, and starts them. The recovered
machine surfaces as a successful probe on the next tick. If start
didn't help (real crashloop), failures keep climbing and the alert
still fires at the threshold.

Requires the `FLY_API_TOKEN` secret on the app — without it, recovery
is a no-op and behavior matches PR #4358 exactly. Mint with
`fly tokens create deploy -a adcp-docs` and set via `fly secrets set`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bokelley bokelley changed the title docs(fly): correct misleading worker autostart comment (#4723) feat(watchdog): active recovery for stopped workers (#4723) May 18, 2026
@bokelley bokelley merged commit 1210435 into main May 18, 2026
13 checks passed
@bokelley bokelley deleted the bokelley/fly-worker-comment-correction branch May 18, 2026 10:01
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.

Worker recovery gap: auto_start_machines is a no-op without ports; watchdog only alerts, doesn't restart

1 participant