garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/ci-build-cost.md

raw


topic: ci-build-cost triggers: [ci.yml, rust-cache, sccache, valid_volumes, actcache, CARGO_BUILD_JOBS, mold, "ci slow", "cache miss", "cargo test workspace", forgejo-runner, "disk full", cartopolis-ci, nextest, "queue blocked", paths-ignore, save-if, "runner capacity", "agents ci"] updated: 2026-08-16

What CI actually costs, measured

Every number here comes from action_task_step in Forgejo's SQLite database, which is the only place per-step timings survive:

select s.name, (s.stopped - s.started)
from action_task_step s
where s.task_id in (select id from action_task where job_id in
      (select id from action_run_job where run_id = <N>))
order by s.id;

Use it before changing anything here. Every wrong conclusion recorded below came from reasoning about CI instead of measuring it.

The measurements, 2026-08-12

The test job, which is the whole of a pull request's CI:

runconfigurationtest time
302five cargo test -p …, cold1918 s
304five cargo test -p …, rust-cache warm272 s
309one cargo test --workspace, cold, no sccache1001 s
310one cargo test --workspace, rust-cache warm163 s

One invocation instead of five is worth about 45%, warm or cold. Under resolver v2 each cargo test -p X unifies features over only the packages it selects, so five invocations meant five different feature sets for the shared Bevy dependencies and five rebuilds of them. The tell was big_space — a small vendored crate — taking 439 s immediately after a step that had just compiled the entire Bevy stack. The cost of collapsing them is the cheapest-first ordering that used to fail in seconds on a geodata regression.

Before collapsing them again after some future split, check what --workspace changes: cartopolis_geo and cartopolis_simulator carry tests/ directories that a --lib would drop, and big_space's only doc fences are ```ignore, so the --lib it used to be given was conservatism rather than a real exclusion.

Where a warm run's time actually goes, 2026-08-16

One stored job log (task 640, PR #92, 448 s) answers this completely, because cargo and libtest both print their own timings:

phasetime
rust-cache restore, 1182 MB, full match~70 s
compiling the five workspace crates6 m 02 s
running all 764 tests2.2 s
rust-cache save (post step)~90 s

Test execution is half a percent of the job. Everything else is compiling our own code — sccache served four of the five crates from cache and missed on cartopolis, which is the whole six minutes. So the cost of a CI run is a function of which crate you touched, not of how many tests exist: touch the client and pay six minutes, touch geo alone and the client comes back from sccache.

That killed the open question below it: cargo nextest was not worth measuring, with 2.2 seconds of test execution to win. That number did not last: by 2026-10-27 the suite ran for 46 s, most of it waiting rather than computing, and the cure was the waits themselves, not a runner (test-suite-build-cost.md).

The ~90 s post step is this action writing its archive, and it is measurable without reading a log — subtract the sum of a job's steps from the job's own duration. Averaged over every green run since 2026-08-05: PR test 518 s of job against 429 s of steps, main test 675 against 593, targets 309 against 217.

Per merged change, the runner does the work three times

A merge costs a PR test job, a main test job and a targets job — about 1500 runner-seconds on a runner with three slots. With several agents holding branches open at once, that queue is the thing that blocks, and four of the runs in it are avoidable rather than slow. ci.yml now declines them, and each mechanism is one if with its reasoning beside it:

Skipping CI on draft pull requests cannot work here, measured 2026-08-16. Forgejo 16.0.1 fires no Actions run at all on the draft→ready transition. On PR #94, with ready_for_review declared in types, removing the title's WIP: prefix moved the API's draft to false and created no run row. Forgejo derives draft state from that title prefix, so the transition arrives as an edited event or as nothing — and putting edited in types would rebuild the world every time somebody fixed a typo in a description. A gate whose release condition never fires is a branch that silently never gets a verdict, so the gate was removed rather than shipped with a caveat.

Both of the trigger types that are used were confirmed on the same PR: opened created run 398, and a push created run 400 as pull_request_sync, matching a plain on: pull_request.

The skip markers do work on a pull-request push, confirmed on the same PR by accident, which is the useful part: the next force-push created no run at all, and the only difference was a commit body that mentioned the marker while explaining that it was the lever to use. SKIP_WORKFLOW_STRINGS is matched as a plain substring over the whole commit message — not a prefix, not a line of its own — so a commit that talks about skipping CI skips CI. Split the brackets when writing about them.

rust-cache is not broken; the rename broke it

Swatinem/rust-cache is worth 6× (2058 s → ~320 s for the whole job) and it very nearly got deleted from ci.yml on the evidence of run 302 alone, where the restore took one second and a Bevy-free crate took 161 s to test. That run was cold for a reason that had nothing to do with the cache being unhealthy:

A cache entry's version hash covers the workspace path. Renaming the repo viberfox → cartopolis changed /workspace/jeroen/viberfox to /workspace/jeroen/cartopolis and invalidated every entry in the store at a stroke — 32.8 GB of them, orphaned to a repo name that no longer resolves. Run 302 was the first run afterwards, so it was cold and wrote a fresh cache; run 304 restored it and was 6× faster.

Never judge a cache from one run. Compare two consecutive runs on the same ref.

The second structural limit is worth knowing because it does not go away: entries carry a writeIsolationKey of the ref that wrote them, so a cache written by a PR run is invisible to every other branch. Caches written on main have an empty isolation key and are readable everywhere, which is why main moving on every merge is what keeps PR runs fast.

The third key input is the one that will catch you, because it is not about the code at all: rust-cache hashes every environment variable whose name begins with CARGO, CC, CFLAGS, CXX, CMAKE or RUST. Changing CARGO_BUILD_JOBS from 3 to 2 — a scheduling knob that changes not one byte of any artifact — invalidated the entire store on 2026-08-16: the run that did it restored in 1 second instead of ~70 and rebuilt Bevy from nothing.

That is survivable once. What made it worth a rule is the second half: the merge that would have re-saved a warm entry under the new key touched only docs/ and .forgejo/, so the tree-already-tested and render-path gates correctly skipped every step that compiles, and the cache would have stayed cold for every pull request until some later merge happened to touch the client.

So the job count lives on the cargo command line as -j "$JOBS" and the env: block holds only variables that really are compilation inputs. Anything in env: that starts with one of those prefixes is a cold run for the whole repo the day someone tunes it — and removing one costs exactly what adding it did, which the run that did it reported as a flat No cache found.

The repair has to be deliberate, because the gates above can produce a main run that compiles nothing and therefore saves nothing: after any key change, dispatch ci.yml on main once (workflow_dispatch, added for this) and let it run whole. Otherwise every pull request stays cold until some later merge happens to touch the client — which is a slow, silent, and very confusing way to lose a cache.

You can read the whole store, which is how the 32.8 GB was identified and deleted without touching the eight live entries:

sudo strings /var/lib/forgejo-runner/.cache/actcache/bolt.db \
  | grep -o '{[^{]*"key":[^}]*}'

Blobs live at cache/<hex(id)>/<id> — note the directory is hexadecimal and the filename is decimal.

sccache sits underneath, for the cases rust-cache cannot serve

A fresh branch, or the whole repo the day after a rename. sccache is keyed on the compiler invocation with no ref scope and no workspace path, so those cost a link rather than a full Bevy build. On a rust-cache hit it is nearly idle — run 310 left only 39 MB in it, because almost nothing needed compiling.

CARGO_INCREMENTAL: "0" stops being a tuning and becomes a requirement: sccache silently declines to cache an incremental compilation.

valid_volumes matches the host path as a pattern, and fails silently

This cost a full run. /data/ci-cache in the runner's valid_volumes does not permit a mount of /data/ci-cache/sccache — the entry has to name the path exactly (or glob it). When it does not match, the runner drops the mount and runs the job anyway: no error, no warning, a green build, and an empty cache directory. Run 309's improvement was real but came entirely from the single invocation, mold and the job cap, because the sccache it was supposedly measuring was never mounted.

Verify a mount by looking at the host directory, not by reading the workflow. sccache --show-stats runs in both jobs (if: always()) for the same reason.

Rejected, with the measurement that rejected it

Host disk: where it goes and what is safe to reclaim

The runner shares an 8-core, 193 GB box with nominatim, overpass, Forgejo and the agent containers. It reached 87% full on 2026-08-12 and came back to 66 GB free without touching anything that costs build time:

reclaimedwhatwhy it was free
33 GBactcache entries scoped to jeroen/viberfoxthe repo does not exist under that name; unreachable forever
30 GBagent_cargo-target/_data/debug/incrementalpure incremental cache — but it regrows, and it does save agent rebuild time
~2 GBdangling images, one orphaned build containerleftovers

Not reclaimable: the ~96 GB of docker volumes is mostly geo_overpass_db and nominatim's database. That is the map services' data, not cache.

It regrows, and the same three places refill it. 2026-08-17, from 31 GB free on /data and 37 GB on /, ~13 GB came back:

reclaimedwhathow it was chosen
8.6 GBdebug/incremental in the agents' shared target dirfind -maxdepth 1 -type d -mtime +2, not a wholesale rm -rf — several agents were mid-build in that directory at the time, and a live session's dirs are the ones with a recent mtime
4.4 GBsix actcache blobsjob names and env hashes no current workflow can generate: v0-rust-build-test-* and v0-rust-check-* (both jobs deleted from ci.yml), and the baf921c2 / 004b9e23 env generations
~0 GBviberfox-ci:latest, the pre-rename CI imageunreferenced by all three repos on this instance — but nearly all of its 6.85 GB is layers shared with cartopolis-ci:latest, so untagging it freed almost nothing

Two things that look reclaimable and are not. catthehacker/ubuntu:act-latest (2.3 GB) is the default image for a job with no container:, which is every job in jeroen/codebrew — this repo's workflows all name cartopolis-ci, the console's deploy included, so it is easy to conclude wrongly that nothing uses it. And the Android emulator's SDK under /data/agent (5.5 GB) is a standing fixture for testing Android behaviour, not a leftover; its cost is RAM, not disk.

Deleting an actcache blob leaves its row in bolt.db, and there is no delete API to do the pair. A dangling row is a failed download that actions/cache reports as a warning rather than a failure — survivable, but it is a cold run nobody ordered, so restrict deletions to keys the current workflows cannot generate. Everything else ages out: entries unused for 30 days are GC'd, and since PR runs stopped saving (save-if) the store only grows on a key change.

What a third runner slot costs on disk

Almost nothing, which is worth stating because it is the opposite of the memory answer. The slot itself is a goroutine. Each concurrent job gets a docker volume for /workspace holding the checkout and its own target/ — measured 645 MB, 1.5 GB and 2.2 GB across three jobs in flight on 2026-08-17, peaking around 5 GB for a test job that has restored its cache and compiled — and act removes the volume when the job ends. The container's own writable layer is ~200 kB; the 5.39 GB it reports is the shared image.

So disk is not what bounds the slot count. Memory is: ~2 GB per job at peak against a 23 GB box with no swap, where the emulator holds up to 12 and the agent containers 12 more.

The job count exists for the same shared-host reason: one rustc per core per slot is 24 compilers on 8 cores, and the load average sat between 8.5 and 11.8 during an ordinary run — 12.2 on 2026-08-16, with two public services and the agent containers' own builds on the same silicon.

A cold job got slower and the queue still got faster. The first cold run at -j 2 took 2671 s against 1918-2058 s for the cold runs recorded at -j 3 above — call it a third slower per job, though it is not a controlled A/B (a different day, a different load, and the runner shares the box). Three slots at that rate is still ~15% more throughput than two at the old one, and throughput was never the point: what improves is that a pull request now finds a free slot while a main run holds one. If a single job's wall clock ever matters more than the queue does, this is the knob that bought the queue and it can be sold back.

Slots and compilers are one budget, and it is six. The runner went to capacity 3 on 2026-08-16 and the per-job count went to 2 in the same change, so the peak compiler count did not move. The third slot buys the overlap of the third of a job that compiles nothing — checkout, the cache restore and save, the scene smoke's settle — and buys an agent's pull request a slot while main has one. Raising it without lowering the other is what the load average forbids.

The memory ceiling is the harder one and it has no swap behind it: 23 GB total, of which the emulator container holds up to 12 and the agent containers 12 more. Six OOM kills are in the kernel log for the 30 days to 2026-08-16, twice with qemu-system-x86 invoking the killer. A CI job container measured 0.4 GB through checkout and cache restore and peaks around 2 GB linking with mold, so three of them is ~6 GB — which fits only while the Android emulator is not left running. Tear it down when a session ends (android-emulator-on-the-vps).

Still open