CI / Speed and debugging
Run Source CI jobs on your machines
You run CI machines for other people, and you want to run the CI jobs of TanStack Source on them. The Source runner contract, version 1, says what your service does for each job: hear of it, claim it, start a fresh VM that runs the agent of the forge, and delete the VM after. The forge keeps the secrets and the job token, so your VMs never hold them.
12 min read
Your service is a Source app with the permission ci:runners. A repository sends a job to it with runsOn: '<your app slug>', or with your app as the runner of the repository.
You need:
- A Source account that owns the app: your own account, or an organization that you own.
- A server that takes webhooks, on https and a public host.
- A way to start a fresh Linux VM for each job.
1. Register a runner app
- Open Settings, then Apps (
/settings/apps), and click New app. - Give the app a Slug. Repositories name your runner by this slug. Do not use
ravion, the runner of the forge, orcloudflare: the forge refuses both. - Set the Webhook URL. Without it, the jobs that name your app fail, because the forge cannot tell you of them.
- Under Permissions, tick
ci:runners. To let other accounts install the app, turn on Public. - Click Register app. Copy the app secret (
tsk_...) and the webhook secret.
You pick no event for jobs. Each install that approved ci:runners gets the event ci_job. Build an app shows the other fields, and how to check the signature of a webhook.
2. Get installed on an account
- The owner of an account opens
/apps/<slug>, clicks Install, and approvesci:runners. See Install an app. - A repository of the install picks your app:
runsOn: '<slug>'on a job, or your app as the runner of the repository. See Pick where CI jobs run.
3. Take the job event
When a job that names your app waits for a VM, your webhook URL gets a ci_job event with the action queued. It is signed and sent as every app webhook is. See Receive app webhooks.
{
"event": "ci_job",
"action": "queued",
"job": {
"id": "6f1c2a4e-8b3d-4e5f-9a7b-1c2d3e4f5a6b",
"attempt": 1,
"workflow": ".source/workflows/ci.ts",
"name": "test (shard: 1)",
"runs_on": "fast-runner",
"size": { "cpu": 4, "memory_gib": 13 },
"image": "node",
"region": "enam",
"timeout_minutes": 60,
"fork": false
},
"repository": {
"id": "8c1e4b7a2f9d0635",
"owner": "alice",
"name": "app",
"full_name": "alice/app",
"url": "https://source.tanstack.com/@alice/app",
"private": false
},
"installation": { "id": "5d2a9e0c71b84f36" }
}
Field of job | What it is |
|---|---|
id | The id of the job. You claim the job with it. |
attempt | The VM of the job that the event is about: 1 for its first VM. A new queued with the next number asks for a new VM. |
workflow, name | The workflow file, and the key of the job with its matrix cell. |
runs_on | The slug of your app. |
size | The vCPU and the memory in GiB of the VM to start. The memory is the memory of the job, plus 1 GiB for the agent and Docker. |
image | node or browser. The agent pulls it from the forge, so your VM needs no copy. |
region | Where the forge runs the job's objects and keeps its data: always enam (AWS us-east-1). Start the VM near it. |
timeout_minutes | The time limit of the job. The forge stops the job at its limit, whatever the VM does. |
fork | true for a pull request whose head is in another repository. |
4. Claim the job
- Get an install token for
installation.id:POST /api/v1/app/installs/<install>/token, with the app secret. A token works for one hour, so keep it for the next jobs of the install. - Claim the job with the token:
curl -fsS -X POST "https://source.tanstack.com/api/v1/repos/alice/app/ci/jobs/$JOB_ID/claim" \
-H "Authorization: Bearer $INSTALL_TOKEN"
| Status | What it means |
|---|---|
201 | The claim: { "claim": "tsc_...", "expiresAt": <ms since 1970> }. |
403 | The install cannot claim the jobs of this repository, for example because it did not approve ci:runners. |
404 | The forge finds no such job of your app in this repository, or your app cannot see the repository. |
409 | The job waits for no VM: it has not started, an agent took it already, or it ended. |
- A claim names one job, works once, and stops after 10 minutes.
- A new claim of the same job replaces the claim before it. So an older VM of the job gets no session.
- Give the claim only to the agent on the VM of the job. Never write it to a log.
5. Start a fresh VM that runs the agent
Start a new VM for the job. Then run this command on it, as root:
curl -fsSL "https://source.tanstack.com/_runner/agent" -o /tmp/source-agent.sh && sh /tmp/source-agent.sh --claim "$CLAIM" --forge https://source.tanstack.com
The bootstrap checks the VM, downloads the agent from the forge, and runs it. The forge serves the agent of its own deploy, so your VM image needs no copy of the agent.
The VM must have:
- The machine: Linux on x86_64, with the vCPU and the memory of
job.size, and nothing left of another job. - The programs:
curl,sh, Docker 26.1 or later, and Node 24 or later. - The network: https on port 443 to the forge and to the internet.
Docker must run each container in a user namespace: "userns-remap": "default" in /etc/docker/daemon.json. When the setting is missing, the agent adds it, and restarts Docker with systemctl restart docker. Put the setting in your VM image to skip that restart. You must do this when systemd does not run Docker.
Start the agent soon. The forge waits for the job container until the job's timeoutMinutes (from 1 to 120, and 60 when the job sets none). That wait includes your webhook, the claim, the boot of the VM and the pull of the image. A job that never gets a runner ends with the error queued, no runner.
6. Delete the VM when the agent exits
When the agent exits, delete the VM, whatever its exit code. Never give a VM a second job.
| Exit code | What happened |
|---|---|
0 | The forge ended the job. |
1 | The agent failed, for example because Docker or Node is missing. It prints the reason on stderr, in a line that starts with source-agent:. |
2 | The command line is wrong. |
3 | The forge refused the claim, or the connection closed before the forge took it. The job did not start on this VM. When the first connect fails, the agent tries the claim again for 30 seconds before it exits. |
4 | The connection broke and did not come back within 2 minutes. The agent removed the job container. |
After exit code 3, you can run the agent again with the same claim. For example, run it on a new host after you lost a spot host. The forge gives the job to one agent only.
Done
A job that names your app runs on your VM. The forge sends in_progress when your agent takes the job, and completed with the result when the job ends.
The events of a job
| Action | When |
|---|---|
queued | The job waits for a VM. Claim it, and start one. |
in_progress | The agent on your VM took the job. |
completed | The job ended. job.conclusion is success, failure, timed_out or error. |
cancelled | The VM is no longer needed. The job was cancelled, or it goes on without this VM. For example, the agent was lost, or the job ran past its time limit. |
The forge sends each action of each attempt once. After completed or cancelled, the VM of that attempt is done. If it still runs, delete it.
A job can get more than one queued: each one has the next attempt, and asks for a new VM. A failed delivery comes again later, so the events of a job can come out of order. Match each event to its VM by job.id and job.attempt, never by job.id alone.
Which jobs you get
- Only the jobs of trusted and protected runs. A job of an untrusted run runs on Ravion, also when it names your app. An example is a pull request from a fork by an author without write access.
- Only the jobs of the repositories that the install covers.
- Never a job of a hidden workflow.
- Each cell of a matrix job is a job of its own, with its own events and its own VM.
What the forge guarantees
- The VM never holds a secret value or the job token. The job gets placeholders. Its requests to the forge, to the image registries, and to the hosts of a secret or an app token go through the forge. The forge adds the values there.
- The job container has no network of its own. The agent answers its DNS, and takes each HTTP and HTTPS request with a CA made for the job. Other requests to a host of the
egressof the job, on port 443, go straight out from the VM. The forge refuses the rest. - Root in the job is not root on the VM, except in a job that runs Docker. Docker runs the job in a user namespace, with 7 capabilities and no new privileges.
- The claim and the session token name one job, and stop when the job ends. The agent keeps them in memory only. It never prints, logs or writes them.
- The agent pulls the CI images through the forge (
/_runner/registry). Your VMs need no registry login.
The job and the agent share the kernel of the VM. Run each job on a fresh VM, so a job never sees what another job left.
Jobs that run Docker
A job with docker: true starts its own Docker daemon, for example to build and push images. Only a protected run has such a job.
The forge sends each job to the agent in a start message. For such a job, the message has docker: true, and the agent runs the job container with other flags:
--privileged --userns=host, with no capability drop and nono-new-privileges.- An anonymous volume at
/var/lib/dockerfor the data of the job's daemon, because overlay on overlay does not work. - The same limits, CA file, internal network and DNS as for any other job.
When the job ends, the agent removes the container and its volume with docker rm -f -v.
Root in such a job is root on the VM. The VM still holds no secret value: only the job's placeholders, the agent's session and the job's CA. The agent still routes each request of the job, but a step that gets control of the VM can send requests without the agent.
Large uploads
The agent sends each request that goes through the forge to /_runner/relay. The relay takes a request body of at most 100 MB. docker push sends each image layer in one request, the cache() step sends each cache entry in one request, and the artifact() step sends each artifact in one request. So the agent splits a large upload on this route:
- A large upload is a blob upload to a registry, or a cache save or an artifact to the CI host. A blob upload is a
PATCH, or aPUTwith adigestquery, to a path with/v2/and/blobs/uploads/. A cache save is aPUTto/cache/saveonci.tanstack-source.internal, and an artifact is aPUTto/artifacts/<name>there. A body of at most 64 MiB goes in one request. - A larger body goes in parts of 64 MiB, with one part in memory at a time. Each part is a
PATCHto the location of the upload, withContent-Range: <start>-<end>,Content-Type: application/octet-streamand the other headers of the job. The next part goes to theLocationof the answer. - For a
PATCH, the job gets the answer to the last part. ItsLocationandRangecover the whole upload. - For a
PUT, the agent then sends aPUTwith no body to the last location, with thedigestquery of the job if it has one. The job gets its answer. - Each part must get
202. Any other answer goes to the job as it is. ALocationon another host gives the job a502.
A request that goes straight to its host is never split.
While the forge restarts
A deploy of the forge can restart the object of a job for some seconds. Then the forge answers /_runner/relay and /_runner/connect with 503 and Retry-After, and the agent tries again:
- A relayed request that is safe to send twice goes again, at most 5 times. The waits are 1, 2, 4 and 8 seconds. A request is safe to send twice when its method is
GET,HEAD,OPTIONS,PUTorDELETE, or when it is a fetch of git (aPOSTtogit-upload-pack), and its body is at most 1 MiB. After the last try, the job gets the503. - When the first connect fails, the agent tries the claim again for 30 seconds. After a drop, it connects again for 2 minutes, as for any lost connection.
When an event does not come
- The forge sends a delivery again when your server answers
429or5xx, or does not answer. It tries for about one day: the first wait is 30 seconds, and each wait is two times the last, up to one hour. - Your server can list the newest 100 deliveries with
GET /api/v1/app/deliveries, and send one again withPOST /api/v1/app/deliveries/<id>/redeliver. Both take the app secret. See Read the delivery log. - Each try and each redelivery keeps the
X-Source-Deliveryid, so use it to drop a repeat.
Who pays
The forge counts the run time of your VMs for the account of the repository, with no CI minutes and no price. The Billing page of the account shows it on rows like Runner app large, 4 vCPU. You bill your customers yourself.