Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 79 additions & 5 deletions .github/workflows/release-bugfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 `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
# 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);
Expand All @@ -39,6 +52,14 @@ 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. 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:
Expand All @@ -57,6 +78,7 @@ jobs:
contents: write
id-token: write
actions: write
pull-requests: write # backport-ship label publish: annotate the ship PR
steps:
- name: Validate trigger + resolve the publish ref
id: resolve
Expand All @@ -82,6 +104,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
# 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.
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" != "backport-ship" ]; then
echo "::notice::label '$LABEL' is not the backport-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=""
Expand All @@ -96,8 +148,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 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 }}"
git rev-parse --verify --quiet "${SHA}^{commit}" >/dev/null || git fetch origin "$SHA"
Expand Down Expand Up @@ -132,7 +187,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'
Expand Down Expand Up @@ -261,6 +325,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:
Expand Down
20 changes: 19 additions & 1 deletion reference/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`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
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
Expand Down Expand Up @@ -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 `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
source fix PR so the carry picks transport it — the publish gate checks the
Expand Down
12 changes: 10 additions & 2 deletions src/error-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 */ }
Expand Down Expand Up @@ -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; }
Expand Down
13 changes: 8 additions & 5 deletions tests/error-dump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
});
Expand All @@ -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");
Expand All @@ -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);
Expand Down
Loading