Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(docker): give :latest exactly one writer (#3154)

Tejas Choprabf651c3dc1b8
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index a3d06f76c..568d11c2d 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -293,6 +293,18 @@ jobs:
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ steps.image-name.outputs.image_name }}
+ # `latest=false` is load-bearing (#3150). The action defaults to
+ # `latest=auto`, which appends a bare `latest` for any semver
+ # release — and it logs `suffixLatest=false`, so the per-tag
+ # `suffix=` below never reaches it. Every one of the 8 variant
+ # cells therefore pushed `ghcr.io/.../headroom:latest`, and the
+ # last cell to finish won. At 0.36.0 that was `code-slim`, so
+ # `:latest` resolved to the distroless build, whose
+ # `import onnxruntime` segfaults on arm64 — `headroom deploy`
+ # crash-looped on Apple Silicon. `:latest` has exactly one
+ # writer: the root-cell promotion step at the end of this job.
+ flavor: |
+ latest=false
tags: |
type=ref,event=branch,enable=${{ inputs.enable_ref_tags != 'false' && github.event_name != 'release' }},suffix=${{ matrix.variant.name != '' && format('-{0}', matrix.variant.name) || '' }}
type=ref,event=pr,enable=${{ inputs.enable_ref_tags != 'false' && github.event_name != 'release' }},suffix=${{ matrix.variant.name != '' && format('-{0}', matrix.variant.name) || '' }}
@@ -311,6 +323,9 @@ jobs:
env:
IMAGE: ${{ env.REGISTRY }}/${{ steps.image-name.outputs.image_name }}
DIGEST_DIR: ${{ runner.temp }}/digests
+ # Read by the bare-`latest` guard below. Via `env:` rather than
+ # inline `${{ }}` so the value is never spliced into the script.
+ VARIANT_NAME: ${{ matrix.variant.name }}
run: |
# Reconstruct full image references from the digest marker
# filenames (each file is named after the bare hex digest
@@ -330,6 +345,16 @@ jobs:
digest_refs+=("${IMAGE}@sha256:${digest}")
done
+ # Belt-and-braces for #3150: only the root cell may ever carry a
+ # bare `latest`. A suffixed variant reaching this point with one
+ # means the tag rules regressed, and shipping it would repoint
+ # `:latest` at a non-default image. Fail instead of publishing.
+ if [ -n "${VARIANT_NAME}" ] && jq -e '.tags[]? | select(endswith(":latest"))' \
+ <<< "${DOCKER_METADATA_OUTPUT_JSON}" >/dev/null 2>&1; then
+ echo "::error::variant '${VARIANT_NAME}' would publish a bare :latest tag" >&2
+ exit 1
+ fi
+
# Build `--tag` args from the metadata-action JSON output.
# Empty tags array is valid (PR builds without ref-tags
# enabled emit nothing); skip manifest creation in that case.
diff --git a/tests/test_release_workflows.py b/tests/test_release_workflows.py
index d43e1ce6d..b3b3a9c07 100644
--- a/tests/test_release_workflows.py
+++ b/tests/test_release_workflows.py
@@ -120,6 +120,51 @@ def test_docker_latest_promotion_is_owned_by_root_manifest_cell() -> None:
assert guard_start < manifest_script.index("exit 1", guard_start) < create_start
+def test_only_the_root_cell_can_ever_publish_a_bare_latest_tag() -> None:
+ """`:latest` must have exactly one writer (#3150).
+
+ The sibling test above proves the *promotion step* is owned by the root
+ cell. That was never the whole contract: it checked the intended writer
+ and not the absence of unintended ones.
+
+ ``docker/metadata-action`` defaults to ``latest=auto``, which appends a
+ bare ``latest`` for any semver release. Its own log line reads
+ ``suffixLatest=false`` — the per-tag ``suffix=`` that keeps every other
+ tag variant-scoped does not reach it. So all eight variant cells emitted
+ ``ghcr.io/.../headroom:latest`` and the last to finish won the tag. At
+ 0.36.0 that was ``code-slim``: ``:latest`` resolved to the distroless
+ build, whose ``import onnxruntime`` segfaults on arm64, and
+ ``headroom deploy`` crash-looped on Apple Silicon with SIGSEGV.
+
+ Two things hold the line, and both are asserted here: ``latest=false``
+ stops the tag being generated at all, and a runtime guard refuses to
+ publish if a suffixed variant ever carries one anyway.
+ """
+ workflow = yaml.safe_load((ROOT / ".github" / "workflows" / "docker.yml").read_text())
+ manifest = workflow["jobs"]["docker-manifest"]
+
+ meta = next(step for step in manifest["steps"] if step.get("id") == "meta")
+ flavor = meta["with"].get("flavor", "")
+ assert "latest=false" in flavor, (
+ "docker/metadata-action defaults to latest=auto; without latest=false "
+ "every variant cell publishes a bare :latest and the last one wins"
+ )
+
+ # No tag rule may reintroduce it explicitly either.
+ assert "value=latest" not in meta["with"]["tags"]
+
+ create = next(
+ step for step in manifest["steps"] if step["name"] == "Create multi-arch manifest"
+ )
+ script = create["run"]
+ # The guard reads the variant name from env, never spliced inline.
+ assert create["env"].get("VARIANT_NAME") == "${{ matrix.variant.name }}"
+ assert 'endswith(":latest")' in script
+ assert script.index('endswith(":latest")') < script.index("docker buildx imagetools create"), (
+ "the bare-latest guard must run before anything is pushed"
+ )
+
+
def test_docker_manifest_downloads_exactly_one_artifact_per_architecture() -> None:
"""Each manifest cell must download exactly its two architecture digests.