Managed fleets design draft (#457)
Self-service managed fleets: boxes a member rents from the deployment's operator, for rootfs and native apps behind the CARLOS router. Three phases: fleet apps without an operator (routes, box choice, #451), managed fleets with no billing, carloku's monthly billing and per-fleet VPC peering.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+380
−0
docs/superpowers/specs/2026-10-28-managed-fleets-design.md+380 −0
CI passed — run details
diff --git a/docs/superpowers/specs/2026-10-28-managed-fleets-design.md b/docs/superpowers/specs/2026-10-28-managed-fleets-design.md| new file mode 100644 |
| index 000000000..6aa15c63b |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-10-28-managed-fleets-design.md |
| @@ -0,0 +1,380 @@ |
| +# Managed fleets: boxes a member rents from the deployment's operator |
| + |
| +Status: draft for Paul's read, 2026-10-28. Discussion: amadan #457. |
| +Branch: `design-managed-fleets-457`. |
| + |
| +## 1. Intent |
| + |
| +A member should be able to say "give me three boxes of this size, ready |
| +for my apps" and get them, from the CLI, without AWS credentials, SSH, |
| +SSM, OpenTofu, hand-minted tokens or an operator writing routes. |
| + |
| +The first user is a team moving an existing app (Rails first, but |
| +anything that runs as a rootfs app) onto CARLOS without rewriting it. |
| +They run the existing app on rented boxes behind the CARLOS router, then |
| +move pieces of it to native CARLOS apps over time. Native CARLOS apps can |
| +be placed on the same boxes. A managed fleet is an ordinary fleet whose |
| +boxes the platform created. |
| + |
| +The boxes live in the cloud account of whoever operates the CARLOS |
| +deployment. On carloku.com that is carloku. On a self-hosted deployment |
| +it is that operator's own account, which is where its databases already |
| +are. This is the first case to ship: an operator runs their own CARLOS |
| +deployment, their app's database is in RDS and its caches in |
| +ElastiCache in the same AWS account, and they want boxes for the app |
| +inside that network. |
| + |
| +## 2. Goals, non-goals, anti-goals |
| + |
| +Goals: |
| + |
| +- A member creates, inspects and removes a managed fleet's boxes through |
| + the console API and `carlos` CLI, and gets every diagnostic there too, |
| + including bootstrap failures. |
| +- Rootfs apps and native apps placed on a managed fleet get a public |
| + CARLOS URL (and custom domains and certificates) with no hand-written |
| + route. |
| +- Creation is safe to interrupt and retry. A lost connection, a console |
| + restart or an ambiguous cloud response never launches a duplicate box |
| + and never leaves a box running that the console does not know about. |
| +- Boxes are useful only to the account that owns the fleet. Nothing on a |
| + managed box can read the platform's deployment bucket or another |
| + account's data. |
| +- On carloku, boxes are paid for monthly, before they are handed over. |
| + |
| +Non-goals (later, separately): |
| + |
| +- Autoscaling, automatic box replacement, several regions per fleet, |
| + other clouds. |
| +- Running one app on several boxes for load or availability. Three boxes |
| + give capacity. Replicas are other work (rootfs replicas, region HA). |
| +- Roles that restrict who in an account may create boxes (Paul, |
| + 2026-10-28: "any member for now and we do roles etc. later"). |
| +- Moving an *existing* app onto a fleet. `carlos apps place` is cut once |
| + the hostname history is active (nearest-region-without-claims spec |
| + §5), so phase 1 places apps at creation with `carlos apps create |
| + --place fleet/<f>`. Moving existing apps is a later item. (My call.) |
| +- Operator-supplied hosted databases. The member's databases stay where |
| + they are. |
| + |
| +Anti-goals (would make this a failure even if it works): |
| + |
| +- A member, or a bug, can make the operator pay for boxes nobody tracks. |
| +- A managed box gains reach into the platform or another tenant: the |
| + deployment bucket, other fleets, the operator's own VPC resources |
| + beyond what the operator listed. |
| +- Self-service that quietly needs an operator step (a manual route, a |
| + hostname-history rescan, a token pasted over SSM). |
| +- A first version that only works on AWS by baking AWS into core |
| + packages. AWS is an adapter (provider-neutral core rule). |
| + |
| +## 3. What already exists (recon, main at 674fec48) |
| + |
| +- **Fleets** (`fleets.go`, `internal/console/fleets.go`, |
| + `internal/registry/fleets.go`, `internal/fleetapi/`). Account-owned; |
| + the owner record is `accounts/<acct>/fleets/` (`fleetowner.go`). A box |
| + joins with a bearer token from `carlos fleets add-box` (sha256 stored, |
| + plaintext printed once) and dials a reverse tunnel to the hub edge. |
| + Fleet boxes have no deployment-bucket credentials; they read and write |
| + only through the edge store door (`internal/edge/storedoor.go`), which |
| + scopes them to `accounts/<sqid>/`, `apps/<sqid>/` and `fleets/<fleet>/`. |
| + The fleet's data bucket is supplied by the customer |
| + (`fleets create --bucket`). |
| +- **Rootfs apps** (#366). Plans 1–4 are merged. A box is rootfs-ready |
| + per `internal/host/rootfsplacement.go`; the console admits a rootfs |
| + placement only when every fresh active box in the fleet reports |
| + `rootfs_ready` on v0.29.0 or later (`internal/console/rootfs.go`). |
| +- **Plans and billing** (`internal/plans`, `internal/billing`, |
| + `internal/billingstripe`). Yearly plans and packs as quantities on one |
| + Stripe subscription; raises charged now with `pending_if_incomplete`; |
| + reductions take effect at renewal; ops recorded before the first send. |
| + Fleets are paid-only (`checkFleets`). |
| +- **PR #183** (`trust-placement`, GitHub only, 1,564 commits behind |
| + main). Built most of an earlier version of this: `internal/compute` |
| + (a provisioner interface, an EC2 adapter and a fake), a hardened |
| + first-boot script (`internal/console/userdata.go`), tag-identified |
| + terminate, an orphan sweep. Its hourly `box_hours` billing and |
| + "re-run to repair" recovery are superseded. The earlier approved |
| + design is |
| + `platform-infrastructure/platform-design/superpowers/specs/2026-08-12-private-instances-design.md`. |
| +- **Nothing on main launches or terminates cloud instances.** EC2 is |
| + used read-only (`internal/awsinv`, `internal/termfence`). |
| + |
| +## 4. Phases |
| + |
| +Each phase is useful on its own and gets its own plan. |
| + |
| +### Phase 1: fleet apps work without an operator |
| + |
| +Three blockers that stop *any* fleet, managed or not, being |
| +self-service today. Phase 1 is visible first (stopping rule 6): the |
| +Rails sample on the dev fleet box serves at its public URL with no |
| +hand-written route. |
| + |
| +**1a. Public routes for fleet-placed apps.** Today the box the router |
| +reaches (the hub edge, which holds fleet tunnels) never has a route row |
| +for a fleet-placed app: platform-box reconcile refuses fleet records |
| +from both sides (`inScope`, `internal/provision/reconcile.go:487-499`) |
| +and the console never writes route rows. Every fleet instance needs a |
| +hand row. Fix: the hub edge holds a *forwarding* row for each |
| +fleet-placed record whose fleet it carries tunnels for, pointing at the |
| +fleet and the box running the instance (`fleetProxy`, |
| +`internal/edge/edge.go:3059`). The tenancy boundary `inScope` protects |
| +stays: a platform box never *runs* a fleet record, and a fleet box never |
| +picks up a platform record. A forwarding row is written only when the |
| +fleet's owner record names the same account as the app's record. |
| +Custom domains and certificates for fleet apps follow from the row. |
| +Covers native and rootfs apps alike. Coordinate with the rootfs session |
| +(#366 Task 11 needs this). |
| + |
| +**1b. Box choice within a fleet.** A fleet of three boxes must put each |
| +instance on exactly one box, spread instances across the boxes, keep |
| +one writer per instance database (the Litestream lease), and tell the |
| +hub which box serves it (`fleetChannelFor`'s `boxLabel`). The recon |
| +found no per-instance box choice for multi-box fleets on main: the |
| +claim-based box placement was shelved (#404). The builder's first task |
| +is to establish what a multi-box fleet does today. If it already |
| +spreads instances with one writer each, 1b is a test. If it doesn't, 1b |
| +is a small placement rule, owned by the console and recorded on the |
| +instance (my guess: least-loaded ready box at create, fixed after). |
| +This is the largest unknown in the design. |
| + |
| +**1c. A reboot doesn't cost 15 minutes (#451).** After a rootfs box |
| +reboots, the agent can't recognise the lease its own previous boot |
| +held, because the lease owner names the pid but not the boot id, so the |
| +instance waits out the lease. Fix #451: a lease is recognisable as this |
| +box's earlier boot and released at start. Verify by rebooting a dev |
| +fleet box under load. |
| + |
| +### Phase 2: managed fleets, no billing |
| + |
| +The core feature, first on a self-hosted deployment with no plan |
| +catalog (so nothing is billed). |
| + |
| +**Member experience** (illustrative syntax; copy review settles the |
| +words): |
| + |
| + carlos fleets create production --managed --region eu-west-1 --size large --boxes 3 |
| + carlos fleets show production # each box: state, version, ready checks, last error |
| + carlos apps create shop --place fleet/production |
| + carlos fleets boxes add production --boxes 1 |
| + carlos fleets boxes remove production box-3 |
| + carlos fleets remove production |
| + |
| +`create` prints what will be launched (and, on carloku, the monthly |
| +price), returns an operation the CLI follows, and keeps working if the |
| +CLI goes away. `carlos fleets show` re-attaches. Re-running the same |
| +command while an operation is open joins that operation; it never buys |
| +more boxes. |
| + |
| +**Operator configuration.** The operator turns the feature on and |
| +decides, per region: the size list (a short list of ARM instance |
| +types, each with a name like `large`), the pinned machine image, the |
| +subnets and security groups boxes launch into, and a deployment-wide |
| +ceiling on managed boxes. On a self-hosted deployment the subnets are |
| +the ones that can already reach the operator's RDS and ElastiCache, so |
| +no peering is needed. Configuration is operator-written, not |
| +member-writable. Where it lives (system config, `host.env`, a signed |
| +catalog object) is the builder's call; it must not add per-box bucket |
| +polling (see §6). |
| + |
| +**Who may create boxes.** Any member of an account (Paul). Limits: the |
| +deployment-wide ceiling and a per-account box limit (on carloku, from |
| +the plan catalog; on self-hosted, defaulting to the ceiling). Both are |
| +checked under a lock that makes two concurrent creates unable to exceed |
| +them together. |
| + |
| +**Provisioning.** |
| + |
| +- Every create is a durable console operation, recorded before anything |
| + is launched. Each box gets its identity (fleet, label, operation) |
| + first, and that identity goes to the cloud as the launch's |
| + idempotency token (EC2 `ClientToken`) and as tags. A retry, a restart |
| + or an ambiguous response re-asks with the same identity and finds the |
| + same box. |
| +- A console-side worker drives open operations to an end, after |
| + restarts too. This replaces the 2026-08-12 design's "synchronous |
| + handler, repaired by re-run" model, which #457 asked to revisit: a |
| + member who closes their laptop must not leave an operation stuck |
| + half-way. |
| +- A periodic sweep lists cloud resources carrying the deployment's tags |
| + and reports (and, past a grace period, terminates) any the console has |
| + no record of. Terminate refuses any instance whose tags don't name |
| + the fleet and box it was asked to end (#183's identity-checked |
| + terminate). |
| +- Partial failure: if some boxes come up and others don't, the fleet |
| + keeps the boxes that are ready, the operation reports which failed and |
| + why, and failed boxes are terminated. The member can retry the |
| + missing count. |
| +- The provisioner sits behind an interface (`internal/compute` from |
| + #183 is the starting point) with a fake for tests. The AWS adapter |
| + loads through `internal/rootaws`. |
| + |
| +**The fleet's storage.** A managed fleet gets a data bucket the console |
| +creates for it, the way object storage creates a store |
| +(`objstore.Provisioner`). Boxes reach only that bucket. How a box gets |
| +credentials for it (an instance profile per fleet, or a per-fleet IAM |
| +user like `objstore.EnsureUser`) is the builder's call, with one |
| +constraint: the console role's new IAM authority is no broader than it |
| +needs, and gets its own security review. #183 created a role per fleet, |
| +which needs `iam:CreateRole` and `PassRole` on the console; prefer a |
| +design that needs less. |
| + |
| +**Enrolment.** A box joins its fleet without any long-lived secret |
| +appearing in user data, logs, progress output or the console's pages. |
| +My guess at the mechanism: user data carries a one-time enrolment token |
| +that expires within minutes and that the box trades, on first contact, |
| +for its ordinary fleet token; the trade is refused after first use. The |
| +box fetches the binary through the store door (`bootstrap/carlos`) and |
| +verifies it as platform boxes do. Port #183's first-boot hardening |
| +(parameter allowlists, IMDS gate, shredding cloud-init copies). |
| + |
| +**Born examined.** The hostname history (nearest-region-without-claims |
| +spec) refuses data-kind creates on a fleet it has not examined, and |
| +refuses new boxes on a fleet it has (`fleetGrowthRefusal`, N9). Both |
| +exist because a BYO box may already hold an app's data. A managed box |
| +was launched by the console from a pinned image onto fresh volumes, so |
| +it cannot. A managed fleet is therefore recorded as examined when it is |
| +created, and a managed box may join it, on one condition: the box's |
| +first report, before it accepts any work, lists its data directory as |
| +empty. A box that reports anything else is refused and terminated. BYO |
| +fleets keep the operator flow unchanged. |
| + |
| +**Ready means ready.** A box counts as ready, and the operation as |
| +done, only when all of these hold: it is registered and active in the |
| +fleet; it runs the deployment's expected platform version; it reports |
| +`rootfs_ready`; the fleet owner record names the member's account; it |
| +can write and read its fleet bucket; and a probe through the router |
| +reaches it over its tunnel. "Running" in EC2 or a bare heartbeat is not |
| +enough. Each check's state shows in `carlos fleets show`. |
| + |
| +**Diagnostics.** Every failure a member can hit, bootstrap included, |
| +is visible through the API and CLI: the cloud's launch errors, the |
| +box's first-boot breadcrumbs (posted through the store door, or read by |
| +the console from the instance console output), the readiness check that |
| +failed. No AWS console, SSH or SSM for the member. |
| + |
| +**Removal.** |
| + |
| +- Removing a box stops new placements on it at once. While it still |
| + runs instances, the removal is refused with a message naming the |
| + apps. (My call.) Moving instances between a fleet's boxes is not |
| + built today: moves refuse fleet routes (`apiinstancemove.go:65`). If |
| + 1b's placement makes an in-fleet move cheap (the instance hibernates |
| + to the fleet bucket and wakes on another box), removal drains instead |
| + of refusing; the builder decides once 1b is known. |
| +- Removing a fleet is refused while any app is placed on it. |
| +- Termination is checked against tags. The fleet bucket is kept while |
| + any box still uses it. After the last box goes it is kept 30 days, |
| + then deleted, and `carlos fleets show` says when. (Carried from the |
| + 2026-08-12 design.) |
| +- On carloku, a removed box keeps running until the end of its paid |
| + month, then is terminated (phase 3). On self-hosted, at once once |
| + drained. |
| + |
| +### Phase 3: carloku layers |
| + |
| +**Monthly billing.** Boxes are billed monthly, per box, priced per size. |
| +Paul, 2026-10-28: monthly is easier. The yearly subscription can't carry |
| +them: Stripe Checkout can't create mixed-interval subscriptions, a |
| +renewal stop ends at the earliest item's period, a failed box invoice |
| +would take the plan with it, and the pinned API version predates mixed |
| +intervals (billing recon; `internal/billingstripe/prepared.go:148`, |
| +`client.go:34`). So boxes go on a separate monthly subscription with |
| +its own role, beside the plan subscription. |
| + |
| +- Buying: the console launches the boxes in a held state (not yet |
| + available to the member), then charges. The first purchase goes |
| + through Checkout; later boxes are prorated raises with |
| + `pending_if_incomplete`, using the existing op machinery. Boxes are |
| + handed over when the charge applies. A failed or abandoned charge |
| + terminates the held boxes, and nothing was charged. A box that fails |
| + to come up is never charged. Holding first avoids needing refunds, |
| + which billing doesn't do today. (Recon's recommendation; my call.) |
| +- Removing: a reduction at renewal, as packs and seats already do. The |
| + box runs until the paid month ends. (Paul: "I don't really mind"; |
| + this matches the existing "leaver comes off at renewal".) |
| +- Box compute is not metered on top. Managed boxes must not accrue on |
| + `fleet_box_hours_*` (`internal/usage/usage.go:24-25`). |
| +- Bandwidth and storage stay under the member's plan and packs. |
| + |
| +**Reaching the member's own databases.** On carloku, the member's |
| +databases are in their AWS account, not carloku's. Each managed fleet |
| +gets its own VPC in carloku's account with an address range the member |
| +chooses, sealed off from other fleets and from the platform's own boxes |
| +except the tunnel to the router. It is peered with the member's VPC; |
| +the member accepts the peering request and opens their security groups. |
| +That one AWS-console step is the only thing the member does outside |
| +CARLOS, and the CLI tells them exactly what to accept. This is phase 3, |
| +not phase 2: on a self-hosted deployment the boxes already launch in |
| +the operator's network. |
| + |
| +## 5. Provider boundary |
| + |
| +- **Core** (no cloud SDK): operations, box records, quotas, readiness, |
| + enrolment, born-examined, removal, billing, the CLI. Tested end to end |
| + against the fake provisioner. |
| +- **AWS adapter**: launch, describe, terminate, tag listing, the fleet |
| + bucket and its credentials, and (phase 3) VPC and peering. Loaded |
| + through `internal/rootaws`. The console role gets launch and |
| + terminate on resources tagged for this deployment, in the operator's |
| + configured regions, with only the configured image, subnets and |
| + security groups. |
| +- **A deployment without AWS** gets no managed fleets (the feature |
| + stays off) and keeps BYO fleets unchanged. An import test keeps the |
| + AWS SDK out of core packages. |
| + |
| +## 6. Request budget |
| + |
| +A managed box is a fleet box: its steady-state store traffic is the |
| +same as a BYO fleet box today, through the store door, and this feature |
| +adds no per-box bucket polling. The provisioning worker calls the cloud |
| +API (EC2 describe calls) only while an operation is open. The orphan |
| +sweep is one list call per configured region per hour. Operator |
| +configuration is read on a change-index generation change, not on a |
| +timer. Each plan states its numbers and has a test counting store |
| +calls. |
| + |
| +## 7. Switch-on (stopping rule 5) |
| + |
| +- Phase 1: who asks is Paul, for the Rails migration case. On when merged |
| + and rolled to dev; proved by the Rails sample on the dev fleet box |
| + with no hand route and a reboot drill. |
| +- Phase 2: on for the first self-hosted deployment after a dev |
| + drill, with Paul's approval of the live test plan (account, region, |
| + resources, cost, duration, cleanup) as AGENTS.md requires. |
| +- Phase 3: on carloku once phase 2 has run on the self-hosted deployment |
| + and the monthly price per size is set by Paul. |
| + |
| +## 8. Acceptance checks |
| + |
| +1. Three boxes requested from the CLI all become ready, with every |
| + readiness check shown passing. |
| +2. A Rails rootfs app and a native app, placed on the fleet at creation, |
| + serve at their public URLs (and a custom domain), with no hand route. |
| +3. Fake-provisioner tests: interrupted create, console restart mid- |
| + operation, ambiguous launch response, retry of the same command, |
| + partial capacity failure, two concurrent creates at the quota edge. |
| + None leaves a duplicate or untracked box. |
| +4. Cross-account refusals: another account can't place on, inspect or |
| + remove the fleet; a managed box's credentials can't reach the |
| + deployment bucket or another fleet's bucket. |
| +5. Enrolment secrets never appear in logs, progress output or pages. |
| +6. Reboot recovery (1c); removal with active workloads (drain, or |
| + refusal); the fleet keeps serving on surviving boxes; the bucket is |
| + retained as stated. |
| +7. Phase 3: buying, failed charge, failed launch and removal each charge |
| + exactly what this spec says and nothing twice. |
| +8. Commands documented in `docs/site/cli.md`; copy review for every |
| + member-facing string. |
| + |
| +## 9. Left to the builder |
| + |
| +- Command and flag names (copy review settles words). |
| +- Where operator configuration lives, within §6's budget. |
| +- Instance profile versus per-fleet IAM user for bucket access, within |
| + §4's constraint. |
| +- The enrolment token's exact form. |
| +- Table and record shapes, the worker's schedule, the sweep's grace |
| + period. |
| +- What to port from #183 versus rewrite. |