feat(run): keep a timings history that CI can cache

Merged
KD
21d ago
+585-19

e2e run already starts the longest files first, but it read the previous run's durations from report.json, which a fresh CI checkout never has. This writes a small versioned history a CI cache can restore and save.

  • Every run that reaches its tests writes <output>/timings.json (timings-1): target::file to milliseconds. It merges into the existing file with a moving average (a run moves an entry a third of the way), and drops files that are gone and targets the config no longer has.
  • A file is timed only when the run carried out all of it, once. A --grep, --last-failed, interrupted (including a retry cut short after a failure), or limit-cut run leaves that file's entry alone, and repeats past the first do not count.
  • A key is a target name, then a project-relative POSIX file with no .. segment. The schema and the reader use the same pattern, and a table test keeps them in step.
  • With one worker the file is still written, but files are ordered only with more than one. Files with no recorded time start first, then the rest longest first.
  • Advisory: a missing, corrupt, or schema-invalid file is no history, never an error. An absent file falls back to report.json, so nothing regresses. A restored cache can reorder files, never change a result.
  • --timings <file> moves it. --last-failed still reads report.json only.
  • Docs: actions/cache recipe in docs/ci/github-actions.mdx (the key ends in github.run_attempt, since a rerun shares run_id and actions/cache never overwrites a key), the provider-neutral rule in docs/ci.mdx. timings.json joins the e2e init and repo .gitignore entries.
  • Wire format: schema/timings-v1.schema.json with a valid and an invalid fixture, in the same change as the producer.

Not here: duration-balanced --shard, a timings.file config key, and dogfooding the recipe in benchmark.yml.

flowchart LR
  A[restore .e2e/timings.json] --> B[e2e run: longest files first]
  B --> C[merge measured files into history]
  C --> D[save .e2e/timings.json]

Refs ENG-1111

Verified

Ran it locally: yes

  • testbed, built CLI, e2e run tests/check.e2e.ts tests/click.e2e.ts tests/controls.e2e.ts tests/browser.e2e.ts --workers 2, once with no history and once seeded with the timings.json the first run wrote:
no historywith timings.json
controls (16 s file) starts2.5 s0 s
click (14 s file) starts1.3 s0 s
check, browser (short) start0 s14 s, 16 s
run19.4 s17.5 s

One run per cell on one machine, so the size of the gain is indicative. The order is the point.

  • Same CLI, edge cases: a valid-JSON file with another schema version, a string value, an array, or a __proto__ key is ignored and rewritten, tests still pass. A NO_TESTS run writes nothing. --last-failed reads report.json, not timings.json (NO_LAST_RUN with only a timings file). An unwritable --timings path is one stderr line and exit 0. --grep on one test leaves the file byte for byte unchanged.
  • pnpm check, pnpm test, the testbed suite (587 passed), and the web benchmark (91 passed) are green locally. pnpm test ran before the review fixes; after them I reran pnpm check, the unit suite (3447 passed), the new integration file, and the testbed ordering check. CI is green on the final head.
  • Not verified: the GitHub Actions recipe against a real workflow, and that a PR can read the base branch's cache but not write it. The page states GitHub's documented rule; I did not run it.

Review

A fresh-context review found two things, both fixed in the second commit (cubic-dev-ai then raised nine smaller points, all fixed in the third and fourth): partial runs wrote non-comparable durations (a --last-failed rerun of one 2 s test cut a 60 s entry to about 40 s), and nothing tested the runner wiring. The new integration test fails with the partial guard removed. The review also noted --timings is not confined to the project root like --output; left as is, since the path is one the user names on their own command line and test code already runs with full authority.

CI notes

  • packages/acp executor.test.ts "retries the session directory removal after the agent exits" failed on test (22), (24), and (22.22.3) in earlier runs of this PR (kill ESRCH after a 500 ms wait), and on oskar/fix-main-failing-tests before it. It does not reproduce locally and this PR does not touch packages/acp; reruns passed. It needs its own fix.
  • The Android agentic Huge Virtualized List step failed once with REPLAY_STALE and passed on rerun, with nothing in this diff that reaches it.

šŸ¤– Generated with Claude Code