Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(release): pin PyPI build to the release commit, not dispatch-time HEAD (#5026)

LearningCircuit6a58b3b74993
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 7220098ebd..d92c9c63e6 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -4,6 +4,14 @@ name: Publish to PyPI
# (after security gate passes). We intentionally do NOT support
# workflow_dispatch because that would bypass security checks.
# To re-publish, trigger a new release through release.yml.
+#
+# REPRODUCIBILITY: repository_dispatch runs on default-branch HEAD at
+# dispatch time — NOT the release commit. The `release` env approval is
+# human-paced, so main can move between the release commit and the
+# dispatch (on v1.9.0 it was 4 PRs ahead, and PyPI shipped code absent
+# from the tag/Docker image). Both build jobs therefore check out
+# `client_payload.sha` — the exact commit every gate ran against — and
+# fail closed if the dispatcher didn't pin it.
on:
repository_dispatch:
types: [publish-pypi]
@@ -33,9 +41,30 @@ jobs:
with:
egress-policy: audit
+ - name: Validate pinned release commit
+ # POSIX sh (this job's container is Alpine — no bash). Fail closed:
+ # without a full 40-hex SHA, checkout would silently fall back to
+ # default-branch HEAD and reintroduce the drift this pin prevents.
+ # The length test matters: grep -E matches PER LINE, so a crafted
+ # multiline value ("<40-hex>\n<junk>") would pass the regex alone;
+ # ${#VAR} counts bytes in POSIX sh, so -eq 40 also excludes any
+ # embedded newline. Ancestry (sha actually on main) is enforced in
+ # build-package — this container has no python3/gh; this job holds
+ # no secrets and its output only reaches PyPI through build-package,
+ # which checks out the same validated sha.
+ env:
+ RELEASE_SHA: ${{ github.event.client_payload.sha }}
+ run: |
+ if [ "${#RELEASE_SHA}" -ne 40 ] || ! printf '%s' "$RELEASE_SHA" | grep -qE '^[0-9a-f]{40}$'; then
+ echo "::error::client_payload.sha is missing or not a full commit SHA — refusing to build from default-branch HEAD. The dispatcher (release.yml trigger-pypi) must pin the release commit."
+ exit 1
+ fi
+ echo "Building from pinned release commit $RELEASE_SHA"
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
+ ref: ${{ github.event.client_payload.sha }}
persist-credentials: false
- name: Check for frontend assets
@@ -132,9 +161,68 @@ jobs:
with:
egress-policy: audit
+ - name: Validate pinned release commit
+ # Same fail-closed shape guard as build-frontend (length test: see
+ # comment there), plus the ANCESTRY check that only this job can
+ # run (python3 in the container): the pinned sha must be reachable
+ # from main. Anyone able to send repository_dispatch (repo write /
+ # the PAT holder) chooses the payload — without this check they
+ # could point the build at ANY commit object in the repo network
+ # (scratch branches, fork-PR heads) that never passed review or the
+ # release gates. release.yml's own build job verifies its sha is on
+ # main, but a forged dispatch bypasses release.yml entirely; the
+ # `release` environment approval on the publish job is then the
+ # only barrier, and an approver has no reason to suspect a
+ # legitimate-looking pending deployment. Enforced here (not in
+ # build-frontend) because every byte that reaches PyPI flows
+ # through this job's checkout.
+ env:
+ RELEASE_SHA: ${{ github.event.client_payload.sha }}
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ if [ "${#RELEASE_SHA}" -ne 40 ] || ! printf '%s' "$RELEASE_SHA" | grep -qE '^[0-9a-f]{40}$'; then
+ echo "::error::client_payload.sha is missing or not a full commit SHA — refusing to build from default-branch HEAD. The dispatcher (release.yml trigger-pypi) must pin the release commit."
+ exit 1
+ fi
+ python3 - <<'PYEOF'
+ import json
+ import os
+ import sys
+ import urllib.request
+
+ sha = os.environ["RELEASE_SHA"]
+ repo = os.environ["GITHUB_REPOSITORY"]
+ req = urllib.request.Request(
+ f"https://api.github.com/repos/{repo}/compare/{sha}...heads/main",
+ headers={
+ "Authorization": f"Bearer {os.environ['GH_TOKEN']}",
+ "Accept": "application/vnd.github+json",
+ },
+ )
+ try:
+ with urllib.request.urlopen(req) as resp:
+ status = json.load(resp)["status"]
+ except urllib.error.HTTPError as exc:
+ # 404 = sha unknown to the repo network. Fail closed either way.
+ print(f"::error::compare API rejected sha {sha}: HTTP {exc.code}")
+ sys.exit(1)
+ # base=sha, head=main: main being "ahead" of (or "identical" to)
+ # the sha means the sha is an ancestor of main. "diverged" or
+ # "behind" means it is not.
+ if status not in ("ahead", "identical"):
+ print(
+ f"::error::pinned sha {sha} is not an ancestor of main "
+ f"(compare status: {status}) — refusing to build unreviewed code"
+ )
+ sys.exit(1)
+ print(f"Pinned sha is on main (compare status: {status})")
+ PYEOF
+ echo "Building from pinned release commit $RELEASE_SHA"
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
+ ref: ${{ github.event.client_payload.sha }}
persist-credentials: false
- name: Install build dependencies
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 51bde08df8..baa5a43773 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -735,9 +735,18 @@ jobs:
# `set -e` does NOT exit on a failing command substitution in an
# assignment, so wrap with explicit failure handling.
+ # target_commitish: for a tag that does not exist yet (the normal
+ # case), generate-notes otherwise resolves the commit range
+ # against default-branch HEAD at call time — after a delayed
+ # approval the auto PR list would include PRs merged AFTER the
+ # gated commit (the notes-side sibling of the dispatch-time-HEAD
+ # drift fixed in this change). Pinning it keeps the PR list
+ # consistent with the wheel/image/tag. Ignored when the tag
+ # already exists.
if ! AUTO_BODY=$(gh api -X POST \
"/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
-f tag_name="${RELEASE_TAG}" \
+ -f target_commitish="${GITHUB_SHA}" \
-q .body); then
echo "ERROR: gh api generate-notes failed for $RELEASE_TAG" >&2
exit 1
@@ -1039,7 +1048,16 @@ jobs:
while IFS= read -r -d '' f; do
CONTAINER_SBOMS+=("$f")
done < <(find . -maxdepth 1 -name 'sbom-container*.spdx.json' -print0)
+ # --target pins the git tag this call MINTS to the gated release
+ # commit. Without it, the Releases API tags default-branch HEAD
+ # at create-release time — which, after a human-paced approval
+ # delay, is a LATER, un-gated commit: the tag-side twin of the
+ # PyPI dispatch-time-HEAD drift fixed in this same change (on
+ # v1.9.0 that would have tagged a commit 4 PRs past the one the
+ # gates ran against). Ignored when the tag already exists (e.g.
+ # tag-push-triggered runs), so it is safe in every trigger mode.
gh release create "$RELEASE_TAG" \
+ --target "$GITHUB_SHA" \
--repo "$GITHUB_REPOSITORY" \
--title "Release $RELEASE_VERSION" \
--notes-file "$NOTES_FILE" \
@@ -1283,6 +1301,7 @@ jobs:
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
RELEASE_TAG: ${{ needs.build.outputs.tag }}
+ RELEASE_SHA: ${{ github.sha }}
with:
# PAT_TOKEN: repository_dispatch from a workflow run cannot be
# fired with GITHUB_TOKEN — the API rejects it to prevent
@@ -1298,12 +1317,23 @@ jobs:
// current pipeline only releases stable versions through this
// dispatch — true prereleases (if added later) would need a
// separate trigger path that flips this flag.
+ //
+ // `sha` pins publish.yml's checkout to the release commit.
+ // repository_dispatch runs on default-branch HEAD *at dispatch
+ // time*, and the `release` env approval is human-paced — on
+ // v1.9.0 the approval came ~30h after the release commit, so
+ // publish.yml built from a HEAD that was 4 PRs ahead of the
+ // tag: PyPI 1.9.0 contains code that is not in the v1.9.0
+ // tag, Docker image, or release notes. The SHA (not the tag)
+ // must be passed because create-release creates the git tag
+ // only AFTER PyPI succeeds — the tag does not exist yet here.
await github.rest.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: 'publish-pypi',
client_payload: {
tag: process.env.RELEASE_TAG,
+ sha: process.env.RELEASE_SHA,
prerelease: false
}
});
@@ -1422,9 +1452,23 @@ jobs:
const pypi = process.env.PYPI_RESULT || 'unknown';
const title = `PyPI publish failure for ${tag}`;
+ // publish.yml fails closed without a full 40-hex client_payload.sha
+ // (the pinned release commit — NOT main HEAD, which may have moved
+ // during the approval wait). Embed the exact ready-to-paste
+ // re-dispatch command so an on-call maintainer under incident
+ // pressure cannot follow a stale two-field payload shape.
+ const redispatch = '```\ngh api repos/' + owner + '/' + repo + '/dispatches \\\n'
+ + " -f event_type=publish-pypi \\\n"
+ + " -F 'client_payload[tag]=" + tag + "' \\\n"
+ + " -F 'client_payload[sha]=" + context.sha + "'\n```";
const action = pypi === 'timed_out'
- ? '**Suggested action:** publish.yml did not complete within 40 minutes. Check the [Actions tab](https://github.com/' + owner + '/' + repo + '/actions) — if the run never appeared, this likely indicates a dispatch issue; re-trigger via `repository_dispatch` event_type `publish-pypi`. If still running, no action may be needed.'
- : '**Suggested action:** Inspect publish.yml logs in the [Actions tab](https://github.com/' + owner + '/' + repo + '/actions), fix the underlying cause, then either (a) re-dispatch publish.yml with the same tag via `repository_dispatch` and re-run release.yml to complete create-release, or (b) manually publish the GitHub Release if Docker promote also succeeded.';
+ ? '**Suggested action:** publish.yml did not complete within 40 minutes. Check the [Actions tab](https://github.com/' + owner + '/' + repo + '/actions)'
+ + ' — if the run never appeared, this likely indicates a dispatch issue; re-trigger with:\n' + redispatch
+ + '\nIf still running, no action may be needed.'
+ : '**Suggested action:** Inspect publish.yml logs in the [Actions tab](https://github.com/' + owner + '/' + repo + '/actions), fix the underlying cause,'
+ + ' then either (a) re-dispatch publish.yml with:\n' + redispatch
+ + '\nand re-run release.yml to complete create-release, or (b) manually publish the GitHub Release if Docker promote also succeeded.'
+ + ' See docs/RELEASE_GUIDE.md "Recovery from PyPI failure".';
const body = `## PyPI publish failed for ${tag}\n\nResult: \`${pypi}\`\n\nNote: At this point in the atomicity flow, Docker promote (publish-docker job) has already succeeded — the Docker release tags exist and are signed. Only PyPI and the GitHub Release are missing.\n\n${action}`;
diff --git a/docs/RELEASE_GUIDE.md b/docs/RELEASE_GUIDE.md
index 7cfd0a2087..53a14025a3 100644
--- a/docs/RELEASE_GUIDE.md
+++ b/docs/RELEASE_GUIDE.md
@@ -99,11 +99,16 @@ succeeded, PyPI failed. At this point Docker `:1.6.9` / `:1.6` /
`monitor-pypi` opens a tracking issue labeled `ci-cd`. To recover:
1. Inspect the `publish.yml` workflow run, fix the underlying cause.
-2. Manually re-dispatch PyPI publish:
+2. Manually re-dispatch PyPI publish. `client_payload[sha]` is REQUIRED
+ (publish.yml fails closed without it) and must be the full 40-hex
+ release commit — the commit the failed `release.yml` run built, NOT
+ current main HEAD (main may have moved during the approval wait).
+ Get it with `gh run view <release-run-id> --json headSha`:
```bash
gh api repos/LearningCircuit/local-deep-research/dispatches \
-f event_type=publish-pypi \
- -F 'client_payload[tag]=v<X.Y.Z>'
+ -F 'client_payload[tag]=v<X.Y.Z>' \
+ -F 'client_payload[sha]=<40-hex release commit>'
```
3. Once PyPI publishes successfully, manually create the GitHub Release
from the existing tag (the SBOM/sig/provenance artifacts are still