Skip to content

ci(frontend): one writer per shared cache key, and only from main - #889

Merged
athvin merged 1 commit into
mainfrom
ci/cache-single-writers
Nov 8, 2026
Merged

athvin merged 1 commit into
mainfrom
ci/cache-single-writers

Conversation

@athvin

@athvin athvin commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #888

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

One writer per shared frontend cache key, and only from main. pnpm-store is
written by check; next-build by e2e's chromium-1 leg. Every other call
site — the e2e shards and the nightly frontend-experiments watchdog — is
restore-only.

Why

The 10 GB Actions cache budget is full with sccache out of it (10,387,544,511
bytes / 73 entries), and ~2.3 GB of that was PR branches minting their own copies
of entries main already owns: pnpm-store held four entries (~1.58 GB),
next-build four (~0.74 GB). Prerequisite for #887, and correct on its own.

Proof

actionlint on both changed files: exit 0, no findings (re-run without a pipe —
the first attempt's $? was tail's). scripts/ci/workflow-shell-check.sh: ok,
12 hand-written workflows, all within budget. Both files parse under
yaml.safe_load, and every actions/cache site in them now carries an explicit
save-if — audited programmatically rather than by eye:

frontend.yml              check    pnpm-store   save-if=${{ github.ref == 'refs/heads/main' }}
frontend.yml              e2e      pnpm-store   save-if=false
frontend.yml              e2e      next-build   save-if=${{ github.ref == 'refs/heads/main' && matrix.slug == 'chromium-1' }}
frontend-experiments.yml  workers  pnpm-store   save-if=false
frontend-experiments.yml  workers  next-build   save-if=false

No Rust changed, so make check is not the gate for this diff; the frontend
tier in CI is, and it exercises both restore paths on this very PR.

Risk & rollback

Risk: a PR branch no longer gets an exact-key next-build hit after touching
src/**, falling back to the lockfile prefix — the same trade rust.yml already
makes. Rollback: git revert <merge-sha>; the guards are additive and nothing
depends on them.

Post-merge ledger

Closed by: agent · session a3ee4d31-1a50-4299-82b3-0eaf6cd8d848 on Mac · 2026-11-08T20:57:23Z

  • main is green with this change on it — merge 3615cf18; all four
    workflows on that SHA concluded success (rust, frontend, infra,
    devcontainer). Corroborated by 9583e470, a later head with this commit
    as an ancestor, whose rust also succeeded.
  • images — n/a — nothing that goes into an image changed. Verified
    rather than assumed: the only workflows that ran on 3615cf18 were
    infra, devcontainer, rust, frontend. images is absent, which is
    correct for a workflow-file change.
  • deploy — n/a — no image was built, so the workflow_run trigger never fired. There is no running process to read a line from.
  • the push-only surface — drift success (b4b0b0fb), kind success
    (0a4aac56), deploy most recently skipped (2b66beb5), its normal
    state when no image changed. None is reachable by a frontend-workflow
    edit.
  • the board card — ci: single-writer guards on the pnpm-store and next-build caches #888 closed by the automation on merge, not by
    hand.
  • follow-ups — n/a — this PR deferred nothing; its scope landed
    whole. The budget question ci: cache-prune will outgrow its 30m timeout now that sccache writes one entry per object again #902 tracks arrived from ci(rust): sccache back on the Actions cache backend, off S3 #893's backend move,
    not from this change.
  • what was learned is written down — in memory, with the sccache cost
    work: check cannot own next-build because it never runs pnpm build,
    so on a four-leg matrix the write must be pinned to one leg for "single
    writer" to be true at all.

Specific to this change

  • Re-measured — and the prediction is not yet observable, which is
    recorded rather than claimed.
    Total usage moved 10,387,544,511 →
    12,026,615,900 bytes and 73 → 1,223 entries, but that is dominated by
    ci(rust): sccache back on the Actions cache backend, off S3 #893's sccache move rather than by this reclaim. The two keys now stand at
    19 entries on main against 20 still in PR scopes — duplicates do not
    vanish at merge, they age out on 7-day idle, so the ~2.3 GB arrives next
    week. deferred — #902, which owns the budget trend.
  • Confirmed, by a stronger test than the one this box asked for.
    Instead of reading log lines I queried the cache API for entries created
    after
    the merge (~19:39Z): the only one is 2026-11-08T19:45:38 refs/heads/main next-build-6e04c46f37abfe5, and no PR ref has created
    either key since
    . last_accessed_at would have been the wrong field —
    it moves on reads, so it showed PR entries as recent; created_at is what
    answers this.
  • Not drained yet, exactly as predicted — 20 PR-scoped entries remain.
    7-day idle expiry makes this a next-week observation, now carried as the
    budget-trend item on ci: cache-prune will outgrow its 30m timeout now that sccache writes one entry per object again #902 rather than a box left quietly open here.
    deferred — #902
Context — plan, discoveries, measurements, files

Plan

  1. Audit which jobs write which shared keys
  2. save-if guards, single writer per key, main-only
  3. actionlint + workflow-shell-check + programmatic save-if audit
  4. Measure the reclaim after merge, feed the number to ci: move sccache off S3 to the Actions cache backend ($209/mo egress -> ~$5) #887

Discoveries

  • check cannot be the next-build writer. It never runs pnpm build, so
    it has no .next/cache to save. That leaves the e2e job, which is a
    four-leg matrix — so the write is pinned to matrix.slug == 'chromium-1'
    rather than to the job. Without the leg pin, "single writer" would have been
    false in the one place it mattered, with three legs racing to save one key.
  • The coverage job is not part of this problem. Its ~1.6 GB of
    v2-rust-coverage entries look like the same pattern but it is
    schedule/workflow_dispatch-only, so no pull request can write them. The
    two entries are rust-cache's ordinary key-churn. Whether a nightly job should
    hold 1.6 GB of a shared budget is a real question and belongs to ci: move sccache off S3 to the Actions cache backend ($209/mo egress -> ~$5) #887's
    measurement phase, not here.

Measurements

$ gh api /repos/athvin/entity-resolution-engine/actions/cache/usage
{"active_caches_size_in_bytes":10387544511,"active_caches_count":73}

$ gh api ".../actions/caches?per_page=100" --jq 'sort_by(-.size_in_bytes)'
0.92 GB  refs/heads/main        v2-rust-coverage-...
0.69 GB  refs/heads/main        v2-rust-coverage-...
0.40 GB  refs/heads/main        pnpm-store-ae7f86f...
0.40 GB  refs/heads/main        pnpm-store-6e04c46...
0.40 GB  refs/pull/829/merge    pnpm-store-6e04c46...   <-- PR branch copy
0.39 GB  refs/heads/main        pnpm-store-ae7f86f...
0.39 GB  refs/pull/829/merge    pnpm-store-6e04c46...   <-- PR branch copy
0.39 GB  refs/heads/main        pnpm-store-6e04c46...
0.19 GB  refs/heads/main        next-build-6e04c46...
0.19 GB  refs/pull/873/merge    next-build-6e04c46...   <-- PR branch copy
0.18 GB  refs/pull/872/merge    next-build-6e04c46...   <-- PR branch copy
0.18 GB  refs/heads/main        next-build-6e04c46...

Files

  • .github/workflows/frontend.yml — three save-if guards
  • .github/workflows/frontend-experiments.yml — two, both restore-only

The 10 GB Actions cache budget was measured FULL with sccache out of it —
10,387,544,511 bytes across 73 entries — and ~2.3 GB of that was PR branches
minting their own copies of entries `main` already owns. Three `actions/cache`
sites in the frontend workflows carried no `save-if`, so every ref saved:
`pnpm-store` held four entries (~1.58 GB) and `next-build` four (~0.74 GB).

rust.yml already states this pattern for `shared-key: rust` ("`lint` is the
SINGLE WRITER, and only from `main`", the other compile jobs `save-if: false`);
the frontend caches never got it. Now:

  pnpm-store   `check` on main; `e2e` and the nightly experiment restore-only
  next-build   `e2e`'s chromium-1 leg on main; experiment restore-only

`next-build` is pinned to one matrix leg rather than to the job, because `check`
never runs `pnpm build` and so cannot be its writer — which leaves a four-leg
matrix whose legs would otherwise race to save one key. All four build the
identical tree, so any leg's cache is equivalent.

PR branches still restore through the existing `restore-keys` prefixes, which is
where nearly all the value is: both keys follow the lockfile, not the branch.

The `coverage` job needs no guard and did not get one — it is
`schedule`/`workflow_dispatch`-only, so no pull request can write its entries.

Prerequisite for #887, which moves sccache back onto this budget, and correct
independently of it.

Closes #888

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 3615cf1 into main Nov 8, 2026
46 checks passed
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.

ci: single-writer guards on the pnpm-store and next-build caches

2 participants