How scheduling works
Takt has one coordinator with a central queue, and a worker on each machine. The scheduler is a pure function: given a snapshot of machines, running jobs, the queue and run history, it returns a list of actions (start, wait, cancel). The coordinator runs it whenever something changes. State lives in one SQLite database.
This page uses the usual cluster-scheduling words. If you only want to build with agents, the short version is: say what a job needs, leave the size out, and Takt puts it where it fits without hurting anything else.
A job’s life
- Submit.
takt runsnapshots the working tree as a git commit, uncommitted changes included, and pushes it to the coordinator. The coordinator keeps one store per repository, which its linked worktrees (git worktree add) share, so a new worktree’s first job sends only the commits the coordinator doesn’t have yet, not the repository’s whole history. - Size. The scheduler computes the job’s effective resource request from what it asked and from history (learned sizing).
- Place. The job is filtered, scored and bound to a machine, or stays queued with a reason.
- Run. The worker fetches the commit (only what its copy of the repository lacks), starts the container or VM with the job’s memory cap, caches and secrets, and streams the log.
- Report. The worker reports the exit code, peak memory and CPU, which feed back into sizing. Files the job declared as artifacts come back to your checkout, whether it passed or failed, and so do the screenshots a failed job’s log names (
tmp/screenshots/,tmp/capybara/).
Binding is late: a job stays in the central queue until a machine has room, and is never pre-assigned to a per-machine queue (as in Sparrow).
Queue order and priority classes
Four priority classes: P0 (landing a change), P1 (checks, the default), P2 (exploration), P3 (idle). The queue is ordered by priority, then age. To keep a steady stream of checks from holding exploration back forever, a P2 or P3 job that has waited 30 minutes queues one class higher (P3 as P2, P2 as P1); P1 never ages into P0, which stays for landing. A job that can’t be placed doesn’t block the jobs behind it: each scheduling pass considers every queued job, so a small job runs as soon as it fits somewhere (no head-of-line blocking).
Takt does not preempt running jobs. A higher priority wins the next free slot, and gets a larger CPU weight while it runs.
Filling every gap with whatever fits could starve a large job: each time memory frees up on the one machine big enough for it, smaller jobs queued behind it take that memory first. So a job that fits a machine’s size but no machine’s room, and has waited 2 minutes, keeps one machine: of those it fits, the one where the least is missing (and where Takt’s own jobs ending would make room, not memory used outside Takt). Until it starts there, a job queued behind it (a lower class, or the same class and submitted later) starts on that machine only if it leaves the large job’s memory, cores and GPU memory free, or if it is tiny (at most 1 core and 1 GB): tiny jobs there may hold up to 2 cores and 2 GB together, when the large job fits beside that, so a screenshot or a quick check doesn’t wait for it; elsewhere it runs as usual, and higher classes are unaffected. Each machine is kept for at most one job, the first in queue order. The large job’s wait reason says it is next on mac-x, and the jobs kept off say so: mac-x is kept free for app: system tests (P0, needs 28 GB and 4 cores). A job that an asleep machine could take waits for that machine’s wake instead, and a request no machine could ever satisfy is clamped (below), never kept for.
Feasibility filtering
A machine is feasible for a job only if all of these hold:
- Constraints. It is online, not asleep (or its lid closed), not stopped by its owner, not in a failure cooldown, and has every feature the job needs (
darwin,windows,cuda,arm64…). A job in its project’s container getsbrowserfrom its image, not from the machine, so any machine that runs containers, a Mac’s Linux VM included, takes it. Before such a job runs, the worker checks its image has a Chromium (on itsPATHor in Playwright’s cache), once per image; if it has none, the job fails at once, since every machine builds the same image, and says to add it to the project’s.devcontainer/(which Takt uses before a rootDockerfile), not to a production image. Jobs name needs, never machines. - Reservations. Its reserved cores, memory and GPU memory, plus this job’s, fit what it may book. Interactive mode takes cores and memory out of the bookable total.
- Live memory floor. Measured
MemAvailablecovers the job plus headroom (5% of RAM, between 512 MB and 2 GB; 4 GB in Interactive mode), and Linux memory pressure (PSIsome avg10) is under 10%. Reservations alone can’t see processes outside Takt; this check can. - Limits per kind. At most two macOS VMs per Mac and two Windows VMs per host.
A request no machine can ever satisfy is clamped to the most the biggest feasible machine could give, and the job says so when it asked for that size (--mem); a size Takt chose itself, such as a Windows job’s 4 GB, is clamped without a word. A job whose needs no machine has, and no setting could give, is rejected at submit with the reason.
Admission control
Takt separates reservations from limits, as Borg and Kubernetes do:
- Memory is a hard limit. Every job runs under a memory cap: a Docker container limit or a systemd scope’s
MemoryMaxon Linux, the VM’s size on a Mac, a Job Object or the VM’s size on Windows (see how jobs are bounded). Admission reserves memory so the sum of reservations fits. - CPU is a weight, not a limit. A job’s cores set its cgroup CPU weight. Exceeding them slows neighbours a little and kills nothing.
- Visible cores. A test runner or build tool starts a worker per core it sees, so a job that sees more cores than it reserved fills its memory cap with workers. A container job on Linux sees only the cores it reserved: its container gets that many CPUs (
--cpuset-cpus, the ones other jobs use least), sonproc, Ruby’sEtc.nprocessorsand Node’sos.availableParallelism()count them. Every job,--hereand macOS VM jobs included, also gets these variables from its reserved cores, unless it sets them itself:TAKT_CORES,PARALLEL_WORKERS(Rails),OMP_NUM_THREADS,CARGO_BUILD_JOBS,GOMAXPROCS,MAKEFLAGS=-jN,CMAKE_BUILD_PARALLEL_LEVELandPYTEST_XDIST_AUTO_NUM_WORKERS. A tool that reads none of them (Jest, say) can be told withTAKT_CORES:jest --maxWorkers=$TAKT_CORES. Ask--coresfor more workers; a job that keeps every core it has busy is given more next time (see learned sizing).
Because CPU is compressible, Takt overcommits cores: a machine may reserve up to 2x its cores while its measured CPU use, plus what this pass already placed, stays under 85%. Memory is never overcommitted.
If no machine has the asked cores, the job may get an elastic grant of at least half of them on a machine that has that many free.
Those hard limits keep jobs out of your session’s memory on every OS. On Linux, sessions also get a guaranteed floor (MemoryLow on takt-agents.slice), and systemd-oomd stops jobs first. macOS and Windows have no equivalent mechanism, so there the jobs’ limits are the protection.
Placement and scoring
Among feasible machines, Takt picks one by these keys, in order:
- No overcommit. A machine that takes the job within its physical cores beats one that would overcommit.
- Spread score. The share of cores and memory left free after placing the job, counting real CPU use where it is higher than reservations. Highest wins. This is spread (worst fit), not bin packing: on a few machines people also use, keeping load even matters more than leaving whole machines empty.
- Not the coordinator’s machine, where someone is most likely working.
- Image locality. A machine that already holds the project’s newest image (no pull, no build).
Building a project’s image on a machine that hasn’t it takes minutes (a Mac’s Linux VM or WSL 2 spends them on apt and bundle), longer than many test suites run. So for a job whose history says it runs for less than 3 minutes, image locality comes right after overcommit, before the spread score, and a machine with the image that would overcommit still beats one without it. When only machines without its image have room, such a job waits up to 3 minutes for one that has it (waits up to 3 minutes for build-box, which has its image ready: building it on mac-mini would take longer than the job runs), then builds where there is room. A job with no history, or a longer one, is placed by room as above.
A Windows job prefers a joined Windows machine with room over a VM, since it starts at once.
Wake-on-demand
Sleeping machines are capacity too. When a job has no feasible awake machine, or the best one would have to overcommit, and an asleep machine with auto-sleep on would take it outright, the coordinator wakes that machine with Wake-on-LAN and holds the job for it. Jobs held for the same machine count against it, so one wake isn’t promised to more work than fits. If the machine isn’t back within 3 minutes, the job overcommits after all.
An auto-sleep machine sleeps after 30 minutes with no jobs, when nothing queued could run on it.
Learned sizing
Agents are bad at guessing resource requests. They over-ask by habit, which strands capacity, or under-ask, which gets jobs killed. Takt learns instead. Each job has a kind (its name, within its project), and every run records its peak memory and average cores.
The learned size is:
- memory: the larger of the p95 and the maximum peak, plus 25%, rounded up to 512 MB (at least 1 GB);
- cores: the p95 of average cores used, plus 25%, rounded up.
The effective request then follows these rules:
| The job asks | Takt reserves | The cap the job runs under |
|---|---|---|
| nothing | the learned size; with no history, its project’s similar jobs, else 2 GB and 1 core | the reservation |
| far more than learned: over 2x after one run, or any amount over after three | the learned size | what it asked |
| less than its measured peak | the peak | the reservation |
| about what it uses | what it asked | what it asked |
So an over-ask no longer strands free memory, and the job still keeps its own limit as a safety margin. When a job asks at least twice its peak over at least three runs, Takt tells the agent: this job peaked at 2.8G over the last 5 runs; ask –mem 4G (or omit –mem: Takt reserves 4 GB). A memory-cap kill is recorded too, at its cap, which says only that the job needs more: when no run reached more, the next estimate is 1.5x that cap, the step its retry got, and the hint says a run of this job was stopped at its 3 GB memory cap, so it needs more than that; ask –mem 5G (or omit –mem: Takt reserves 4.5 GB), never the cap as its peak. One cap kill may be an accident (a leak in one branch) rather than what the job needs, so it sizes only until the runs after it say otherwise: once three passing runs recorded after it each used less than that cap, the kill stops counting, and the job is sized from its passing runs again. A job that really needs more passes above the cap, or is killed again, and stays sized up. Only passing runs and memory-cap kills set the learned size. A failed run may have stopped before its real work (a missing database), so its peak can only raise the size above what passing runs used, and alone it never sizes a job below the 2 GB default; a run that failed within 10 seconds, or for an infrastructure reason, counts for nothing.
A job whose name has no history yet (names that change every run, such as “app: test
Cores work the same way, with one more rule: since CPU is a weight, a job that uses more cores than it asks is reserved at what it really uses, so the machine isn’t overcommitted unseen.
Rescheduling
- Memory cap. A job killed at its cap is requeued once with 1.5x the memory it reached (bounded by the biggest machine), and placed again. On Linux the first process the kernel kills at the cap stops the whole job: a
--herejob’s scope goes at once (OOMPolicy=kill, which setsmemory.oom.group), and a container job’s container within a fraction of a second, so the kernel never kills its processes one at a time while the job starts new ones. Its log says it in one line, stopped at its 4G memory cap; retrying with 6G, and so does the result of a job stopped there again (stopped at its 6G memory cap; it was retried once already, so ask for more with –mem). A cap hit is never reported as an infrastructure failure, even when the job’s runner was lost with it. - Infrastructure failure. A run that ended without a result (its runner was lost) or a known crash pattern requeues the job once on another machine. It is never blamed on the commit. A
--herejob is the exception: it runs in your folder as it is, and what it already did there isn’t undone, so it is never run again by itself. It ends as lost and says why, for example the job’s runner on build-box ended without a result (its worker restarted, or the runner was stopped); it was not rerun because –here jobs may have side effects. Two infrastructure failures in a row put a machine in a short cooldown. - Link failure at start. A job whose machine’s link fails as it starts (its worker restarting to update, say) never ran, so it goes back to the queue under its own id and place, waits for the machine to reconnect, or starts elsewhere first. Only after 3 such trips within 3 minutes is it lost.
- Lid closed. When a Windows laptop’s lid closes, its worker lets Windows sleep and tells the coordinator, which puts its running jobs back in the queue under the same id, counted as neither failure nor retry, and places nothing there until the lid opens.
- Going to sleep. A Linux worker hears from logind that its machine is about to sleep (a closed lid, a suspend from a menu) and tells the coordinator first, holding the sleep off for the moment that takes. Its running jobs go back to the queue at once, counted as neither failure nor retry, and the machine takes nothing until it wakes. This needs systemd 257 or later.
- Machine gone offline. A machine whose link drops without a word (it slept without saying so, or lost its network) keeps its running jobs for 2 minutes, which covers a network blip or its worker restarting to update: if it reconnects in time, Takt attaches to them again and they finish there. Meanwhile the dashboard shows them as waiting (laptop went offline at 21:36; back to the queue at 21:38 unless it reconnects), not as holding room. After that they go back to the queue, counted as neither failure nor retry, and run elsewhere (a
--herejob ends as lost instead, as above). Whatever is left of their run there is stopped once the machine connects again. - Drain. Turning Run jobs here off on a machine stops its jobs and puts them back in the queue under the same id, counted as neither failure nor retry.
takt drainstops new placements so the coordinator can restart. - Ownership. If the agent that ran
takt rungoes away, its job is cancelled.takt run --detachjobs keep running on their own.
Not wasting work
- Fail-fast groups. When a job in a
--groupfails, the group’s other jobs are cancelled on every machine. - Supersede. A newer job with the same
--supersedekey cancels the older one. - In-flight deduplication. An identical job already queued or running is joined instead of run twice: the same snapshot (uncommitted and untracked files included), command, subdirectory, features, environment, artifact patterns and
--withsnapshots. The joined job names the run it joined, gets its result, and gets its artifacts in its own checkout. If that run is cancelled, it runs on its own.--no-cacheopts out.
takt status reports wasted machine-hours by cause, and submit-to-result latency at p50 and p90.
Prior art
| From | Takt borrows | Takt leaves out |
|---|---|---|
| Borg, Kubernetes | filter then score, reservations vs limits, compressible CPU, image locality | preemption, the plugin framework |
| Nomad | one Go binary, workers that dial in, constraints, spread | Raft, Serf, placement by declared asks only |
| HTCondor | probed machine features matched against job needs | the ClassAd language |
| Slurm | multi-resource accounting, priority classes | backfill, fair-share trees |
| Sparrow | late binding | random probing |
| Bazel remote execution | in-flight deduplication | hermetic action caching |
| Zuul, merge queues | fail-fast groups, supersede | rebasing inside the scheduler |