Skip to content

fix: build release images and stop :latest racing - #380

Merged
neuromechanist merged 2 commits into
developfrom
fix/issue-379-release-images
Sep 17, 2026
Merged

neuromechanist merged 2 commits into
developfrom
fix/issue-379-release-images

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Closes #379.

The bug, in one line

Production served 0.8.9.dev0 while main said 0.8.9, and there was no versioned image to roll back to because none has been published since 0.6.2.

Two independent causes, both verified

1. A release does not emit a tag push. docker-build.yml triggered only on push, so it never ran for a release. The single workflow run on the v0.8.9 ref was Publish to PyPI, with event: release -- and publish.yml is the one workflow that already listed release among its triggers, which is why it was also the only one that fired.

$ gh run list --limit 200 --json headBranch,workflowName,event | ... filter v0.*
2026-09-17T00:08  v0.8.9  success  release  Publish to PyPI

That is the whole reason the versioned tags are missing. Every named tag on the package today:

0.5, 0.5.1, 0.6, 0.6.2, dev, develop, latest, main

The other 192 are sha-*. So 0.7.x and all of 0.8.x produced no rollback target.

2. :latest was written by a race. The workflow had no concurrency: guard and wrote :latest on every default-branch push. The 0.8.9 release pushed two commits to main ten seconds apart and both built:

sha b869884  (version.py = 0.8.9.dev0)  started 00:08:13  finished 00:09:58
sha 5b1f9c3  (version.py = 0.8.9)       started 00:08:23  finished 00:09:59

Both wrote :latest, one second apart, with no ordering between them. Production running 0.8.9.dev0 through eleven hours of hourly auto-updates is the evidence of which one won.

The fix

  • release: [published] added to the triggers, so a release builds its images. The push/tags trigger stays for a tag pushed by hand.
  • concurrency: keyed on the ref, cancel-in-progress: false. Two pushes to the same ref serialize instead of interleaving their tag writes. Never cancel: a cancelled run can be one already pushing layers.
  • :latest now means the latest RELEASE, not the head of main. Production pulls :latest (deploy/auto-update.sh), so this is what decides what it serves. :main still follows the branch for anyone who wants that.
  • workflow_dispatch added, so a maintainer can rebuild a tag: gh workflow run docker-build.yml --ref v0.8.9. That is also the recovery path for releases that predate this fix.
  • deploy/DEPLOYMENT_ARCHITECTURE.md gains a table saying what each tag means and when it moves, since "latest" no longer means what a reader would assume.

Behavior change worth calling out

Pushing to main no longer updates production. Publishing a release does. That is the intended reading of "promote to production" and it is what makes a promotion reversible, but it is a real change: a hotfix committed straight to main will not deploy until it is released, or until someone points the host at :main.

Two things this PR does not do

  • It does not fix production's current image. :latest is still the 0.8.9.dev0 build until either a new release is published or someone runs the dispatch above against v0.8.9. Rebuilding a tag pushes to the production image tag, so that is a deploy and I have not run it.
  • It does not take effect for releases until it reaches main. Workflows for release events run from the default branch, so this needs the normal develop -> main path first. workflow_dispatch works from any ref immediately.

Testing

actionlint is clean, the YAML parses, and all four triggers plus the concurrency block are present. The pull_request trigger and the build-and-test gate are untouched, so PR builds behave exactly as before -- this PR's own checks exercise that path.


Review round

All findings addressed in 7e60eb9. One was a defect that would have reproduced the very bug this PR exists to fix.

Critical: a pre-release would have moved :latest

This workflow subscribes to the release event's published type, and GitHub fires published for pre-releases too. My first expression was:

enable=${{ github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v') }}

So ticking "pre-release" on a release, or pushing v1.2.3-rc1, would have moved :latest -- and production pulls :latest hourly. A release candidate would have deployed itself. That is the same failure this PR was written to prevent, moved one step earlier.

Worse, it was internally inconsistent: type=semver deliberately does not move {{major}}.{{minor}} for a pre-release, so the workflow already had the protection one block up and I did not apply it to the raw tag.

While fixing it I found a second hole of my own. The obvious repair still leaks:

(event == 'release' && !prerelease) || (startsWith(ref,'refs/tags/v') && !contains(ref,'-'))

A maintainer can tick "pre-release" on a tag with no hyphen in it. The payload says pre-release; the tag name gives no hint; the second clause waves it through on the very event whose own payload said not to. The second clause now excludes the release event, so on a release the payload decides and nothing else gets a vote.

Important: concurrency did not order across different releases

Keying on github.ref puts two releases published minutes apart into two groups. A slow v1.2.3 finishing after v1.2.4 leaves :latest on the older one -- last-writer-wins again, just needing two releases instead of two commits. Every tag and release build now shares one group; branch builds stay per-branch, since main and develop write different tags.

Important: workflow-level concurrency would have queued PR builds

cancel-in-progress: false across the whole workflow meant consecutive pushes to an open PR queued behind each other, including a container build and a 60s health-check loop, where before they ran independently. My "never cancel, a cancelled run can be pushing layers" reasoning is true for build-and-push and false for build-and-test, which never touches the registry. Now cancel-in-progress: ${{ github.event_name == 'pull_request' }}.

Moderate: my root cause was wrong

I wrote that a release creates its tag inline and emits no tag push. Real behavior in general, not what happens here. tag-release.yml pushes the tag itself at line 64, after an actions/checkout@v4 with no token: override -- so it is authored by the default GITHUB_TOKEN, and GitHub does not start workflow runs from events that token created. The release in the same job is seen only because gh release create runs under CI_ADMIN_TOKEN, a PAT (line 104). That asymmetry is the whole bug, and it means anything else added to this pipeline that must trigger a workflow has to be authored by the PAT. Corrected in the workflow comment, in the deployment doc, and on issue #379.

Moderate: "runs from the default branch" conflated two things

For a release event GITHUB_SHA is the tagged commit, not main's tip, so the build content is correct. The real constraint is that the on: triggers are only honored once the file is on the default branch. Both statements are now separate, and I have dropped the claim that workflow_dispatch is an immediately available escape hatch -- it needs the same merge first.

Moderate: two docs claimed main auto-deploys

CLAUDE.md and CONTRIBUTING.md both said main auto-deploys to production. Both updated.

Tests

tests/test_latest_tag_policy.py is new and reads the enable= expression out of the workflow file rather than restating it, so editing the workflow re-runs these cases against the new expression instead of diverging from a copy. Its evaluator models only the operators the expression is allowed to use and asserts on anything else, so a change reaching for a new construct fails loudly rather than being mis-evaluated.

Ten event shapes: pushes to main and develop, hand-pushed stable and rc tags, stable release, pre-release, pre-release whose tag has no hyphen, dispatch against a tag and against a branch, and a pull request.

Mutation-checked, each applied and reverted:

mutation result
the original reviewed defect (no pre-release guard) 3 failed
hyphen check dropped 1 failed
release-event exclusion dropped 1 failed
reverted to enable={{is_default_branch}} 10 failed

actionlint clean, ruff check and ruff format clean.

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