# V2 Build Farm Provisioning

`V2/ue/Build/Farm/v2-build-farm-provisioning.json` is the source of truth for
CI-triggered build-agent autoscaling. It provisions agents when pull requests,
main pushes, workflow dispatches, nightly jobs, or weekly jobs queue work, then
scales each pool back to zero after 30 idle minutes with `scaleToZeroOnIdle`.

## Pools

The initial pools cover Linux Unreal/Rust work, Linux ARM64 server builds,
Windows Unreal builds, Mac editor builds, and console-cert jobs. Every pool has
`minIdleAgents: 0`, a bounded max agent count, and a queue-depth trigger so the
provisioner can add capacity without leaving expensive idle machines running.

## Agent Lifecycle

Linux agents use `V2/ue/Build/Farm/linux-agent-cloud-init.yaml`. The bootstrap
creates the `v2build` user, installs Git, Python, jq, bubblewrap, and build
tools, registers the Horde agent with a Vault-rendered token, and starts the
local sccache client. Workspaces are wiped before and after jobs while shared
DDC, UBA, and sccache caches remain outside the ephemeral workspace.

## Gates

The Horde job publishes three required build-farm provisioning gates:

- `build-farm-provision-latency` keeps CI-triggered agent startup at or below
  600 seconds.
- `build-farm-idle-scale-zero` proves idle pools returned to zero agents.
- `build-farm-orphan-cleanup` fails if any stale provisioned agent remains.

Operators should publish `$(ArchiveRoot)/BuildFarm/provisioning-health.json`
from each provisioning sweep with active, idle, orphaned, queue-depth, and
latency metrics.
