Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): let the draft janitor sweep stranded stable releases (#4069)
Andrew Mikofalvyeb5bd346ff6d
diff --git a/.github/scripts/select-stuck-drafts.mjs b/.github/scripts/select-stuck-drafts.mjsnew file mode 100644index 000000000..b15b8fff4--- /dev/null+++ b/.github/scripts/select-stuck-drafts.mjs@@ -0,0 +1,88 @@+import { pathToFileURL } from 'node:url';+import { compareVersions, highestVersion } from './write-back-gate.mjs';++export const STUCK_DRAFT_MAX_AGE_SECONDS = 10800;++const PIPELINE_TAG_RE = /^v\d+\.\d+\.\d+(?:-beta\.\d+)?$/;+const BETA_SUFFIX = /-beta\.\d+$/;++export function isPipelineTag(tagName) {+ return PIPELINE_TAG_RE.test(String(tagName ?? '').trim());+}++export function cycleOf(tagName) {+ return String(tagName).replace(/^v/, '').replace(BETA_SUFFIX, '');+}++export function highestPublishedStable(releases) {+ const cycles = [];+ for (const release of releases ?? []) {+ if (release.isDraft || release.isPrerelease) continue;+ if (!isPipelineTag(release.tagName)) continue;+ cycles.push(cycleOf(release.tagName));+ }+ return highestVersion(cycles);+}++export function objectAgeSeconds(release, nowMs) {+ const stamp = release.updatedAt ?? release.publishedAt;+ if (!stamp) return null;+ const ageSeconds = (nowMs - Date.parse(stamp)) / 1000;+ return Number.isFinite(ageSeconds) ? ageSeconds : null;+}++export function selectStuckDrafts({ releases, nowMs, maxAgeSeconds }) {+ const maxStable = highestPublishedStable(releases);+ if (maxStable === null) {+ return { maxStable: null, sweep: [], keep: [] };+ }+ const sweep = [];+ const keep = [];+ for (const release of releases ?? []) {+ if (!release.isDraft) continue;+ if (!isPipelineTag(release.tagName)) {+ keep.push({ tagName: release.tagName, cycle: null, reason: 'unrecognized tag shape' });+ continue;+ }+ const ageSeconds = objectAgeSeconds(release, nowMs);+ if (ageSeconds === null) {+ keep.push({ tagName: release.tagName, cycle: cycleOf(release.tagName), reason: 'no usable timestamp' });+ continue;+ }+ if (!(ageSeconds > maxAgeSeconds)) {+ keep.push({ tagName: release.tagName, cycle: cycleOf(release.tagName), reason: 'younger than the age gate' });+ continue;+ }+ const cycle = cycleOf(release.tagName);+ const entry = { tagName: release.tagName, cycle };+ if (compareVersions(cycle, maxStable) <= 0) sweep.push(entry);+ else keep.push({ ...entry, reason: 'cycle not yet covered by a published stable' });+ }+ return { maxStable, sweep, keep };+}++function main() {+ const releases = JSON.parse(process.env.RELEASES_JSON ?? '[]');+ const maxAgeSeconds = Number(process.env.MAX_AGE_SECONDS ?? STUCK_DRAFT_MAX_AGE_SECONDS);+ const result = selectStuckDrafts({ releases, nowMs: Date.now(), maxAgeSeconds });+ if (result.maxStable === null) {+ console.error(+ 'No published stable release yet; keeping all drafts (their bodies feed the first stable changelog).',+ );+ return;+ }+ console.error(`Highest published stable version: ${result.maxStable}`);+ for (const { tagName, reason } of result.keep) {+ console.error(`Keeping ${tagName}: ${reason} (newest published stable ${result.maxStable}).`);+ }+ for (const { tagName, cycle } of result.sweep) {+ console.error(+ `Selected ${tagName} for sweeping: its ${cycle} cycle is closed (stable ${result.maxStable} exists).`,+ );+ }+ console.log(result.sweep.map((entry) => entry.tagName).join('\n'));+}++if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {+ main();+}diff --git a/.github/scripts/select-stuck-drafts.test.mjs b/.github/scripts/select-stuck-drafts.test.mjsnew file mode 100644index 000000000..db786f656--- /dev/null+++ b/.github/scripts/select-stuck-drafts.test.mjs@@ -0,0 +1,343 @@+import { spawnSync } from 'node:child_process';+import { readFileSync } from 'node:fs';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { describe, expect, test } from 'vitest';+import {+ cycleOf,+ highestPublishedStable,+ isPipelineTag,+ objectAgeSeconds,+ selectStuckDrafts,+ STUCK_DRAFT_MAX_AGE_SECONDS,+} from './select-stuck-drafts.mjs';++const NOW = Date.parse('2026-09-01T18:00:00Z');+const MAX_AGE = STUCK_DRAFT_MAX_AGE_SECONDS;+const OLD = '2026-08-27T19:41:28Z';+const FRESH = '2026-09-01T17:30:00Z';+const AT_GATE = new Date(NOW - MAX_AGE * 1000).toISOString();+const PAST_GATE = new Date(NOW - (MAX_AGE + 1) * 1000).toISOString();++const stableDraft = (tagName, updatedAt = OLD) => ({+ tagName,+ isDraft: true,+ isPrerelease: false,+ updatedAt,+});+const betaDraft = (tagName, updatedAt = OLD) => ({+ tagName,+ isDraft: true,+ isPrerelease: true,+ updatedAt,+});+const publishedBeta = (tagName) => ({+ tagName,+ isDraft: false,+ isPrerelease: true,+ updatedAt: OLD,+});+const published = (tagName) => ({+ tagName,+ isDraft: false,+ isPrerelease: false,+ updatedAt: OLD,+});++const select = (releases) => selectStuckDrafts({ releases, nowMs: NOW, maxAgeSeconds: MAX_AGE });+const swept = (releases) => select(releases).sweep.map((entry) => entry.tagName);+const kept = (releases) => select(releases).keep.map((entry) => entry.tagName);++describe('cycleOf', () => {+ test('strips the v prefix and any beta suffix', () => {+ expect(cycleOf('v0.68.0-beta.4')).toBe('0.68.0');+ expect(cycleOf('v0.65.0')).toBe('0.65.0');+ });+});++describe('highestPublishedStable', () => {+ test('ignores drafts and prereleases', () => {+ const releases = [+ published('v0.68.3'),+ stableDraft('v0.99.0'),+ betaDraft('v0.99.0-beta.1'),+ publishedBeta('v0.99.0-beta.2'),+ ];+ expect(highestPublishedStable(releases)).toBe('0.68.3');+ });++ test('orders numerically, not lexically', () => {+ expect(highestPublishedStable([published('v0.9.0'), published('v0.68.3')])).toBe('0.68.3');+ });++ test('is null when nothing stable has been published', () => {+ expect(highestPublishedStable([betaDraft('v0.1.0-beta.0')])).toBeNull();+ });+});++describe('isPipelineTag', () => {+ test('admits the shapes the release pipeline creates', () => {+ expect(isPipelineTag('v0.68.3')).toBe(true);+ expect(isPipelineTag('v0.68.0-beta.4')).toBe(true);+ });++ test('refuses anything else, including a plausible hand-drafted tag', () => {+ for (const tag of ['v0.60.0-rc.1', 'nightly', 'docs-preview', 'v1.2', '']) {+ expect(isPipelineTag(tag)).toBe(false);+ }+ });+});++describe('objectAgeSeconds', () => {+ test('measures the release object, never the tagged commit', () => {+ const draft = {+ tagName: 'v0.69.0',+ isDraft: true,+ isPrerelease: false,+ updatedAt: '2026-09-01T17:59:00Z',+ createdAt: '2020-01-01T00:00:00Z',+ publishedAt: null,+ };+ expect(objectAgeSeconds(draft, NOW)).toBe(60);+ });++ test('falls back to publishedAt when no updatedAt is supplied', () => {+ expect(objectAgeSeconds({ publishedAt: '2026-09-01T17:00:00Z' }, NOW)).toBe(3600);+ });++ test('is null when the object carries no timestamp of its own', () => {+ expect(objectAgeSeconds({ createdAt: '2020-01-01T00:00:00Z' }, NOW)).toBeNull();+ });+});++describe('selectStuckDrafts', () => {+ test('sweeps a stranded STABLE draft once a later stable is published', () => {+ const releases = [published('v0.68.3'), stableDraft('v0.65.0'), stableDraft('v0.66.0')];+ expect(swept(releases)).toEqual(['v0.65.0', 'v0.66.0']);+ });++ test('still sweeps a stranded beta draft on a closed cycle', () => {+ expect(swept([published('v0.68.3'), betaDraft('v0.64.0-beta.6')])).toEqual([+ 'v0.64.0-beta.6',+ ]);+ });++ test('keeps a draft whose cycle no published stable covers yet', () => {+ const releases = [published('v0.68.3'), stableDraft('v0.69.0'), betaDraft('v0.69.0-beta.1')];+ expect(swept(releases)).toEqual([]);+ expect(kept(releases)).toEqual(['v0.69.0', 'v0.69.0-beta.1']);+ });++ test('sweeps the draft of the newest published stable cycle itself', () => {+ expect(swept([published('v0.68.3'), betaDraft('v0.68.3-beta.1')])).toEqual(['v0.68.3-beta.1']);+ });++ test('spares a draft younger than the age gate, whatever its cycle', () => {+ expect(swept([published('v0.68.3'), stableDraft('v0.65.0', FRESH)])).toEqual([]);+ });++ test('a draft with only a commit-age createdAt is never swept', () => {+ const draft = {+ tagName: 'v0.65.0',+ isDraft: true,+ isPrerelease: false,+ createdAt: '2020-01-01T00:00:00Z',+ publishedAt: null,+ };+ const result = select([published('v0.68.3'), draft]);+ expect(result.sweep).toEqual([]);+ expect(result.keep).toEqual([+ { tagName: 'v0.65.0', cycle: '0.65.0', reason: 'no usable timestamp' },+ ]);+ });++ test('an unparseable timestamp is never swept and never narrated as young', () => {+ const corrupt = stableDraft('v0.65.0', 'not-a-date');+ expect(objectAgeSeconds(corrupt, NOW)).toBeNull();+ const result = select([published('v0.68.3'), corrupt]);+ expect(result.sweep).toEqual([]);+ expect(result.keep).toEqual([+ { tagName: 'v0.65.0', cycle: '0.65.0', reason: 'no usable timestamp' },+ ]);+ });++ test('a hand-drafted release the pipeline never created is kept, not swept', () => {+ const handDrafted = {+ tagName: 'v0.60.0-rc.1',+ isDraft: true,+ isPrerelease: false,+ updatedAt: OLD,+ };+ const result = select([published('v0.68.3'), handDrafted]);+ expect(result.sweep).toEqual([]);+ expect(result.keep).toEqual([+ { tagName: 'v0.60.0-rc.1', cycle: null, reason: 'unrecognized tag shape' },+ ]);+ });++ test('an unrecognized tag never reaches the published-stable ceiling either', () => {+ expect(highestPublishedStable([published('v0.68.3'), published('nightly')])).toBe('0.68.3');+ });++ test('a draft exactly at the age gate is spared; one second past it is swept', () => {+ expect(swept([published('v0.68.3'), stableDraft('v0.65.0', AT_GATE)])).toEqual([]);+ expect(swept([published('v0.68.3'), stableDraft('v0.65.0', PAST_GATE)])).toEqual(['v0.65.0']);+ });++ test('a patch-level cycle above the newest stable is kept', () => {+ expect(swept([published('v0.68.3'), stableDraft('v0.68.4')])).toEqual([]);+ });++ test('the cycle gate compares numerically, so a low single-digit cycle is swept', () => {+ expect(swept([published('v0.68.3'), stableDraft('v0.9.0')])).toEqual(['v0.9.0']);+ });++ test('every draft the sweep declines is narrated with a reason', () => {+ const releases = [+ published('v0.68.3'),+ stableDraft('v0.69.0'),+ stableDraft('v0.65.0', FRESH),+ { tagName: 'nightly', isDraft: true, isPrerelease: false, updatedAt: OLD },+ ];+ const reasons = select(releases).keep.map((entry) => entry.reason);+ expect(reasons).toHaveLength(3);+ expect(reasons.every((reason) => typeof reason === 'string' && reason.length > 0)).toBe(true);+ });++ test('never proposes a published release for deletion', () => {+ expect(swept([published('v0.68.3'), published('v0.67.2')])).toEqual([]);+ });++ test('sweeps nothing at all before the first stable is published', () => {+ const result = selectStuckDrafts({+ releases: [stableDraft('v0.1.0'), betaDraft('v0.1.0-beta.0')],+ nowMs: NOW,+ maxAgeSeconds: MAX_AGE,+ });+ expect(result).toEqual({ maxStable: null, sweep: [], keep: [] });+ });+});++describe('the module CLI contract the workflow depends on', () => {+ const SCRIPT = join(dirname(fileURLToPath(import.meta.url)), 'select-stuck-drafts.mjs');++ const run = (releases) =>+ spawnSync(process.execPath, [SCRIPT], {+ encoding: 'utf8',+ env: { ...process.env, RELEASES_JSON: JSON.stringify(releases) },+ });++ test('stdout carries only the sweep tags, one per line', () => {+ const r = run([published('v0.68.3'), stableDraft('v0.65.0'), stableDraft('v0.66.0')]);+ expect(r.status).toBe(0);+ expect(r.stdout).toBe('v0.65.0\nv0.66.0\n');+ });++ test('narration goes to stderr, never stdout', () => {+ const r = run([published('v0.68.3'), stableDraft('v0.65.0')]);+ expect(r.stderr).toContain('Highest published stable version');+ expect(r.stdout).not.toContain('Highest published stable version');+ });++ test('an empty sweep prints nothing on stdout and still exits 0', () => {+ const r = run([published('v0.68.3')]);+ expect(r.status).toBe(0);+ expect(r.stdout.trim()).toBe('');+ });++ test('no published stable prints nothing on stdout and still exits 0', () => {+ const r = run([stableDraft('v0.1.0')]);+ expect(r.status).toBe(0);+ expect(r.stdout.trim()).toBe('');+ });+});++describe('the janitor workflow drives this module', () => {+ const workflow = readFileSync(+ join(+ dirname(fileURLToPath(import.meta.url)),+ '..',+ 'workflows',+ 'desktop-release-draft-janitor.yml',+ ),+ 'utf8',+ );++ test('the sweep step calls the module rather than filtering inline', () => {+ expect(workflow).toContain('node .github/scripts/select-stuck-drafts.mjs');+ });++ test('the release list carries the object timestamp, not the commit date', () => {+ const start = workflow.indexOf('RELEASES_JSON=$(');+ const end = workflow.indexOf('sweep=$(');+ if (start === -1 || end === -1) throw new Error('the janitor no longer lists releases then sweeps');+ const listCommand = workflow.slice(start, end);+ expect(listCommand).toContain('updatedAt: .updated_at');+ expect(listCommand).not.toContain('created_at');+ expect(listCommand).not.toContain('createdAt');+ });++ test('the release list is narrowed to what the selector actually reads', () => {+ const start = workflow.indexOf('RELEASES_JSON=$(');+ const end = workflow.indexOf('sweep=$(');+ if (start === -1 || end === -1) throw new Error('the janitor no longer lists releases then sweeps');+ expect(workflow.slice(start, end)).toContain('select(.draft or (.prerelease | not))');+ });++ test('dropping published prereleases does not change the sweep set', () => {+ const releases = [+ published('v0.68.3'),+ publishedBeta('v0.68.3-beta.4'),+ publishedBeta('v0.69.0-beta.1'),+ stableDraft('v0.68.0'),+ betaDraft('v0.68.1-beta.0'),+ stableDraft('v0.69.0'),+ ];+ const narrowed = releases.filter((r) => r.isDraft || !r.isPrerelease);+ expect(narrowed.length).toBeLessThan(releases.length);+ expect(select(releases).sweep).not.toEqual([]);+ expect(select(releases)).toEqual(select(narrowed));+ });++ test('no inline filter re-narrows the sweep to prereleases', () => {+ expect(workflow).not.toContain('select(.isDraft and .isPrerelease)');+ });++ test('the sweep annotation fires after its delete, not before', () => {+ const loopStart = workflow.indexOf('while IFS= read -r tag');+ if (loopStart === -1) throw new Error('the janitor no longer loops over the sweep set');+ const loop = workflow.slice(loopStart);+ const deleteAt = loop.indexOf('gh release delete');+ const noticeAt = loop.indexOf('::notice::Swept stuck draft');+ if (deleteAt === -1 || noticeAt === -1) {+ throw new Error('the delete loop no longer deletes and annotates');+ }+ expect(noticeAt).toBeGreaterThan(deleteAt);+ });++ test('a runaway sweep set is capped rather than deleted', () => {+ expect(workflow).toContain('MAX_SWEEP_PER_RUN');+ const capAt = workflow.indexOf('::error::Refusing to sweep');+ const loop = workflow.indexOf('while IFS= read -r tag');+ if (capAt === -1 || loop === -1) throw new Error('the janitor no longer caps the sweep set');+ expect(capAt).toBeLessThan(loop);+ });++ test('a dry run is checked before the cap, so it can preview an over-cap set', () => {+ const dryRunAt = workflow.indexOf('if [ "${DRY_RUN:-false}" = "true" ]');+ const capAt = workflow.indexOf('if [ "${count}" -gt "${MAX_SWEEP_PER_RUN}" ]');+ if (dryRunAt === -1 || capAt === -1) throw new Error('the janitor no longer branches on a dry run and a cap');+ expect(dryRunAt).toBeLessThan(capAt);+ });++ test('a dry run is available and deletes nothing', () => {+ expect(workflow).toContain('dry_run');+ const dryRunAt = workflow.indexOf('if [ "${DRY_RUN:-false}" = "true" ]');+ if (dryRunAt === -1) throw new Error('the janitor no longer branches on a dry run');+ const dryRunBlock = workflow.slice(dryRunAt);+ const exitAt = dryRunBlock.indexOf('exit 0');+ const deleteAt = dryRunBlock.indexOf('gh release delete');+ if (exitAt === -1 || deleteAt === -1) throw new Error('the dry-run branch no longer guards the delete');+ expect(exitAt).toBeLessThan(deleteAt);+ });+});diff --git a/.github/workflows/desktop-release-draft-janitor.yml b/.github/workflows/desktop-release-draft-janitor.ymlindex cd5262653..99e85a0f3 100644--- a/.github/workflows/desktop-release-draft-janitor.yml+++ b/.github/workflows/desktop-release-draft-janitor.yml@@ -26,6 +26,48 @@ name: Draft release janitor# body is safe to reap. Drafts on a not-yet-promoted cycle are left for a human# to re-run desktop-release.yml against or promote. The git TAG is always kept# (npm-provenance source ref + version lineage); only the Release object goes.+#+# The sweep covers stable drafts on the same gate. A stable draft strands the+# same way (v0.65.0 and v0.66.0 sat draft with zero assets from 2026-08-27 to+# 2026-09-01, swept by hand) but its body feeds no later changelog, so the+# `cycle <= maxstable` gate is if anything more conservative for it than for a+# beta. The selection lives in .github/scripts/select-stuck-drafts.mjs, which is+# unit-tested; this workflow only acts on what that returns.+#+# The age gate reads the release OBJECT's timestamp, never `createdAt`: on a+# GitHub Release `createdAt` is the TARGET COMMIT's date, so a draft created+# from an older commit reads as already-aged the moment it exists and the gate+# that is meant to spare an in-flight build would never fire. `publishedAt` is+# no use either: it is null until the release leaves draft, which is every+# release this job looks at. That leaves `updated_at`, which `gh release list`+# cannot return, so the list comes from the REST endpoint instead.+#+# The gate must exceed desktop-release.yml's SEQUENTIAL CRITICAL PATH, not any+# single job's timeout. build-macos deliberately does NOT need prepare (it is+# self-contained, per its own comment), so those overlap and only the longer leg+# counts: build-macos (75) -> publish-assets (20) -> finalize (15) = 110 minutes+# worst case. publish-assets needs every build and finalize needs publish-assets;+# build-windows and build-linux each finish at 30+45=75, inside the mac leg.+# STUCK_DRAFT_MAX_AGE_SECONDS is 10800 (180 min), clearing 110 with margin for+# cold caches and build-macos's one retry. An earlier 5400 was derived from+# build-macos's 75-minute timeout alone and did not cover the path.+#+# The list is narrowed to drafts plus PUBLISHED STABLES, which is exactly what+# the selector reads (drafts are the candidates, published stables set the+# ceiling). The narrowing is gh's LOCAL --jq transform of the full paginated+# response: the releases endpoint has no filter parameter, so every release+# still crosses the wire; what is bounded is the payload handed to the module.+# That matters because Published betas are dead weight and this repo has+# hundreds: unnarrowed, the payload measured 90,670 bytes across 915 releases,+# and it crosses execve's per-string MAX_ARG_STRLEN (131,072 on Linux, applying+# to env as well as argv) at roughly 1,300 releases. Narrowed, the same snapshot+# is 16,460 bytes across 175 entries and yields an identical sweep set.+#+# Age is a backstop, not the real protection: an in-flight cycle is kept by the+# cycle gate whatever its age, and age is load-bearing only where a draft's+# cycle EQUALS the just-published stable. It cannot cover an operator re-running+# a days-old stranded build at all; the sweep cap and dry_run are the rails for+# that case.on:schedule:@@ -33,6 +75,11 @@ on:- cron: "37 */6 * * *"# Manual sweep, e.g. right after a known stuck-draft incident.workflow_dispatch:+ inputs:+ dry_run:+ description: "Print the sweep set without deleting anything."+ type: boolean+ default: falsepermissions:# contents: write is required to delete Release objects via the API.@@ -46,60 +93,61 @@ jobs:sweep:runs-on: ubuntu-latesttimeout-minutes: 10+ env:+ MAX_SWEEP_PER_RUN: "5"steps:+ - name: Checkout+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ persist-credentials: false++ - name: Set up Node+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0+ with:+ node-version: "24"+- name: Delete superseded stuck draft releasesenv:GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ DRY_RUN: ${{ inputs.dry_run }}run: |set -euo pipefail- ALL=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 300 \- --json tagName,isDraft,isPrerelease,createdAt)+ RELEASES_JSON=$(gh api "repos/$GITHUB_REPOSITORY/releases?per_page=100" --paginate \+ --jq '.[] | select(.draft or (.prerelease | not)) | {tagName: .tag_name, isDraft: .draft, isPrerelease: .prerelease, updatedAt: .updated_at}' \+ | jq -sc '.')+ export RELEASES_JSON++ sweep=$(node .github/scripts/select-stuck-drafts.mjs)- # Highest published STABLE (non-draft AND non-prerelease) version,- # bare (leading v stripped). We gate on a STABLE, not merely a newer- # beta: a stuck draft beta's body must survive until its cycle has- # been promoted to stable (see header). `sort -V` is GNU coreutils on- # ubuntu-latest; both operands here are bare X.Y.Z (no prerelease- # suffix), so version-sort ordering is unambiguous.- maxstable=$(printf '%s' "$ALL" \- | jq -r '.[] | select((.isDraft | not) and (.isPrerelease | not)) | .tagName' \- | sed 's/^v//' \- | sort -V | tail -n1)- if [ -z "${maxstable}" ]; then- echo "No published stable release yet; keeping all drafts (their bodies feed the first stable's changelog)."+ if [ -z "${sweep}" ]; then+ echo "Nothing to sweep."exit 0fi- echo "Highest published stable version: ${maxstable}"- # Candidates: draft AND prerelease AND older than 90 min. The age- # gate must exceed desktop-release.yml's job budget (75 min) so a- # draft that a still-running per-tag build will promote is never- # swept — 5400s leaves margin above the timeout.- candidates=$(printf '%s' "$ALL" | jq -r --argjson maxage 5400 '- .[]- | select(.isDraft and .isPrerelease)- | select((now - (.createdAt | fromdateiso8601)) > $maxage)- | .tagName')+ count=$(printf '%s\n' "${sweep}" | grep -c . || true)- if [ -z "${candidates}" ]; then- echo "No stuck draft prereleases older than 90 min; nothing to sweep."+ # The dry run is checked BEFORE the cap so it can always preview,+ # including an over-cap set; it deletes nothing, so the cap is+ # information for it rather than a gate on it.+ if [ "${DRY_RUN:-false}" = "true" ]; then+ echo "Dry run: would sweep ${count} release(s), deleting nothing."+ if [ "${count}" -gt "${MAX_SWEEP_PER_RUN}" ]; then+ echo "Dry run: this set exceeds the per-run cap (${count} > ${MAX_SWEEP_PER_RUN}), so a real run would refuse it."+ fi+ printf '%s\n' "${sweep}"exit 0fi- printf '%s\n' "${candidates}" | while IFS= read -r tag; do+ if [ "${count}" -gt "${MAX_SWEEP_PER_RUN}" ]; then+ echo "::error::Refusing to sweep ${count} releases in one run (cap ${MAX_SWEEP_PER_RUN}). A healthy repo strands one or two at a time, so this is more likely a bad snapshot or a selector bug than a real backlog. Re-dispatch with dry_run to see the whole set; raising the cap itself is a code change to this workflow."+ printf '%s\n' "${sweep}"+ exit 1+ fi++ printf '%s\n' "${sweep}" | while IFS= read -r tag; do[ -z "${tag}" ] && continue- base="${tag#v}"; base="${base%-beta.*}" # vX.Y.Z-beta.N -> X.Y.Z- # Delete only once a published stable covers this beta's cycle,- # i.e. base <= maxstable. top==maxstable holds when base < maxstable- # (older closed cycle) and when base == maxstable (this cycle's- # stable exists). base > maxstable => cycle not yet promoted => keep.- top=$(printf '%s\n%s\n' "${base}" "${maxstable}" | sort -V | tail -n1)- if [ "${top}" = "${maxstable}" ]; then- echo "::notice::Sweeping stuck draft ${tag}: its ${base} cycle is closed (stable ${maxstable} exists), so its body is already aggregated. Git tag kept."- gh release delete "${tag}" --repo "$GITHUB_REPOSITORY" --yes- else- echo "Keeping ${tag}: cycle ${base} not yet promoted (newest stable ${maxstable}) — its body still feeds the future stable changelog. Re-run desktop-release.yml or promote it."- fi+ gh release delete "${tag}" --repo "$GITHUB_REPOSITORY" --yes+ echo "::notice::Swept stuck draft ${tag}: its cycle is closed. Git tag kept."doneecho "Draft-release janitor sweep complete."