From c0b5ab566d4a1ff4264805df4d1fca8452e4755b Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Tue, 1 Dec 2026 23:33:03 -0800 Subject: [PATCH 1/2] fix(vale): hold the upgrade wait until the registry reaches the manifest's Vale A push-triggered upgrade run waited for the Release Vale run, then took the first registry answer "newer than the pins" as the new release. On 3.29.0 the pins were at 3.27.0 (the 3.28.1 upgrade unmerged) and npm still served 3.28.1 as latest for a minute and a half after the publish succeeded, so the run rebuilt vendor/vale/upgrade at 3.28.1, older than the release that started it. On a push, waitForRegistry now also requires the base version of the published stamp to equal the manifest's valeVersion at GITHUB_SHA. A registry that never gets there ends as the existing registry-stale warning, and non-push runs are unchanged. --- .github/scripts/vale-upgrade-wait.cjs | 77 +++++++++--- .github/scripts/vale-upgrade-wait.test.cjs | 140 ++++++++++++++++++++- .github/workflows/vale-upgrade.yml | 17 ++- 3 files changed, 212 insertions(+), 22 deletions(-) diff --git a/.github/scripts/vale-upgrade-wait.cjs b/.github/scripts/vale-upgrade-wait.cjs index 1e38fa8ae..ca92b9dd8 100644 --- a/.github/scripts/vale-upgrade-wait.cjs +++ b/.github/scripts/vale-upgrade-wait.cjs @@ -30,19 +30,33 @@ * in seconds, occasionally longer. Ask the registry the exact question * the detect step is about to ask, with the same script and no side * effects (`--json` alone, which the script refuses to combine with - * `--write`), up to five times a minute apart. + * `--write`), up to five times a minute apart, and hold until the + * published set is AT THE VALE VERSION THIS COMMIT'S MANIFEST RECORDS. + * + * WHY "AT THE MANIFEST'S VERSION" AND NOT "NEWER THAN THE PINS". The pins can + * lag more than one release behind, because the previous upgrade pull request + * may still be open. Measured on 3.29.0 (2026-12-02): the pins were at 3.27.0 + * with the 3.28.1 upgrade unmerged, the Release Vale run for the 3.29.0 + * manifest succeeded at 07:10:47Z, and the registry still served 3.28.1 as + * latest until 07:12:28Z. "Newer than the pins" was already true of 3.28.1, + * so the first probe returned at once and the run rebuilt the upgrade branch + * at 3.28.1, an older Vale than the release that triggered it. The manifest + * at GITHUB_SHA names the release this run exists for, so the wait holds + * until the base version inside the published stamp (3.29.0 of + * 3.29.0-20261202071030) equals it. * * EVERY EXIT IS 0. A publish that concludes anything but success, one that - * never appears inside the bound, a registry that still says "current" at the - * end: each is a `::warning::` and a clean exit, never a failed check. This + * never appears inside the bound, a registry that has not reached the + * manifest's version at the end: each is a `::warning::` and a clean exit, never a failed check. This * workflow must not go red over a race it did not cause, and a red here would * say "the upgrade is broken" when the truth is "the publish is". The daily * schedule in vale-upgrade.yml retries once the packages are actually there, * which is what a backstop is for. * * What the workflow learns is the `ready` output: whether the detect step - * should run at all. It is "true" when the registry serves a newer set, and - * "false" when waiting established there is nothing to upgrade to yet. + * should run at all. It is "true" when the registry serves a newer set at the + * manifest's version, and "false" when waiting established there is nothing + * to upgrade to yet. * * TWO CASES ARE "true" WITHOUT A NEWER SET, on purpose: * @@ -65,8 +79,9 @@ * [--workflow ] [--timeout-minutes ] [--poll-seconds ] * [--attempts ] [--interval-seconds ] [--call-timeout-seconds ] * - * Reads GITHUB_EVENT_NAME and GITHUB_SHA. `gh` needs GH_TOKEN with - * `actions: read`. + * Reads GITHUB_EVENT_NAME and GITHUB_SHA, and on a push the `valeVersion` of + * vale-manifest.json as checked out, which is the manifest at GITHUB_SHA. `gh` + * needs GH_TOKEN with `actions: read`. * * Outputs (appended to $GITHUB_OUTPUT when set): * ready "true" when the detect step should run @@ -75,11 +90,12 @@ */ const { execFileSync } = require("node:child_process"); -const { appendFileSync } = require("node:fs"); +const { appendFileSync, readFileSync } = require("node:fs"); const { join } = require("node:path"); const RELEASE_WORKFLOW = "release-vale.yml"; const DETECT_SCRIPT = join(__dirname, "vale-upgrade-detect.cjs"); +const MANIFEST_PATH = join(__dirname, "vale-manifest.json"); const MINUTE = 60 * 1000; const SECOND = 1000; @@ -212,6 +228,21 @@ function probeRegistry({ } } +/** + * The Vale release the checked-out manifest records. On a push the checkout + * is GITHUB_SHA, so this is the release whose publish this run waited for. + */ +function readManifestVersion(path = MANIFEST_PATH) { + const { valeVersion } = JSON.parse(readFileSync(path, "utf8")); + if (typeof valeVersion !== "string" || valeVersion === "") { + throw new TypeError(`${path} records no valeVersion`); + } + return valeVersion; +} + +/** `3.29.0-20261202071030` -> `3.29.0`: the upstream release inside a stamp. */ +const stampBase = (stamped) => String(stamped).split("-")[0]; + const sleepFor = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); /** `gh run list --json status,conclusion` as a list of {status, conclusion}. */ @@ -311,14 +342,19 @@ async function waitForReleaseRun({ } /** - * Hold until the registry serves a newer set than the pins. + * Hold until the registry serves a newer set than the pins, and, when + * `expectedVersion` is given, one whose base version is exactly that release. + * A newer set at any other version (an intermediate release published before + * this one, while the pins were further behind) is not what this run is for, + * and counts as "not yet" like an answer of "current". * * Resolves to `{ outcome: "ahead" | "stale" | "probe-errored", ... }`. "stale" - * means at least one probe answered and the answer was "current" every time it - * did; "probe-errored" means no probe answered at all, which is a different - * fact and is reported as one. + * means at least one probe answered and no answer was the set waited for; + * "probe-errored" means no probe answered at all, which is a different fact + * and is reported as one. */ async function waitForRegistry({ + expectedVersion, attempts = DEFAULTS.attempts, intervalMs = DEFAULTS.intervalMs, probe = probeRegistry, @@ -330,14 +366,19 @@ async function waitForRegistry({ try { const comparison = await probe(); answered += 1; - if (comparison.ahead === true) { + const reached = + expectedVersion === undefined || + stampBase(comparison.upstream) === expectedVersion; + if (comparison.ahead === true && reached) { log( - `The registry serves a newer set than the pins: ${JSON.stringify(comparison)}` + `The registry serves a newer set than the pins${expectedVersion === undefined ? "" : `, at Vale ${expectedVersion}`}: ${JSON.stringify(comparison)}` ); return { outcome: "ahead", comparison, attempt }; } log( - `The registry still serves the pinned version (attempt ${attempt} of ${attempts}): ${JSON.stringify(comparison)}` + comparison.ahead === true + ? `The registry serves a newer set than the pins, but not yet Vale ${expectedVersion} (attempt ${attempt} of ${attempts}): ${JSON.stringify(comparison)}` + : `The registry still serves the pinned version (attempt ${attempt} of ${attempts}): ${JSON.stringify(comparison)}` ); } catch (error) { log( @@ -364,6 +405,7 @@ async function main({ sleep = sleepFor, log = (line) => console.log(line), now = Date.now, + manifestVersion = readManifestVersion, } = {}) { const options = parseArgs(argv); const finish = (ready, outcome) => { @@ -384,6 +426,7 @@ async function main({ if (!sha) { throw new Error("GITHUB_SHA must be set on a push"); } + const expectedVersion = manifestVersion(); // The per-call bound reaches the real runners through a second argument an // injected fake is free to ignore. @@ -413,6 +456,7 @@ async function main({ log(`Release Vale succeeded for ${sha}.`); const registry = await waitForRegistry({ + expectedVersion, attempts: options.attempts, intervalMs: options.intervalMs, probe: () => probe(call), @@ -424,7 +468,7 @@ async function main({ } if (registry.outcome === "stale") { log( - `::warning::no probe in ${registry.attempts} attempts after the publish succeeded reported a newer set than the pins; each attempt is logged above with its result. The daily schedule will retry.` + `::warning::no probe in ${registry.attempts} attempts after the publish succeeded reported a newer set than the pins at Vale ${expectedVersion}, the version this commit's manifest records; each attempt is logged above with its result. The daily schedule will retry.` ); return finish(false, "registry-stale"); } @@ -464,6 +508,7 @@ module.exports = { parseArgs, parseRuns, probeRegistry, + readManifestVersion, recover, runGh, waitForRegistry, diff --git a/.github/scripts/vale-upgrade-wait.test.cjs b/.github/scripts/vale-upgrade-wait.test.cjs index ed10101a9..b55145549 100644 --- a/.github/scripts/vale-upgrade-wait.test.cjs +++ b/.github/scripts/vale-upgrade-wait.test.cjs @@ -26,6 +26,7 @@ const { parseArgs, parseRuns, probeRegistry, + readManifestVersion, recover, runGh, waitForRegistry, @@ -90,6 +91,26 @@ const failed = { status: "completed", conclusion: "failure" }; const stale = { pinned: "3.21.0-1", upstream: "3.21.0-1", ahead: false }; const ahead = { pinned: "3.21.0-1", upstream: "3.22.0-2", ahead: true }; +/** The manifest version `ahead` is at, which main() is told it waits for. */ +const MANIFEST_VERSION = "3.22.0"; + +/* + * The 3.29.0 incident (2026-12-02), in stamps: pins at 3.27.0 because the + * 3.28.1 upgrade was still open, the registry still serving 3.28.1 when the + * 3.29.0 publish run succeeded, and 3.29.0 visible a minute and a half later. + */ +const pinsBehind = "3.27.0-20261101000000"; +const intermediate = { + pinned: pinsBehind, + upstream: "3.28.1-20261120000000", + ahead: true, +}; +const atManifest = { + pinned: pinsBehind, + upstream: "3.29.0-20261202071030", + ahead: true, +}; + test("parseRuns reads gh's JSON and tolerates a null conclusion", () => { assert.deepEqual(parseRuns("[]"), []); assert.deepEqual(parseRuns("\n"), []); @@ -342,8 +363,80 @@ test("registry: one answer among errors is still 'stale'", async () => { assert.equal(result.answered, 1); }); +test("registry: an intermediate newer set is not the manifest's version, so it waits", async () => { + const time = clock(); + const logged = []; + const { probe, count } = probeScript([ + intermediate, + intermediate, + atManifest, + ]); + const result = await waitForRegistry({ + expectedVersion: "3.29.0", + probe, + sleep: time.sleep, + log: (line) => logged.push(line), + }); + assert.equal(result.outcome, "ahead"); + assert.equal(result.attempt, 3); + assert.deepEqual(result.comparison, atManifest); + assert.equal(count(), 3); + assert.equal( + logged.filter((line) => + /newer set than the pins, but not yet Vale 3\.29\.0/.test(line) + ).length, + 2 + ); +}); + +test("registry: a newer set that never reaches the manifest's version is 'stale'", async () => { + const time = clock(); + const { probe } = probeScript([intermediate]); + const result = await waitForRegistry({ + expectedVersion: "3.29.0", + probe, + sleep: time.sleep, + log: () => {}, + }); + assert.equal(result.outcome, "stale"); + assert.equal(result.answered, DEFAULTS.attempts); +}); + +test("registry: without an expected version, any newer set is ahead", async () => { + const time = clock(); + const { probe } = probeScript([intermediate]); + const result = await waitForRegistry({ + probe, + sleep: time.sleep, + log: () => {}, + }); + assert.equal(result.outcome, "ahead"); + assert.equal(result.attempt, 1); +}); + +test("readManifestVersion reads valeVersion and refuses a manifest without one", () => { + const directory = mkdtempSync(join(tmpdir(), "vale-upgrade-wait-test-")); + try { + const path = join(directory, "vale-manifest.json"); + writeFileSync(path, JSON.stringify({ valeVersion: "3.29.0" })); + assert.equal(readManifestVersion(path), "3.29.0"); + writeFileSync(path, JSON.stringify({})); + assert.throws(() => readManifestVersion(path), /records no valeVersion/); + } finally { + rmSync(directory, { recursive: true, force: true }); + } + // The real manifest parses, so a push run never falls back to wait-errored. + assert.match(readManifestVersion(), /^\d+\.\d+\.\d+$/); +}); + /** Drive main() with everything injected and read back $GITHUB_OUTPUT. */ -async function run({ event = "push", gh, probe, argv = [] }) { +async function run({ + event = "push", + gh, + probe, + argv = [], + manifestVersion = MANIFEST_VERSION, +}) { const directory = mkdtempSync(join(tmpdir(), "vale-upgrade-wait-test-")); const outputPath = join(directory, "github-output"); const time = clock(); @@ -361,6 +454,10 @@ async function run({ event = "push", gh, probe, argv = [] }) { sleep: time.sleep, now: time.now, log: (line) => logged.push(line), + manifestVersion: + typeof manifestVersion === "function" + ? manifestVersion + : () => manifestVersion, }); let outputs = {}; try { @@ -467,6 +564,46 @@ test("main: probe never ahead -> warning, ready=false", async () => { assert.deepEqual(outputs, { ready: "false", outcome: "registry-stale" }); assert.equal(warnings.length, 1); assert.match(warnings[0], /no probe in 5 attempts .* reported a newer set/); + assert.match( + warnings[0], + /at Vale 3\.22\.0, the version this commit's manifest records/ + ); +}); + +test("main: pins behind, registry at an intermediate release, then at the manifest's -> waits for the manifest's", async () => { + const probed = probeScript([intermediate, atManifest]); + const { outputs, warnings, slept } = await run({ + probe: probed.probe, + manifestVersion: "3.29.0", + }); + assert.deepEqual(outputs, { ready: "true", outcome: "ahead" }); + assert.deepEqual(warnings, []); + assert.equal(probed.count(), 2); + assert.deepEqual(slept, [DEFAULTS.intervalMs]); +}); + +test("main: registry stuck at an intermediate release -> registry-stale, detect never runs", async () => { + const { outputs, warnings } = await run({ + probe: probeScript([intermediate]).probe, + manifestVersion: "3.29.0", + }); + assert.deepEqual(outputs, { ready: "false", outcome: "registry-stale" }); + assert.equal(warnings.length, 1); + assert.match( + warnings[0], + /at Vale 3\.29\.0, the version this commit's manifest records/ + ); + assert.match(warnings[0], /daily schedule will retry/); +}); + +test("main: a non-push event never reads the manifest", async () => { + const { outputs } = await run({ + event: "schedule", + manifestVersion: () => { + throw new Error("a non-push run read the manifest"); + }, + }); + assert.deepEqual(outputs, { ready: "true", outcome: "skipped" }); }); test("main: a non-push event skips both waits with ready=true", async () => { @@ -659,6 +796,7 @@ test("main: the call timeout reaches gh and the probe as a second argument", asy }, sleep: async () => {}, log: () => {}, + manifestVersion: () => MANIFEST_VERSION, }); } finally { rmSync(directory, { recursive: true, force: true }); diff --git a/.github/workflows/vale-upgrade.yml b/.github/workflows/vale-upgrade.yml index 551c252e1..25242bae8 100644 --- a/.github/workflows/vale-upgrade.yml +++ b/.github/workflows/vale-upgrade.yml @@ -81,7 +81,10 @@ on: # OLD latest, found nothing to do, and exited clean. The wait step before # detect exists for that: vale-upgrade-wait.cjs holds until the `Release # Vale` run for this same commit has concluded, then until the registry - # actually serves a newer set. It cannot fail the run; see below. + # actually serves the set at the Vale version this commit's manifest records + # (not merely one newer than the pins: on 3.29.0 the pins were two releases + # behind and the registry still served 3.28.1, which an earlier wait took for + # the new release). It cannot fail the run; see below. push: branches: [main] paths: @@ -129,12 +132,16 @@ jobs: # minutes; on 3.22.0 the run had stamped the packages 14 s after it # started, so the bound is for a queued runner, not for the work), then # until the registry answers the exact question the detect step is about - # to ask with "a newer set" (five probes a minute apart, using the same - # script with `--json` alone, a read that changes nothing). + # to ask with "a newer set, at the manifest's Vale version" (five probes a + # minute apart, using the same script with `--json` alone, a read that + # changes nothing). A newer set at an intermediate release, published + # while an earlier upgrade pull request was still open, counts as "not + # yet": proposing it would rebuild the upgrade branch at an older Vale + # than the release this push is for. # # EVERY EXIT HERE IS 0. A publish that concludes anything but success, - # one that never appears inside the bound, or a registry that still says - # "current" at the end is a `::warning::` and `ready=false`, never a + # one that never appears inside the bound, or a registry that has not + # reached the manifest's version at the end is a `::warning::` and `ready=false`, never a # failed check: this workflow must not go red over a race it did not # cause, and a red here would say "the upgrade is broken" when the truth # is "the publish is". The daily schedule above retries once the packages From bafc1241bb25ba1108b2e5d4c5d9a7850843fcc9 Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Tue, 1 Dec 2026 23:44:11 -0800 Subject: [PATCH 2/2] fix(vale): count a registry already past the manifest's Vale as reached Review on #736: an exact match would report registry-stale when a later manifest bump published first. Compare with compareValeVersions so at or past the manifest's version counts. --- .github/scripts/vale-upgrade-wait.cjs | 22 ++++++++++++++------- .github/scripts/vale-upgrade-wait.test.cjs | 23 ++++++++++++++++++++-- .github/workflows/vale-upgrade.yml | 4 ++-- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/scripts/vale-upgrade-wait.cjs b/.github/scripts/vale-upgrade-wait.cjs index ca92b9dd8..5d304884a 100644 --- a/.github/scripts/vale-upgrade-wait.cjs +++ b/.github/scripts/vale-upgrade-wait.cjs @@ -31,7 +31,8 @@ * the detect step is about to ask, with the same script and no side * effects (`--json` alone, which the script refuses to combine with * `--write`), up to five times a minute apart, and hold until the - * published set is AT THE VALE VERSION THIS COMMIT'S MANIFEST RECORDS. + * published set is AT (OR PAST) THE VALE VERSION THIS COMMIT'S MANIFEST + * RECORDS. * * WHY "AT THE MANIFEST'S VERSION" AND NOT "NEWER THAN THE PINS". The pins can * lag more than one release behind, because the previous upgrade pull request @@ -43,7 +44,10 @@ * at 3.28.1, an older Vale than the release that triggered it. The manifest * at GITHUB_SHA names the release this run exists for, so the wait holds * until the base version inside the published stamp (3.29.0 of - * 3.29.0-20261202071030) equals it. + * 3.29.0-20261202071030) is at least it. "At least" rather than "equal": if a + * later manifest bump has already published by the time this run probes, the + * registry is past this run's release, and upgrading to it is still never + * older than what triggered the run. * * EVERY EXIT IS 0. A publish that concludes anything but success, one that * never appears inside the bound, a registry that has not reached the @@ -93,6 +97,8 @@ const { execFileSync } = require("node:child_process"); const { appendFileSync, readFileSync } = require("node:fs"); const { join } = require("node:path"); +const { compareValeVersions } = require("./vale-release.cjs"); + const RELEASE_WORKFLOW = "release-vale.yml"; const DETECT_SCRIPT = join(__dirname, "vale-upgrade-detect.cjs"); const MANIFEST_PATH = join(__dirname, "vale-manifest.json"); @@ -343,10 +349,11 @@ async function waitForReleaseRun({ /** * Hold until the registry serves a newer set than the pins, and, when - * `expectedVersion` is given, one whose base version is exactly that release. - * A newer set at any other version (an intermediate release published before + * `expectedVersion` is given, one whose base version is that release or later. + * A newer set at an EARLIER version (an intermediate release published before * this one, while the pins were further behind) is not what this run is for, - * and counts as "not yet" like an answer of "current". + * and counts as "not yet" like an answer of "current". A set already past it + * (a later manifest bump that published first) counts as reached. * * Resolves to `{ outcome: "ahead" | "stale" | "probe-errored", ... }`. "stale" * means at least one probe answered and no answer was the set waited for; @@ -368,7 +375,8 @@ async function waitForRegistry({ answered += 1; const reached = expectedVersion === undefined || - stampBase(comparison.upstream) === expectedVersion; + compareValeVersions(stampBase(comparison.upstream), expectedVersion) >= + 0; if (comparison.ahead === true && reached) { log( `The registry serves a newer set than the pins${expectedVersion === undefined ? "" : `, at Vale ${expectedVersion}`}: ${JSON.stringify(comparison)}` @@ -468,7 +476,7 @@ async function main({ } if (registry.outcome === "stale") { log( - `::warning::no probe in ${registry.attempts} attempts after the publish succeeded reported a newer set than the pins at Vale ${expectedVersion}, the version this commit's manifest records; each attempt is logged above with its result. The daily schedule will retry.` + `::warning::no probe in ${registry.attempts} attempts after the publish succeeded reported a newer set than the pins at or past Vale ${expectedVersion}, the version this commit's manifest records; each attempt is logged above with its result. The daily schedule will retry.` ); return finish(false, "registry-stale"); } diff --git a/.github/scripts/vale-upgrade-wait.test.cjs b/.github/scripts/vale-upgrade-wait.test.cjs index b55145549..c394d6704 100644 --- a/.github/scripts/vale-upgrade-wait.test.cjs +++ b/.github/scripts/vale-upgrade-wait.test.cjs @@ -402,6 +402,25 @@ test("registry: a newer set that never reaches the manifest's version is 'stale' assert.equal(result.answered, DEFAULTS.attempts); }); +test("registry: a set already past the manifest's version counts as reached", async () => { + const time = clock(); + const later = { + pinned: pinsBehind, + upstream: "3.30.0-20261203000000", + ahead: true, + }; + const { probe } = probeScript([later]); + const result = await waitForRegistry({ + expectedVersion: "3.29.0", + probe, + sleep: time.sleep, + log: () => {}, + }); + assert.equal(result.outcome, "ahead"); + assert.equal(result.attempt, 1); + assert.deepEqual(result.comparison, later); +}); + test("registry: without an expected version, any newer set is ahead", async () => { const time = clock(); const { probe } = probeScript([intermediate]); @@ -566,7 +585,7 @@ test("main: probe never ahead -> warning, ready=false", async () => { assert.match(warnings[0], /no probe in 5 attempts .* reported a newer set/); assert.match( warnings[0], - /at Vale 3\.22\.0, the version this commit's manifest records/ + /at or past Vale 3\.22\.0, the version this commit's manifest records/ ); }); @@ -591,7 +610,7 @@ test("main: registry stuck at an intermediate release -> registry-stale, detect assert.equal(warnings.length, 1); assert.match( warnings[0], - /at Vale 3\.29\.0, the version this commit's manifest records/ + /at or past Vale 3\.29\.0, the version this commit's manifest records/ ); assert.match(warnings[0], /daily schedule will retry/); }); diff --git a/.github/workflows/vale-upgrade.yml b/.github/workflows/vale-upgrade.yml index 25242bae8..5d8d7d629 100644 --- a/.github/workflows/vale-upgrade.yml +++ b/.github/workflows/vale-upgrade.yml @@ -81,7 +81,7 @@ on: # OLD latest, found nothing to do, and exited clean. The wait step before # detect exists for that: vale-upgrade-wait.cjs holds until the `Release # Vale` run for this same commit has concluded, then until the registry - # actually serves the set at the Vale version this commit's manifest records + # actually serves the set at (or past) the Vale version this commit's manifest records # (not merely one newer than the pins: on 3.29.0 the pins were two releases # behind and the registry still served 3.28.1, which an earlier wait took for # the new release). It cannot fail the run; see below. @@ -132,7 +132,7 @@ jobs: # minutes; on 3.22.0 the run had stamped the packages 14 s after it # started, so the bound is for a queued runner, not for the work), then # until the registry answers the exact question the detect step is about - # to ask with "a newer set, at the manifest's Vale version" (five probes a + # to ask with "a newer set, at or past the manifest's Vale version" (five probes a # minute apart, using the same script with `--json` alone, a read that # changes nothing). A newer set at an intermediate release, published # while an earlier upgrade pull request was still open, counts as "not