Skip to content

ci: zig-restat, taking a restored zig cache's new inodes into its manifests - #2609

Merged
whilp merged 4 commits into
mainfrom
ci-zig-restat
Oct 3, 2026
Merged

whilp merged 4 commits into
mainfrom
ci-zig-restat

Conversation

@whilp

@whilp whilp commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

zig 0.17 (pinned in #2600) recompiles every C file after CI restores its build cache: a boot of ~100 s where 0.16 took 8 s.

Cause: zig's own cache check. std/Build/Cache.zig's checkInputPath re-hashes a direct input whose stat moved. It then compares the hash against a digest addInputPath never computes, which starts as zeros, instead of the digest the manifest holds. The compiler adds every C source that way (src/Compilation.zig:1323), and a restore from a tarball gives every file a new inode, so every C compile misses. This is in 0.17.0 and in upstream master.

This PR adds ci/cosmic_ci/zig_restat.tl. The driver's boot runs it before its first build, wherever the project cache was restored (CI's seed) or copied (run-local). For each file a manifest lists:

  • Same size and nanosecond mtime, new inode (what a restore leaves): it takes the new inode.
  • Same size, moved mtime (a fresh checkout's file): it re-hashes the file with zig's SipHash128-1-3 key and takes the stat if the digest still matches, as a fixed zig would.
  • Anything else (changed bytes, a different size, a missing file, a directory, a stat-only record, a prefix with no known root): it leaves the record for zig to miss on.

Trusting a restored file by size and mtime adds no trust: zig never reads a restored output's bytes at all. The run logs one line, e.g. zig-restat: 295557 files listed: 68852 given their new inode, 53 re-hashed and taken, 32 left; 1815 manifests rewritten. There's also a driver.tl zig-restat verb.

zig_prune.tl now shares a ZigPrune.records reader and exports ZigPrune.key, and its tests are unchanged. The ci.yml TODO about this cost becomes a plain comment, and the TODO moves to the workaround itself.

Verification

  • Restored-cache boot: a tar --posix round trip of real 0.17 caches, at the same path, then bin/zig build boot:
    • 97 s without restat
    • 7 s with it
    • restat itself takes about 2 s
  • A Python prototype of the same rule gave the same result: 106 s against 8 s.
  • Tests: ci/cosmic_ci/zig_restat_test.tl covers:
    • a restored file taking its new inode
    • a moved mtime re-hashed and taken
    • changed bytes, a different size, a missing file, a directory, and a prefix with no root, all left
    • the output a manifest vouches for being unchanged
    • a second pass rewriting nothing
    • a bad manifest leaving every manifest as it was
    • the command's summary line and zig env parsing
  • cosmic_ci (198 tests, unsandboxed as CI runs them), ci/'s fix --check, fix --check ., build/workflows_test.tl and ci/run-local all pass.

Review

A separate agent checked this against zig 0.17's Cache.zig and the real caches. It found nothing blocking:

  • Digests: 37,281 recomputed digests matched zig's, with 0 mismatches.
  • Prefixes and integers: prefix resolution, u64 round-trips, and running before any zig process all check out.

Its nits:

  • Fixed:
    • bin/zig env now runs only when there is a cache to restat, in the tree, with the driver's cache settings.
    • run-local's copied cache is restatted too.
    • Added a test for the same mtime with a different size.
  • Left:
    • The queue's seed tarball (queue-seed.sh, plain tar -cf) keeps whole-second mtimes, so a seeded entry goes through the re-hash path instead: about 15–20 s, still correct. The fix is a format flag that differs between GNU tar, the macOS legs' BSD tar, and BusyBox in the Alpine container, so I didn't touch it.
    • Directory records are left for zig, which checks them correctly.
    • One unreadable manifest leaves every manifest as it was, documented and matching the pruner.

TODOs

🤖 Generated with Claude Code

https://claude.ai/code/session_01CA9Ta9WPb5KjCoDaYyN7qE


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants