Skip to content

ghac: cache writes are dropped on HTTP 429 because GHACache::build installs no RetryLayer #2821

Closed

Description

@paulirotta

GHACache::build (src/cache/gha.rs) builds its opendal Operator with only a logging layer:

let op = Operator::new(builder)?
    .with_context(OperationContext::new().with_http_transport(set_user_agent()))
    .layer(LoggingLayer::default());

GitHub's Actions cache service rate limits per workflow run, shared across every job in it, and
answers a burst of writes with HTTP 429. opendal marks that error temporary, but RetryLayer
appears nowhere in the repository, so nothing acts on it: sccache increments cache_write_errors
and the compilation result is never stored. Confirmed unchanged on main as of 2026-08-23 and on
v0.17.0.

What it costs

A dropped write is not slow, it is gone, until that object is recompiled and re-offered on some
later run that happens to win the rate limit.

We moved a six-job CI matrix from a tarball cache to SCCACHE_GHA_ENABLED=on. Two consecutive
runs, same code, all six jobs writing at once (run 1,
run 2). Run 2's hit rate reads out
what run 1 managed to store:

job family run 1 stored / attempted run 2 Rust hit rate
windows-latest 337 / 610 (55%) 41.29%
macos-latest 369 / 905 (41%) 39.20%
ubuntu-24.04-arm 274 / 895 (31%) 34.37%
Android (cargo-ndk) 128 / 819 (16%) 23.92%

Because sccache keys on the whole compiler invocation, each family's objects are private to it
(different target triples, cargo check vs cargo build, different RUSTFLAGS), so a write one
job loses is never covered by another job's write. The loss rate is an upper bound on the
achievable hit rate, not a warm-up effect.

The control: one job family ran ghac alone for seven consecutive runs before the others migrated,
and sustained 96.79% Rust hit rate with zero write errors, read errors, cache errors and timeouts
in every one of them. Same repo, same sccache version, same backend. Adding five concurrent
writers took write loss from 0% to 45-90%.

Why it can't be worked around

SCCACHE_GHA_RW_MODE only turns writing off. The limit is shared across the whole run, so no
single job can observe it or throttle against it, and retrying at the CI level is impossible
because the put happens inside the compile request.

Suggested fix

sccache pins opendal 0.58.1 and already pulls layers as separate crates (opendal-layer-logging).
opendal-layer-retry is published at the same version, so this is a dependency plus a layer:

.layer(RetryLayer::new().with_jitter())

RetryLayer retries only errors opendal marks temporary, so it does not paper over real failures.
Given the service asks for retry-after: 1, even a small max_times should recover most of
these. The default matters more than a tuning knob: the failure is silent, so people are far more
likely to report "GHA cache builds are surprisingly slow" than "my cache is 40% smaller than it
should be".

Possibly related: #1485 reports the same 429s against the older v1 cache service, diagnosed as far
as Cache write error: ... 429 Too Many Requests, and never closed.

Environment

sccache 0.17.0, SCCACHE_GHA_ENABLED=on, ACTIONS_CACHE_SERVICE_V2=true, SCCACHE_DIRECT=true,
GitHub-hosted runners: ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest.

Activity

  1. paulirotta commented on Aug 23, 2026

    @paulirotta
    Author

    I built the RetryLayer patch and ran it on the same workload, on the same six-family
    matrix, against the live cache service. Run:
    https://github.com/paulirotta/ahma/actions/runs/32626626090

    It works, but opendal's default backoff is too impatient for this service.

    Across the run there were 56 HTTP 429s, all of them on
    CacheService/CreateCacheEntry. The retry layer retried 51 of them. Of the 18
    distinct operations that were throttled, 13 recovered and 5 were lost — all writes.
    Reads recovered 10 of 10. Total write loss was 7 of 509 attempts (1.4%), and two of
    those seven were AlreadyExists 409s from another job storing the same key, not rate
    limiting. No read errors, no cache errors, no timeouts, and ordinary misses still come
    back NotFound (persistent), so nothing is retried that should not be.

    The reason for the five that were still lost is in the response headers. GitHub sends
    retry-after on these 429s and asks for 1 to 21 seconds, median around 7:

    1s×3  2s×2  3s×6  4s×2  5s×4  6s×9  7s×8  8s×6  9s×2
    11s×2  13s×2  15s×1  16s×2  17s×1  18s×3  19s×2  21s×1
    

    RetryLayer ignores that header and backs off exponentially — I measured 1.2s, 2.8s,
    5.1s, so about 10 seconds of patience across the three default retries. Every one of
    the five losses is the same shape: the service asked for 11, 18 or 21 seconds and the
    retry budget ran out first.

    So I would suggest the layer be configured rather than left at defaults, e.g.
    .with_max_times(6).with_max_delay(Duration::from_secs(8)), which puts attempts at
    roughly 1, 3, 7, 15, 23 and 31 seconds and covers the observed range. Honouring
    retry-after would be better still, but opendal's error type carries no delay hint,
    so max_times is the lever available.

    One caveat on the numbers: this run started warm, 509 write attempts against roughly
    4000 in the runs quoted above, so 1.4% is not directly comparable to the 45-90% there.
    What it does show is that the layer engages on real 429s and recovers 91% of them.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions