Skip to content

feat: serve the cache service v2 API from the cache server - #6

Merged
simota merged 20 commits into
mainfrom
factory/cache-v2
Nov 21, 2026
Merged

simota merged 20 commits into
mainfrom
factory/cache-v2

Conversation

@simota

@simota simota commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Summary

The local cache server now answers the GitHub cache service v2 API (ACTIONS_CACHE_SERVICE_V2), which actions/cache@v4 uses, from the same store as the v1 API. It was listed under "Not supported" until now.

  • Protocol (src/servers.rs): Twirp CacheService (CreateCacheEntry, FinalizeCacheEntryUpload, GetCacheEntryDownloadURL) at the root of the cache port, forwarded from the artifact port when --artifact-server-path is set, plus signed /cache-v2/upload|download/<id> blob URLs (Put Blob, Put Block, Put Block List).
  • Job environment: jobs get ACTIONS_CACHE_SERVICE_V2=true while the cache server runs and, without --artifact-server-path, an ACTIONS_RESULTS_URL at the cache server. ACTIONS_CACHE_URL (v1) is unchanged.
  • cache-mode: carried in the per-job runtime token (runthrough_cache_mode claim). Under the caller's own ACTIONS_RUNTIME_TOKEN, non-write jobs are pointed at v1 by default, which still enforces the mode.
  • Access control: Twirp calls need the run's runtime token; blob URLs are signed with their own per-run key. A reservation belongs to the token that made it (each job leg's token is unique through jti).
  • Uploads are staged and only Finalize publishes them, so a late or repeated PUT cannot change a committed entry.
  • BuildKit (type=gha): with the flag set, buildx uses v2 as well, so the download route serves byte ranges and HEAD, and the 409 answer is one its Go client recognises.
  • Design and protocol facts: docs/specs/cache-v2.md.

Changes to existing behaviour

  • v1 cache API: a reservation is written to index.json at once, a successful PATCH refreshes it for gc, a PATCH whose reservation was dropped meanwhile answers 404, and v1 routes answer 404 for a reservation id made through v2.
  • Artifact server: only the URL signer moved (UrlSigner) and the cache v2 routes are forwarded; upload handling is as before.
  • No new dependencies.

Testing

  • make check CARGO_FLAGS=--offline: pass (130 unit tests, 46 e2e).
  • cargo test --offline --test e2e -- --ignored real_actions_cache_v4_saves_and_restores_through_v2 cache_and_artifact_servers_roundtrip real_upload_and_download_artifact_v3_and_v4: pass. The first runs the real actions/cache@v4 with ACTIONS_CACHE_URL blanked, so only v2 can serve it.
  • make ci CARGO_FLAGS=--offline: pass.
  • runner::tests::tool_cache_lock_is_taken_in_turn_and_given_up_on_cancel failed once on main before this work and passed on rerun (flaky, not touched here).

Not confirmed

  • BuildKit over v2 was not run against a real BuildKit. The routes were built from the client's source (go-actions-cache) and tested at the handler level only. Since v2 is on by default, docker/build-push-action with type=gha should be tried before a release; a job can stay on v1 with env: { ACTIONS_CACHE_SERVICE_V2: "" }.

Known limits (not addressed)

  • Several runthrough processes using one cache directory at the same time can collide on entry ids (same as v1).
  • Under the caller's own ACTIONS_RUNTIME_TOKEN the server cannot tell jobs apart.
  • A repeated FinalizeCacheEntryUpload after a lost success answer gets ok: false (the entry is saved).
  • Keys are lowercased (as in v1), which can break BuildKit's index update for a scope with upper-case letters.

actions/cache@v4 (@actions/cache >= 4) switches to the Twirp CacheService
API when ACTIONS_CACHE_SERVICE_V2 is set. The cache server now answers it
at the root of its origin, with Azure-blob-style uploads and plain
downloads at signed /cache-v2/ URLs, on the same store as the v1 API.

- CacheStore::reserve / commit are shared by v1 and v2; gc also removes
  the blocks of abandoned v2 uploads.
- UrlSigner replaces ArtifactStore's sign/verify; the cache gets its own
  key and kinds, so artifact and cache URLs cannot open each other.
- The job's cache-mode travels as a runthrough_cache_mode claim in the
  runtime token (RuntimeAuth::claims); Twirp calls need the run's token.
- job_env sets ACTIONS_CACHE_SERVICE_V2 and, without the artifact server,
  ACTIONS_RESULTS_URL at the cache origin; the artifact port forwards the
  v2 routes. With the caller's own token, only write jobs get v2.
- The cache port answers ArtifactService calls with a JSON bad_route
  pointing at --artifact-server-path.
…eaks

- Answer the v2 Twirp calls with proto field names, so the toolkit masks the
  signatures of signed_upload_url / signed_download_url before logging.
- Give jobs that stay on v1 under the caller's token an empty
  ACTIONS_CACHE_SERVICE_V2, so a host job cannot inherit v2.
- Stage uploads in a temporary file and rename them into place under the
  lock while the entry is still pending; only Finalize publishes the staging
  file as the blob, so a late PUT never changes a committed or dropped entry.
- Refuse a second CreateCacheEntry while a reservation of the same key and
  version is in use (409 already_exists), and commit only the caller's own
  reservation on Finalize. v1 still replaces a pending reservation.
- Make Put Block List atomic and repeatable: blocks stay until the upload is
  finalized (cache) or FinalizeArtifact (artifacts).
- Count uploads as use for gc, remove the files of dropped or replaced
  reservations, and persist new reservations.
- Sign blob URLs for the --cache-server-external-url origin on the cache port.
- Refuse unparsable or negative size_bytes and missing upload data, answer a
  non-object body with 400 malformed, and never repeat the key in a message.
…ions

- Restore the artifact server's Put Blob, Put Block and Put Block List
  handling to write in place as before; the staged, atomic upload path now
  serves the cache v2 API only.
- The v1 PATCH, commit and download routes refuse a pending v2 reservation
  (404, nothing changed); a v1 reservation is still committed by v1.
- A successful v1 PATCH refreshes the reservation's last use, so neither gc
  nor a v2 CreateCacheEntry takes an active v1 upload for abandoned.
- CreateCacheEntry creates no file: FinalizeCacheEntryUpload succeeds only
  after a Put Blob (zero bytes included) or a Put Block List placed data.
- Refuse a block list that does not parse and an unknown comp with 400,
  leaving the staged upload as it was.
- job_env adds a random jti claim, so two jobs whose names coincide (as
  --reuse names can) no longer share a token, and one cannot finalize the
  other's cache v2 reservation.
- A v1 PATCH whose reservation was dropped while the chunk was written
  answers 404 and removes the chunk's file, instead of 204.
Byte ranges (x-ms-range or Range) and HEAD on /cache-v2/download/, and a
409 conflict that carries a message saying "already exists" so the Go
client treats it as os.ErrExist and moves on to the next index key.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T04:20:13.894969Z 1a65fee PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@simota
simota merged commit b7f07a5 into main Nov 21, 2026
2 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.

1 participant