ox CI test job: where 16 minutes go, and how to get to 5
The PR test job takes about 16 minutes. About 11 of those minutes go to two things: one test package that runs its tests one at a time while 3 of 4 cores sit idle, and steps that run one after another when they could run side by side. The 5-minute target looks reachable without removing a test. I checked the core change in a 4-CPU container that mimics the CI runner. It has not been run on GitHub yet.
Source run: CI #36810996436 attempt 2 (PR #1125, green, 2026-10-01). Container runs: Linux arm64, --cpus=4 --memory=16g, Go 1.26.5, same test flags as CI. measured marks numbers I observed. projected marks estimates; the method is in the appendix.
Today16.0 minmeasured PR test job, one 4-vCPU runner Stage 1: CI layout only≈5.5 minprojected no test code changes Stage 1 + 2: fix slow tests≈4–5 minprojected every assertion kept Core change in container316s → 151smeasured unit tests, cmd/ox split four ways; same tests, same coverage
1. What the test job does
The PR gate runs one make target, make coverage-integration, on one GitHub runner with 4 vCPUs and 16 GB of memory. It does three things in order:
- Unit tests. These are all 164 Go packages, built with the race detector and coverage.
go testruns up to 8 packages at once. - Acceptance tests. These run the compiled
oxbinary through real customer journeys. They run one test at a time. - Digital twins. These run against fake cloud, Ledger and knowledge-base servers.
Then it merges the coverage from all three and enforces the coverage floors. Main-branch pushes skip all of this and run a faster test tier, which is why they finish in about 5 minutes.
2. Where the 16 minutes go
The timeline below is the real run. Each row is one piece of work. Unit tests share a lane per package; only the long one is shown on its own.
Read it left to right. After 8.5 minutes, every package except cmd/ox is done. For the next 3.5 minutes, one test process runs on a 4-core machine. Then acceptance and twins start, but only after that wait.
Three findings explain most of it
| Finding | Cost | Why it happens |
|---|---|---|
cmd/ox runs its tests one at a time. | 7.5 min | 82% of its 3,664 top-level tests do not call t.Parallel(). Most of those use t.Setenv or os.Chdir, which Go forbids in parallel tests. So the package runs as one serial chain: 447s of its 452s. |
| Steps wait for each other. | 3.8 min | Acceptance and twins don't depend on the unit tests, but they start only after the unit tests finish. |
| The build cache is stale. | 3.4 min | The cache key is a hash of go.sum, which last changed on Sep 15. GitHub never overwrites a key. Every run therefore restores the same Sep-18 snapshot and recompiles every package changed since then with the race detector. |
3. The long pole: a few packages with serial test chains
The bars show each package's wall time in the real run. The label gives the share of that time spent in tests that run one at a time. Every package with a serial chain longer than about 2 minutes sets a floor that no amount of cores can beat, unless the chain is split.
Inside cmd/ox: four tests take 195 seconds
A background investigation traced each slow test to a cause. None needs to be deleted or weakened.
| Test | CI | Root cause | Fix that keeps the proof | After |
|---|---|---|---|---|
TestSessionUpload_ScansLongLinesUnderSizeCap | 68.5s | Redacts a 4 MiB line twice. About 190 regex patterns scan it with the race detector on, and the whole string is lowercased again for each pattern. | Unit-test the shared line scanner at the size cap without regexes. Keep the end-to-end test with a line just over 64 KiB. | <1s |
TestConfigFileCLI | 66.3s | It runs go build to make its own ox binary, and so do 17 other test sites. The test run never sets OX_TEST_OX_BINARY. | Build ox once per run and export OX_TEST_OX_BINARY. Memoize the helper that builds it. | 2–5s |
TestFixLedgerUnmergedPaths_RepairsAgreeingAutostash | 30.1s | Waits out a hard-coded 30s lock timeout. | Pass the timeout in as a parameter. Production keeps 30s; the test uses 200ms. | ≈0.5s |
TestFixLedgerBranchBehind_LockBusy_FailsFastInsteadOfRacing | 30.1s | Same 30s timeout. | Same fix. Tighten the assertion to the injected budget, which proves more than today. | ≈0.5s |
TestSessionCapture_UploadsNativeEntries (daemon/agentwork) | 50.1s | A watcher polls every 2s, and push failures retry with 1s and 2s backoff. | Make the poll interval and the backoff injectable for tests. Retry count and semantics stay the same. | 6–10s |
internal/codedb/store (about 70 tests) | 97s pkg | The SQLite driver guards every memory allocation with one process-wide lock. Each open re-runs 74 schema statements, so parallel tests queue behind each other. | Skip schema setup when the database is already current, which also speeds up the daemon. Copy one template database across tests. | ≈30–45s |
4. What I tested: split cmd/ox across idle cores
The cheapest fix needs no new runners and no test changes. Compile cmd/ox once, then run it as four processes. Each process gets an explicit list of test names, balanced on CI timings. Every test lands in exactly one list. The rest of the packages run alongside as before.
Same container and flags for every bar, with a warm cache. The split run was repeated twice and finished in 157s and 151s.
| Check | Baseline | Split four ways | Verdict |
|---|---|---|---|
| Wall time, unit tier | 316s | 151s | −52% |
| Test results recorded | 24,863 | 24,863 | Identical set. 4 subtest names differ only by a random port. |
| Failures | The same 2 in both runs. Both are process-group kill tests that fail only inside the container. | No new failures | |
| Covered code blocks | 46,240 (66.76%) | 46,254 (66.78%) | Same within noise. Two identical runs differ by 9 blocks. |
One catch I hit and fixed: putting the complement in a single -skip regex made a 130 KB argument, which Linux rejects (the per-argument limit is 128 KB). Explicit per-shard lists of about 38 KB each work. A production version should build the lists from go test -list, so new tests are always assigned. It should also fail loudly if a list nears the limit.
5. Options
Savings are measured from today's 16.0 minutes. They do not simply add up, because removing one long pole exposes the next one. Section 6 combines them properly.
| # | Option | Saves | Effort | Risk / cost | Evidence |
|---|---|---|---|---|---|
| A | Run acceptance and twins as their own jobs, in parallel with the unit tests. A small final job merges coverage and runs the ratchets. | ≈3.8 min | CI YAML + Makefile | More artifacts to merge. Free on this public repo. | measured durations; projected overlap |
| B | Split cmd/ox four ways inside the runner (section 4). | ≈4 min | Script + Makefile | Tests from separate processes could collide on shared fixed paths. None did in 2 container runs. | measured in container |
| C | Fresh build cache. Main pushes save a cache built with the PR flags; PRs restore the newest one; old entries are pruned. | ≈2.5 min | CI YAML | The repo cache is at 9.6 of 10 GB. The new 1.4 GB entry replaces the 1.0 GB one, so pruning is required. Older CodeQL entries may get evicted. | measured 128s cold vs 52s after an edit (container); projected CI |
| D | Move go build ./... and the docs check to the lint job. | ≈0.6 min | CI YAML | None. | measured step times |
| E | Fix the slow tests in section 3. | ≈1–1.5 min on top of A–C | Test + small product changes | Code review per test. Also speeds up local make test-all. | measured causes; projected savings |
| F | Split internal/daemon the same way. | ≈0.5–0.8 min after B | Same tooling as B | Same as B. | projected |
| G | Shard across 2 or more runners instead of, or as well as, B. | extra margin | CI matrix | Each runner pays its own setup and compile, about 1.3 min with a fresh cache. Free on a public repo, but uses concurrency slots. | projected |
| H | Larger runners (8 or 16 cores). | unknown | Org setting | Billed per minute, even for public repos. The serial chains don't get faster, only the parallel parts. | not measured |
Not proposed, because each one stops a test from proving something: dropping -race on PRs, skipping acceptance tests based on which paths changed, or moving tests to a nightly run.
6. Recommended path
Stage 1 is A + B + C + D. It changes only CI layout, with no test code. The projected PR job is shown below. The unit runner finishes at about 5.0 minutes, including its upload, and the merge job ends at about 5.5.
Same scale as the first timeline. Each lane is its own runner.
Stage 2 is E + F, landed as separate test PRs. They give the margin to stay under 5 minutes as the suite grows. Once cmd/ox loses its 195s of fixed waits, internal/daemon becomes the long pole, so F matters after E.
Before anything ships, the projections need one real CI measurement. A draft PR with Stage 1 would show the true runner numbers. Container time maps to CI time by a factor of about 1.43, but that ratio is a hypothesis taken from one baseline comparison.
7. Flaky tests found along the way
internal/codedb/store TestConcurrentSelfHeal_MultiProcess: failed PR #1125 on a lock conflict in the search index. Tracked asox-jz0x.internal/ledger TestBackfillPRCommits: panicked with an index out of range in 1 of 4 container runs (github_sync_test.go:551). The panic kills the whole package, so 369 results disappear at once. Not tracked before this report.
Appendix: evidence and method
A. Phase timestamps from the real run
| Phase | Start | End | Seconds | Source |
|---|
Times are seconds after the job started (03:42:41 UTC). "Compile" is the gap between the start of the coverage step and the first package result. Go also starts test binaries as they finish linking, so a little compiling overlaps the tests.
<!-- ox:details -->B. Package and test data
| Package | Wall s | Serial tests s | Parallel tests s (summed) | Top-level tests |
|---|
"Serial" means the test's own source does not call t.Parallel(), found by a static scan of each Test* body. Summed parallel time can exceed wall time because those tests overlap.
C. Container measurements
| Measurement | Seconds | What it isolates |
|---|---|---|
| Cold compile, all test binaries | 128 | Worst case, with an empty cache |
| Warm compile | 31 | Nothing to compile. The time is launching 164 race-instrumented test binaries. |
Compile after editing one file in internal/session | 52 | A typical PR against a fresh cache: about 21s of real compiling |
| Unit tier, baseline | 316 | Same flags as CI: -race -p 8 -parallel 32, atomic coverage |
Unit tier, cmd/ox split four ways (2 runs) | 157 / 151 | Option B |
Container to CI mapping: cmd/ox took 311s in the container and 452s on CI, a factor of 1.45. internal/daemon gave 1.42. I applied about 1.43 to project CI times. This is the main uncertainty: the container runs on Apple Silicon cores, while CI uses x86 cores and has different I/O. The host machine was also busy (load average about 15 on 18 cores), which if anything makes the container numbers pessimistic.
D. How the Stage 1 projection is built
- Setup 31s: today's 67s minus build (29s) and docs check (7s), which move to lint.
- Compile 45s: the container's 21s for an incremental compile, times 1.43, plus margin for cache restore. Today it is 202s.
- Unit run 216s: the container's 151s split run, times 1.43.
- Upload 10s, then the merge job about 30s: checkout, download artifacts, merge profiles and run the ratchets. No Go compile is needed.
- Acceptance job: setup plus the three acceptance phases (173s today), less the share of compiling a fresh cache saves. That share is a hypothesis.
- Twins job: setup plus today's 52s.
What would prove this wrong: CI compiles much slower than 1.43× the container, or the four cmd/ox processes contend for I/O on the CI runner in a way the container didn't show. A single draft-PR run settles both.
E. Run-time history: no recent regression
Successful PR runs averaged 11–12 minutes on Sep 18–22 and about 14 minutes from Sep 23 on. No single CI or Makefile change in that window explains the jump; the likely cause is test growth. I didn't bisect it. Today's PRs #1111, #1113 and #1125 each took 15–16 minutes per run.
<!-- /ox:details -->
