Skip to content

Commit 4ab7129

Browse files
ci(docs-deploy): retry a Vercel upload that dies on a connection failure, and name the cause when it keeps failing (#38826)
<!-- claude-projects-attribution: {"github_login":"huangyiirene"} --> _Requested by **Irene** · [project thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67xYKeQBd9mhFCVMsawYWmMsa)_ Fixes #36022 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户无感:文档站部署上传失败时会自动重试,最多 3 次;读者只会看到文档站恢复更新。 - 为什么做:文档站已连续 3 次定时部署失败,从 11-30 06:59Z 起就没更新。日志显示每次都是某一个上传请求 300 秒没有回应,Vercel 命令行工具不重试这种错误,直接放弃整个部署。 - 出错会怎样:重试只针对还没创建出部署时的连接失败;一旦部署已创建、或遇到令牌失效等其他错误,都不重试、立即报错,避免重复发布。三次都失败时,报错写明每次用时和失败的那一行,原因仍待查。撤回本 PR 即还原。 - 要你做的:这是部署流程文件的改动,需要你批准后才能合并。合并后要不要手动跑一次 Docs Deploy,由座位决定。 ## What I read - The card, triage's comments 7288839768 and 7298197294, and seat 4's reading 7065138531 (11-21). - The deploy-step logs of the three failed runs (46421807466, 46487702664, 46551161614), the two green runs before them (46370316694 at 06:59Z, 46331835071 at 00:56Z), and the two 11-21 failures (44846520026, 44877001751). - The upload code in the published `vercel@60.1.3` bundle (`npm pack`, `dist/chunks/chunk-U6AYMUHX.js`: `uploadFiles`, `isClientNetworkError`). | Run | Head | Result | Upload began | Last progress line | `fetch failed` | From upload start | |:--|:--|:--|:--|:--|:--|:--| | 46370316694 | 5a77a70 | green | 07:06:09.9 | 100% at 07:06:58.2 | none | Ready at 07:07:17 (74 s step) | | 46421807466 | 8426fa0 | failure | 12:52:41.4 | 100% at 12:53:45.8 | 12:57:43.6 | 302.2 s | | 46487702664 | 8455490 | failure | 18:50:22.7 | 100% at 18:51:24.1 | 18:55:24.3 | 301.5 s | | 46551161614 | d97aaae | failure | 01:16:53.9 | 50% at 01:17:20.9 | 01:21:56.0 | 302.1 s | Findings: - **Measured:** all three failures stop 301-302 s after the `Uploading [---]` line, with one `fetch failed` (no HTTP status, no 429, no size or quota message), then `AbortError` for the other uploads in flight (46551161614 also shows 71 `Upload aborted` lines for the queued ones; the other two show 2 `AbortError` and no `Upload aborted`). In two of them every byte had been sent a minute earlier; the step then waited about 4 minutes with no output. A green upload of the same size takes about 50-60 s. - **Inferred:** 300 s is the default response timeout of Node's fetch (undici `headersTimeout` / `bodyTimeout`). So one request from the first batch got no answer at all, and the timeout fired. The CLI prints `fetch failed` without its cause, so the timeout type is not printed in the log. This is not the CLI's own upload timeout: 60.1.3 sets none on file uploads. It is not a reset either, since a reset would fail early. - **Measured (CLI source):** `uploadFiles` retries a failed file (5 retries) only when the error text, or its cause, contains ETIMEDOUT, ECONNRESET, ECONNREFUSED, ENOTFOUND, EAI_FAIL, `socket hang up` or `network socket disconnected`. Any other error goes to "Other error, bailing": it aborts every in-flight upload, which is where the `AbortError` and `Upload aborted` lines come from, and the deploy exits 1. An undici timeout matches none of those texts. So one unanswered request fails the whole deploy, even though the CLI has a retry loop. - **The 11-21 failures are a different shape:** they stopped 56 s and 71 s in, which is a dropped connection, not the 300 s stall. The CLI did not retry them either. - **What changed between 5a77a70 (green) and 8426fa0 (first red):** nothing on our side that the logs show. The workflow is the same, CLI 60.1.3 and Node 22.23.5 are the same, and the runner image is the same (`ubuntu26/20261122.9`, which also deployed the green 00:56Z and 06:59Z runs). The output grew by 48 deployment files and 2.4 MiB (9655 → 9703 files, 473.3 → 475.7 MiB distinct, from the measurement step). The failures came from three different runner regions (northcentralus, westus2, centralus). Why the request went unanswered is NOT MEASURED: the network path, Vercel's upload endpoint, or one file that stalls every time are all still open (three runs in a row stopped at the same point, and a retry re-sends only what the API says it lacks, so a per-file stall is not ruled out). ## What changes `.github/workflows/docs-deploy.yml`, the `Deploy the prebuilt output to production` step only. The measurement step is unchanged. - **Bounded retry, 3 attempts, waiting 30 s and then 60 s.** Each attempt is a new CLI process with new connections, and it asks the API again which files are missing. The logs show single, isolated stalls (green runs before and between, at different hours), so a fresh attempt is the remedy they support. No log measures the right wait, so the waits are kept short, enough for a new connection pool, so that the worst case fits the job clock (see budget below). - **Retries only when the attempt printed nothing on stdout** (CLI 60.1.3 prints only the deployment URL there, at `created`; any stdout counts as a created deployment, L2 N5) AND either its fatal error line (`Error:` / `TypeError:` at line start, not a warning earlier in stderr) carries a connection-failure text (`fetch failed`, ECONNRESET, ETIMEDOUT, `socket hang up`, `other side closed`) or the attempt hit its own cap. The fatal lines are matched from a here-string, not a pipe: under `pipefail`, `printf | grep -m1` reads false once the lines pass the 64 KiB pipe buffer (L2 S2). `Upload aborted` and `AbortError` are deliberately not on the list: they follow ANY bail, including an HTTP 4xx on one file. - **Never retried once a deployment exists** (L2 S1). CLI 60.1.3 prints the URL at `created`, before Building, Ready and Aliased, so an attempt that printed a URL and then failed (a status poll's `fetch failed`, or the cap while waiting for Ready) has a deployment Vercel goes on to finish, and a retry would publish a second one. That run fails with an `::error::` naming the URL and saying its final state is unknown, and writes `url=` so the run summary shows it. - **Also never retried:** a refused token, a config error, an HTTP error with a message (the `::error::` quotes the CLI's first fatal line), and an exit 0 that printed no URL (the `::error::` says whether a deployment exists is unknown). No message claims production kept its previous deployment unless that is known. - **Each attempt is capped at 6 minutes** (`timeout --kill-after=30s 6m`, which signals the CLI's whole process group). A failed attempt took 307-312 s (jobs API step times) and a green one 74 s. The cap only stops a hang somewhere other than the upload (undici already ends a stalled upload at 300 s) from using up the job's 30 minutes. **No longer timeout:** a request with no answer for 300 s, when the whole upload takes 60 s, is stalled, not slow. Waiting longer would only delay the failure. - **Budget:** the deploy step started 5:12-6:29 into the failed runs. Worst case, counting `--kill-after`, is 3 × 6.5 min + 90 s = 21 min, about 27.5 min with the build, inside the job's unchanged `timeout-minutes: 30`. The expected stall path is 3 × ~310 s + 90 s ≈ 17 min. - **The failure says what it saw.** A deploy that needed a retry stays green with a `::warning::` that lists each earlier attempt (its failing line and seconds), so a recovered abort is still visible on the run page. When all attempts fail, the `::error::` lists every attempt's failing line and time, says no attempt got a deployment URL back (so the run created no deployment the CLI knows of), and explains the two shapes: ~300 s means an upload request that got no answer within Node fetch's timeout, and a minute or so in means a dropped connection. It does not name a cause. It points at the next reading if this repeats: which file the stalled request carried (a `--debug` run logs `File <sha> (<name>) uploaded` per file, and the stalled one never gets that line). Exit 137 is `--kill-after`'s SIGKILL; an out-of-memory kill would also read 137 and be labelled the cap (L2 N2, noted in the comment). stderr is still streamed live (`tee`), so the log keeps the per-line timestamps this reading was made from. - **CLI stays pinned at 60.1.3.** The same version deployed the ten green runs before the first failure, so the logs give no reason to move it. Newer majors (66.x and later) also replace the JS CLI with a native-binary launcher (`@vercel/vc-native-*` optionalDependencies), so the upload code changes entirely and could not be read here. Moving the pin is a separate reviewed change. - `skip-changeset`: a workflow file, nothing publishes. ## Tests - The step's `run:` block, extracted from the YAML and run under `bash -e` (the runner's shell) with a fake `npx` on `PATH`, one scenario per run: - `ok`: 1 attempt, exit 0, `url=` written. - `stall,ok` (`fetch failed` then success): 2 attempts, exit 0, `url=` written, `::warning::` names attempt 1. - `stall,stall,stall`: 3 attempts, exit 1, `::error::` lists all three. - `auth` (a non-network `Error:`): 1 attempt, exit 1, no retry, `::error::` quotes the CLI line. - `nourl` (exit 0 with empty stdout): 1 attempt, exit 1, no retry. - `hang,ok` with the cap at 2 s: attempt 1 killed by `timeout` (the grandchild `sleep` went with it, and `tee` returned), attempt 2 deploys, exit 0. - `stall2` (run 46487702664's shape: `Error: This operation was aborted`, then `TypeError: fetch failed`), then `ok`: retried, exit 0. - `postcreate` (URL on stdout, then `Error: fetch failed`, exit 1): 1 attempt, exit 1, no retry, `::error::` names the URL, `url=` written. - `posthang` (URL on stdout, then a hang) with the cap at 2 s: 1 attempt, exit 1 (124 inside), no retry, `::error::` names the URL and the cap. - `warnauth` (a `WARN! ... fetch failed` warning line, then a non-network `Error:`): 1 attempt, exit 1, no retry. - `bigfatal` (`Error: fetch failed`, then 2000 more `Error:` lines, about 130 KB), then `ok`: retried, exit 0. The same case on 702a8ff (the pipe) went red with "not a connection failure", so the case reproduces S2. - `prefixurl` (stdout `Deployed to https://…`, then `Error: fetch failed`, exit 1): 1 attempt, no retry, `::error::` names the extracted URL. - `shellcheck -s bash` on the extracted block: clean. - The YAML parses, and the step's `env` reads `DEPLOY_ATTEMPTS: '3'` and `ATTEMPT_LIMIT: '6m'`. - No check-run runs this step (Docs Deploy runs only from `main`). Its first real run is the first deploy after merge. Per the card's thread I have not run or dispatched Docs Deploy. ## Verification Read first: the new comment block and step above `Publish the run to the summary` in `.github/workflows/docs-deploy.yml`. Two-minute check after merge: on the next Docs Deploy run (scheduled, or "Run workflow" on `main` when the seat decides), the deploy step logs `Deploy attempt 1 of 3` and ends at `Deployed:`. If it needed a retry, a warning annotation says so. If every attempt fails, the error annotation says which shape each attempt took. <details><summary>Gates at 932a261</summary> - `node scripts/pm/dispatch-gates.mjs --commands`: 36 derived families, each run with its exit code captured before any pipe (`NODE_OPTIONS=--max-old-space-size=8192`), all exit 0. `--ran`: 36 derived, 36 run, 0 NOT-MEASURED, 0 UNRUN. - `node scripts/check-commit-card-trailers.mjs --range origin/main..HEAD`: clean. - `node scripts/pm/overlap-check.mjs`: VERDICT clean, merges cleanly into origin/main (7625001). - `dispatch-gates.mjs --tier .github/workflows/docs-deploy.yml`: no path-derived mandate. The path is a governed surface (Tier H). - The same 36 families were derived and green at 239bde1 and 702a8ff; on those heads every CI check-run concluded success (30 each) or skipped by path. - Every family CI runs: this PR's check-runs. </details> --- _Generated by [Claude Code](https://claude.ai/code)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01J8VVAm7mxkbu9XywnqFzRc <!-- signed: repo:objectstack@huangyiirene · huangyiirene · session_01J8VVAmaT5PwLmXgonaxjYG --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1de73c0 commit 4ab7129

1 file changed

Lines changed: 129 additions & 6 deletions

File tree

‎.github/workflows/docs-deploy.yml‎

Lines changed: 129 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,141 @@ jobs:
222222
echo '```'
223223
} >> "$GITHUB_STEP_SUMMARY"
224224
225+
# ## A bounded retry of the upload, and a failure that names what it saw
226+
#
227+
# Read from the logs of the failed runs 46421807466, 46487702664 and
228+
# 46551161614 (2026-11-30 12:46Z to 2026-12-01 01:10Z, CLI 60.1.3,
229+
# Node 22.23.5, the same runner image as the green runs before them):
230+
# each upload stopped with ONE `fetch failed` 301-302 s after its
231+
# `Uploading [---]` line, then `AbortError` for the other uploads in
232+
# flight (one log also shows `Upload aborted` for the queued ones). A
233+
# green upload of the same ~540 MB finishes in about 60 s, so that
234+
# request was not slow: nothing answered it. 300 s is Node fetch's
235+
# default response timeout (undici's headersTimeout / bodyTimeout); that
236+
# it fired is inferred from the timing, since the CLI prints `fetch
237+
# failed` without its cause. The 2026-11-21 failures stopped 56 s and
238+
# 71 s in: another `fetch failed` with no HTTP status. WHY the request
239+
# went unanswered is not shown: the network path, Vercel's upload
240+
# endpoint, or one file that stalls every time are all still open.
241+
#
242+
# The CLI retries a failed file upload only when the error text matches
243+
# ETIMEDOUT, ECONNRESET, ECONNREFUSED, ENOTFOUND, EAI_FAIL, `socket hang
244+
# up` or `network socket disconnected` (`isClientNetworkError` in the
245+
# 60.1.3 bundle). An undici timeout ("Headers Timeout Error") matches
246+
# none of them, and neither did the cause of any failure above, so the
247+
# CLI aborted every other upload and exited 1: one stalled request
248+
# fails the whole deploy.
249+
#
250+
# So this step runs the deploy up to DEPLOY_ATTEMPTS times, and retries
251+
# ONLY when the attempt never got a deployment URL AND either its fatal
252+
# error line (`Error:` / `TypeError:`, not a warning earlier in stderr)
253+
# carries a connection-failure text or it hit its own attempt cap. Each
254+
# attempt is a new CLI process with new connections, and it asks the
255+
# API again which files it lacks (the CLI's `missing_files` exchange)
256+
# and uploads only those; how many that is depends on what Vercel kept
257+
# from the aborted attempt, which no log shows.
258+
#
259+
# Never retried: CLI 60.1.3 prints the deployment URL at `created`,
260+
# before Building, Ready and Aliased, so an attempt that printed a URL
261+
# and then failed (a status poll's `fetch failed`, a cap hit waiting for
262+
# Ready) has a deployment that Vercel goes on to finish; a retry would
263+
# publish a second one. That run fails naming the URL, its final state
264+
# unknown. Also never retried: any other error (a refused token, a
265+
# config error, an HTTP error with a message) and an exit 0 with no URL.
266+
#
267+
# A deploy that needed a retry is green with a warning, so a recovered
268+
# abort stays visible on the run page. When every attempt fails, the
269+
# error lists each attempt's time and failing line. If retries keep
270+
# failing the same way, the next reading is which file the stalled
271+
# request carried: a run with `--debug` logs `File <sha> (<name>)
272+
# uploaded` for each file, and the stalled one never gets that line.
273+
#
274+
# The CLI pin stays at 60.1.3: the same version deployed the ten green
275+
# runs before the first failure, so the logs give no reason to move it.
276+
#
277+
# Budget: the deploy step started 5-6.5 minutes into the failed runs; a
278+
# failed attempt took 307-312 s and a green one 74 s. ATTEMPT_LIMIT caps
279+
# one attempt (`timeout` signals the CLI's whole process group, and
280+
# `--kill-after` follows with SIGKILL 30 s later) so a hang outside the
281+
# upload cannot eat the job: 3 x 6.5 min + the 30 s and 60 s waits is
282+
# 21 minutes, about 27.5 with the build before it, inside the job's 30.
283+
# Exit 137 is that SIGKILL; an out-of-memory kill of the CLI would also
284+
# read 137 and be labelled the cap.
225285
- name: Deploy the prebuilt output to production
226286
id: deploy
227287
env:
228288
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
289+
DEPLOY_ATTEMPTS: '3'
290+
ATTEMPT_LIMIT: '6m'
229291
run: |
230292
set -euo pipefail
231-
# stdout is the deployment URL and nothing else; progress goes to
232-
# stderr. `set -e` fails the step on a non-zero exit before the URL
233-
# is used.
234-
url=$(npx --yes "vercel@${VERCEL_CLI_VERSION}" deploy --prebuilt --prod --token="$VERCEL_TOKEN")
235-
echo "url=${url}" >> "$GITHUB_OUTPUT"
236-
echo "Deployed: ${url}"
293+
url_file="$RUNNER_TEMP/vercel-deploy-url.txt"
294+
err_file="$RUNNER_TEMP/vercel-deploy-stderr.txt"
295+
retry_waits=(30 60)
296+
transient='fetch failed|ECONNRESET|ETIMEDOUT|socket hang up|other side closed'
297+
history=""
298+
for attempt in $(seq 1 "$DEPLOY_ATTEMPTS"); do
299+
echo "Deploy attempt ${attempt} of ${DEPLOY_ATTEMPTS} ($(date -u +%H:%M:%SZ))"
300+
started=$(date +%s)
301+
status=0
302+
# stdout is the deployment URL and nothing else, into url_file.
303+
# Progress and errors go to stderr: shown live in this log
304+
# (its timestamps are how the 300 s stall was read) and kept in
305+
# err_file for the retry decision.
306+
timeout --kill-after=30s "$ATTEMPT_LIMIT" \
307+
npx --yes "vercel@${VERCEL_CLI_VERSION}" deploy --prebuilt --prod --token="$VERCEL_TOKEN" \
308+
2>&1 >"$url_file" | tee "$err_file" >&2 || status=${PIPESTATUS[0]}
309+
elapsed=$(( $(date +%s) - started ))
310+
# Anything on stdout means the CLI reached `created` (it prints
311+
# nothing else there); `url` is the address it printed, for the
312+
# messages and the step output.
313+
created=""
314+
if grep -q '[^[:space:]]' "$url_file"; then created=yes; fi
315+
url=$(grep -oE 'https://[^[:space:]]+' "$url_file" | tail -n 1 || true)
316+
# The CLI's fatal error lines; warnings it carries on past are not
317+
# among them.
318+
fatal=$(grep -E '^(Error|TypeError): ' "$err_file" || true)
319+
first_fatal=${fatal%%$'\n'*}
320+
if [ "$status" -eq 0 ] && [ -n "$url" ]; then
321+
echo "url=${url}" >> "$GITHUB_OUTPUT"
322+
echo "Deployed: ${url}"
323+
if [ "$attempt" -gt 1 ]; then
324+
echo "::warning::Docs deployed on attempt ${attempt} of ${DEPLOY_ATTEMPTS}, after a retry.${history}"
325+
fi
326+
exit 0
327+
fi
328+
if [ -n "$created" ]; then
329+
# A deployment exists: see the header. Never retried.
330+
url=${url:-$(grep -m1 '[^[:space:]]' "$url_file")}
331+
reason=${first_fatal:-no error line}
332+
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then reason="stopped by the ${ATTEMPT_LIMIT} attempt cap"; fi
333+
echo "url=${url}" >> "$GITHUB_OUTPUT"
334+
echo "::error::vercel deploy created the deployment ${url} and then failed (exit ${status} after ${elapsed} s: ${reason}). Its final state (Ready, aliased to production) is unknown: open it in the Vercel dashboard. Not retried, since a retry would publish a second deployment."
335+
exit 1
336+
fi
337+
if [ "$status" -eq 0 ]; then
338+
echo "::error::vercel deploy exited 0 but printed no deployment URL, so whether it created a deployment is unknown: check the Vercel dashboard. Not retried, since a retry could publish a second deployment."
339+
exit 1
340+
fi
341+
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then
342+
cause="stopped by the ${ATTEMPT_LIMIT} attempt cap, exit ${status}"
343+
elif line=$(grep -m1 -E "$transient" <<<"$fatal"); then
344+
cause="${line}"
345+
else
346+
first=$(grep -m1 . <<<"$fatal" || tail -n 1 "$err_file" || true)
347+
echo "::error::vercel deploy failed (exit ${status}) before printing a deployment URL, with an error that is not a connection failure, so it is not retried: ${first:-no stderr}"
348+
exit 1
349+
fi
350+
history="${history} Attempt ${attempt} failed after ${elapsed} s (${cause})."
351+
echo "Attempt ${attempt} failed after ${elapsed} s: ${cause}."
352+
if [ "$attempt" -lt "$DEPLOY_ATTEMPTS" ]; then
353+
wait_s=${retry_waits[$(( attempt - 1 ))]:-60}
354+
echo "Retrying in ${wait_s} s."
355+
sleep "$wait_s"
356+
fi
357+
done
358+
echo "::error::The Vercel upload failed on all ${DEPLOY_ATTEMPTS} attempts.${history} No attempt got a deployment URL back (CLI ${VERCEL_CLI_VERSION} prints it the moment a deployment is created), so this run created no deployment that the CLI knows of. A stop about 300 s after the Uploading line is one upload request that got no answer within Node fetch's 300 s timeout; a stop a minute or so in is a dropped connection. Why is not shown: if this repeats, find which file the stalled request carried (see the comment above this step)."
359+
exit 1
237360
238361
- name: Publish the run to the summary
239362
if: always()

0 commit comments

Comments
 (0)