Skip to content

fly: flyApply — direct flaps REST applier (leases, wait, owned-only prune) (#739) - #753

Merged
lex00 merged 1 commit into
mainfrom
fly-apply-739
Jul 11, 2026
Merged

lex00 merged 1 commit into
mainfrom
fly-apply-739

Conversation

@lex00

@lex00 lex00 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Closes #739 (Phase 1 spine — the meat of the epic). A native applier that speaks flaps REST directly, the peer of gcpApply. Consumes the #738 serializer plan and drives flaps in dependency order (app → [volumes, #741] → machines).

Decisions honored

  • D1 — direct REST, no flyctl shell-out, no state file.
  • D2 — owned-only prune via config.metadata["managed-by"] == "chant"; an unmarked machine survives an apply that would otherwise delete it.
  • D3 — FLY_FLAPS_BASE_URL / explicit endpoint override (default https://api.machines.dev, /v1). Same knob points at real Fly or mudflaps. Bearer FLY_API_TOKEN when set.

The tricky paths (fidelity, from mudflaps' Go source)

  • Wait on new version: after create/update, poll GET .../wait?state=started&version=<new instance_id>; 408 / not-settled → re-poll (client self-caps past the server's 60s long-poll).
  • Leases: acquire → mutate with the fly-machine-lease-nonce header → release. On a stale-nonce 409 (lease_currently_held / "machine is leased"), re-acquire a fresh nonce and retry the mutation once.

Tests — two layers

  • 21 unit tests, injected FlyHttp: endpoint resolution, wait-on-version, re-apply no-op, image-change update, owned-only prune (unmarked survives), and the lease-conflict retry (asserts the nonce carried on each attempt).
  • Live mudflaps integration test (fly lexicon: chant-side flaps wrapper (boot the mudflaps image for local tests) #740 wrapper): full acceptance loop (create → started → no-op → update → new version → prune; unmarked machine survives) + the gated-update 409 → re-acquire → succeed path. Runs locally against a real container; skips deterministically in CI (CI env — no docker pull, the only emulator-backed test in the repo).

Full fly suite: 39 passing locally (incl. the live integration run). validate types-compile + check-lexicon clean.

Deferred to #741: volumes are ordered between apps and machines (hook in place); non-app/non-machine plan entries pass through the classifier untouched, ready for volume/IP/cert/secret handling.

🤖 Generated with Claude Code

…ly prune (#739)

Native applier that speaks flaps REST directly (D1: no flyctl, no state file),
the peer of gcpApply. Consumes the #738 serializer plan and drives flaps in
dependency order (app → [volumes #741] → machines):

- Endpoint override (D3): FLY_FLAPS_BASE_URL or explicit endpoint, default
  https://api.machines.dev with the /v1 prefix — same knob points at real Fly
  or mudflaps. Bearer FLY_API_TOKEN sent when set.
- Machines: GET-then-create/update/destroy; after each mutation poll
  GET .../wait?state=started&version=<new instance_id> (408/not-settled → re-poll,
  client self-caps past the server's 60s long-poll).
- Owned-only prune (D2): only machines with config.metadata["managed-by"]=="chant"
  are touched; an unmarked machine survives an apply that would otherwise delete it.
- Leases: acquire → mutate with the fly-machine-lease-nonce header → release; on a
  stale-nonce 409 (lease_currently_held / "machine is leased") re-acquire a fresh
  nonce and retry the mutation once.

Pure logic (diff, prune filter, url/lease-conflict decisions) is factored into
exported functions and unit-tested with an injected FlyHttp (21 tests). A live
mudflaps integration test (#740 wrapper) proves the full acceptance loop and the
lease-conflict retry against real wire behavior; it runs locally (docker) and
skips deterministically in CI (CI env, no docker pull).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lex00
lex00 merged commit d3d2eb7 into main Jul 11, 2026
5 checks passed
@lex00
lex00 deleted the fly-apply-739 branch July 11, 2026 16:59
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.

fly lexicon: flyApply — direct flaps REST applier (endpoint-overridable, owned-only prune, leases)

1 participant