Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

feature/Dispatch-retry-rebuilds-dists · L-260920-487091 (#1223)

Louis Choquel3847e7158ec2
diff --git a/.claude/skills/release/SKILL.md b/.claude/skills/release/SKILL.md
index be3a8010d..7cbab8bb3 100644
--- a/.claude/skills/release/SKILL.md
+++ b/.claude/skills/release/SKILL.md
@@ -29,7 +29,9 @@ pip index versions pipelex # the regist
git -C <main> fetch --tags --prune origin && git -C <main> tag --list vX.Y.Z
```
-`gh release view vX.Y.Z` confirms the Release and its notes. A publish that failed *after* the merge is recovered by re-running that run's **failed jobs**, which keeps the successful ones. Once the dists have reached PyPI that is the only path: the publish job sets no `skip-existing`, so a fresh run fails on the files already there and never reaches the `github-release` job that depends on it. The Release step itself is idempotent — it edits an existing release rather than failing on one. Reserve `workflow_dispatch` for a failure that needs the workflow file changed, since a re-run replays the file the run started with; it accepts `main`, `release/vX.Y.Z` and `pre-release/v*` and nothing else, and its run lists under the ref it was dispatched from rather than under the release branch.
+`gh release view vX.Y.Z` confirms the Release and its notes. A publish that failed *after* the merge is recovered by **re-running that run's failed jobs**, which keeps the successful ones, and that is the path to reach for. It is safe once the dists have reached PyPI: `skip-existing` opens on a re-run and on a dispatch, so the publish job no longer dies on the files already there, and the build job recovers the bytes this version published rather than rebuilding them — the artifact an attempt of the same run stored, else one an earlier run stored for the same commit, else the files PyPI serves — then refuses to go on unless what it holds is byte-for-byte what PyPI publishes. The Release step itself is idempotent: it edits an existing release rather than failing on one.
+
+`workflow_dispatch` is the other path, needed when the failure calls for a change to the workflow file, since a re-run replays the file the run started with. **Once the release exists, a dispatch succeeds only from a ref whose head is the commit the release is tagged at** — the release pull request's base branch, `main` normally, while nothing further has landed on it. The tag names the merge commit, a dispatch ships the head of the ref it was dispatched from, and `github-release`'s tag guard refuses any other commit: a dispatch from `release/vX.Y.Z` is therefore always refused, although it is the ref the failed run is listed under. That dispatch recovers from PyPI rather than from an artifact, the release branch's build being keyed to a different commit, and the bytes are the same either way. A dispatch accepts `main`, `release/vX.Y.Z` and `pre-release/v*` and nothing else, and its run lists under the ref it was dispatched from rather than under the release branch.
## Version files and the lock
diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml
index 9211c85f4..2c7393ee9 100644
--- a/.github/workflows/publish-pypi.yml
+++ b/.github/workflows/publish-pypi.yml
@@ -10,6 +10,8 @@ on:
# expired token) is otherwise unrecoverable: re-running a run replays the
# workflow file it started with, and the only other trigger is merging a PR
# into main — which the branch guard restricts to release/vX.Y.Z branches.
+ # A dispatch is a new run and so holds no artifact of its own; the build job
+ # below recovers the bytes this version published rather than rebuilding them.
workflow_dispatch:
jobs:
@@ -20,7 +22,18 @@ jobs:
permissions:
contents: read
- actions: read # reading this run's own artifact list, below
+ actions: read # reading artifact lists — this run's, and the repository's
+
+ env:
+ # The commit whose build this job is looking for, resolved into HEAD_SHA
+ # below. The two triggers name it differently: on the `pull_request` path
+ # `github.sha` is the event's own merge ref, while the run — and so the
+ # artifact it stores — records the release branch's last commit as its
+ # `head_sha`. Deliberately NOT a `${{ cond && a || b }}` expression, for the
+ # reason spelled out in `github-release`: that idiom falls through to `b`
+ # whenever `a` is empty. Two plain inputs and a shell branch fail loudly.
+ PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ DISPATCH_SHA: ${{ github.sha }}
steps:
# A manual run can target any ref that contains this workflow, and every
@@ -41,73 +54,292 @@ jobs:
echo "::error::Manual publish is allowed only from main, release/vX.Y.Z or pre-release/v*. Got: $REF"
exit 1
fi
+ - uses: actions/checkout@v4
+ with:
+ persist-credentials: false
+ - name: Read the package, the version and the commit being shipped
+ id: project
+ run: |
+ set -euo pipefail
+ NAME=$(grep -m 1 '^name = ' pyproject.toml | cut -d '"' -f 2)
+ VERSION=$(grep -m 1 '^version = ' pyproject.toml | cut -d '"' -f 2)
+ if [ -z "$NAME" ] || [ -z "$VERSION" ]; then
+ echo "::error::Could not read the package name and version out of pyproject.toml."
+ exit 1
+ fi
+ if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
+ HEAD_SHA="$PR_HEAD_SHA"
+ else
+ HEAD_SHA="$DISPATCH_SHA"
+ fi
+ if [ -z "$HEAD_SHA" ]; then
+ echo "::error::Could not determine which commit this run is shipping ($GITHUB_EVENT_NAME). Refusing to look for, or make, a build without it."
+ exit 1
+ fi
+ {
+ echo "name=$NAME"
+ echo "version=$VERSION"
+ echo "head_sha=$HEAD_SHA"
+ } >> "$GITHUB_OUTPUT"
+ echo "Shipping $NAME $VERSION from $HEAD_SHA"
# A recovery re-run — the one the signing fallback in `github-release`
- # prescribes — must attach and sign the exact bytes the first attempt
- # published, because PyPI's copies of them are immutable. Rebuilding cannot
- # promise that: `[build-system] requires = ["hatchling"]` names no version,
- # so a hatchling release landing between two attempts changes the output of
- # the same commit, and GitHub would then serve — and Sigstore would attest —
- # dists that differ from the ones on PyPI. Artifacts are scoped to the run
- # rather than to the attempt, so the build the first attempt stored is still
- # here; reuse it and skip the rest of this job.
+ # prescribes — must attach and sign the exact bytes this version published,
+ # because PyPI's copies of them are immutable. Rebuilding cannot promise
+ # that: `[build-system] requires = ["hatchling"]` names no version and
+ # `actions/setup-python` asks for `3.x`, so a backend or interpreter release
+ # landing between two attempts changes the output of the same commit, and
+ # GitHub would then serve — and Sigstore would attest — dists that differ
+ # from the ones on PyPI. So this job recovers those bytes from the first of
+ # three places that holds them, builds only when nothing was ever published,
+ # and checks whatever it ends up with against PyPI before anything is
+ # published, attached or signed.
#
- # This covers "Re-run all jobs". It cannot cover the `workflow_dispatch`
- # retry, which is a NEW run and so holds no earlier artifact and rebuilds.
- # The tag guard in `github-release` does not close that gap either — it
- # compares commits, and this is the same commit built twice. Open as
- # L-260920-487091; prefer re-running this run over dispatching a new one.
- - name: Look for a build stored by an earlier attempt
- id: earlier_build
+ # PyPI is asked first, once, because its answer decides both halves of that:
+ # whether there are published bytes to recover at all, and what every dist
+ # below is measured against. A layer cannot skip a check it does not carry.
+ - name: Ask PyPI what this version has published
+ id: published
+ env:
+ NAME: ${{ steps.project.outputs.name }}
+ VERSION: ${{ steps.project.outputs.version }}
+ run: |
+ set -euo pipefail
+ # `--retry` covers a transient 5xx or a rate limit; a 404 is not an error
+ # to curl without `-f`, so the "never published" answer below is reached
+ # on the first call rather than after three.
+ CODE=$(curl -sS --retry 3 --retry-delay 2 --retry-all-errors \
+ -o "$RUNNER_TEMP/pypi-release.json" -w '%{http_code}' \
+ "https://pypi.org/pypi/$NAME/$VERSION/json" || echo " transport-failure")
+ case "$CODE" in
+ 200)
+ FILES=$(jq '.urls | length' "$RUNNER_TEMP/pypi-release.json")
+ if [ "$FILES" -eq 0 ]; then
+ echo "::error::PyPI knows $NAME $VERSION but serves no files for it. Refusing to guess at what this release published."
+ exit 1
+ fi
+ echo "PyPI serves $NAME $VERSION, so that release's files are what this run must carry."
+ echo "published=true" >> "$GITHUB_OUTPUT"
+ ;;
+ 404)
+ echo "PyPI serves no $NAME $VERSION, so nothing has been published under this version yet."
+ echo "published=false" >> "$GITHUB_OUTPUT"
+ ;;
+ *)
+ # A guard that reads an outage as "never published" would rebuild —
+ # and attest — exactly when it is least able to tell what it is
+ # replacing.
+ echo "::error::Could not ask PyPI whether $NAME $VERSION is published (got '$CODE'). Refusing to publish bytes that cannot be checked against what PyPI already serves — re-run this job once PyPI answers."
+ exit 1
+ ;;
+ esac
+ # Layer 1: an attempt of THIS run. Artifacts are scoped to the run rather
+ # than to the attempt, so "Re-run all jobs" finds the build the first
+ # attempt stored, which is the ordinary Sigstore recovery.
+ - name: Look for a build an earlier attempt of this run stored
+ id: this_run
env:
GH_TOKEN: ${{ github.token }}
run: |
+ set -euo pipefail
+ # `all` rather than `any`: one live record is enough to reuse, and only a
+ # set where every record has expired is a dead end. v4 artifact names are
+ # unique per run, so in practice there is one record or none.
STATE=$(gh api \
"repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts" \
--jq '[.artifacts[] | select(.name == "python-package-distributions")]
| if length == 0 then "absent"
- elif any(.expired) then "expired"
+ elif all(.expired) then "expired"
else "present" end')
case "$STATE" in
present)
- echo "An earlier attempt stored a build — reusing it."
- echo "reuse=true" >> "$GITHUB_OUTPUT"
+ echo "An earlier attempt of this run stored a build — reusing it."
+ echo "found=true" >> "$GITHUB_OUTPUT"
+ echo "The dists come from the build an earlier attempt of this run stored." >> "$GITHUB_STEP_SUMMARY"
;;
expired)
- echo "::error::The build stored by an earlier attempt has expired, so this run cannot attach the bytes it built, and a rebuild here cannot be shown to match whatever reached PyPI. Check whether this version is on PyPI: if it is, bump the version; if it is not, dispatch this workflow again."
- exit 1
+ # No longer a dead end: the layers below can still recover the bytes
+ # this version published. The artifact record does hold this run's
+ # name, though, so the upload at the end has to replace it.
+ echo "::notice::The build stored by an earlier attempt of this run has expired; recovering the published bytes instead."
+ echo "expired=true" >> "$GITHUB_OUTPUT"
;;
*)
- echo "reuse=false" >> "$GITHUB_OUTPUT"
+ echo "This run holds no build yet."
;;
esac
- - uses: actions/checkout@v4
- if: steps.earlier_build.outputs.reuse != 'true'
+ # Downloaded rather than left in place, because the verification below reads
+ # the files. This run's own artifact is precisely the one that can be stale:
+ # it was built before whatever ended up on PyPI.
+ - name: Download the build this run already holds
+ if: steps.this_run.outputs.found == 'true'
+ uses: actions/download-artifact@v4
with:
- persist-credentials: false
+ name: python-package-distributions
+ path: dist/
+ # Layer 2: an earlier RUN of the same commit. A `workflow_dispatch` retry is
+ # a new run, so layer 1 finds nothing there. Artifacts are listed
+ # repository-wide and each carries the head commit of the run that stored
+ # it, so a build an earlier attempt at this same commit made is still
+ # reachable — which is what saves a retry of a publish that never reached
+ # PyPI. The dispatch a released version is actually recovered by is one from
+ # the base branch, whose tip is the commit the release was tagged at and the
+ # only ref the tag guard in `github-release` admits; that names a different
+ # commit than the release run's head, so it falls through to layer 3.
+ - name: Reuse a build an earlier run stored for this commit
+ id: earlier_run
+ if: steps.this_run.outputs.found != 'true'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ HEAD_SHA: ${{ steps.project.outputs.head_sha }}
+ run: |
+ set -euo pipefail
+ # Piped through the runner's own `jq` rather than `gh --jq`, so the
+ # commit can be passed in with `--arg` instead of read out of the
+ # environment. `pipefail` is what makes a failed `gh` call fail the
+ # pipeline rather than quietly yielding an empty list.
+ if ! CANDIDATES=$(gh api --paginate \
+ "repos/$GITHUB_REPOSITORY/actions/artifacts?name=python-package-distributions&per_page=100" \
+ | jq -r --arg head "$HEAD_SHA" \
+ '.artifacts[]
+ | select(.expired == false and .workflow_run.head_sha == $head)
+ | "\(.created_at) \(.id)"'); then
+ # Reading an outage as "no earlier build" only sends this job down to
+ # layer 3, which reuses what PyPI itself serves — a strictly better
+ # source than either an artifact or a rebuild. A warning is enough.
+ echo "::warning::Could not list this repository's artifacts, so the earlier-run layer is being skipped."
+ CANDIDATES=""
+ fi
+ ARTIFACT_ID=$(printf '%s\n' "$CANDIDATES" | sort | tail -1 | cut -d ' ' -f 2)
+ if [ -z "$ARTIFACT_ID" ]; then
+ echo "No earlier run holds a build for $HEAD_SHA."
+ exit 0
+ fi
+ echo "Reusing artifact $ARTIFACT_ID, stored by an earlier run of $HEAD_SHA."
+ gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$ARTIFACT_ID/zip" \
+ > "$RUNNER_TEMP/earlier-build.zip"
+ mkdir -p dist
+ unzip -q -o "$RUNNER_TEMP/earlier-build.zip" -d dist
+ echo "found=true" >> "$GITHUB_OUTPUT"
+ echo "The dists come from artifact $ARTIFACT_ID, stored by an earlier run of $HEAD_SHA." >> "$GITHUB_STEP_SUMMARY"
+ # Layer 3: PyPI itself, when it serves this version. Its files are the
+ # release, so downloading them is what makes the GitHub Release assets
+ # provably the bytes PyPI serves rather than a build that probably matches
+ # them — and it needs no artifact to have survived.
+ - name: Take the files PyPI publishes for this version
+ if: steps.published.outputs.published == 'true'
+ && steps.this_run.outputs.found != 'true'
+ && steps.earlier_run.outputs.found != 'true'
+ run: |
+ set -euo pipefail
+ mkdir -p dist
+ while read -r SHA256 FILENAME URL; do
+ echo "Downloading $FILENAME"
+ curl -fsSL --retry 3 --retry-delay 2 --retry-all-errors -o "dist/$FILENAME" "$URL"
+ # Checked here as well as in the verification below, so that a
+ # truncated transfer is reported as the download failure it is.
+ printf '%s %s\n' "$SHA256" "dist/$FILENAME" | sha256sum -c -
+ done < <(jq -r '.urls[] | "\(.digests.sha256) \(.filename) \(.url)"' "$RUNNER_TEMP/pypi-release.json")
+ echo "The dists are the files PyPI publishes for this version." >> "$GITHUB_STEP_SUMMARY"
+ # Whether a build is still needed is a question about `dist/`, and asking the
+ # directory keeps it honest: no bookkeeping flag can disagree with what the
+ # layers above actually left there. It stays empty only when nothing was
+ # published and no artifact survived, which is the ordinary first pass.
+ - name: Decide whether a build still has to be made
+ id: acquire
+ run: |
+ set -euo pipefail
+ shopt -s nullglob
+ RECOVERED=(dist/*)
+ if [ "${#RECOVERED[@]}" -eq 0 ]; then
+ echo "Nothing holds this version's bytes yet, so this run builds them."
+ echo "build=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "build=false" >> "$GITHUB_OUTPUT"
+ fi
- name: Set up Python
- if: steps.earlier_build.outputs.reuse != 'true'
+ if: steps.acquire.outputs.build == 'true'
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
- if: steps.earlier_build.outputs.reuse != 'true'
+ if: steps.acquire.outputs.build == 'true'
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
- if: steps.earlier_build.outputs.reuse != 'true'
- run: python3 -m build
- # Deliberately no `overwrite`: artifacts are immutable in v4, and the guard
- # above means this step is reached only when the run holds no build yet. A
- # second attempt reuses the first one's bytes rather than replacing them.
+ if: steps.acquire.outputs.build == 'true'
+ env:
+ HEAD_SHA: ${{ steps.project.outputs.head_sha }}
+ run: |
+ set -euo pipefail
+ python3 -m build
+ echo "The dists are a fresh build of $HEAD_SHA — this version had not been published." >> "$GITHUB_STEP_SUMMARY"
+ # The one check every path passes through, because what is in `dist/` now is
+ # what the jobs below publish, attach and sign. It runs on the reused
+ # artifact as well as on the recovered or freshly built files: an artifact is
+ # not evidence of anything on its own — it was stored by a run this one did
+ # not watch, and a run whose own publish failed can hold a build that a later
+ # run then published differently.
+ - name: Verify the dists are this version's, and are what PyPI serves
+ env:
+ VERSION: ${{ steps.project.outputs.version }}
+ PUBLISHED: ${{ steps.published.outputs.published }}
+ run: |
+ set -euo pipefail
+ shopt -s nullglob
+ WHEELS=(dist/*.whl)
+ SDISTS=(dist/*.tar.gz)
+ DIST_FILES=(dist/*)
+ if [ "${#WHEELS[@]}" -ne 1 ] || [ "${#SDISTS[@]}" -ne 1 ]; then
+ echo "::error::Expected exactly one wheel and one source tarball in dist/, found: ${DIST_FILES[*]:-nothing}"
+ exit 1
+ fi
+ for DIST in "${WHEELS[@]}" "${SDISTS[@]}"; do
+ case "${DIST##*/}" in
+ *-"$VERSION"-*.whl|*-"$VERSION".tar.gz) ;;
+ *)
+ echo "::error::$DIST is not a $VERSION distribution. Refusing to publish it as v$VERSION."
+ exit 1
+ ;;
+ esac
+ done
+ if [ "$PUBLISHED" = "true" ]; then
+ # PyPI's copies are immutable, so its digests are the only statement of
+ # what this version IS. Every published file has to be here and intact:
+ # `sha256sum -c` fails on a digest that differs and on a file that is
+ # missing altogether.
+ jq -r '.urls[] | "\(.digests.sha256) dist/\(.filename)"' \
+ "$RUNNER_TEMP/pypi-release.json" > "$RUNNER_TEMP/published.sha256"
+ if ! sha256sum -c "$RUNNER_TEMP/published.sha256"; then
+ echo "::error::The dists this job holds are not the bytes PyPI serves for v$VERSION, so attaching and signing them would contradict the release PyPI is already publishing. A build stored by this run is stale — dispatch a fresh run from the ref this release is tagged at, which recovers the published files instead of reusing that build."
+ exit 1
+ fi
+ # The digests say nothing about a file PyPI never published, and an
+ # extra one would be attached and signed alongside the others.
+ PUBLISHED_NAMES=$(jq -r '.urls[].filename' "$RUNNER_TEMP/pypi-release.json" | sort)
+ LOCAL_NAMES=$(printf '%s\n' "${DIST_FILES[@]##*/}" | sort)
+ if [ "$PUBLISHED_NAMES" != "$LOCAL_NAMES" ]; then
+ echo "::error::dist/ does not hold the same set of files PyPI publishes for v$VERSION. PyPI serves: $(echo "$PUBLISHED_NAMES" | tr '\n' ' '). This job holds: $(echo "$LOCAL_NAMES" | tr '\n' ' ')."
+ exit 1
+ fi
+ echo "The dists are byte-for-byte the files PyPI publishes for v$VERSION."
+ fi
+ ls -l dist
+ # Artifacts are immutable in v4, and layer 1 above means this step is
+ # reached only when this run holds no usable build — so an ordinary second
+ # attempt reuses the first one's bytes rather than replacing them.
+ # `overwrite` opens for exactly one case: the record is still here but its
+ # contents have expired, and the name it holds has to be freed before the
+ # recovered bytes can take it.
- name: Store the distribution packages
- if: steps.earlier_build.outputs.reuse != 'true'
+ if: steps.this_run.outputs.found != 'true'
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
+ overwrite: ${{ steps.this_run.outputs.expired == 'true' }}
publish-to-pypi:
name: >-
@@ -397,7 +629,11 @@ jobs:
run: >-
echo "::warning::Sigstore signing failed. v$VERSION is released and its
dists are attached, but it carries no signature bundles. Once Sigstore is
- healthy, use 'Re-run all jobs' on this run to attach them — signing is
- non-fatal, so this job succeeded and 'Re-run failed jobs' is not offered.
- Re-running this run reuses the build it already published rather than
- making a new one, so prefer it over a fresh manual dispatch."
+ healthy, use 'Re-run all jobs' on this run to attach them: the build job
+ recovers the bytes this version published rather than building new ones.
+ A manual dispatch does the same, but only from a ref whose head is the
+ commit this release is tagged at — the release pull request's base branch,
+ while nothing further has landed on it — because the guard above refuses a
+ run that is shipping any other commit, and the release branch's own tip is
+ never that commit. Signing is non-fatal, so this job succeeded and 'Re-run
+ failed jobs' is not offered."
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e24e1bc29..e98a49864 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,7 @@
- **Claude Sonnet 5 is priced at its standard rate**: `claude-5-sonnet` carried the $3 / $15 per million tokens it was announced at, but its $2 / $10 introductory rate became the standard price and the scheduled increase was cancelled. The entry is corrected on the Anthropic backend and in both hosted catalogs, so cost reporting and budget ceilings no longer overstate a Sonnet 5 run.
-- **A failed publish can be recovered without damaging what already shipped**: `publish-pypi.yml` scopes the signature upload to `dist/*.sigstore.json` so it no longer clobbers the wheel and sdist attached just before it, turns `skip-existing` on for a re-run or a manual dispatch, reuses the build an earlier attempt of the same run stored instead of rebuilding it, and refuses to touch a release whose tag names a commit other than the one being published. The release is now tagged at the commit it ships, named explicitly with `--target`, rather than at the default branch's head.
+- **A failed publish can be recovered without damaging what already shipped**: `publish-pypi.yml` scopes the signature upload to `dist/*.sigstore.json` so it no longer clobbers the wheel and sdist attached just before it, turns `skip-existing` on for a re-run or a manual dispatch, and refuses to touch a release whose tag names a commit other than the one being published. A retry no longer rebuilds the dists either: the build job asks PyPI once what this version published, recovers those bytes from the first place that holds them — the build an earlier attempt of this run stored, then an artifact an earlier run stored for the same commit, then the files PyPI itself serves — and builds fresh only when PyPI answers that nothing was published under this version. Whatever it ends up holding is then checked, on every one of those paths, to be one wheel and one source tarball of the version being released and, when PyPI serves that version, to be byte-for-byte the files PyPI publishes; a divergence fails the job instead of reaching the release, so a build stored before another run published different bytes can no longer be attached and attested over them. That makes the release assets the bytes PyPI serves rather than a rebuild that probably matches them, which an unpinned build backend and an unpinned interpreter cannot promise, and it turns an expired artifact from a dead end into one more layer to fall through. The release is now tagged at the commit it ships, named explicitly with `--target`, rather than at the default branch's head.
- **A generated image is stored under its own media type, so a store no longer serves it as `binary/octet-stream`**: `GeneratedContentFactory.make_image_content` resolves the effective mime type once and already used it to mint the storage key's extension, but passed no `content_type` to `StorageProviderAbstract.store` on either the direct-bytes path or the fetched-remote one. The S3 provider only sets `ContentType` when it is given one, so every generated image landed untyped and S3 answered `binary/octet-stream` on the way back out — which reached any consumer that trusts the stored type, a same-origin assets route serving the object to a browser among them. Both calls now pass the resolved mime type, so the key's extension, the object's stored type and the reported `mime_type` cannot diverge.