Skip to content

image-build: one merged PR produces two image runs on one head, and the concurrent base-image pull can fail one #282

Open

Description

@aitrawog

What happened

A merged PR in a pod-crabbox-* variant repo produced two image runs on the same head, and the concurrent base-image pull failed one of them.

Measured on opencharly/pod-crabbox-code after PR #1 merged (merge commit bf8b985f8f0342dd6da67fc9bdfffb24f9456f20, tag v2026.309.0049):

$ gh run list --repo opencharly/pod-crabbox-code --limit 6 --json databaseId,name,event,conclusion,headSha,createdAt
41944191711 image workflow_run success  9fc857b3 2026-11-05T00:49:38Z
41944161642 image workflow_run failure  9fc857b3 2026-11-05T00:49:23Z
41944147253 tag-on-merge push         success 9fc857b3 2026-11-05T00:49:17Z
41944025333 tag-on-merge workflow_run success 4f3a8953 2026-11-05T00:48:17Z

The failing run (41944161642) failed while fetching the pinned base, not while building this image:

image / build  ...  failed to extract layer (application/vnd.oci.image.layer.v1.tar+gzip sha256:88ce6f55f333d06f1cee320d6f3ad444f48d808248e252801469cddb39b10c6a) to overlayfs as "extract-675267696-5Ysf ...": mount callback failed on /var/lib/containerd/tmpmounts/containerd-mount701355380: failed to Lchown "/var/lib/containerd/tmpmounts/containerd-mount701355380/usr/bin/gdb" for UID 0, GID 0: lchown ...: no such file or directory
image / build  ...  ensure-image: pull ghcr.io/opencharly/pod-crabbox:2026.307.1828 failed: exit status 1
image / build  ...  charly: error: command "build": building pod-crabbox-code: base image ghcr.io/opencharly/pod-crabbox:2026.307.1828 is not present locally, could not be fetched from its registry ...

The publish itself SUCCEEDED on the sibling run: ghcr.io/opencharly/pod-crabbox-code:2026.309.0049 resolves anonymously (skopeo inspect --no-tags, rc=0, digest sha256:237598d9bd83743f76264eba2386a1eae45290156d52af358f0c135d2c6a5d7f), so no release was lost.

RCA

Mechanism (two parts).

  1. Two triggers, two tag-on-merge completions. The org dispatcher .github/workflows/tag-on-merge.yml fires on workflow_run (pr-validator completion), push to main, and schedule. For this merge both the workflow_run-driven run (41944025333) and the push-driven run (41944147253) completed successfully.
  2. The caller fires on EVERY tag-on-merge completion. The variant caller .github/workflows/image.yml has on: workflow_run: workflows: ["tag-on-merge"] types: [completed] with no dedupe by tag, so two completions started two image runs on one head. The two runs then raced on the runner's rootful containerd store while extracting the same base layer; one lost the extraction (lchown … /usr/bin/gdb: no such file or directory) and failed.

Blast radius. This is not specific to pod-crabbox-code: opencharly/pod-crabbox-systemd shows the same pair on one head (41935033023 and 41934997140, both image workflow_run, head 7b2f27fa), which happened to survive because both pulls won. Every repo carrying this caller wastes a full duplicate build per merge and can lose one of the pair to the race. The published tag is not lost when one sibling succeeds, but a repo whose only surviving run is the failed one publishes nothing.

Missed control. Nothing dedupes or serialises the caller's runs — neither by the resolved tag nor on the workflow-run event id — and the reusable image-build.yml does not no-op when the target image tag already exists.

Proposed fix

Either (a) make the caller trigger only on the push path (or dedupe by the resolved tag / github.event.workflow_run.id), or (b) make image-build.yml skip when :<tag> already exists. Option (a) removes the duplicate work; (b) makes the race harmless. A concurrency group keyed on the repo+tag would also serialise them.

Filed from

Found post-merge while landing the W5.2 variant image pod-crabbox-code (opencharly/pod-crabbox-code#1); the image published, so this did not block that landing.

Agent: containerd-crabbox-program/w5b · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (analysed on a live system)

Activity

  1. aitrawog commented on Nov 5, 2026

    @aitrawog
    ContributorAuthor

    Additional evidence — the duplicate runs do not just waste work, they MOVE THE TAG.

    Measured on opencharly/pod-crabbox-nested, merge 8828123e04b0ec9c436fa1bbb8ca4c03e23f7dd8 (tag v2026.309.0149):

    image ev=workflow_run  in_progress   ×3     ← three concurrent publish runs for ONE merge
    

    All three completed/success, and they published different content under the same tag:

    pull digest
    first pullable sha256:29a17b9c…
    final state of the tag sha256:ac96d62248de21e2ba2f7a1bbe568977f9f1f46e1b147f043a912e5191616e59

    So ghcr.io/opencharly/pod-crabbox-nested:2026.309.0149 is stable by name and not by digest — the last writer wins. That is the same set of concurrent runs this issue was filed for, and it upgrades the severity:

    • The plan's W5.4 invariant is "immutable tags, never moved", on the reasoning that import: '@github.com/opencharly/pod-crabbox:v2026.x' and ghcr.io/opencharly/pod-crabbox:2026.x must name the same build. With N concurrent publishes of one commit, two consumers can resolve the same tag to different image digests at different times.
    • The failure mode already observed on pod-crabbox-code is the same concurrency: one of a pair failed on ensure-image: pull … failed while its sibling published. Here all three succeeded — so the race is intermittent, which is worse for diagnosis, not better.
    • A child image that pins pod-crabbox-nested:2026.309.0149 as its base: may build against 29a17b9c… and later pull ac96d622… — different bytes, same reference.

    The fix is the dedupe this issue already asks for, and it should be judged by whether the tag is written exactly once per merge. A publish that runs N times against one commit cannot be made safe by retrying; it has to not run N times.

    Reproduce: merge anything to a pod-crabbox* repo, then gh run list -R opencharly/<repo> --json name,event,status — the image entries with ev=workflow_run for a single merge are the tell.

    Agent: containerd-crabbox-program · session 8b1c01cf-7f79-4a75-bff8-240415a06208
    Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

  2. aitrawog commented on Nov 5, 2026

    @aitrawog
    ContributorAuthor

    The mechanism — tag-on-merge triggers itself once, and image fans out on every completion.

    Measured on opencharly/pod-crabbox-k3s, merge 091ec9cb (tag v2026.309.0459), 2026-11-05. Literal output:

    $ gh run list -R opencharly/pod-crabbox-k3s --limit 12 --json name,event,status,conclusion,headSha,createdAt \
        --jq '.[] | select(.name=="tag-on-merge" or .name=="image") | "\(.name)\tev=\(.event)\t\(.status)/\(.conclusion)\tsha=\(.headSha[0:12])\t\(.createdAt)"'
    image	ev=workflow_run	completed/success	sha=f3ceffecd16a	2026-11-05T05:00:34Z
    image	ev=workflow_run	completed/success	sha=f3ceffecd16a	2026-11-05T05:00:18Z
    tag-on-merge	ev=push	completed/success	sha=f3ceffecd16a	2026-11-05T05:00:14Z
    tag-on-merge	ev=workflow_run	completed/success	sha=0c4dc3930b5a	2026-11-05T04:59:37Z
    image	ev=pull_request	completed/success	sha=4f878630d89e	2026-11-05T04:56:35Z
    image	ev=workflow_dispatch	completed/success	sha=4f878630d89e	2026-11-05T04:52:36Z
    tag-on-merge	ev=push	completed/success	sha=0c4dc3930b5a	2026-11-05T04:51:57Z
    image	ev=workflow_dispatch	completed/success	sha=1c8dc7ac2fec	2026-11-05T04:45:00Z
    $ git -C pod-crabbox-k3s log --format='%H %ci %s' -3
    f3ceffecd16af5e309ca4bbf4cf978d79fdaf33f 2026-11-05 05:00:12 +0000 docs: add CHANGELOG 2026.309.0459 for PR #1
    091ec9cbdb27a62215d31eb53b850acfe5e70b36 2026-11-05 04:59:58 +0000 feat(image): add the k3s control-plane lease image pod-crabbox-k3s (#1)
    0c4dc3930b5af4481e48f395703901e32e85b35b 2026-11-05 04:51:54 +0000 ci: install the org tag-on-merge dispatcher (opencharly/.github#180)

    Read the two together. The workflow_run arm runs at 04:59:37 against head 0c4dc393. The squash lands at 04:59:58 (091ec9cb). At 05:00:12 tag-on-merge writes its own CHANGELOG/2026.309.0459.md commit f3ceffec and pushes it to main. Two seconds later there is a tag-on-merge run with ev=push on exactly that commit. The workflow has re-entered on its own push.

    That is the whole of it: tag-on-merge declares push as a secondary trigger for human and contents-API merges, and the CHANGELOG commit it writes on the primary path is itself a push to main. The second run is a no-op — the sweep is idempotent and finds nothing — but it is a real run and it completes.

    Why that doubles the image. image keys on workflow_run: workflows: [tag-on-merge], so it fires on the completion of every tag-on-merge run rather than on the merge. Two completions, two image runs, 16 s apart, both on head f3ceffec — two concurrent publishes to one tag.

    So the duplicate is not a scheduling flake and not a runner race. It is the tag-writing workflow triggering itself exactly once, with the image workflow keyed on the thing that fires twice. That is why the count is consistently two rather than intermittent.

    What follows for the fix. Cancelling duplicates is not sufficient by itself: the two runs already overlap by 16 s, which is why one of a pair can fail at ensure-image: pull … while its sibling publishes. Two properties must hold together:

    1. Exactly one publisher per tag. A concurrency: group keyed on the resolved tag, plus a registry existence check inside the job that skips when ghcr.io/opencharly/<image>:<tag> already resolves. The group alone serializes but still lets the second run through; the existence check alone is racy across a 16 s overlap. Together they are deterministic.
    2. W5.4 — a tag is never moved. The same existence check is the guard: if the tag already resolves, the run must skip, not overwrite. Today the last writer wins, which is what lets one tag resolve to different digests.

    One inference, stated as such. That the two image runs correspond one-to-one with the two tag-on-merge completions is inferred from the event type, the timestamps and the shared head — I did not read each run's workflow_run.id. The check that settles it: one merge where the second tag-on-merge completes after the first image run has finished. If a second image run still appears, the fan-out is on the completion and point 1 is the fix.

    Verified alongside this on the same merge: skopeo inspect --no-tags docker://ghcr.io/opencharly/pod-crabbox-k3s:2026.309.0459 returns rc=0 anonymously with digest sha256:c50feb9dbfaa91ac09f70ee4f101ac5c58c665e75221f6564d53c36e10f49285, and the git tag is v2026.309.0459 — image tag equals git tag, so the W5.2 half holds here.

    Agent: containerd-crabbox-program · session 8b1c01cf-7f79-4a75-bff8-240415a06208
    Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (analysed on a live system)

  3. added
    category:governance
    type:fix
    on Nov 23, 2026
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

    category:governancetype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions