release: stop automatic dispatches from cancelling in-flight releases; make runs terminal #48

Merged
founder merged 1 commit from claude/release-cancel-storm into main 2026-08-16 10:44:59 +00:00
Owner

What

Stops the release cancel storm and makes build-release runs terminal. See the commit message for the full analysis; headline numbers (Forgejo DB, 2026-08-16): 25/25 build-release runs in 48 h ended cancelled, 23 within 1 s of the next dispatch, ~14.7 runner-hours wasted, 0 Publish on main.

Three causes, three fixes:

  1. Auto dispatch cancels in-flight releases -> release-if-needed automatic ticks now wait until no release has real work in flight ("latest wins after completion"; newer pushes collapse into the newest waiter via the existing release-if-needed-main group; the attempted-guard keeps the no-loop property). Manual dispatch keeps its founder-only hotfix semantics.
  2. No run can terminate (Build (Windows Native Payload) pinned to runner-less key-store-winrunner; Forgejo evaluates job if: only after pickup) -> one knob vars.KEYSTORE_WINDOWS_LANE_ENABLED gates the plan, the runs-on label and the if:; while unset the forge runner skips the job. Expressions in runs-on/if with vars verified on this forge (scratch run 17182). Also refuses upload_microsoft_store=true / Windows-only plans while disabled.
  3. Stale-task sweeper cancelled just-requeued jobs on the next tick -> age from greatest(created,started,updated) with a 4 h hard ceiling. Takes effect only after the next forge deploy (the timer runs the script from the NixOS closure).

Active-run detection is now job-based (0/5/6 + a 2-min quiescence guard for blocked rows), ignores never-terminal rows, uses psql -v ON_ERROR_STOP=1, and ssh has ConnectTimeout/ServerAlive.

Verification

  • YAML parses; extracted run bodies pass bash -n; wait loop exercised under set -euo pipefail with stubs (always-active -> error after deadline; probe failures tolerated 4x then error; empty -> proceed).
  • New active-run SQL probed against the live DB with ON_ERROR_STOP: 0 active runs right now; the only live rows are the never-scheduled Windows rows in 17168/17181 (correctly ignored).
  • Adversarial 4-lens review (44 agents) before this PR: all major findings addressed (probe tolerance, job-based predicate, MS-Store consistency, single Windows knob, sweeper hard ceiling); residual builds/N collision between a manual release/* dispatch and a main auto run is documented in KSE-0186 (the auto side already waits for all refs).

Follow-ups

  • Forge deploy to activate the sweeper change (coordinate with the in-flight KSE-0182 nixos changes).
  • KSE-0186 (release pipeline caching / Bazel scope / Namespace capacity) records this policy change (supersedes KSE-0142's cancel-stale-work clause).
## What Stops the release cancel storm and makes build-release runs terminal. See the commit message for the full analysis; headline numbers (Forgejo DB, 2026-08-16): 25/25 build-release runs in 48 h ended cancelled, 23 within 1 s of the next dispatch, ~14.7 runner-hours wasted, 0 Publish on main. Three causes, three fixes: 1. **Auto dispatch cancels in-flight releases** -> release-if-needed automatic ticks now wait until no release has real work in flight ("latest wins after completion"; newer pushes collapse into the newest waiter via the existing release-if-needed-main group; the attempted-guard keeps the no-loop property). Manual dispatch keeps its founder-only hotfix semantics. 2. **No run can terminate** (`Build (Windows Native Payload)` pinned to runner-less key-store-winrunner; Forgejo evaluates job `if:` only after pickup) -> one knob `vars.KEYSTORE_WINDOWS_LANE_ENABLED` gates the plan, the runs-on label and the `if:`; while unset the forge runner skips the job. Expressions in runs-on/if with `vars` verified on this forge (scratch run 17182). Also refuses `upload_microsoft_store=true` / Windows-only plans while disabled. 3. **Stale-task sweeper** cancelled just-requeued jobs on the next tick -> age from greatest(created,started,updated) with a 4 h hard ceiling. **Takes effect only after the next forge deploy** (the timer runs the script from the NixOS closure). Active-run detection is now job-based (0/5/6 + a 2-min quiescence guard for blocked rows), ignores never-terminal rows, uses `psql -v ON_ERROR_STOP=1`, and ssh has ConnectTimeout/ServerAlive. ## Verification - YAML parses; extracted run bodies pass `bash -n`; wait loop exercised under `set -euo pipefail` with stubs (always-active -> error after deadline; probe failures tolerated 4x then error; empty -> proceed). - New active-run SQL probed against the live DB with `ON_ERROR_STOP`: 0 active runs right now; the only live rows are the never-scheduled Windows rows in 17168/17181 (correctly ignored). - Adversarial 4-lens review (44 agents) before this PR: all major findings addressed (probe tolerance, job-based predicate, MS-Store consistency, single Windows knob, sweeper hard ceiling); residual builds/N collision between a manual release/* dispatch and a main auto run is documented in KSE-0186 (the auto side already waits for all refs). ## Follow-ups - Forge deploy to activate the sweeper change (coordinate with the in-flight KSE-0182 nixos changes). - KSE-0186 (release pipeline caching / Bazel scope / Namespace capacity) records this policy change (supersedes KSE-0142's cancel-stale-work clause).
release: stop automatic dispatches from cancelling in-flight releases; make runs terminal
Some checks failed
Release: If Needed / Check (Release Needed) (push) Successful in 8s
Deploy: API / Deploy (API) (push) Has been cancelled
Deploy: Web / Deploy (Web) (push) Has been cancelled
Release: Signing Preflight / Release (Signing Preflight) (push) Has been cancelled
a155b63794
On 2026-08-16 every build-release run on main died before Publish: 25 of 25
runs in 48 h ended "cancelled", 23 of them within 1 s of the next dispatch,
~14.7 runner-hours thrown away, nothing shipped. Three independent causes,
all measured from the Forgejo DB and job logs:

1. release-if-needed.yml dispatches build-release on every push to main
   (median gap ~10 min today) and build-release's concurrency group
   `release-linux-v2-<ref>` has cancel-in-progress: true, so each auto
   dispatch superseded the previous run mid-flight (a full run needs
   45-65 min because of the Flatpak legs).
2. `Build (Windows Native Payload)` targets key-store-winrunner, a label with
   no runner since 2026-06-14. Forgejo evaluates a job's `if:` only after a
   runner picks it up, so the row sat in "waiting" for the life of every run
   and no build-release run could ever reach a terminal state on its own --
   run 17132 published builds/136 and still ended "cancelled". Since
   90e4c8aa the auto plan (build_windows=true from Scripts/release-impact.py)
   also fails Publish after the 25-minute Windows gate.
3. forgejo-requeue-stale-action-tasks measured a waiting job's age from the
   run's creation, so a job it had just requeued after a runner death was
   cancelled on the very next 2-minute tick inside any run older than 30 min
   (17094, 17114), flipping the whole run to "cancelled" while its other
   lanes were still building.

Changes:

- release-if-needed.yml: automatic (push/schedule) ticks now WAIT until no
  build-release run has real work in flight before they evaluate and
  dispatch ("latest wins after completion"). A newer push cancels the older
  waiter through the existing release-if-needed-main group, so only the
  newest commit's tick dispatches and intermediate commits collapse into it;
  the "attempted for this SHA" guard (41286f4f) still prevents any re-dispatch
  loop. Tags, build number and impact are (re)computed after the wait; a
  cheap version/impact pre-check exits early for docs-only pushes; up to 5
  consecutive probe failures are tolerated; the bound is
  vars.KEYSTORE_RELEASE_WAIT_MAX_SEC (default 7200 s) under a 240-minute job
  timeout; schedule ticks resolve the real main head instead of the stale
  workflow SHA. Manual (workflow_dispatch) ticks keep their immediate,
  founder-only, hotfix semantics. This deliberately supersedes KSE-0142's
  "newer commits dispatch so concurrency cancels stale work"; recorded in
  KSE-0186.
- Scripts/forgejo-active-release-runs-via-host.sh: "active" is decided from
  job rows (0/5/6, with a 2-minute quiescence guard for blocked rows) rather
  than action_run.status, so a run Forgejo already aggregated to
  failure/cancelled because of an experimental lane keeps being waited for;
  never-terminal rows (Apple Launch Smoke, Build (Windows Native Payload))
  are ignored; psql runs with ON_ERROR_STOP so schema drift cannot read as
  "no active runs"; ssh gets ConnectTimeout/ServerAlive so a hung probe
  cannot stall the loop.
- build-release.yml: one repo variable, KEYSTORE_WINDOWS_LANE_ENABLED, gates
  the Windows lane end to end: Prepare drops Windows from any plan while it
  is unset (error if upload_microsoft_store or a Windows-only plan was
  requested), and build-windows-native runs-on the forge label and is
  skipped, so every run reaches a terminal state (expressions in runs-on/if
  with `vars` verified on this forge, scratch run 17182). Set the variable to
  "true" when the VM lane is back.
- Scripts/forgejo-requeue-stale-action-tasks.py: age waiting jobs from
  greatest(created, started, updated) so a requeue grants a fresh grace, with
  a hard ceiling (--waiting-job-max-age-seconds, default 4 h) so a
  deterministically dying runner cannot keep a job bouncing forever. Takes
  effect only after the next forge deploy (the timer runs the script from
  the NixOS closure).

Residual (documented in KSE-0186): a manual release/* dispatch started while
a main auto run is in flight can still collide on builds/N at Tag Build; the
auto side waits for all refs, the manual side is expected to check.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
key-store/key.store!48
No description provided.