Repository navigation
Description
Context
A Sprite carries two pieces of genuine desired-state config, distinct from the sprite itself (whose create body is nearly empty — { name, wait_for_capacity, url_settings }, no reconcilable fields). Both are set via the API after create, and both persist across cold boots:
- Network policy —
/.sprite/policy/network.json, a DNS-based outbound allowlist. Read-only inside the Sprite, modified via the Sprites API. Rule-based with specificity ordering:{ "include": "defaults" },{ "domain": "*.example.com", "action": "allow" }, deny-by-default when rules are present. Changes reload live. - Services — background processes the runtime owns: auto-start on boot, restart on crash,
--needsstartup ordering, optional--http-portrouting to the public URL, signal/stop/logs. REST at/v1/sprites/{name}/services. The docs note the REST surface "enables fleet provisioning where service configurations persist" — i.e. desired-state.
This is chant's core competency (typed config → serialize → reconcile → lint). But it does not fit the declarable-resource mold: a Sprite is an Op primitive (#762), not a stable long-lived resource, and there is no sprite-level desired state to hang these off. So the shape needs a design decision before code.
The design question
How should chant express and reconcile a Sprite's network policy and services?
Leading option — apply activities (the flyApply plan→CRUD pattern, scoped to a live Sprite):
spriteApplyNetworkPolicy({ id, rules })— diff desired rules againstnetwork.json, PUT the reconciled policy.spriteApplyServices({ id, services })— diff desired service set against the live set, create/update/stop to converge; owned-only so foreign services are untouched.
Typed config authored in the Op (or a small typed builder), reconciled at runtime. Keeps the imperative-primitive model intact while giving the config a typed, diffable shape.
Alternative to weigh — a thin declarative overlay (typed NetworkPolicy / Service config objects with a serializer + lint) consumed by the apply activities, so the same config gets build-time lint even though it is reconciled imperatively.
To investigate / decide
- Reconcile semantics: what is drift for a live Sprite's services (config vs running state)? What does read-back return?
- Ownership: services/policy have no metadata marker — is there a labels mechanism, or is the Sprite id the boundary? (ties the ownership convention fly lexicon: ownership convention — machine metadata + app boundary (ties #686) #743)
- Owned-only convergence: can we scope service prune to chant-authored services, or is it all-or-nothing?
- Lint value: service
--needsdependency cycles; network-rule validation (unreachable rules, raw-IP rules, over-broad wildcards). Which are build-time vs runtime checks? - Whether config lives as typed objects (serializer + lint) or plain activity args.
- Boundary: stays in the fly lexicon.
Drivers
- The Managed Agents runner (feat(fly): Managed Agents worker Op on Sprites (per-session sandbox execution) #847) runs as a supervised service —
spriteApplyServicesis the typed way to declare it. - Egress allowlisting for agent sandboxes is a security story that ties into the governance/audit theme (#787, supply-chain/pinning cycle governance: supply-chain pinning cycle #474) — a typed, linted network policy is a natural fit.
Acceptance criteria (design)
- A written recommendation: apply-activities vs declarative-overlay (or hybrid), with the reconcile/ownership/drift semantics spelled out.
- A proposed typed shape for network policy and service config, and the lint rules worth having.
- Decomposition into implementation issues if greenlit; the reason recorded if not.
Parent epic: #736 (Fly.io apply path). Builds on #762; relates to #847 (services driver) and #743 (ownership).
Activity
lex00 commentedon Jul 13, 2026
Demo plan — showcased inside the #847 worker tutorial, no standalone example (unless declarative)
The reconcile primitives from this issue (
spriteApplyNetworkPolicy,spriteApplyServices) are demonstrated inside the #847 Managed Agents worker tutorial, not a separate example:spriteApplyServices,spriteApplyNetworkPolicy(the security angle).Give this its own example only if the design lands as a declarative overlay (typed config + serializer + lint) that needs a distinct build → plan → apply demo separate from the worker. If it lands as apply-activities, the worker tutorial is the showcase and no new example is added. Fold the demo decision into the design recommendation.
lex00 commentedon Jul 13, 2026
Design recommendation: apply-activities (not a declarative overlay)
Grounded the two surfaces against the API docs:
Network policy — whole-object replace.
GET /v1/sprites/{id}/policy/network→{rules:[{action,domain}]}POST /v1/sprites/{id}/policy/networkwith{rules:[...]}replaces the set; changes apply live.Services — keyed by name, PUT-idempotent.
GET /v1/sprites/{id}/services(list),GET .../services/{svc}(get)PUT /v1/sprites/{id}/services/{svc}with{cmd,args,env,dir,needs,http_port}— create-or-updatePOST .../start|stop|restart(NDJSON). No DELETE in the documented REST surface.Decision
Apply-activities, not a declarative overlay. A Sprite isn't a stable declarable resource (empty create body, per #848 findings), and there's no build→plan→apply pipeline to hang a serializer/post-synth-lint off. So the reconcile lives in the Op/activity layer, matching the
flyApplypattern scoped to a live Sprite:spriteApplyNetworkPolicy({ id, rules })— GET current, diff, POST desired only if changed. Returns{ changed }.spriteApplyServices({ id, services, start? })— list current, PUT each desired (create/update), optionally start. Returns{ applied }.Lint → pure validators called at apply time (no post-synth rules, since there's no build phase):
validateNetworkRules(non-empty domain, valid action) andvalidateServices(needsreferences resolve + are acyclic). They throw before any HTTP, and are unit-testable.Prune caveat (deferred)
Services expose no DELETE, so owned-only prune of stale services isn't cleanly achievable and is out of scope for v1. Services reconcile is additive + update. Network policy is a whole-object replace, so it converges by construction. If a DELETE endpoint appears (or stop-as-prune is acceptable), prune is a follow-up.
No new example
Demonstrated inside the #847 worker tutorial (runner-as-service + per-session egress allowlist), per the demo plan. Integration tests here prove reconcile against the fake.
feat(fly): reconcile a Sprite's network policy + services (#849)
feat(fly): Managed Agents worker Op on Sprites + keep-alive Tasks (#847)
feat(fly): reconcile a Sprite's network policy + services (#849) (#854)
feat(fly): Managed Agents worker Op on Sprites + keep-alive Tasks (#847)
feat(fly): Managed Agents worker Op on Sprites + keep-alive Tasks (#847…
lifecycle: emit --json for the --live diff path (#852) (#857)
fly: pin spritzer 0.4.0 + extend the Sprites contract for fs/policy/s…
release: chant 0.18.8 (#861)
docs: Managed Agents worker tutorial + sidebar (#864)
docs: Managed Agents worker tutorial + sidebar (#864) (#865)