Skip to content

fix(ci): give each image build its own cache scope #4928

Description

@dan-petty

Problem Description

All image builds of ci.yml, release.yml and service-image-test.yml use the GitHub Actions cache (type=gha) with no scope, so they share the default scope buildkit. Each cache-to replaces the cache index of that scope. release.yml builds the Service, runner and MCP server images in parallel jobs (service-image, runner-image and mcp-server-image, each with needs: release-please), so the job that ends last decides which stages the next build can find.

#4872 (#4550) puts the dependencies of the runner and Service images in the cached stages runner-deps and service-deps, and k8s/README.md (Image paragraph) says that a release keeps those layers. But at the next release, the dependency stages of at least one image are not in the cache. They build again, give new layer digests, and each node pulls them again. So the 10 s container start that #4550 expects is not sure.

Reproduction Steps

  1. git grep -n "type=gha" .github/workflows on main: 19 entries, none with scope=.
  2. Read the cache list of main: devops gh api "repos/{owner}/{repo}/actions/caches?key=index-buildkit&ref=refs/heads/main". It holds one index for all image builds, index-buildkit-1-f921bd05#907 (2026-11-12).
  3. The Docker documentation of the cache backend (https://docs.docker.com/build/cache/backends/gha/, section Scope) gives the default scope buildkit and says: "If you build multiple images, each build will overwrite the cache of the previous, leaving only the final cache."

Expected vs Actual Behavior

Expected: each build of an image reads and writes the cache in a scope named after its target (scope=service, scope=runner, scope=mcp-server), so a release finds the dependency stages that the last build of the same image on main wrote, and keeps their layers.

Actual: all builds share one index, and a release finds the cached stages of only the image that the last build made.

Proposed Fix

  • Set cache-from: type=gha,scope=<target> and cache-to: type=gha,scope=<target>,mode=max on each image build of ci.yml and release.yml, and cache-from: type=gha,scope=service in service-image-test.yml. A build with no target builds service.
  • Add an invariant test in tests/invariants/test_image_layers.py: each type=gha entry of cache-from and cache-to of a build of ./Dockerfile names scope= with its target. This test fails on main with 19 entries and passes with the fix.
  • Add one sentence about the scopes to the Image paragraph of k8s/README.md, and a requirement to the spec container-image-layers.
  • perf(ci): stop the cache export of pull request image builds #4646 removes the cache export of the pull request image builds and changes the same lines. One of the two pull requests rebases on the other.

Existing tool: the scope parameter of the BuildKit gha cache backend. No code. Cost: about 20,000 tokens and 1 hour. A registry cache per image (type=registry) has no 10 GB limit, but the pull request builds have only contents: read and cannot write it.

Acceptance Criteria

  • Each type=gha entry of an image build names scope= with its target, and the test fails when one does not.
  • After the merge, the cache list of main holds one index for each of the scopes service, runner and mcp-server.
  • At the second release after the merge, the push of the Service and runner images uploads only the project layer and the apt upgrade layer: the dependency layers of the release before keep their digests.

Environment Diagnostics

  • Repository cache: 12,577,035,846 bytes in 309 entries, against a limit of 10 GB (actions/cache/usage, actions/cache/storage-limit, 2026-11-12). GitHub evicts the entries that nobody read for the longest time, so a stage whose blobs it evicts also builds again. A scope does not change that, and perf(ci): stop the cache export of pull request image builds #4646 lowers the size.

Logs, Traces, or Terminal Output

None. The evidence is the configuration, the documentation and the cache list above. Found by the review of #4872.

Alternatives check of 2026-11-15: none.
Tool: none found.

Proposed design

Problem statement

All image builds in ci.yml, release.yml and service-image-test.yml use the BuildKit gha cache with the default scope buildkit. The parallel release jobs replace one cache index, so a release cannot find the dependency stages of every image. The change gives each image target its own cache scope and adds an invariant test.

Acceptance criteria

Requirement: Per-target gha cache scope

Each image build of ./Dockerfile SHALL set cache-from: type=gha,scope=<target> and cache-to: type=gha,scope=<target>,mode=max.

Scenario: Release builds use three scopes

  • WHEN The invariant test reads the Service, runner and MCP server builds in release.yml.
  • THEN It finds scope=service, scope=runner and scope=mcp-server, and each cache-to entry sets mode=max.

Requirement: Service image test reads the service scope

The Service image build in service-image-test.yml SHALL read the gha cache with scope=service.

Scenario: The pull request image test uses the service cache

  • WHEN The invariant test reads service-image-test.yml.
  • THEN It finds cache-from: type=gha,scope=service for the Service image build.

Requirement: Invariant rejects an unscoped cache entry

The invariant test SHALL fail when a cache-from or cache-to entry of an image build lacks scope=.

Scenario: An unscoped cache entry fails the test

  • WHEN A workflow has cache-to: type=gha with no scope.
  • THEN The test fails and names the workflow file and the line.

Requirement: Image documentation names the scopes

The Image paragraph of k8s/README.md SHALL state that each image build uses its target as its gha cache scope.

Scenario: The Image paragraph lists the scopes

  • WHEN A docs check reads the Image paragraph of k8s/README.md.
  • THEN It finds the scopes service, runner and mcp-server.

Requirement: Spec records per-image cache scopes

The container-image-layers spec SHALL state that each image build uses a gha cache scope named after its target.

Scenario: The spec delta adds the cache scope requirement

  • WHEN A checker reads the change's spec delta for container-image-layers.
  • THEN It finds the requirement and a scenario that name the service, runner and mcp-server scopes.

Existing Tool Considered

No open, maintained tool covers the need. The alternatives check of 2026-11-15 found none. The BuildKit gha cache backend provides the scope parameter, but it does not set per-image scopes or add the invariant test. The change edits the workflows and adds the test, at about 20,000 tokens and 1 hour.

Key questions

  • Which cache scope does each image build use?: Use the image target as the scope: service, runner and mcp-server. A build of ./Dockerfile with no target uses service. (best practice) [sources: .github/workflows/ci.yml, .github/workflows/release.yml, .github/workflows/service-image-test.yml]
    • Chosen: Target name. The target names the image and stays stable across workflows.
    • Rejected: Workflow name. One workflow builds several images, so the scopes would collide.
    • Rejected: Default buildkit scope. It makes each build replace the cache index of the other images.
  • How does the repository keep the scopes in place?: Add tests/invariants/test_image_layers.py. It reads the three workflows and fails when a cache-from or cache-to entry of ./Dockerfile lacks scope=. (best practice) [sources: tests/invariants/test_k8s_manifests.py]
    • Chosen: Invariant test. It checks each workflow offline and blocks a regression in CI.
    • Rejected: Review checklist. A person can miss one of the many cache entries.
    • Rejected: No check. The default scope returns when a build copies an old entry.
  • Which cache export mode does each cache-to entry use?: Use mode=max. It exports the dependency stages, and the default min mode does not. (best practice) [sources: .github/workflows/release.yml]
    • Chosen: mode=max. It exports every stage, including the runner-deps and service-deps stages.
    • Rejected: mode=min. It exports only the final stage and leaves the dependency stages out.
  • How does the change record the scopes in the documentation and the spec?: Add one sentence to the Image paragraph of k8s/README.md and one requirement to the container-image-layers spec delta. (best practice) [sources: k8s/README.md, openspec/specs/container-image-layers/spec.md]
    • Chosen: README and spec. The project records image behavior in both places.
    • Rejected: README only. The spec would not state the cache rule.
    • Rejected: Spec only. A reader of the k8s README would not see the scopes.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/ci
    status/new
    value/medium
    effort/low
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/ci. The (ci) scope of the title gives the scope.
    • Priority: P2-Medium. The shared cache scope causes release builds to rebuild dependency layers and miss the 10 s start goal, but it does not block the pipeline.
    • Value: Medium. It restores the expected cache hit for each image at release time and keeps the dependency-layer digests stable across releases.
    • Effort: Low. The fix is a parameter change on existing cache lines, one invariant test, and one README sentence, estimated at about one hour.
    • Related: perf(ci): stop the cache export of pull request image builds #4646, which asks for a different change. Both modify the same type=gha lines in ci.yml, but #4646 removes PR cache exports while this candidate adds a per-image scope to keep release caches correct.
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches returned nothing but the Docker documentation of the BuildKit gha cache backend, whose built-in scope parameter (default buildkit) is exactly the mechanism the issue already names: the docs state that each build overwrites the previous cache unless a per-image scope is set. No open tool or library provides per-image cache scopes or the repository-specific invariant test, so the need is a configuration change to this project's own workflow files, not an adoption of a tool.

    Tool: none found

    Lacks:

    • No tool sets scope= on the type=gha cache entries of ci.yml, release.yml and service-image-test.yml; the workflows themselves must be edited.
    • No tool adds or maintains the invariant test in tests/invariants/test_image_layers.py that fails when an image build omits scope=.
    • No tool writes the scope sentence into k8s/README.md or the container-image-layers spec requirement.
    • The gha backend keeps GitHub's 10 GB cache limit and its eviction, which the issue notes a scope does not change.

    Searches run:

    • docker build-push-action cache-to type=gha scope multiple images separate scopes, results: 5
    • GitHub Actions cache type=gha scope per image build overwrite cache, results: 5
    • buildkit gha cache backends scope parameter docker documentation, results: 5
    • buildx cache gha separate cache per Dockerfile target image GitHub Actions action, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 16, 2026
  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at fccb781 (see proposed design in issue body).

    Moved to new items: #5942.

  7. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 18, 2026
  8. removed
    status/in-review
    on Nov 18, 2026
  9. added a commit that references this issue on Nov 18, 2026
  10. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-18 04:24 UTC

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

    effort/lowpriority/p2-mediumscope/cisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions