Skip to Content
Tukang

How it works

The states a job passes through, what Tukang asks GitHub, and what happens on a restart.

docker ps --filter label=tukang.role=job

That lists the runner containers Tukang has started. While no job is queued for your label, it lists nothing.

The life of a job

The dashboard shows each repo's runner in one of these states.

A job moves through five states: starting runner, waiting for GitHub (up to 10 minutes), waiting for the gate once the hook reports the job, running, and cooling down after the container exits and is removed.

StateWhat's happening
Starting runnerTukang registers a just-in-time runner with GitHub and starts its container, named tukang-job-<short-name>.
Waiting for GitHubThe runner is online, and GitHub hasn't handed it the job yet.
Waiting for the gateThe runner's job-started hook reported the job. Tukang runs the gate command, if you set one.
RunningThe gate printed go (or there's no gate), and the job's steps run.
Cooling downThe container is gone. The repo waits TUKANG_COOLDOWN (30 s) before its next poll, because GitHub's jobs API can still say "queued" for a job that just ended.

A repo has at most one runner at a time. Across all repos, at most TUKANG_MAX_JOBS (2) runners exist at once.

Finding queued jobs

Each poll, Tukang asks GitHub, per repo, for the newest runs with the status queued. It keeps every run it has seen as a candidate until the run completes, and checks each candidate's jobs for one that's queued and carries your label.

Every 10th poll (TUKANG_SWEEP_EVERY) it also asks for runs that are in_progress or pending. That catches a run whose first job went to a GitHub-hosted runner before Tukang saw it, a later job that waited on needs:, and a run that waited on a concurrency group.

Each poll costs one API call per repo, plus one per candidate run. With the shell script Tukang grew out of, 8 repos polled every 30 s used about 960 calls an hour of the token's 5,000 (measured on a Mac mini M4 with OrbStack). The dashboard shows the calls left.

The runner

Tukang registers each runner with these labels, so a job matches with runs-on: [self-hosted, tukang]:

  • self-hosted
  • Linux
  • ARM64 or X64, from the host's CPU
  • your label, tukang unless you set TUKANG_LABEL

The runner's name is tukang-<short-name>-<unix time>. Its container runs as the unprivileged runner user, from the exact image tukang serve runs (by image id, so a moved tag can't split them). Tool downloads from setup-node, setup-go and friends go to the tukang_toolcache volume, so the next job doesn't download them again.

A runner that gets no job within TUKANG_IDLE_TIMEOUT (10 min) is stopped and its registration deleted. That happens when a job is cancelled or another runner takes it.

The job token

tukang serve gives each job container its own random token, so the hook can talk back to it. When the container starts, tukang job moves the token into a file only the hook reads, and the hook deletes the file once the job may start. The job's own steps never see it.

Restarts

Job containers keep running when tukang serve stops or restarts. On start, serve lists the containers it started (label tukang.role=job) and picks each one up again:

  • A runner still waiting for a job goes back to waiting.
  • A runner whose job was already assigned takes the gate again, because the restart ended the old gate command. Serve keeps which runners had a job in state.json in its data directory.
  • A container that stopped while serve was down is recorded and removed.

The last 100 jobs are kept in the same state.json, so the dashboard's history survives a restart.

Next

On this page