From 1b3ed6e9e4978faac789a4906c26044b2c0f677b Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sun, 25 Oct 2026 00:29:22 +0800 Subject: [PATCH 1/4] fix(release): label-gated head-tree publish for conflicted carve-out ship PRs A patch lane cut from an old tag whose fixes already landed on master conflicts with master at ship time: the merge button refuses, resolving on the lane would leak unreleased master work into the published head tree, and resolving on master needs a direct master push. Also, lanes cut from old tags carry an old release-bugfix.yml that predates the bugfix-v* marker, so even a clean merge would silently skip publish. - add pull_request_target [labeled] trigger: the carve-out-ship label on an OPEN same-repo ship PR (bugfix-v* / bugfix-release/* head) publishes the PR head tree with every existing guard + full gate, no merge needed - run the master copy of the workflow (pull_request_target), fixing the old-tag lane marker gap for this path - manifest sync check fails open with a notice on pre-#4449 trees (same existence-guard philosophy as release-manual's lane guard, #4576) - annotate the ship PR after publish (audit trail; publish != merge) - document the label path in reference/release.md (carve-out + ship-the-lane) --- .github/workflows/release-bugfix.yml | 82 ++++++++++++++++++++++++++-- reference/release.md | 20 ++++++- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release-bugfix.yml b/.github/workflows/release-bugfix.yml index 4214236e0b..c30142a189 100644 --- a/.github/workflows/release-bugfix.yml +++ b/.github/workflows/release-bugfix.yml @@ -21,8 +21,21 @@ name: Bugfix Release (carve-out) # deliberately does not match it, so merging the PR cannot double-publish the # post-merge master through the normal channel. # -# Emergency fallback: manual workflow_dispatch against an explicitly chosen ref -# (a human picks the exact ref in the Actions UI; every guard below still runs). +# CONFLICTED SHIP PRs (label path, #4576 follow-up): a patch lane cut from an +# OLD tag whose fixes already landed on master can CONFLICT with master on +# merge -- GitHub's merge button then refuses, resolving on the lane would +# absorb unreleased master work into the published head tree, and resolving on +# master needs a direct master push. For that case the ship PR can be +# published AS THE HEAD TREE by adding the `carve-out-ship` label (a +# triage-capable human action; `labeled` fires on ADD only). pull_request_target +# runs THIS master copy of the workflow, so lanes cut from old tags -- whose +# own release-bugfix.yml predates the bugfix-v* marker and would silently skip +# the closed-PR path -- publish correctly too. Fork PRs are still rejected and +# every guard below still runs. +# +# Patch-lane publish (formerly the emergency fallback): manual workflow_dispatch +# against an explicitly chosen ref (a human picks the exact ref in the Actions +# UI; every guard below still runs). # # Guarded so it can never: # - move `latest` backwards (target must be strictly newer than npm latest); @@ -39,6 +52,12 @@ on: pull_request: types: [closed] branches: [master] + pull_request_target: + # Label-gated head-tree publish for conflicted carve-out ship PRs -- see + # the header comment. No branches filter (pull_request_target does not + # support one); the resolve step no-ops on every other label within + # milliseconds, same as the closed-PR trigger above no-ops on every close. + types: [labeled] workflow_dispatch: inputs: fast: @@ -57,6 +76,7 @@ jobs: contents: write id-token: write actions: write + pull-requests: write # carve-out-ship label publish: annotate the ship PR steps: - name: Validate trigger + resolve the publish ref id: resolve @@ -82,6 +102,36 @@ jobs: echo "::error::fork PRs cannot use the carve-out channel (repo secrets are unavailable for them)" exit 1 fi + elif [ "$GITHUB_EVENT_NAME" = "pull_request_target" ]; then + # carve-out-ship label publish (conflicted ship PRs, #4576 follow-up): + # publish the HEAD tree with NO merge into master. `labeled` fires on + # ADD only, so reaching past the label check means a triage-capable + # actor armed it just now. + LABEL="$(jq -r '.label.name' "$GITHUB_EVENT_PATH")" + BRANCH="$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")" + SHA="$(jq -r '.pull_request.head.sha' "$GITHUB_EVENT_PATH")" + STATE="$(jq -r '.pull_request.state' "$GITHUB_EVENT_PATH")" + SAME_REPO="$(jq -r '(.pull_request.base.repo.full_name == .pull_request.head.repo.full_name)' "$GITHUB_EVENT_PATH")" + if [ "$LABEL" != "carve-out-ship" ]; then + echo "::notice::label '$LABEL' is not the carve-out-ship gate — nothing to do" + exit 0 + fi + if [ "$STATE" != "open" ]; then + echo "::notice::PR $GITHUB_EVENT_NUMBER is '$STATE' — the label gate only arms open ship PRs" + exit 0 + fi + case "$BRANCH" in + bugfix-v*) ;; # current patch lane (dual-lane model) + bugfix-release/*) ;; # legacy one-off carve-out + *) + echo "::notice::head branch '$BRANCH' is not a patch lane (bugfix-v*) or a legacy bugfix-release/* carve-out — nothing to publish" + exit 0 + ;; + esac + if [ "$SAME_REPO" != "true" ]; then + echo "::error::fork PRs cannot use the carve-out channel (repo secrets are unavailable for them)" + exit 1 + fi else BRANCH="$GITHUB_REF_NAME" SHA="" @@ -96,8 +146,11 @@ jobs: with: fetch-depth: 0 - - name: Switch to the carve-out PR head (pre-merge tree) - if: steps.resolve.outputs.proceed == 'true' && github.event_name == 'pull_request' + - name: Switch to the carve-out head tree (pre-merge / label publish) + # pull_request: pre-merge head of a MERGED ship PR (publish the exact + # reviewed tree, never the post-merge master). pull_request_target: + # head of the carve-out-ship-labeled PR (publish without merging). + if: steps.resolve.outputs.proceed == 'true' && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') run: | SHA="${{ steps.resolve.outputs.sha }}" git rev-parse --verify --quiet "${SHA}^{commit}" >/dev/null || git fetch origin "$SHA" @@ -132,7 +185,16 @@ jobs: # manifests — drift fails fast here instead of shipping a release whose # marketplace update detection never fires. See reference/release.md. if: steps.resolve.outputs.proceed == 'true' - run: node scripts/sync-codex-plugin-version.mjs --check + # #4576 follow-up: lanes cut from a pre-#4449 tag do not carry the + # manifest sync script at all -- fail-open with a notice there instead + # of MODULE_NOT_FOUND (same existence-guard philosophy as release-manual's + # lane guard). + run: | + if [ -f scripts/sync-codex-plugin-version.mjs ]; then + node scripts/sync-codex-plugin-version.mjs --check + else + echo "::notice::this tree predates #4449 (no scripts/sync-codex-plugin-version.mjs) — manifest sync check skipped for the pre-#4449 lane" + fi - name: Publish guard (monotonic + not-already-live) if: steps.resolve.outputs.proceed == 'true' @@ -261,6 +323,16 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Annotate the ship PR (label publish) + # Head-tree publish leaves the ship PR open; leave the audit trail on + # the PR itself so a later reader knows publish != merge here. + if: github.event_name == 'pull_request_target' && steps.resolve.outputs.proceed == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr comment "$GITHUB_EVENT_NUMBER" --body "Published v${{ steps.version.outputs.version }} from head ${{ steps.resolve.outputs.sha }} (pure carve-out head tree; master NOT involved). Keep this PR open as the publish record, or close it unmerged — merging into master is NOT required and may conflict by design." \ + || echo "::notice::could not annotate PR $GITHUB_EVENT_NUMBER (non-fatal)" + - name: Create GitHub Release if: steps.resolve.outputs.proceed == 'true' env: diff --git a/reference/release.md b/reference/release.md index 812643433e..42d80079e0 100644 --- a/reference/release.md +++ b/reference/release.md @@ -266,6 +266,21 @@ nothing else. ref (picked in the Actions UI) still works and runs every guard above — for when the PR dance is slower than the fire. +**Conflicted ship PRs (label publish):** a lane/carve cut from an OLD tag can +conflict with master at ship time — the fixes already landed there and master +moved on, so GitHub's merge button refuses. Resolving on the lane is FORBIDDEN +(`Never merge master into a lane` below — the publish tree must stay leak-free) +and resolving on master needs a direct master push. For that case: add the +`carve-out-ship` label to the OPEN ship PR (head branch must match `bugfix-v*` / +`bugfix-release/*`, same-repo, not a fork). `release-bugfix.yml`'s +`pull_request_target` trigger then publishes the PR's HEAD tree with every guard +above — no merge required; the PR stays open as the publish record (the workflow +leaves the audit comment on it). `pull_request_target` runs the master copy of the +workflow, so lanes cut from old tags — whose own `release-bugfix.yml` predates the +`bugfix-v*` marker and would silently skip the closed-PR path — publish correctly +too. Master syncs later via a normal metadata-only PR, or simply advances on its +next regular release (which must be higher anyway). + **Master interaction:** merging the carve-out PR brings the version bump INTO master (master then equals npm latest, so the one-click fast path's drift guard sees a clean tree again). Master advances independently on its next normal release, which MUST be @@ -330,7 +345,10 @@ lane, dispatches the FULL CI set, and opens the ship PR against master with a changelog. You merge it; `release-bugfix.yml` publishes the PRE-MERGE head tree (tag + carried fixes) and creates the fresh tag — which by derivation CLOSES this cycle: the next `backport` label automatically cuts `bugfix-v{NEXT}` from -the fresh tag. No closeout step exists because nothing is stored. +the fresh tag. No closeout step exists because nothing is stored. If the ship +PR CONFLICTS with master (fixes already landed there, master moved on): do not +resolve on the lane, do not touch master — apply the `carve-out-ship` label to +publish the head tree without merging (see the carve-out channel section). ⚠ Severe fixes riding the lane: include the release-notes entry (#1870) in the source fix PR so the carry picks transport it — the publish gate checks the From c07e5e3be80c8f9b60a1d93c482d7c69efdf3971 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sun, 25 Oct 2026 00:32:08 +0800 Subject: [PATCH 2/4] rename the publish gate label to backport-ship (backport / backport-carry family prefix) --- .github/workflows/release-bugfix.yml | 12 ++++++------ reference/release.md | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release-bugfix.yml b/.github/workflows/release-bugfix.yml index c30142a189..8d0b6baa3c 100644 --- a/.github/workflows/release-bugfix.yml +++ b/.github/workflows/release-bugfix.yml @@ -26,7 +26,7 @@ name: Bugfix Release (carve-out) # merge -- GitHub's merge button then refuses, resolving on the lane would # absorb unreleased master work into the published head tree, and resolving on # master needs a direct master push. For that case the ship PR can be -# published AS THE HEAD TREE by adding the `carve-out-ship` label (a +# published AS THE HEAD TREE by adding the `backport-ship` label (a # triage-capable human action; `labeled` fires on ADD only). pull_request_target # runs THIS master copy of the workflow, so lanes cut from old tags -- whose # own release-bugfix.yml predates the bugfix-v* marker and would silently skip @@ -76,7 +76,7 @@ jobs: contents: write id-token: write actions: write - pull-requests: write # carve-out-ship label publish: annotate the ship PR + pull-requests: write # backport-ship label publish: annotate the ship PR steps: - name: Validate trigger + resolve the publish ref id: resolve @@ -103,7 +103,7 @@ jobs: exit 1 fi elif [ "$GITHUB_EVENT_NAME" = "pull_request_target" ]; then - # carve-out-ship label publish (conflicted ship PRs, #4576 follow-up): + # backport-ship label publish (conflicted ship PRs, #4576 follow-up): # publish the HEAD tree with NO merge into master. `labeled` fires on # ADD only, so reaching past the label check means a triage-capable # actor armed it just now. @@ -112,8 +112,8 @@ jobs: SHA="$(jq -r '.pull_request.head.sha' "$GITHUB_EVENT_PATH")" STATE="$(jq -r '.pull_request.state' "$GITHUB_EVENT_PATH")" SAME_REPO="$(jq -r '(.pull_request.base.repo.full_name == .pull_request.head.repo.full_name)' "$GITHUB_EVENT_PATH")" - if [ "$LABEL" != "carve-out-ship" ]; then - echo "::notice::label '$LABEL' is not the carve-out-ship gate — nothing to do" + if [ "$LABEL" != "backport-ship" ]; then + echo "::notice::label '$LABEL' is not the backport-ship gate — nothing to do" exit 0 fi if [ "$STATE" != "open" ]; then @@ -149,7 +149,7 @@ jobs: - name: Switch to the carve-out head tree (pre-merge / label publish) # pull_request: pre-merge head of a MERGED ship PR (publish the exact # reviewed tree, never the post-merge master). pull_request_target: - # head of the carve-out-ship-labeled PR (publish without merging). + # head of the backport-ship-labeled PR (publish without merging). if: steps.resolve.outputs.proceed == 'true' && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') run: | SHA="${{ steps.resolve.outputs.sha }}" diff --git a/reference/release.md b/reference/release.md index 42d80079e0..a090cd6f4d 100644 --- a/reference/release.md +++ b/reference/release.md @@ -271,7 +271,7 @@ conflict with master at ship time — the fixes already landed there and master moved on, so GitHub's merge button refuses. Resolving on the lane is FORBIDDEN (`Never merge master into a lane` below — the publish tree must stay leak-free) and resolving on master needs a direct master push. For that case: add the -`carve-out-ship` label to the OPEN ship PR (head branch must match `bugfix-v*` / +`backport-ship` label to the OPEN ship PR (head branch must match `bugfix-v*` / `bugfix-release/*`, same-repo, not a fork). `release-bugfix.yml`'s `pull_request_target` trigger then publishes the PR's HEAD tree with every guard above — no merge required; the PR stays open as the publish record (the workflow @@ -347,7 +347,7 @@ changelog. You merge it; `release-bugfix.yml` publishes the PRE-MERGE head tree this cycle: the next `backport` label automatically cuts `bugfix-v{NEXT}` from the fresh tag. No closeout step exists because nothing is stored. If the ship PR CONFLICTS with master (fixes already landed there, master moved on): do not -resolve on the lane, do not touch master — apply the `carve-out-ship` label to +resolve on the lane, do not touch master — apply the `backport-ship` label to publish the head tree without merging (see the carve-out channel section). ⚠ Severe fixes riding the lane: include the release-notes entry (#1870) in the From 22e98806d15f981cb8ecfa0c72237f0743f1131b Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 25 Oct 2026 03:41:50 +0800 Subject: [PATCH 3/4] fix(release): restrict backport-ship label trigger to PRs targeting master Review finding on #4596: the labeled path lacked the base-branch filter the closed-PR path carries, and its comment claimed pull_request_target does not support one -- false per GitHub docs (on.. is matched against the PR base). A backport-ship label on a PR targeting any non-master branch would arm the publish path (still version-guarded, but needlessly). Add branches: [master] to match the closed-PR trigger and fix the comment. --- .github/workflows/release-bugfix.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-bugfix.yml b/.github/workflows/release-bugfix.yml index 8d0b6baa3c..49b943972e 100644 --- a/.github/workflows/release-bugfix.yml +++ b/.github/workflows/release-bugfix.yml @@ -54,10 +54,12 @@ on: branches: [master] pull_request_target: # Label-gated head-tree publish for conflicted carve-out ship PRs -- see - # the header comment. No branches filter (pull_request_target does not - # support one); the resolve step no-ops on every other label within - # milliseconds, same as the closed-PR trigger above no-ops on every close. + # the header comment. Same base-branch filter as the closed-PR trigger + # above (pull_request_target supports branches filters, matched against + # the PR base); the resolve step additionally no-ops on every other label + # within milliseconds, same as the closed-PR trigger no-ops on every close. types: [labeled] + branches: [master] workflow_dispatch: inputs: fast: From d515aeae8297d395fd2b0098966c6946857e307e Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sun, 25 Oct 2026 11:08:51 +0800 Subject: [PATCH 4/4] fix(dump): count the #4482 banner in the dump4xx byte cap (#4297) eb483c6b made every BILI_DUMP_4XX err/summary-err dump lead with DUMP_PLAINTEXT_BANNER, but the cap budget still measured only the body, so every file overshot the operator's byte knob by exactly the banner (1024-cap file => 1111 bytes) and the #4297 final-UTF-8-bytes contract plus the JSON.parse assertions went red on master (masked until the LIVE_FILES tripwire stopped failing shards first). - cappedBudget(): knob minus banner bytes (floor 0), used by both dumpRejectedBody and dumpSummaryRejection so the file on disk honors the cap - #4297 tests: stripDumpBanner before exactness/JSON asserts and banner-aware boundary budgets, matching how issue1993/reasoning-echo already consume these dumps --- src/error-dump.ts | 12 ++++++++++-- tests/error-dump.test.ts | 13 ++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/error-dump.ts b/src/error-dump.ts index 116b03f2c6..d7dba973a9 100644 --- a/src/error-dump.ts +++ b/src/error-dump.ts @@ -18,6 +18,14 @@ import { safePrefix } from "./text-safe.js"; let failCount = 0; let lastFailLog = 0; +// #4482 follow-up (#4297): the banner line is part of the file on disk, so it +// must count against the operator's byte cap — otherwise every dump exceeds +// the knob by exactly the banner and the "final UTF-8 bytes" contract breaks. +function cappedBudget(): number { + const bannerOverhead = Buffer.byteLength(DUMP_PLAINTEXT_BANNER) + 1; // banner + "\n" + return Math.max(knobDump4xxMaxBytes() - bannerOverhead, 0); +} + function warnDumpFailure(err: unknown): void { failCount++; const now = Date.now(); @@ -56,7 +64,7 @@ export function dumpRejectedBody(status: number, sessionId: string, body: string const raw = typeof body === "string" ? body : body.toString("utf8"); if (!raw) return null; try { - const cap = knobDump4xxMaxBytes(); + const cap = cappedBudget(); let text = raw; if (Buffer.byteLength(raw) <= cap) { try { text = JSON.stringify(JSON.parse(raw), null, 2); } catch { /* keep non-JSON bodies raw */ } @@ -89,7 +97,7 @@ export function dumpSummaryRejection(status: number, sessionId: string, request: if (!knobDump4xxEnabled()) return null; if (!request && !response) return null; try { - const cap = knobDump4xxMaxBytes(); + const cap = cappedBudget(); const side = (raw: string): string => { if (Buffer.byteLength(raw) > cap) return raw; try { return JSON.stringify(JSON.parse(raw)); } catch { return raw; } diff --git a/tests/error-dump.test.ts b/tests/error-dump.test.ts index 34ae245a85..2c1ccc12ab 100644 --- a/tests/error-dump.test.ts +++ b/tests/error-dump.test.ts @@ -208,11 +208,13 @@ test("#4297 main dump enforces final UTF-8 bytes including markers and pretty pr test("#4297 main dump preserves bodies that fit exactly at the byte limit", () => { process.env.BILI_DUMP_4XX = "1"; process.env.BILI_DUMP_4XX_MAX_BYTES = "1024"; + // #4482: the banner line rides along, so the body budget is the knob minus it. + const budget = 1024 - Buffer.byteLength(DUMP_PLAINTEXT_BANNER) - 1; try { - for (const raw of ["x".repeat(1024), "汉".repeat(340) + "😀", "small raw body"]) { + for (const raw of ["x".repeat(budget), "汉".repeat(Math.floor((budget - 4) / 3)) + "😀", "small raw body"]) { const out = dumpRejectedBody(400, "boundary", raw); assert.ok(out); - assert.equal(fs.readFileSync(out, "utf8"), raw); + assert.equal(stripDumpBanner(fs.readFileSync(out, "utf8")), raw); } } finally { restoreDumpEnv(); } }); @@ -232,7 +234,7 @@ test("#4297 summary cap covers both sides, JSON escaping and envelope bytes", () const out = dumpSummaryRejection(413, `summary-bytes-${i}`, request, response); assert.ok(out); assert.ok(fs.statSync(out).size <= 1024, `${i}: ${fs.statSync(out).size} bytes`); - const parsed = JSON.parse(fs.readFileSync(out, "utf8")) as { status: number; request: string; response: string }; + const parsed = JSON.parse(stripDumpBanner(fs.readFileSync(out, "utf8"))) as { status: number; request: string; response: string }; assert.equal(parsed.status, 413); assert.equal(typeof parsed.request, "string"); assert.equal(typeof parsed.response, "string"); @@ -247,13 +249,14 @@ test("#4297 summary cap covers both sides, JSON escaping and envelope bytes", () test("#4297 summary exact byte boundary stays complete; one more byte truncates valid JSON", () => { process.env.BILI_DUMP_4XX = "1"; process.env.BILI_DUMP_4XX_MAX_BYTES = "1024"; - const overhead = Buffer.byteLength(JSON.stringify({ status: 400, request: "", response: "" }, null, 2)); + const overhead = Buffer.byteLength(JSON.stringify({ status: 400, request: "", response: "" }, null, 2)) + + Buffer.byteLength(DUMP_PLAINTEXT_BANNER) + 1; // #4482 banner shares the cap const exact = "x".repeat(1024 - overhead); try { for (const request of [exact, exact + "x"]) { const out = dumpSummaryRejection(400, "summary-boundary", request, ""); assert.ok(out); - const parsed = JSON.parse(fs.readFileSync(out, "utf8")) as { request: string; response: string }; + const parsed = JSON.parse(stripDumpBanner(fs.readFileSync(out, "utf8"))) as { request: string; response: string }; assert.ok(fs.statSync(out).size <= 1024); assert.equal(parsed.response, ""); if (request === exact) assert.equal(parsed.request, exact);