Repository navigation
Description
Epic: #736 · Phase: 1 (spine) · Depends on: #737, #738 · Blocks: #744 · Local target: #740
Reviewed 2026-07-11. The local target is live:
flyApplyis developed and
tested againstmudflapsv0.3.0 (ghcr.io/intentius/mudflaps,:4280),
booted by the #740 wrapper. It exercises the tricky paths (lease-conflict
retry, wait-on-new-version) with real fidelity, so those are testable today.
Context
The meat of the epic: flyApply, a native applier that speaks flaps REST directly. Peer of
gcpApply (#706) — read lexicons/gcp/src/op/activities/gcp-apply.ts first; this mirrors its
shape (a direct-REST applier that does its own diff + owned-only prune). See #736 for the
decisions log.
Decisions that constrain this (from #736)
- D1 — direct REST, no
flyctlshell-out, no state file. - D2 — owned-only prune via the
managed-by: chantmachine metadata; app-scope for
metadata-less types. - D3 — endpoint override via
FLY_FLAPS_BASE_URL(defaulthttps://api.machines.dev,
/v1prefix). Same mechanism points the applier at real Fly or atmudflaps(:4280) with
no code change.
What to build
- Consume chant's Fly resources (the generated types from fly lexicon: scaffold chant-lexicon-fly (chant init lexicon + OpenAPI generate) #737 + fly lexicon: App + Machine typed resources + serializer (machine-config / fly.toml) #738) and the lifecycle
change-set (packages/core/src/lifecycle/change-set.ts— create/update/delete/adopt already
classified) in dependency order (app → volumes → machines). - Drive flaps per resource:
- Apps:
GET/POST /v1/apps,GET/DELETE /v1/apps/{app}. - Machines:
POST /v1/apps/{app}/machines(create),POST .../{id}(update),
DELETE .../{id}(destroy),GET .../{id}+GET /v1/apps/{app}/machines(list). - After each mutation, poll
GET .../{id}/wait?state=started&version=<new instance_id>
(fly-go sendsversion; client self-caps at 60s → re-poll) until settled.
- Apps:
- Owned-only prune (D2): list machines, filter by
managed-by: chant; never touch an
unmarked machine; destroy a declared-then-removed owned machine. - Leases: acquire (
POST .../{id}/lease) before mutating; send the nonce in the
fly-machine-lease-nonceheader on update/stop/destroy; release after; on a stale/lost nonce
(409 with the holder's lease), re-acquire + retry. - Endpoint override (D3): honor
FLY_FLAPS_BASE_URLor an explicitendpointoption.
Where it lives
lexicons/fly/src/op/activities/fly-apply.ts (+ fly-apply.test.ts, index.ts) — mirror the
gcp op/activities/ files.
References
- Pattern:
lexicons/gcp/src/op/activities/gcp-apply.ts(diff, LRO wait, prune). - Behavioral oracle:
superfly/fly-goflaps/flaps.go(base URL +FLY_FLAPS_BASE_URLoverride),
flaps_machines.go(NonceHeader, update/lease semantics),flaps_machines_wait.go
(version/repeatablestate, 60s cap). Endpoints:openapi3.json. - Local target:
mudflaps(fly lexicon: chant-side flaps wrapper (boot the mudflaps image for local tests) #740) — supports the full loop incl. the version filter and
lease-conflict envelope, so every acceptance criterion below is reproducible offline.
The catch (be honest)
No server-side declarative apply — this loop is hand-rolled (the gcp model). The genuinely
tricky paths are lease-conflict retry and waiting on the correct version (new instance_id)
after an update; both are exercised by mudflaps.
Acceptance criteria
- Applies App + Machine to a flaps endpoint: create →
/waitstarted; re-apply is a no-op;
image change → update to a new version; removing the owned machine prunes it. - Owned-only prune proven: an unmarked machine survives an apply that would otherwise delete it.
- Endpoint override proven against
mudflapsand (smoke) real Fly with a token. - Lease-conflict path exercised against
mudflaps(stale nonce → 409 → re-acquire → succeed).
Out of scope
Volumes/IPs/certs/secrets applying (#741); the deploy Op + example (#744).
Activity
fly: App + Machine serializer emitting flaps create bodies (#738) (#751)
fly: flyApply — direct flaps REST applier with leases, wait, owned-on…
fly: describeResources for plan + drift (#767) (#775)