Repository navigation
Description
An organization that runs fctl's runners in its own cloud can enroll machines automatically today: an EC2 Auto Scaling group, a GCP managed instance group, an Azure scale set or a Kubernetes cluster. It can't scale them on demand, though:
- Nothing tells its autoscaler how many sessions wait for a runner.
- Scaling in stops sessions in the middle of their work.
- Every runner takes every project's sessions, so a workspace can't keep a pool of large machines for one project, or a pool in one region for another.
The result is a fleet sized by hand: too big at night, too small at 10 a.m.
How it works now
- Enrollment. Machines enroll themselves with a workspace's enrollment token (
fctl_et_…). The token caps how many runners it keeps, may ask for approval, and removes runners that stay offline a while.- ADR 0071 and 0072;
crates/fctl-control/src/api/enrollment.rs,crates/fctl-domain/src/enrollment.rs; docs/getting-started.md#many-machines-and-autoscaling.
- ADR 0071 and 0072;
- Placement and waiting. FleetDO places each queued session with
fctl_domain::schedule::pick(crates/fctl-domain/src/schedule.rs).- It knows exactly why a session waits (
Wait::NoRunner,Busy,TooBig,Image,Driver…), and the session's status says so. - Nothing outside FleetDO can read those numbers: no endpoint or metric says what waits for which runners.
- It knows exactly why a session waits (
- Spreading.
picktakes the least-loaded runner with a free slot (active ÷ capacity). Sessions spread across the fleet, so machines rarely empty out to be scaled in. - Labels. Hosts send
host.toml'slabelsin their hello, andpickcan require labels. FleetDO passes none (pick(&slots, &[], …)incrates/fctl-control/src/do_fleet.rs), and no project or token sets any. - Draining and leaving.
- A host drains with
fctl host drain --wait(POST /api/v1/runner/drain, ADR 0015) and leaves withfctl host uninstall(ADR 0016). - Nothing runs either when a cloud takes a machine away: its sessions stop mid-turn and resume elsewhere ten minutes later.
- A resume on another runner starts a new Claude conversation, so they also lose their context (Sessions keep their conversation and uncommitted work when they resume on another runner #616).
- A host drains with
- Capacity. Each host runs at most
capacitysessions at once (crates/fctl-host/src/config.rs).
What should happen
-
Pools.
- An enrollment token gets labels (
fctl runners enrollment-tokens create "AWS large" -w acme --labels aws,large). Every runner it enrolls carries them beside itshost.tomllabels. - A project chooses the labels its sessions need (
fctl projects set -p ml --runners gpu, or Settings → Runners), and FleetDO passes them topick. - A session that no pool takes says which labels it waits for.
- An enrollment token gets labels (
-
Packed placement. A pool (an enrollment token) chooses how its sessions are placed:
spread: today's least-loaded, the default;packed: the busiest runner that still has room, so that in an elastic pool some machines empty out and can go.
-
Demand.
GET /api/v1/runner/enroll/demand, read with the pool's enrollment token, answers what the pool needs now.GET /api/v1/workspaces/{id}/runners/demandgives the same to the workspace's admins and service accounts.- Its runners online, draining and waiting for approval.
- Busy and free slots.
- Sessions waiting that this pool could run, by reason (
Wait), and the oldest wait. wanted: the number of runners that would run everything running and waiting, at the capacity its runners announce.- With no runner online, the pool answers from the last shape its runners announced (capacity, sandbox limits, images), so autoscaling can start from zero.
-
Exporters.
fctl runners demand --pool "AWS large" --json.fctl runners demand … --cloudwatchputsWaitingSessions,BusySlotsandWantedRunnersin CloudWatch, with the pool's name as a dimension, for target tracking with metric math.- A Prometheus
/metricson self-hosted control planes, with the same numbers per workspace and pool. - KEDA's metrics-api scaler reads the JSON as it is (
valueLocation: wanted).
-
Hosts that retire when idle.
host.tomlgetsretire_when_idle = "20m"andretire_command. A host whose runner has run nothing for that long drains, uninstalls and runs the command:aws autoscaling terminate-instance-in-auto-scaling-group --instance-id … --should-decrement-desired-capacity;gcloud compute instance-groups managed delete-instances …;- or
systemctl poweroff.
With every instance protected from scale-in, the autoscaler only ever adds machines and never picks a busy one.
-
Draining when the cloud takes a machine.
fctl host drain --waitgains a--timeout, after which it stops what still runs. It's documented and tested for each cloud's termination signal:- an EC2 Auto Scaling lifecycle hook (heartbeat up to 2 hours, extendable to 48);
- Spot's two-minute notice;
- GCP's graceful shutdown (up to 6 hours);
- Azure's terminate notification (5 to 15 minutes);
- Kubernetes' preStop hook.
Running turns get the time there is. Then sessions stop with
StopReason::Shutdown, so their agents push their work. -
Hosts in pods that scale. A host running in a Kubernetes pod sets
controller.kubernetes.io/pod-deletion-costto its number of sessions, so that a Deployment KEDA scales down removes empty hosts first. -
Reference deployments.
- A Terraform module for AWS: an Auto Scaling group; a launch template; an AMI with Docker and the sandbox image pre-pulled (EC2 Image Builder); the enrollment token in SSM Parameter Store; the demand exporter; target tracking; the lifecycle hook.
- Smaller examples for GCP and Azure.
Pre-pulling the multi-GB sandbox image does more for start times than any scaling rule.
-
Docs:
- docs/self-hosting.md, and the guide for runners in a cloud (Guides for organizations that run fctl in their own cloud #614);
- docs/architecture.md (pools, placement, demand);
- docs/cli.md, docs/api.md and docs/llms.txt.
Notes on the design
wanted= ceil((sessions running + sessions waiting that the pool could run) ÷ capacity per runner), within the token's--max-runners. A session waiting for its home runner (Wait::Home) counts only once it would start elsewhere.- A token's labels are the pool's identity in demand and placement. FleetDO takes them from D1 rather than from the host's hello, so a host can't claim a pool it didn't enroll in.
- The demand endpoint returns counts, never sessions, projects or people. A token's holder learns nothing they couldn't learn by running the pool.
- Packed placement still respects a session's home runner (resumes), its size and its image. It changes only the choice among runners that could all take the session.
Design and UX
An admin should get from "we have an AWS account" to "a pool that scales itself" in one sitting, without the docs, and see at a glance whether the pool is the right size.
-
Pools on the Runners tab. Runners group under their pool (the enrollment token's name). Each pool is a card with:
- its labels as chips;
- "6 of 8 runners busy · 3 sessions waiting · longest 2 minutes";
- a small live chart of busy slots against capacity, and of waiting sessions, over the last 24 hours (the same series as Insights, Insights: what agents got done, for a workspace, a project and each person #621);
- its placement in words ("Packed: fills one runner before the next, so idle ones can go");
- its scaling state in words: "Scaling up: 3 sessions have waited 2 minutes" or "Idle: 2 runners retire in 14 minutes".
-
Making a pool follows the Runners tab's step-by-step setup (docs/web-app/explaining.md, "A workspace's Runners tab"):
- Name it.
- Choose its labels and capacity.
- Choose where it runs: AWS, Google Cloud, Azure, Kubernetes or your own machines.
- Copy what that cloud needs, with every value filled in: the user data, the Terraform module block, the KEDA ScaledObject or the CloudWatch target-tracking policy.
A preview shows how the pool will look once its first runner is online.
-
Projects choose pools by name, not by raw labels. Settings → Runners offers "Any runner" or a pool ("AWS large: 4 runners with 16 CPUs and 64 GiB"), and shows the labels underneath for those who set them directly. A project that requires labels no runner has says so in amber, and says who can add such a runner.
-
Waiting sessions say what's happening: "Waiting for AWS large: a runner is starting (2 minutes so far)", not "Waiting for a runner". A pool that can't grow says why: "AWS large is at its limit of 20 runners".
-
The CLI shows the same.
fctl runners poolslists pools with their demand, andfctl runners demandprints a one-screen summary (--watchkeeps it live). -
Follow hyperstructure/design's docs:
docs/principles.md;docs/web-app/explaining.mdfor pages that set something up (a headline that names the outcome, a lead built from this place's facts, a preview of the result, one primary action, and who can act);docs/web-app/kit.mdfor controls. -
Design every state before building it: the first visit, loading, errors and refusals, waiting, partial setups and long lists.
-
Say what happens, plainly, and never leave someone at a disabled control without saying who can act.
-
Prototype the main screens with realistic data (
cargo xtask demo's world) and review them before building the rest. -
Check both themes, a phone's width, the keyboard, screen readers and reduced motion, and show screenshots in each pull request.
-
Give the CLI the same care: readable output,
--json, and errors that say what to do next. -
Add or update the pages of hyperstructure/design's docs for each new component, with the reasons behind its choices.
Compatibility
- Data and endpoints.
- Labels on enrollment tokens, a project's runner labels and a pool's placement are new D1 columns (a new migration). FleetDO computes demand from what it already has.
- New endpoints need client methods in
crates/fctl-client, CLI commands with--json, and their place in docs/llms.txt.
- Releases.
retire_when_idle, the pod deletion cost anddrain --timeoutneed a host release.- Older hosts keep working: their pool's labels come from D1, not from their hello.
- Scaling from zero needs the pool to have seen one runner of the new version, to know its shape.
Decisions for a person
- Whether demand is read with the enrollment token (one secret for the machines and their autoscaler), or only with a separate read-only credential.
- Whether
packedbecomes the default for tokens that remove offline runners, which are elastic by nature. - Whether fctl keeps the Terraform module and Helm chart in this repository (
deploy/) or in a new one. - Whether a project requires its pool (its sessions wait for it), or prefers it (another runner takes a session that waited a while).
Related: #616, #617, #614, #621
Session: https://app.fctl.sh/s/ses_01M8450BECFP8DN88R0ZP0N0MS
Activity
fctl-sh commentedon Nov 23, 2026
Where this stands (from fctl session #1545), in two pull requests, both open and green:
spread, orpacked, the default for tokens that remove offline runners); a project'srunner_labelswith an optional fallback after N minutes; waiting reasons that name the pool; demand with the enrollment token (GET /api/v1/runner/enroll/demand) and for a workspace's admins, members' own and service accounts (GET /api/v1/workspaces/{id}/runners/demand), counted from the pool's last known shape when no runner is online;fctl runners poolsandfctl runners demand(--jsonas KEDA's metrics-api scaler reads it,--watch,--cloudwatch); Prometheus at/api/v1/metricswhereFCTL_METRICS_TOKENis set. It also rewrites the How many machines section of the cloud guide from docs: add guides for organizations that run fctl in their own cloud #633 aroundwanted.retire_idle_minutesandretire_commandinhost.toml(fctl host install --retire-when-idle 20m --retire-command '…'), which drain, check, run the command and only then leave;fctl host drain --timeout, which stops what still runs at the deadline so that agents push; a pod'scontroller.kubernetes.io/pod-deletion-costkept at its number of sessions.Still to do: the web app's part (pools on the Runners tab, making a pool step by step, Settings → Runners choosing a pool by name), and the reference deployments (a Terraform module for AWS, smaller GCP and Azure examples). Nothing here ran on a real cloud: each cloud's termination signal is documented in the guide, not tested there.
feat(control): add runner pools with labels, placement and demand (#634)
fctl-sh commentedon Nov 23, 2026
#634 merged (9bd1c17): pools with labels and placement, projects' runner labels with a fallback, pool-named waiting reasons, demand for the token, the workspace and Prometheus, and
fctl runners poolsandfctl runners demandwith--cloudwatch. I ticked Packed placement, Demand and Exporters. Pools stays open for its web part (Settings → Runners choosing a pool by name), as do Docs until #635's docs land.The control plane's part is deployed to app.fctl.sh. The CLI's commands and flags ship with the next release: no tag contains 9bd1c17 yet.
Left: #635 (retiring machines,
drain --timeout, the pod deletion cost, open), the web app's pools (Runners tab, making a pool, project settings), and the reference deployments.fctl-sh commentedon Nov 23, 2026
#635 merged (b8adfa1):
retire_idle_minutesandretire_commandinhost.toml(fctl host install --retire-when-idle 20m --retire-command '…'),fctl host drain --timeout, and a Kubernetes pod's deletion cost kept at its number of sessions. It is the host's and the CLI's, so it ships with the next release: no tag contains b8adfa1 yet. Its docs reach fctl.sh once CI pins them.I ticked Hosts that retire when idle, Hosts in pods that scale and Docs. Draining when the cloud takes a machine stays open:
--timeoutis built and documented, beside the cloud guide's drain hooks, but nobody has tested it against each cloud's termination signal yet.Left: that testing, Pools' web part (choosing a pool by name in a project's settings, pools on the Runners tab), and the Reference deployments (a Terraform module for AWS, smaller GCP and Azure examples).
fctl-sh commentedon Nov 24, 2026
Where this stands (fctl session #1545). What's left is in these open pull requests, all green:
deploy/cloud's runner scripts and Packer template, and a Terraform module for AWS: Image Builder, the token in Secrets Manager, the group with its drain hook, machines that retire once idle, and a function that sizes the group from what the pool needs. Google Cloud and Azure get smaller examples, and the cloud guide gets a With Terraform section.#644 and #645 are stacked on #643 and #641, the snapshots' pull requests for #616.
Two things they don't do:
fctl host drain --timeout, and the drain hooks in feat: add Terraform reference deployments for runner pools #639's deployments) and documented, but not yet tested against each cloud's termination signal: this session has no cloud accounts.fctl-sh commentedon Nov 24, 2026
#639 merged (34ed1f9): the reference deployments.
deploy/cloudhas the machines' scripts and a Packer template, anddeploy/cloud/terraform/awsa module for AWS: an image from EC2 Image Builder with the sandbox image pulled, the enrollment token in Secrets Manager, the Auto Scaling group with its drain hook, machines that retire once idle, and a function that sizes the group from the pool'swanted. Google Cloud and Azure have smaller examples, and the cloud guide has a With Terraform section. I checked it withterraform validateand shellcheck. It hasn't run in a real cloud account. Its docs reach fctl.sh once main's CI pins them. The machines it starts need the release after v0.37.1 for pool labels,--retire-when-idleanddrain --timeout: no tag contains #634, #635 or #639 yet.I ticked Reference deployments, and I'm closing this as Carl Oscar asked, with three things left as they are:
fctl host drain --timeout(feat(host): retire idle machines and drain within a cloud's deadline #635) and the drain hooks in feat: add Terraform reference deployments for runner pools #639's deployments are built and documented for each cloud's termination signal, but nobody has tested them against those signals. Carl Oscar decided to close this without that testing.feat(web): show pools on the Runners tab, and choose one in a project (…
feat(web): make a pool step by step, with what each cloud needs (#645)
fctl-sh commentedon Nov 24, 2026
#644 (c336ff8) and #645 (2febd7d) merged, and are deployed to app.fctl.sh. They put pools on the Runners tab, let a project's Settings → Runners choose a pool by its name, and make a pool step by step with what each cloud needs. I ticked Pools, so only Draining when the cloud takes a machine stays unticked, untested on real clouds as decided.
The review findings left unanswered on #644 and #645 are fixed in #648, which is open, with hyperstructure/design#80 for their design docs. Projects are no longer offered members' own pools, the capacity a pool's form sets reaches its machines' commands, and there are smaller fixes to the Runners page and pool cards.
fctl-sh commentedon Nov 24, 2026
#648 merged (5ab7c26) and is deployed to app.fctl.sh. It's web-only, so it's live there now. hyperstructure/design#80 merged too, with the design docs for pools on the Runners tab, making a pool and choosing one. That leaves nothing open for this issue.