Cluster
Reaktor Cluster would let Reaktor instances on several machines share one workspace's work. A plan item in Hangar can start a coding agent on whichever Mac, Windows or Linux machine suits it, and that agent can ask for a build or a phone check on another machine. Every run stays tied to its plan item, the exact source it ran on, the resources it held and the evidence it produced.
This page is a design. Today two Macs share Gradle work through ~/dev/tools/remote-dev, a router that copies the checkout to one SSH worker, runs the build there and copies outputs back. Plans, claims and conductor tasks live on one machine. What exists today lists the pieces, and Replacing remote-dev maps each part of the router to its place in this design. The design uses Capabilities to know what each machine can do.
Overview#
The design has three parts, each with one job:
- The workspace authority decides. One per workspace. It chooses a machine for each run, records who owns the run, and accepts or refuses results. Its records are durable, so a restart loses nothing.
- A host agent runs work on its machine. One per machine: a headless Reaktor process that reports the machine's capabilities, owns all of the machine's capacity, and runs tasks in isolated checkouts made from source snapshots.
- Hangar and the conductor say what to do. Plans, tasks, checks and reviews stay where they are today. The cluster adds where a task runs and who owns it while it runs.
One rule holds the design together: every run holds a lease with a generation number. A machine that loses its lease stops, a run that is started again gets the next number, and every result carries its number, so a machine that comes back late cannot overwrite newer work.
Try it#
The box below plays an iOS build on two Macs. The m1-worker starts it, loses its connection at 25 seconds and comes back at 70. Leases last 30 seconds and renew every 10. After the worker's lease runs out and a 10-second margin passes, the authority starts generation 2 on the Mac Studio. When the worker comes back and reports its old result, the authority refuses it, because generation 1 is older than generation 2.
- Choose Without generations to see the same events accepted blindly: both runs finish the task, and whichever reports last replaces the other's result.
- Change the worker's
reconnect()toat(40). It is back before its lease runs out, renews in time and keeps the task, so the Mac Studio never starts and its report is refused. - Delete the worker's
finish("ios-build")line. Nothing changes for the Mac Studio, which finishes generation 2 normally. - Add
val linux = host("Linux box")under the other hosts andstudio.at(90) { disconnect() }at the end. Once the Mac Studio's lease runs out, generation 3 starts on the Linux box, and the Mac Studio's report at 120 seconds never arrives because it is offline.
val studio = host("Mac Studio")
val worker = host("m1-worker")
worker.at(0) { start("ios-build") }
worker.at(25) { disconnect() }
worker.at(70) { reconnect() }
worker.at(75) { finish("ios-build") }
studio.at(120) { finish("ios-build") }
How it works#
Built from Reaktor parts#
Each part of the cluster is made from pieces Reaktor already has.
| Part | Built from | Job |
|---|---|---|
| Scheduler | An ActorNode, one per workspace | Chooses machines one decision at a time, so two decisions never take the same capacity |
| Allocation | A PersistentActorNode per run, keyed allocation/<id> | Holds one run's state machine, lease and generation; its store orders every change |
| Host admission | An ActorNode, one per machine | Owns every reservation on its machine: CPU slots, memory, phones, disk budget |
| Runners | Nodes in the host agent, one per kind of work | Run a Gradle build, a coding agent or a phone flow in an isolated checkout |
ClusterApi | A Reaktor service over one SocketLink | Carries enrolment, assignments, capability changes, lease renewals and results |
| Artifact store | Content-addressed storage at the workspace | Keeps outputs, logs and receipts by hash |
The contract is declared like any other Reaktor service:
open class ClusterApi : Service("reaktor.cluster") {
open val enroll by call<Invitation, HostCredential>(effect = Effect.CredentialWrite)
open val attach by stream<HostHello, Assignment>()
open val observe by call<CapabilityChanges, Unit>(idempotency = Idempotency.Keyed)
open val renew by call<Renewal, Lease>(idempotency = Idempotency.Keyed)
open val report by call<RunReport, Verdict>(idempotency = Idempotency.Keyed)
}
A host agent calls attach once and receives its assignments as a stream; everything it sends back is a keyed call, so a retry after a lost reply repeats the same request. The contract's fingerprint travels with every call, so a host running an older build is recognised as incompatible before it gets work.
The Reaktor V2 paper describes the same structure in its own terms: machines are places, capabilities constrain placement, and a call between places needs an explicit connection. The design keeps that rule and builds on today's graph, actors and services, without waiting for the paper's full runtime.
Hosts and admission#
Each machine's admission actor is the only thing that reserves capacity on that machine. Every Reaktor process on the machine, every workspace that uses it and, during the move, every remote-dev run asks it first. It holds named pools:
| Pool | Example | Counted |
|---|---|---|
| Slots | Two Gradle jobs at once on the m1-worker | Per job |
| Memory | 32 GB installed, agents may use 16 | In bytes, against the configured and measured amounts |
| Devices | One iPhone on USB | Per physical device, however many bridges reach it |
| Disk | The 40 GB budget for remote work in storage-limits.json | In bytes |
A shared subscription is a pool too. Several machines signed in to the same Claude or Codex plan share one usage limit, so the workspace authority owns that pool and admits runs against it, whatever machine they run on.
Admission says how firmly it enforces each pool. Linux cgroups and Windows job objects can cap memory and CPU for a process tree. macOS has no equivalent, so admission there counts reservations and watches usage, and the pane says so.
Admission never waits while holding part of a reservation. It reserves pools in a fixed order and gives everything back when one pool refuses, then reports the reason as a wait: no free slot, phone in use, quota resets at 14:00. An agent that asks for a build on its own machine gives back the slot it does not need while it waits, so a one-slot machine cannot deadlock against its own child.
A run from start to finish#
A run is an allocation: one attempt at one task on one machine. Its state machine is declared on its PersistentActorNode, so every transition is written through the actor's store before anything acts on it.
| State | What it means | Next |
|---|---|---|
| Admitting | The scheduler chose a machine and is reserving capacity there | Admitted, or released if the machine refuses |
| Admitted | Capacity is reserved and the lease is granted | Running |
| Running | The host reports the run started, and renews the lease | Finishing, Unknown |
| Finishing | The host is uploading results and artifacts | Succeeded, Failed |
| Succeeded, Failed, Cancelled | Final for this generation | |
| Unknown | The lease ran out and the host is silent | Reconciling |
| Reconciling | The scheduler asks the host what happened, or waits for proof that it stopped | A final state, or a new allocation with the next generation |
The authority records an assignment before it sends it, and the host journals the assignment before it starts it. A start, cancel or result message that arrives twice returns what was recorded the first time. A crash between recording a start and starting the process is a case the host checks when it comes back; recording the intent does not prove the process ran.
Leases and generations#
Leases and generations follow Gray and Cheriton's leases and the fencing tokens that Chubby calls sequencers:
- A lease is time-limited ownership. Each assignment carries a lease, for example 30 seconds renewed every 10. The authority measures the lease on its own clock. The host counts its copy from the moment it sent the renewal, so the host's copy always ends first.
- A host stops when it cannot renew. It starts no new step, cancels its processes, and later reports what actually stopped.
- A task that writes moves only after the lease has ended. The authority waits for the lease plus a margin, then starts the task again with the next generation number. Read-only work, such as a check whose result anyone can recompute, may start again sooner when its task says so.
- Every write carries its generation. Results go to the authority, artifacts to the store, candidate patches to the conductor and plan updates to the plan store, each with the allocation and generation. Every receiver keeps the newest generation it has seen for that task and refuses anything older. A refused result is kept as unaccepted evidence, so its logs can still be read.
- Outside systems need their own keys. A deploy, a store upload or a message to a person cannot check a generation number. Those effects go through keyed calls whose idempotency key the cluster records, and an outcome that stays unknown goes to the owner's review under the kernel's existing policy.
Generations are the safety net for what leases cannot promise: a host that kept running a process it believed it had stopped, or a message delayed in a queue. Clocks only decide when to stop renewing. Safety comes from the numbers.
| Failure | What happens |
|---|---|
| A reply to a start is lost | The authority repeats the same keyed request, and the host returns what it journalled. No second run starts. |
| A host goes silent | Its capabilities become unknown and admission there stops. A writing task moves only after its lease ends. |
| A stale host comes back | Its results and artifacts are refused by generation and kept as unaccepted evidence. |
| The authority restarts | It reloads its allocations and renews or cancels them. It never replays a start blindly. |
| A plan item's claim expires while its run continues | The open allocation keeps the item claimed. |
| A host restarts | It comes back as a new incarnation, reports its journal and any processes that survived, and its reservations are checked again. |
| An outside write times out | The authority looks the result up by its idempotency key. An unknown outcome goes to review. |
| A shared quota runs out | New starts against that pool stop, and the wait shows the provider's reset time. |
| A host is drained or revoked | Admission stops at once. Running work follows the declared cancel policy, and the pane shows what actually stopped. |
Placement#
The scheduler places a run in five steps:
- Check the task is ready. The plan and the conductor still want it, and its source snapshot exists.
- Ask the capability resolver where it can run. The resolver returns the eligible machines with the exact capabilities that matched, and the reason every other machine failed. An unknown requirement never counts as met.
- Estimate when it would finish on each machine. The wait in that machine's queue, plus the time to bring the snapshot there, plus how long the same task took on that machine before. A warm checkout on the machine costs almost nothing to bring.
- Reserve capacity through the chosen machine's admission actor, which checks the evidence again. If it refuses, the scheduler tries the next machine or reports the wait.
- Record the allocation, then send it. A send that times out is reconciled by asking about the same allocation. It never starts a second one.
Hard requirements always win over preferences: a busy Mac with Xcode beats an idle Linux machine for an iOS build, and the run waits for it. Shared things are counted once: memory shared by CPU and GPU, a phone reached through two USB bridges, a VM and the containers on it.
| Machine | Typical work | What placement must check |
|---|---|---|
| macOS | Apple builds, desktop agents, checks on attached phones | Xcode and other toolchains, signing access, attached devices |
| Windows | Windows builds and agents | The Windows runtime and its paths; WSL counts as a separate Linux machine |
| Linux | Headless agents, container builds, GPU work | Architecture, drivers and container limits |
| Kubernetes or a managed container service | A declared worker image or a bounded job | The provider's limits for the pod or job |
| A managed service such as a SQL database or a queue | Calls to that service | A service offers its API; it never runs agents or shell commands |
| A phone or a browser | Device checks and bounded tasks while it is in the foreground | Permissions and background limits; phones and browsers do not host agents |
Source snapshots#
Every run executes an exact source snapshot. A snapshot lists each repository in the workspace with its base commit, the files that differ from that commit by content hash, the lock files and the toolchain versions. bestbuds with the reaktor build it includes is one workspace, so one snapshot covers both, and a single commit hash cannot describe it. remote-dev freeze already captures a checkout's source for later builds, and the snapshot builder grows from it.
A snapshot includes the untracked files a build needs, and leaves out credentials, caches and machine state. The host materialises it as a worktree at the base commits plus the changed files, checks every hash before the run starts, and reports any file name, case, link, executable bit or line ending its file system cannot hold. Paths in a task are relative to the workspace, and each platform's runner translates them.
A coding agent works in a worktree that belongs to its allocation, and returns a candidate patch against its snapshot. The workspace applies it through the conductor's existing review and landing rules. Nothing copies a remote checkout over the owner's working tree. When the candidate changes, checks recorded against its old snapshot no longer count.
Artifacts#
Outputs, logs and receipts go to the workspace's artifact store, addressed by their content hash, with the allocation, generation, snapshot and toolchain that produced them. The store accepts an upload only from the current generation, and transfers resume and skip content the store already has.
Build outputs that Gradle can cache travel through the Gradle build cache, which remote-dev already pilots as an HTTP cache over an SSH tunnel. A host fetches a cached output by its cache key and does not copy a build directory. Deliverables a person or a deploy needs, such as an app bundle, are declared outputs of their build nodes; they reach the owner's checkout only through the authority, which checks the generation and the snapshot before it writes.
A successful exit is evidence about a process. A deploy or a phone install keeps its own verification receipt. Caches are separated by trust domain, retention follows the workspace's storage budgets, and cleanup keeps anything an open or unaccepted run still refers to.
Agents on other machines#
A plan item that needs an agent gets an allocation like any other run. The host agent starts the harness, such as Claude Code or Codex, in a worktree made from the item's snapshot, under the agent's own identity. The agent's reaktor MCP server talks to the workspace's kernel through the host agent's connection, so the kernel stays the workspace's single owner, and the remote machine never holds the owner's credentials.
The agent reads and edits the plan with the same operations it uses today, with base revisions, access scopes and approvals unchanged. Its code comes back as a candidate patch, and its checks run wherever their own requirements place them. A host that loses its connection keeps the agent's logs and its candidate, and it cannot mark plan state while it is cut off.
Live processes never move between machines. An agent's conversation moves only when its harness can resume it on another machine; otherwise the next attempt starts fresh with a short summary of the last one and links to its evidence.
Plans in Hangar#
A plan item, its conductor task and its allocation refer to each other by global references made of the workspace, the plan thread and the item id. The plan keeps its statuses: Todo, Doing, Done and Dropped. A launched agent does not make an item Done. A check completes when its receipt is accepted, and a writing task completes through its review.
Today WorkPlanStore.next picks the next ready item and can take it for the calling agent, and a taken item's PlanLease lasts ten minutes, extended by recorded activity. That expiry suits planning work that someone abandoned. It must not hand away work that is still running on another machine, so the design adds one rule: while an item has an open allocation, its lease cannot expire, and only reconciling the allocation releases it. The same rule covers manual starts and retries.
Items gain requirements and preferences, taken from the agent profile, the kind of task, its build node and explicit constraints: an OS, a toolchain, a device, a trust domain, or a preference for a machine with a warm checkout. Readiness and priority still decide which item runs next. Hangar shows why an item waits: a dependency, no capable machine, a full machine, a quota reset, an approval, or a run whose outcome is unknown.
Joining a machine#
Four identities stay separate:
- The machine. Enrolled once and kept across restarts.
- The host incarnation. New each time the host agent starts, so a restarted host never continues with its old authority by accident.
- The agent. The harness's own identity, whichever machine runs it.
- The authority and its epoch. The epoch increases whenever the authority restarts or moves, and allocations issued under an old epoch are reconciled before new ones go out.
A machine joins with an invitation the owner creates for the workspace. The invitation is short-lived and works once; it buys the machine its own credential, kept in the platform's keychain. A cloned disk does not clone an enrolment, and a revoked machine is refused at its next call.
The host agent connects out to the workspace over TLS, through a SocketLink that carries calls and streams over one WebSocket, so no machine needs an open port. A private network such as Tailscale can provide the route between machines; identity and permissions stay with Reaktor. The contract fingerprint decides whether a host's build can talk to this authority, and a host that is too old or too new stays visible with that reason. Each renewal carries the host's capability changes and progress, a gap in sequence numbers asks for a fresh snapshot of its graph, and large files travel through the artifact store.
The Cluster pane#
The Cluster subpane would sit in Hangar's Compute pane at cloud/cluster, next to the proposed Capabilities subpane.
- Machines and runs. Each machine with its enrolment, connection age, offered and reserved capacity, running allocations, quota waits and drain state, as a graph and as a list.
- The allocation inspector. Why this machine, which machines were rejected and why, the snapshot it runs, what it reserved, when its lease ends, and which result was accepted. An unknown or stale fact says so. A green connection never stands for a successful task.
- Links both ways. From a plan item to its runs, machines, snapshots, logs, checks and candidates, and from a machine back to the plan items it serves. An older attempt keeps its generation and evidence when you open it.
- Operations. Enrol, drain, resume, cancel, revoke and retry are kernel operations with previews and the kernel's usual approvals. Drain stops new starts; revoke also removes trust. Neither starts an uncertain writer somewhere else.
Every wait says what would end it: free a phone, reconnect a machine, install a toolchain, wait for a quota reset, loosen a requirement, settle an unknown outcome, or review a candidate.
Replacing remote-dev#
Each piece of the two-Mac router has a place in the design. The move happens piece by piece, and the router's commands keep working until their replacement has passed the same tests.
| remote-dev today | In the cluster |
|---|---|
The worker host named in ~/dev/.remote-dev/config.json | Enrolled machines, any number, any OS |
local-gradle.lock and the queue of tickets in local-gradle.line | The admission actor on this Mac |
worker-gradle.lock, worker-slot-<n>.lock and the job folders slots/job-<n> | The admission actor on the worker, with slots as a pool |
A mirror kept up to date with git ls-files and rsync | Snapshots, materialised as worktrees and checked by hash |
remote-dev freeze and snapshot-build | The snapshot builder |
Receipts in ~/dev/.remote-dev/logs | Allocation records and their evidence |
Copy-back by artifact family, from taskFamilies in build/dependeasy/remote/hosts.json | The Gradle build cache and declared outputs in the artifact store |
publications.sqlite3, which stops an older run overwriting a newer file | Generation and snapshot checks at every write |
Abandoned runs marked by remote_retention.py once their router process is gone | Leases that end, and reconciliation |
execution: Local in hosts.json, which keeps deploys on this Mac | A requirement, such as this Mac's Wrangler sign-in, that placement checks |
Capacity probes with macOS tools such as memory_pressure | Capability collectors on every OS |
Budgets in storage-limits.json | The disk pool in each machine's admission |
remote-dev mobile and mobile_worker.py for phones on USB | Device capabilities on the machine the phone is plugged into |
What exists today#
- Plans.
WorkPlan,PlanSchedule,PlanLeaseandWorkPlanStoreinreaktor-conductorhold components, tasks, checks and decisions, rank ready work, filter by profile and seat, and keep claims with a ten-minute lease extended by activity.WorkPlanStoreapplies every write in one process. - Conductor.
AgentWorkspace.attachPlangives a plan a seat, submits an agent run and binds its run id.AgentWorkspace.startTaskandTaskGraphRuntimedrive task attempts through graph-owned actors. All of it runs on one machine. - remote-dev. Routes Gradle work between this Mac and one SSH worker by observed capacity, with up to two jobs at once on the worker, a ticket queue for the local Gradle lease, receipts, artifact families, guarded publication, retained snapshots and a separate path for phones on USB. It probes capacity with macOS tools.
- A build cache pilot.
~/dev/reaktor/plane-machines/reaktor-cluster/tooling/build-cache.gradlepoints Gradle at an HTTP build cache through an SSH tunnel to the worker. - Reaktor parts the design uses.
ActorNodeandPersistentActorNodewith their stores, services with streams and keyed calls,SocketLink, and the capability design. - The k3s cluster. A single-node k3s cluster on a GCP VM runs production services. It is a cloud resource in the Compute pane and is not meant for builds or agents.
What the cluster improves#
The left column describes the router as it works now; the middle column lists problems it has actually had.
| Today | What has gone wrong | In the cluster |
|---|---|---|
| Outputs are copied back by artifact family | A worker build published an older library over a newer local one, and a copy-back restored test classes whose sources had been deleted | Outputs are addressed by content and published only when their generation and snapshot are current |
| Each host is guarded by lock files and a ticket queue | Wrapping ./gradlew in gradle-lease deadlocked every Gradle build on the Mac for fifteen minutes | One admission actor per machine owns every reservation, and nothing else takes locks |
The worker keeps a mirror up to date with rsync | A folder that existed only in the mirror made build models stale, and a slot reported compile errors that were not in the source | Each run materialises its snapshot and checks every hash before it starts |
| Builds read the working tree | Deploys carried other sessions' uncommitted work | A run names its snapshot, so a deploy can run from a chosen snapshot |
| A run counts as abandoned when its router process is gone | A killed run left publications pending that a later resume would have written over newer outputs | Leases end, generations rise, and a stale run's results are refused |
| One SSH worker and macOS-only probes | No Windows or Linux machines, and no way to place work by toolchain | Machines on any OS, placed by their capabilities |
| Agents run where the workspace owner runs | Agents cannot spread across machines | Agents run on any machine and talk to the one workspace kernel |
Limitations#
- Nothing is built. The router covers two Macs; everything else here is a design.
- One authority per workspace. While it is down, nothing new starts, and running work continues until its leases end. Failing over to a second authority needs a store with transactions or consensus behind it, and running two authorities over the same files does not provide that.
- Generations protect only receivers that check them. Every outside effect needs its own idempotency key.
- Live work does not move. Processes and agent conversations restart elsewhere unless the harness can resume them.
- Each OS needs its own runner. Process control, path handling, credentials and supported harness versions differ on Windows and Linux.
- Phones and browsers are limited hosts. They offer device checks and short tasks, and background limits can stop them at any time.
- Enrolled machines run workspace code. Only the owner's machines, or machines inside the same trust domain, should be enrolled.
Delivery plan#
- One admission owner per Mac. Host agents on this Mac and the m1-worker, with admission actors that
remote-devalso asks. Gradle runs become allocations with leases and generations, routing behaves as today, and the Cluster subpane shows machines and runs read-only. - Snapshots and artifacts. Snapshots and the artifact store replace the mirror and the copy-back, and the Gradle build cache moves from pilot to default.
- Agents on the worker. Plan items start coding agents on the m1-worker, with candidate patches coming back for review.
- Windows and Linux. Runners, collectors and snapshot checks for both, tested with the same scenarios on all three systems.
- Cloud and devices. Kubernetes jobs and other cloud runners through adapters, and phones as device hosts.
- Measured scale. Simulated fleets of 2, 10 and 100 hosts, measuring scheduling delay, admission contention, renewal traffic, transfer volume and recovery time, before any fleet size is promised.
These scenarios have to pass before the first release counts as done:
- A plan sends two independent tasks to two machines and holds a dependent task until both checks are accepted.
- Two workspaces and the old router share one Mac without exceeding its budget, and one phone behind two bridges is reserved once.
- Two machines on one subscription respect one usage limit.
- Duplicate starts and results, lost replies and an authority restart leave one accepted generation.
- A cut connection during a writing task leaves an unknown outcome, and the stale result is refused after the task moves.
- A snapshot change between a build and its review invalidates the old check.
- Cancelling, draining, revoking and restarting report what actually stopped.
Sources#
Papers and articles:
- Cary G. Gray and David R. Cheriton, Leases: An Efficient Fault-Tolerant Mechanism for Distributed File Cache Consistency, SOSP, 1989. Time-limited ownership that survives lost messages and crashed holders.
- Mike Burrows, The Chubby lock service for loosely-coupled distributed systems, OSDI, 2006. Sequencers, the lock service's fencing tokens.
- Martin Kleppmann, How to do distributed locking, 2016. Why a lease alone cannot protect a write, and how fencing tokens do.
- Abhishek Verma and colleagues, Large-scale cluster management at Google with Borg, EuroSys, 2015.
- Abhinandan Das, Indranil Gupta and Ashish Motivala, SWIM: Scalable Weakly-consistent Infection-style Process Group Membership Protocol, DSN, 2002. Failure detection for membership at larger fleet sizes.
- Ali Ghodsi and colleagues, Dominant Resource Fairness: Fair Allocation of Multiple Resource Types, NSDI, 2011. Sharing machines fairly when tasks need different mixes of CPU, memory and devices.
- Rajesh Raman, Miron Livny and Marvin Solomon, Matchmaking: Distributed Resource Management for High Throughput Computing, HPDC, 1998.
- Martin Kleppmann, Designing Data-Intensive Applications, O'Reilly, 2017. Chapter 8 covers leases, fencing and unreliable clocks.
Systems:
- Nomad architecture: clients report resources and servers place jobs as allocations.
- Ray resources: logical resources for scheduling, kept apart from enforcement.
- Temporal activities: retries, heartbeats and idempotent work.
- Kubernetes leases and Buildkite queues.
- Bazel Remote Execution API: content-addressed inputs and outputs for remote builds.
- Gradle build cache.
- Tailscale DERP servers: direct connections with a relay as fallback.
Related docs#
- Capabilities - What each machine can do, and the resolver placement asks.
- Actors -
ActorNodeandPersistentActorNode, which the scheduler, admission and allocations are made of. - Service Layer - Contracts, streams, keyed calls and
SocketLink. - Agents - The conductor, plans and agent runs that the cluster places.
- Dependeasy - Build nodes and their declared outputs.
- Reaktor V2 - Places, capability offers and placement in the paper.