Skip to content

Runner pools that grow and shrink with the sessions waiting for them #615

Done

Description

@fctl-sh

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.
  • 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.
  • Spreading. pick takes 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's labels in their hello, and pick can require labels. FleetDO passes none (pick(&slots, &[], …) in crates/fctl-control/src/do_fleet.rs), and no project or token sets any.
  • Draining and leaving.
  • Capacity. Each host runs at most capacity sessions 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 its host.toml labels.
    • A project chooses the labels its sessions need (fctl projects set -p ml --runners gpu, or Settings → Runners), and FleetDO passes them to pick.
    • A session that no pool takes says which labels it waits for.
  • 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/demand gives 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 … --cloudwatch puts WaitingSessions, BusySlots and WantedRunners in CloudWatch, with the pool's name as a dimension, for target tracking with metric math.
    • A Prometheus /metrics on 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.toml gets retire_when_idle = "20m" and retire_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 --wait gains 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-cost to 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:

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"):

    1. Name it.
    2. Choose its labels and capacity.
    3. Choose where it runs: AWS, Google Cloud, Azure, Kubernetes or your own machines.
    4. 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 pools lists pools with their demand, and fctl runners demand prints a one-screen summary (--watch keeps it live).

  • Follow hyperstructure/design's docs: docs/principles.md; docs/web-app/explaining.md for 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.md for 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 and drain --timeout need 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 packed becomes 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

  1. added
    enhancement
    host
    control-plane
    web
    cli
    on Nov 23, 2026
  2. fctl-sh commented on Nov 23, 2026

    @fctl-sh
    ContributorAuthor

    Where this stands (from fctl session #1545), in two pull requests, both open and green:

    • feat(control): add runner pools with labels, placement and demand #634, runner pools: an enrollment token's labels (from D1, never the host's hello) and placement (spread, or packed, the default for tokens that remove offline runners); a project's runner_labels with 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 pools and fctl runners demand (--json as KEDA's metrics-api scaler reads it, --watch, --cloudwatch); Prometheus at /api/v1/metrics where FCTL_METRICS_TOKEN is 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 around wanted.
    • feat(host): retire idle machines and drain within a cloud's deadline #635, machines that retire: retire_idle_minutes and retire_command in host.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's controller.kubernetes.io/pod-deletion-cost kept 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.

  3. fctl-sh commented on Nov 23, 2026

    @fctl-sh
    ContributorAuthor

    #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 pools and fctl runners demand with --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.

  4. fctl-sh commented on Nov 23, 2026

    @fctl-sh
    ContributorAuthor

    #635 merged (b8adfa1): retire_idle_minutes and retire_command in host.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: --timeout is 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).

  5. fctl-sh commented on Nov 24, 2026

    @fctl-sh
    ContributorAuthor

    Where this stands (fctl session #1545). What's left is in these open pull requests, all green:

    • feat: add Terraform reference deployments for runner pools #639: reference deployments. It adds 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.
    • feat(web): show pools on the Runners tab, and choose one in a project #644: pools on the Runners tab. Each pool is a card with its labels, what it needs now as a sentence and facts, its placement, and its runners under it. Making and editing a pool take labels and a placement, and a project's Settings → Runners chooses a pool by its name, with how long its sessions wait for it.
    • feat(web): make a pool step by step, with what each cloud needs #645: making a pool step by step. It asks for a name, the labels and machines, and where the pool runs, shows a preview of the pool's card, then gives what to copy there with every value filled in: machines of your own, the AWS module, the Google Cloud and Azure examples, or KEDA's objects for Kubernetes.

    #644 and #645 are stacked on #643 and #641, the snapshots' pull requests for #616.

    Two things they don't do:

  6. fctl-sh commented on Nov 24, 2026

    @fctl-sh
    ContributorAuthor

    #639 merged (34ed1f9): the reference deployments. deploy/cloud has the machines' scripts and a Packer template, and deploy/cloud/terraform/aws a 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's wanted. Google Cloud and Azure have smaller examples, and the cloud guide has a With Terraform section. I checked it with terraform validate and 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-idle and drain --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:

  7. fctl-sh commented on Nov 24, 2026

    @fctl-sh
    ContributorAuthor

    #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.

  8. fctl-sh commented on Nov 24, 2026

    @fctl-sh
    ContributorAuthor

    #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.

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

    clicontrol-planeenhancementhostweb

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions