carlos / platform Public

docs: guide for apps with one instance per customer (#994)

A hub app beside the per-customer app: provisioning with an instance
credential, sign-in once with a signed pass, shared data, a shared
rate-limited API, background work without always-on instances, reports,
busy customers, and the gaps today (#990, #993, #992).

Copy: Luna-drafted, plain and humane passes, Luna copy gate (Paul's
2026-11-06 docs delegation) with both changes applied.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1f9c7968f09e15a7c1f38b2060b8b027743278e0 parent 7e0c953
2 files changed, +136 −0
  • docs/site/nav.json +5 −0
  • docs/site/one-instance-per-customer.md +131 −0

CI passed — run details

Intent

Human

<task-notification> <task-id>aa936e2e07e762637</task-id> <tool-use-id>toolu_01WXgeYr1oemP6QDPZPJ2vxK</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/96a09f74-e398-48ed-a97f-140bd1f7e255/tasks/aa936e2e07e762637.output</output-file> <status>completed</status> <summary>Agent "Implement #991 GOMEMLIMIT for instances" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I've added the GOMEMLIMIT default for binary instances. The new tests and the census tests pass. The branch is three commits; nothing is pushed, merged or posted. **One number differs from the brief.** I used your formula, `max/10*8`, the same style as `HighOf`. For small that gives **214748360**, not the 214748364 in your example (that one is `max*8/10`). The others are standard 429496728, large 858993456 and xlarge 1717986912. **Launch paths:** - **Flat exec child** (`spawnChildFrom`, backend_exec.go:2601-2613): now sets it. This covers Start, StartGen, StartGenExe and StartStaged. The tier is read once and the same value goes to the cgroup spawn. With no cgroup delegation the child runs uncapped and gets nothing. - **Nested unit** (`spawnUnitFrom`, backend_exec.go:2905-2915): now sets it. The value comes from the tier passed to `startRole`, which is the memory_max root applies. `startRole` (containment.go:366-371) now takes a tier its caller already read at generation 0, instead of reading the live tier a second time. - **gVisor:** writes nothing. Root's `gvisorLauncher` already removes any launch value and puts in its fixed 241591905, so that behaviour is unchanged. - **Unchanged:** rootfs (`rootfsenv.go` not touched), co-spawned sidecars (they share the instance's cgroup), sidecar members, seeds, `carlos run` commands and unit-backed rows. - **Move env pins:** `LaunchLayers` leaves the default out on purpose. Otherwise every move between a box that sets it and one whose agent predates it would be refused. An app-set value is still included. - **App wins:** if the app's config or `&lt;host&gt;.env` names GOMEMLIMIT at all, its value is kept as written, including empty. **Tests added:** - `TestWithGoMemLimit` - `TestFlatStartSetsGoMemLimitFromTheChildsCgroup` (compares against `memory.max` in a fake cgroupfs) - `TestNestedStartSetsGoMemLimitFromTheTierRootApplies` (compares against the memory_max root was asked for) - `TestNestedGVisorStartLeavesGoMemLimitToRoot` - `TestSizeTableIsTheSpecsBytes` (existing, extended to the new values) Commands, all passing: - `TMPDIR=/tmp/g go test ./internal/activator/ -run 'TestWithGoMemLimit|TestFlatStart…|TestNestedStart…|TestNestedGVisor…|Swap|Size|Tier|StartGen|Identity|Plan14Generation|TestSandbox|…' -count=1` - `go test ./internal/cgroup/ -run 'TestSizeTable|TestSizesTableIsLiteral' -count=1` - `go test ./internal/provision/ -run 'TestPlan14RootReadCensus|TestCensusScopeIsTheRootBinary' -count=1` - `go test ./internal/docsite/ -count=1` `go build ./...`, `go vet`, `gofmt -l` and the darwin and windows builds are clean. **Mutation check:** with the app-override check, the gVisor guard and the no-cgroup guard all removed, the matching tests failed (app-set flat and nested cases, uncapped, gVisor). I then put the guards back. **Census:** overlay `plan14-root-reads-instance-gomemlimit-991.tsv` covers `spawnChildFrom`, `spawnUnitFrom` and `startRole`, and re-pins the activator and cgroup envelopes. The card is `docs/superpowers/notes/census-proposal-instance-gomemlimit-991.md`. It needs the reviewer's verdict on #280. **Docs sentence** (docs/site/cli.md, after the table in "What an instance is started with"): &gt; The box also sets `GOMEMLIMIT` to 80% of the instance's memory size, unless your app's config or `&lt;host&gt;.env` sets its own. **Commits:** b96db100 (code and tests), c058ec65 (census), 75e0c87f (docs). **Open questions:** - The same docs section says seeds and `carlos run` get "the same environment", but they don't get GOMEMLIMIT. Copy review may want to say so. - Sidecar members (`StartWorkerStaged`, `startHAWorker`) run alone in their own cgroup with a known tier, so they could take the same default as a follow-up. - If a flat best-effort `memory.max` write fails, the child still gets the default; that is harmless. Files are in /home/paulca/amadan.net/carlos/platform/.claude/worktrees/instance-gomemlimit-991: - internal/activator/gomemlimit.go - internal/activator/gomemlimit_test.go - internal/cgroup/cgroup.go</result> <usage><subagent_tokens>222581</subagent_tokens><tool_uses>86</tool_uses><duration_ms>808752</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>ade6c61052e7d7173</task-id> <tool-use-id>toolu_01CLLn9hyaoTdZpuYQACvoXv</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/96a09f74-e398-48ed-a97f-140bd1f7e255/tasks/ade6c61052e7d7173.output</output-file> <status>completed</status> <summary>Agent "Recon for #992 instance-to-fleet move" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I couldn't find any way to place a single instance today: placement is one setting per app, and moves only work between platform regions. The one thing I couldn't find is an offline-move refusal at the console door that rejects nested rows. The only one is on the landing box. All paths are relative to `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/docs-hub-guide-994` (origin/main 7e0c953e). **1. Placement model: stored on both the app and each instance** - **App level:** the store's placement column, `""` or `fleet/&lt;name&gt;`, read by `appPlacement` (`internal/console/fleets.go:700-737`). Instance create lets it override whatever region the request sends, and does so before region validation runs (`internal/console/apiinstances.go:1907-1917`). - **Instance level:** `provision.Record.Region` holds a region code or `fleet/&lt;name&gt;`. The record also carries `Pool`, `FleetBox`/`FleetBoxAt`/`FleetBoxMoved`, `HA`, `Move`/`LastMove` and `RegionChangedAt` (`internal/provision/provision.go:44-112`). `Pool` is copied from the app manifest (`provision.go:377`, `apiinstances.go:2218`). - **`placeAppTarget`** re-stamps every record of the app with `SetRecordRegion`. Its own comment calls the per-record copy a "tripwire" (`fleets.go:781-809`). It is refused for good with S3, "An app's placement can't be changed once it exists", once the hostname history is active or invalidated (`hostsused.go:52`, `fleets.go:826-835`). It is also refused for rootfs apps. - **Mixing placements in one app:** - Different platform regions: yes. Region is per record, limited by the manifest's `Regions` list. - Pooled vs fleet in one app: not supported. A fleet-placed app forces every instance onto the fleet. - Replicas: separate records with `Role`, each with its own region. - HA: the `HA` flag is stamped per record at create, and never cleared. **2. Moves** - **What changes:** the region only. The target is a region code checked by `provision.ValidRegion` against `^[a-z0-9-]{0,16}$` (`provision.go:904-906`). A `/` can't pass, so a fleet can't be named as a target. Live doors: `apiinstancemove.go:36-40, 442-449, 614-630`. Offline: `apiinstancemove_offline.go:526-533`. - **Live moves exclude fleets:** `moveGate` refuses them with "fleet-placed instances keep state-does-not-follow semantics" (`apiinstancemove.go:45-49, 95-98, 127, 146`). - The rule is D6 (`docs/superpowers/specs/2026-08-28-instance-move-design.md:177-178`). A fleet's data lives in the fleet's own bucket, and placement changes where an app serves, not where its data is (commit 03ff0013). - Pooled instances are refused too, because their data is on the pool's own box (`apiinstancemove.go:99-102`). - The Phase 1 spec also refuses records with `FleetBox`, `Pool` or `Tunnel` set (`move-any-app-design.md:1082-1083, 2093`). - **Offline moves refuse nested rows** on the landing box: "the row's paths are nested, and an offline move lands flat rows only" (`internal/host/movesoffline_land.go:476, 486-487`). The comment says the row must be held `landing` by this move "at flat paths". The Phase 1 spec says the same: "Phase 1 lands flat" (`move-any-app-design.md:2088`). - **Other offline rules:** exactly one box in the target region (`apiinstancemove_offline.go:399-405`), and off while host claims or Phase 1 moves are on (`:104-107`). Docs: `docs/site/cli.md:3325-3389`. - **Move specs:** - `2026-08-28-instance-move-design.md`: two-phase, data-following moves (#331); fleets refused. - `2026-10-02-move-any-app-design.md`: Phase 1 safe single-instance move between non-fleet placements; rev 7.24 adds moves into home (#236). - `2026-10-21-self-serve-offline-moves-design.md`: a tenant's customer moves their own instance offline, behind `CARLOS_SELF_SERVE_MOVES`. - `CODEX-FINDINGS-MOVES-R1.md` and `-R2.md`: review findings on the Phase 1 spec. **3. Boxes within a managed fleet** - **Pinning to a box:** not found. At create the console picks the ready box holding the fewest records (`chooseDestination`, `fleetbox.go:148-160`; `apiinstances.go:2511-2530`). It only does this behind the activation gate: two or more boxes, no sidecars, every box at `FleetBoxLabelFloor` v0.33.0 (`fleetbox.go:22-45`, `internal/release/layoutintent.go:267`). - **Moving between boxes:** only as a side effect. The relabel worker moves records off a box that is draining, lost or gone, and `carlos fleets drain` moves everything on one box (`fleetrelabel.go:20-56, 412`). Only `movable` records qualify, which excludes HA and addr-backed ones (`fleetbox.go:171-190`). There is no command to move one chosen instance. **4. Hostname** - **No link to placement:** the hostname is `slug + "." + manifest.Domain` (`apiinstances.go:2212-2215`). - **Platform regions:** every box publishes `control/edges/&lt;box&gt;.json`. Any other edge backhauls a request to the home box (`instancesplacement.go:18-24`). - **Fleets:** the hub (the console's box) mints a `forward` row for each fleet-placed record and serves it down that fleet's tunnel. The fleet box dials out to `/register` (`fleet-public-routes-design.md` §3.3, §4.1). DNS is unchanged: "No DNS change is needed for a fleet app" (§3.7, §4.10). - **What a move would need:** no DNS change. The ingress change is automatic, but there is a gap between the two passes where the host can't be reached (§4.6 row 5, §4.7). One risk: if a host is named by both a platform and a fleet record, neither gets a row (commit 65fd8060). **5. Closest existing pieces** - `carlos apps place`: whole app only, and permanently cut once the hostname history is active. - Live and offline moves: region codes only. - Moves into home (#236): delivered (`move-any-app-design.md:6356`). - Self-serve offline moves: built, off by default. - Fleet drain and relabel: between boxes within one fleet only. - `carlos instances import` (`apiinstanceimport.go:1-20`): loads a snapshot into a new record. - `--from` seeding: starts a database from a sibling's replica, also a new record. - `carlos adopt` is release adoption and unrelated. - "Member moves" exists only as a reference to a design (`appregionset.go:22`). I didn't find a member-move door.</result> <usage><subagent_tokens>108614</subagent_tokens><tool_uses>41</tool_uses><duration_ms>244572</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>b58yp8gc4</task-id> <tool-use-id>toolu_01KiA6Dzb7fKhV3WNCbJsxzQ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/96a09f74-e398-48ed-a97f-140bd1f7e255/tasks/b58yp8gc4.output</output-file> <status>completed</status> <summary>Background command "Rerun Luna copy gate with stdin closed" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 14.3 g CO₂e (1,781,471 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on docs-hub-guide-994, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/site/nav.json b/docs/site/nav.json
index abfe2e391..8587a2955 100644
--- a/docs/site/nav.json
+++ b/docs/site/nav.json
@@ -28,6 +28,11 @@
"label": "Stateless replicas",
"blurb": "Run more than one copy of each instance across your fleet. Learn what happens when a box stops."
},
+ {
+ "slug": "one-instance-per-customer",
+ "label": "One instance per customer",
+ "blurb": "Give each customer their own instance, with a hub app for sign-in, shared data, shared keys and reports."
+ },
{
"slug": "pdfs",
"label": "PDFs",
diff --git a/docs/site/one-instance-per-customer.md b/docs/site/one-instance-per-customer.md
new file mode 100644
index 000000000..5ea6b7c35
--- /dev/null
+++ b/docs/site/one-instance-per-customer.md
@@ -0,0 +1,131 @@
+# Apps with one instance per customer
+
+When an app gives every customer their own instance, each customer’s data can live in its own SQLite database, idle customers sleep, and a busy one can get a bigger size. A few things span customers: signing in once, shared data, a shared API key, background work and reports. Put those in a second, small app beside it, called a hub here.
+
+This guide uses `shop`, with one instance per customer, and its hub, `shop-hub`.
+
+## The two apps
+
+`shop` has one instance per customer, each with that customer’s database and settings. `shop-hub` has one instance. It signs people in, keeps shared data and keys, and creates customer instances.
+
+Turn on provisioning once:
+
+```sh
+carlos instances enable --app shop
+```
+
+Create a credential for the hub. This credential can manage instances of `shop` only:
+
+```sh
+carlos services create --role instance --app shop shop-signup
+```
+
+The command prints the secret once. Store it on the hub:
+
+```sh
+carlos secrets set --app shop-hub CARLOS_SERVICE_TOKEN=<secret>
+```
+
+At signup, the hub runs `carlos instances create --app shop` with that credential. The public HTTP API is still being designed ([API reference](/docs/api)).
+
+Give each customer their own settings in a named bundle. Write the bundle, then create the instance on it:
+
+```sh
+carlos env set --app shop --environment <name> CUSTOMER_NAME=<value>
+carlos secrets set --app shop --environment <name> CUSTOMER_SECRET=<value>
+carlos instances create --app shop --host <customer-host> --environment <name>
+```
+
+The bundle is layered on top of the app’s default config.
+
+## Sign in once
+
+People sign in at `shop-hub` only. The hub keeps each person’s profile and which customers they belong to, with their role at each.
+
+When someone opens a customer, the hub gives the browser a short-lived signed pass: for example, a token signed with the hub’s private key, valid for a minute, naming the person, the customer’s host and the role.
+
+Each `shop` instance checks the pass with the hub’s public key. Put that key in the app-wide configuration:
+
+```sh
+carlos env set --app shop HUB_PUBLIC_KEY=<public-key>
+```
+
+The instance then starts its own session.
+
+When an instance needs profile data, such as an address or a phone number, it asks the hub. The hub records the grant, and the person can revoke it there.
+
+Don’t build passwords. Email sign-in links or an OAuth provider at the hub cover sign-in.
+
+## Shared data
+
+Instances never open a shared database. Choose where shared data lives based on how it changes.
+
+Data that changes with your code, such as lookup tables or tax rates, ships inside the release as an embedded file or SQLite database. Every instance has it after a deploy.
+
+Small settings and keys go in the app’s default config, which every instance receives:
+
+```sh
+carlos env set --app shop TAX_RATE=20
+```
+
+Data people edit while the app runs belongs to `shop-hub`. Instances read it over HTTPS and cache it.
+
+## A shared third-party API
+
+If an API you share across customers has a request or cost limit, keep its key on `shop-hub`:
+
+```sh
+carlos secrets set --app shop-hub THIRD_PARTY_API_KEY=<key>
+```
+
+Each `shop` instance calls the hub. The hub calls the third-party API, enforces the limit and counts use for each customer.
+
+The hub has to know which customer is calling. When it creates an instance, it puts a token of that instance’s own in the instance’s bundle and keeps the matching value itself.
+
+A sidecar won’t do this job: it belongs to one instance, and nothing can call it.
+
+Some shared services come with the platform: `carlos email`, [PDF rendering](/docs/pdfs), `carlos store` and `carlos schedule`.
+
+## Background work
+
+None of this needs an instance that stays awake.
+
+For work a request causes, write an outbox row in the same transaction, send it at the end of the request, and retry what’s left on the next wake.
+
+For regular work on every customer, add a schedule:
+
+```sh
+carlos schedule set --app shop --name sync --every 1h --path /jobs/sync
+```
+
+Each instance fires at its own point in the hour, so a hundred instances wake about one every 36 seconds, never all at once. A tick doesn’t keep an instance awake.
+
+For work at a known time, set a one-shot timer: the app asks the platform on `CARLOS_CONTROL_SOCKET`, with its `CARLOS_ADMIN_TOKEN`, and the platform wakes that instance and POSTs to the path at that time. Only instances with work wake.
+
+For one job across the whole app, such as a nightly roll-up, schedule it on `shop-hub`. It has one instance, so the job runs once.
+
+## Reports across customers
+
+Don’t query every customer when someone opens a report. Each `shop` instance sends the facts reports need, such as orders and refunds, to the hub through its outbox as they happen. The hub keeps the reporting tables and knows which customers belong together.
+
+For a one-off check, read a copy of one instance’s database on your own machine:
+
+```sh
+carlos db query --app shop --instance <host> --sql "SELECT count(*) FROM orders"
+```
+
+The copy is read-only, and the live instance is untouched.
+
+## When one customer gets busy
+
+An operator can give that one instance a bigger size: `small` (256 MiB), `standard` (512 MiB), `large` (1 GiB) or `xlarge` (2 GiB). See [carlos apps](/docs/cli#carlos-apps).
+
+To give customers machines of your own, place the app on your own fleet when you create it (`--place fleet/<name>`).
+
+If `shop` keeps no local database, an instance can run as several copies across a fleet. See [Stateless replicas](/docs/stateless-replicas).
+
+## Gaps today
+
+- A hub and a customer instance that land on the same box can’t reach each other through the edge yet.
+- The platform doesn’t yet issue an identity an instance can show the hub, so the per-instance token is yours to manage.
+- One instance can’t yet be moved onto a box of its own.