# CI speed and flakes (branch ci-speed)

CI runs on docs-t1, a shared box at load 25 to 40. Amadan's cloud runner
is off the table for now (arm64, bwrap 0.9, no writable user cgroup;
Equipo pins x86 codex and bwrap 0.11), so this branch makes the shared
runner path as calm as it can be.

## What changed

- **Test cache on.** `make test` no longer passes `-count=1`. A package
  whose test binary, declared inputs and environment are unchanged
  replays its pass, so a rerun after one failure runs only what failed.
  The amadan runner keeps a per-repo `GOCACHE` between jobs and reuses a
  branch's worktree (`git checkout --force`), so unchanged files keep
  their modification times and the cache holds across pushes.
- **Hidden inputs declared** (`internal/testci`). go test's cache sees
  only what the test process opens and the environment it reads, so:
  - `testci.GoCommand` / `GoPackages`: a child `go build`, `go test -c`
    or `go list` of repo packages declares their source (cmd/equipo,
    the runner and tool proxy builds, directlive's fake driver, the
    try-equipo chain, the runnerproto boundary check).
  - `testci.Files`: scripts and fixtures a child runs (no-fake-worker,
    live-gate, install manifest, plan3 copy check, release check).
  - `testci.RepoFiles`: the dead-reference scan and the release tree copy
    read every file git lists.
  - `testci.Tools`: codex, claude, bwrap, git, python3, sh, srt, tar and
    the pinned try binaries; `scripts/ci-test.py` fingerprints them into
    `EQUIPO_TEST_TOOLS`, so upgrading one reruns its tests.
  - Still uncached: the perf lane (a measurement), and the separate
    `runner-adapter-test`, `runner-namespace-test` and `migration-check`
    targets. `UNCACHED` in `scripts/ci-test.py` is empty.
- **Slow packages split into lanes.** Measured from CI receipts on
  092d8ce, 62aa30c and four other branches: headless 6 to 10 min,
  equipotest 2.2 to 3.4, runner 1.6 to 3, directlive 1.4 to 2.9,
  thintest about 1, runner/checks 0.6 to 1, runner/thin 0.5. Lanes:
  headless, thintest, directlive, runner-thin, runner, contracts
  (equipotest, plan3test), rest. amadan runs separate ci.d steps one
  after another, so seven steps would add their times (about 15 min);
  its parallel mechanism is a step's `@N` shards, so the lanes are the
  seven shards of `30-test@7`, each with its own log and verdict, and
  `make test-lane LANE=x` runs one locally.
- **Cache keys stay stable across jobs.** The amadan runner moves the
  worktree root's modification time at the start of every job, and go
  test records the directory a child process starts in, so any test that
  started a child in the root missed the cache every time (directlive,
  equipotest, release, tryequipo). Those children now start in the test's
  own package directory, and each lane prints a `cache miss:` line per
  package that ran, so a new miss is visible in the log.
- **Timing budgets report on shared runners.** Time budgets fail the
  step only where `EQUIPO_CI_DEDICATED=1` is in the runner's environment
  (for a dedicated x86 box later; amadan passes the runner's own
  environment through, and has no runner tags in the step env). Size
  budgets stay enforced by `make budget` everywhere.

## Known flakes

Fixed:
- **tryequipo `provider_account_busy`**: `openAccount` closed the home's
  lock descriptor on its error paths without unlocking it. A child
  forked at that moment (parallel tests fork constantly) keeps the
  descriptor, and the lock, until it execs, so the wizard's immediate
  re-lock found the home busy. It now unlocks before closing, as
  `Close` already did.
- **tryequipo "text file busy"**: a test-written fake program (and
  `pinExecutable`'s copy) was open for writing while another goroutine
  forked; the child held it open and exec failed with ETXTBSY. Writes of
  programs now hold `syscall.ForkLock` until the file is closed
  (tryequipo and directlive tests, `pinExecutable`).
- **transfer contract timeouts** (thintest): the fake runner waited 10 s
  per frame, and the rig 30 s per contract. At load 78 locally,
  `TestContractWorkerTaintIsSticky` hit the same "waiting for send_pack:
  context deadline exceeded" as CI. Now 45 s per frame, 2 min per
  contract.

Quarantined (`scripts/ci-quarantine.txt`, step `test-quarantine`, one
automatic retry, a pass on the retry printed as `FLAKE`):
- TestMixedVersions (headless M8). Its first run in this step failed
  locally and passed on the retry: sampleToReady saw ready to merge, then
  re-read the task as `merging` and called that not ready. Fixed (merging
  is accepted); it stays here until a clean week shows that was the only
  cause.
- TestHeadlessConnections A5, C4 and the seven C5 scenarios. C4's fake
  sign-in callback got EOF at load 78 locally; cause not found yet.
- TestRunnerCancelAndSupersede (runner/thin): the runner closed the
  stream after acking; cc6567a logs why, so the next failure names it.
- TestCheckSandboxDeniedPathsTampering (runner/checks): "child survived
  cancellation". Cancelling at 1 to 60 ms after start left no survivor
  in 50 local runs at load 50 to 78, so it is not the start-up window.

Not addressed:
- **directlive `provider_account_containment`**: no failing CI log names
  the test, and containment has some twenty sources. Not quarantined
  blind; the openAccount unlock fix may cover it if it was a lingering
  lock. Quarantine it by name once a log shows it.

## Timings (docs-t1 CI, whole job, sum of steps)

Before (thin-v1-darwin 092d8ce, `-count=1`, load 25 to 40): 524 s, test
step 450 s (headless alone 7m28s). thin-v1-claudetoken: test step 600 s.
Every run paid this: a rerun after a flake, a docs edit, a one-package
change.

After (ci-speed, box load about 3 to 10 this evening, so not like for
like):

| run | job | test step | quarantine step |
|---|---|---|---|
| first run of the branch, nothing cached (5a1890a) | 511 s | 313 s (headless lane) | 114 s |
| rerun, nothing changed (d747ee8) | 67 s | 13 s | 7 s |
| one package changed, internal/tryequipo (88f8111) | 218 s | 165 s | 8 s |
| testci changed, imported by most heavy packages (d747ee8) | 436 s | 286 s | 92 s |

A one-package change reruns that package, its importers, and
equipotest: its release and dead-reference tests read the whole tree
(testci.RepoFiles), so it reruns on any commit (about 2.5 min).

Needs a dedicated runner: strict per-package time budgets
(`EQUIPO_CI_DEDICATED=1` in the runner's environment). runner/thin
measured 52 to 74 s locally against its 45 s record, reported only here.
