Skip to content

design(fly): reconcile a Sprite's network policy + services (typed config) #849

Closed

Description

@lex00

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:

  1. 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.
  2. Services — background processes the runtime owns: auto-start on boot, restart on crash, --needs startup ordering, optional --http-port routing 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 against network.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 --needs dependency 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

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

  1. added
    enhancement
    on Jul 13, 2026
  2. lex00 commented on Jul 13, 2026

    @lex00
    ContributorAuthor

    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:

    • the Anthropic runner runs as a supervised service → spriteApplyServices,
    • the per-session Sprite gets an egress allowlist → 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.

  3. lex00 commented on Jul 13, 2026

    @lex00
    ContributorAuthor

    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/network with {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-update
    • POST .../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 flyApply pattern 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) and validateServices (needs references 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions