From b45d21d5fb39ca0590e653ca33d6f72bb65d117b Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 10 Nov 2026 18:31:23 +0800 Subject: [PATCH] release: the dispatch to magpie-releases waits out the API rate limit trigger-release dispatched with peter-evans/repository-dispatch and RELEASES_REPO_TOKEN, the owner's PAT. It shares the 5,000/hr core limit with every agent session running gh as the owner, and on 11-10 the limit ran out: v0.1.3561, 3566, 3568, 3569, 3571 and 3573 failed at that step with "API rate limit exceeded for user ID 1206493" and have no release in magpie-releases. They are not dispatched again: a release published after a newer one would become Latest, and their commits are in newer releases. The step is now curl to POST /repos/yetone/magpie-releases/dispatches with the same token and payload (built with jq). A 403 or 429 that is a rate limit (retry-after, x-ratelimit-remaining 0, or "rate limit" in the body) waits until retry-after or x-ratelimit-reset (60s when neither is given) plus 5s and tries again, up to 65 minutes in all. Any other non-2xx, or a curl failure, fails at once with the status and body; the token is never printed. The job has timeout-minutes 75. Other API calls checked: mirror-release and the notes issue use GITHUB_TOKEN (its own per-repo limit), docker.yml uses github.token, and no other workflow uses RELEASES_REPO_TOKEN. Run: the step's run block, extracted from the YAML with PyYAML, against a local Python fake server. 403 with x-ratelimit-remaining 0 and a reset 3s out, then 204: waited 8s, succeeded on try 2. 429 retry-after 2, then 403 rate limit, then 204: waited 7s and 8s, succeeded on try 3. 404 and a 403 "Resource not accessible" (no rate-limit sign): failed at once after one request with status and body. A reset 2h out: failed at once as past the wait. A refused connection: failed at once with curl's exit. The payload the server got was {"event_type":"release","client_payload":{"ref":"v0.1.9999","version":"0.1.9999"}}, and no log held the token. bash -n ok; actionlint ok for the new step (its only findings are two SC2086 infos in Get version, the same at the base). Run locally: mote refused ssh at the time. Broken by hand: with the rate-limit detection never matching, the first 403 rate limit failed at once. Not tried: the real dispatch endpoint. It runs on the next tag. --- .github/workflows/release.yml | 70 +++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 538e0cebe..b9c169ebe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,6 +21,8 @@ on: jobs: trigger-release: runs-on: ubuntu-latest + # room for the dispatch to wait out the owner's API rate limit (65 min) + timeout-minutes: 75 outputs: version: ${{ steps.version.outputs.version }} ref: ${{ steps.version.outputs.ref }} @@ -45,13 +47,67 @@ jobs: echo "Triggering release for version: $VERSION (ref: $REF)" - name: Trigger release workflow in magpie-releases - uses: peter-evans/repository-dispatch@v3 - with: - # PAT with contents write on yetone/magpie-releases. - token: ${{ secrets.RELEASES_REPO_TOKEN }} - repository: yetone/magpie-releases - event-type: release - client-payload: '{"ref": "${{ steps.version.outputs.ref }}", "version": "${{ steps.version.outputs.version }}"}' + env: + # PAT with contents write on yetone/magpie-releases. It is the + # owner's, so it shares the 5,000/hr core limit with every `gh` + # the owner runs: v0.1.3561 to v0.1.3573 failed here with "API + # rate limit exceeded" and never got a release. A rate-limited + # answer waits for the reset and tries again, up to 65 minutes. + TOKEN: ${{ secrets.RELEASES_REPO_TOKEN }} + API_URL: ${{ github.api_url }} + REF: ${{ steps.version.outputs.ref }} + VERSION: ${{ steps.version.outputs.version }} + run: | + set -euo pipefail + payload=$(jq -nc --arg ref "$REF" --arg version "$VERSION" \ + '{event_type: "release", client_payload: {ref: $ref, version: $version}}') + url="$API_URL/repos/yetone/magpie-releases/dispatches" + tmp=$(mktemp -d) + deadline=$(( $(date +%s) + ${DISPATCH_MAX_WAIT:-3900} )) + header() { awk -v k="$1" -F': *' 'tolower($1) == k { v = $2 } END { sub(/\r$/, "", v); print v }' "$tmp/headers"; } + for try in $(seq 1 100); do + code=$(curl -sS -o "$tmp/body" -D "$tmp/headers" -w '%{http_code}' -X POST \ + -H "Authorization: Bearer $TOKEN" \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + --data "$payload" "$url") || { echo "::error::dispatch request failed (curl exit $?)"; exit 1; } + if [[ "$code" == 2* ]]; then + echo "Dispatched release for $REF (HTTP $code, try $try)" + exit 0 + fi + retry_after=$(header retry-after) + remaining=$(header x-ratelimit-remaining) + reset=$(header x-ratelimit-reset) + limited= + if [[ "$code" == 403 || "$code" == 429 ]]; then + if [[ -n "$retry_after" || "$remaining" == 0 ]] || grep -qi 'rate limit' "$tmp/body"; then + limited=1 + fi + fi + if [[ -z "$limited" ]]; then + echo "::error::dispatch failed with HTTP $code" + cat "$tmp/body"; echo + exit 1 + fi + now=$(date +%s) + if [[ "$retry_after" =~ ^[0-9]+$ ]]; then + until=$(( now + retry_after )) + elif [[ "$reset" =~ ^[0-9]+$ ]] && (( reset > now )); then + until=$reset + else + until=$(( now + 60 )) # a secondary limit may give neither + fi + until=$(( until + 5 )) + if (( until > deadline )); then + echo "::error::rate limited (HTTP $code) until $(date -u -d "@$until" 2>/dev/null || echo "$until"), past the wait allowed" + cat "$tmp/body"; echo + exit 1 + fi + echo "::warning::rate limited (HTTP $code, try $try); waiting $(( until - now ))s for the limit to reset" + sleep $(( until - now )) + done + echo "::error::dispatch still rate limited after $try tries" + exit 1 - name: Output status run: echo "Watch the build at https://github.com/yetone/magpie-releases/actions"