Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
feat(ship-policy): gstack adopts the release gate; a pre-adoption backstop freeze only warns (GST-1133) (#4031)
Garry Tan6666b7296766
diff --git a/.gstack/ship-policy.json b/.gstack/ship-policy.jsonindex 2e8281470..e8d58459c 100644--- a/.gstack/ship-policy.json+++ b/.gstack/ship-policy.json@@ -23,5 +23,6 @@"bun run scripts/test-free-shards.ts --files-from test/land-merged-checks.txt --wall-timeout 600"]},+ "release_gate": { "cadence_hours": 8, "gate_workflow": "evals.yml", "branch": "main", "stable_ref": "stable", "check_name": "main-backstop", "on_red": "hold-release", "bisect_spend_cap_usd": 80 },"min_gstack_version": "1.96.0.0"}diff --git a/changelog.d/gsta258-g2-release-gate-adoption.md b/changelog.d/gsta258-g2-release-gate-adoption.mdnew file mode 100644index 000000000..8c058754d--- /dev/null+++ b/changelog.d/gsta258-g2-release-gate-adoption.md@@ -0,0 +1 @@+- **gstack's own policy turns on the release gate.** `.gstack/ship-policy.json` now declares `release_gate`, so one full paid gate runs on main every 8 hours instead of a gate on every push, and a red gate holds the stable release rather than freezing the queue. The per-push main backstop stands down. `land --pin` now only warns about a backstop freeze written before the switch, and `release-cut` lets that freeze go once a green release gate runs on a later commit. The bisect after a red gate counts the red case's rerun against `bisect_spend_cap_usd` (now $80), follows the policy's current cap, and resumes when the cap is raised again. (GST-1133)diff --git a/docs/ship-policy.md b/docs/ship-policy.mdindex 85b8080fe..0f018fc77 100644--- a/docs/ship-policy.md+++ b/docs/ship-policy.md@@ -67,6 +67,7 @@ refuses the file (`POLICY_GSTACK_TOO_OLD`). `validate` ends with| `train` | `{ gate_workflow, free_workflow, full_gate_check, record_artifact, max_size, fill_hours, screen_selection, trial_reservation_usd, land? }`, `{ gates, land, max_size, fill_hours }` or `null` | `null` | Turns on [merge trains](#run-a-merge-train), read from the base revision only. Every field is required and an unknown field is `POLICY_INVALID`: `max_size` 1 to 6, `fill_hours` above 0 and at most 24, `screen_selection` `gstack-paid` \| `none`, `trial_reservation_usd` above 0 and at most 100. A block with `gates` ([any repository](#train-gates)) takes `max_size` 1 to 5 and needs `min_gstack_version` at least `TRAIN_GATES_KEY_VERSION`. `null` keeps the per-PR queue exactly as it is. Needs `min_gstack_version`. || `merge` | `train` \| `direct` | `train` | `direct` lands each READY PR at its own green head with [`land --pr <n> --pin <sha>`](#land-direct): no train and no stamp commit, and `train build` refuses. A PR then leaves VERSION, the `package.json` version and the CHANGELOG at its merge base, and the release sets them. Needs `changelog_fragments`, and the stamping `land --pr <n>` refuses under it. `train` keeps merge trains. Read from the base revision only. Needs `min_gstack_version`. || `land` | `{ merged_checks }` or `null` | `null` | Under `merge: direct`, the shell commands (1 to 16, one line of at most 512 characters each, 15 minutes each) [`land --pin`](#land-direct) runs on the pin merged onto the base tip when the base moved past the pin's merge base; it lands only when every one exits 0. They are repo commands, so land runs them only with `--allow-repo-commands`, never under `--dry-run`. `null` lands a stale base untested with a `STALE_BASE: warn` line. Read from the base revision only. Needs `min_gstack_version`. |+| `release_gate` | `{ cadence_hours, gate_workflow, branch, stable_ref, check_name, on_red, bisect_spend_cap_usd }` or `null` | `null` | One full paid gate on main every `cadence_hours` (8 to 168) instead of the per-push main backstop, feeding the stable release; see [release_gate](#release-gate). Every field is required: `on_red` is `hold-release`, `bisect_spend_cap_usd` 0 to 500 (0 skips the bisect). `null` keeps the per-push backstop. Needs `min_gstack_version`. || `bookkeeping` | glob list | `[]` | <a id="bookkeeping"></a>Root-anchored globs of bookkeeping tables a verify or ratchet step rewrites (size baselines, serial lists, limits), each ending in `.tsv`, `.csv` or `.txt` and never under `.gstack/` or `.github/` (`["scripts/*-baseline.tsv"]`). A matching file changed at most 20 lines after review binds, first touched or not, takes finish's [one scoped reader](review-policy.md#bounded-post-review-edits) instead of Steps 5–11.5; the reader still reads every changed row. Read from the base revision only. Needs `min_gstack_version`. || `base_red` | `{ setup, select, timeout_sec }` or `null` | `null` | How `/ship` Step 5 proves a failure is the base branch's own before pausing on it; see [base_red](#base-red). Read from the base revision only. Needs `min_gstack_version`. || `changelog_fragments` | `{ dir, required_checks? }` or `null` | `null` | PRs carry unversioned [CHANGELOG fragments](#changelog-fragments) in `dir` (one flat, repo-relative directory, no `..`) and the merge step ([`land`](#land)) assigns the version (under `merge: direct`, the [release PR](#release-stamp) does). `required_checks` (up to 50 distinct names) are the checks [`train land`](#stamped-trains-under-changelog_fragments-train-land) requires present and green on a stamp commit. `null` keeps `[Unreleased]` sections and per-PR stamps. Needs `min_gstack_version`. |@@ -1151,7 +1152,13 @@ block, with `min_gstack_version` at least the release that introduced the keyEvery field is required. `cadence_hours` runs from 8 (the workflow'sschedule) to 168. `check_name` is the check run release-cut reads as gated,so gstack keeps `main-backstop`. `bisect_spend_cap_usd` caps one red gate's-bisect (0 skips it).+bisect (0 skips it). Each case reserves two trials on every prefix, one trial+and its one rule-16 rerun, and books the trials it ran at $1.50 each, since+prefix records carry no cost. So the cap bounds trials at that price, not+the bill: trials that cost more can carry a bisect past it. A running bisect+follows the policy's cap (lowering it to 0 stops it, and `bisect` resumes a+capped one once the cap exceeds what it spent); `bisect --spend-cap` applies+to that one run only.**What runs.** `.github/workflows/release-gate.yml` fires every 8 hours andon a manual dispatch from main. Without the block it stops after a git-and-jq@@ -2099,7 +2106,7 @@ release-file rows):| the PR head is the pin | [`QUEUE_LAND_PIN_MOVED`](troubleshooting.md#queue-land-pin-moved) || the PR body's /ship receipt is bound to the pin | `QUEUE_RECEIPT_MISSING`, `QUEUE_RECEIPT_STALE` || a READY note from `ready` exists at the pin | `QUEUE_NOT_READY` |-| no freeze is active (with `--repair`: one is, and its repair slot is free or already this pin; see [direct freeze](#direct-freeze)) and no land lock is held | [`QUEUE_TRAIN_FROZEN`](troubleshooting.md#queue-train-frozen), `QUEUE_NOT_READY`, `QUEUE_LAND_LOCKED` |+| no freeze is active (with `--repair`: one is, and its repair slot is free or already this pin; a backstop freeze left from before `release_gate` only warns; see [direct freeze](#direct-freeze)) and no land lock is held | [`QUEUE_TRAIN_FROZEN`](troubleshooting.md#queue-train-frozen), `QUEUE_NOT_READY`, `QUEUE_LAND_LOCKED` || VERSION, the `package.json` version, the CHANGELOG and `.gstack/version-path` are unchanged since the merge base | [`QUEUE_LAND_STAMPED`](troubleshooting.md#queue-land-stamped) || every check at the pin is green with none pending, and each `changelog_fragments.required_checks` entry passed there | [`QUEUE_LAND_CHECKS`](troubleshooting.md#queue-land-checks) || GitHub reports the PR `MERGEABLE` and `CLEAN` | [`QUEUE_LAND_NOT_CLEAN`](troubleshooting.md#queue-land-not-clean) |@@ -2167,7 +2174,12 @@ While main's policy keeps a `train` block, the main backstop gates every pushto main, and a red gate writes a freeze record (`train backstop`) to`refs/notes/gstack-trains`. `land --pin` and `release-cut` refuse while it isactive (`QUEUE_TRAIN_FROZEN`), and `train build --repair` is off with the-trains. So the repair goes through land:+trains. Once main's policy declares [`release_gate`](#release-gate) the+backstop stands down and writes no freeze, so `land --pin` prints a+`FREEZE: warn only:` line for a backstop freeze left from before and lands;+a train's freeze still refuses. `release-cut` keeps refusing on that freeze+until a green release gate sits on a commit that contains its main+(`gstack-release-gate run --ignore-cadence` runs one now). Otherwise the repair goes through land:1. `gstack-ship-queue land --pr <n> --pin <sha> --repair` admits exactly one PR.It runs every check in the table above. Then, under the land lock and afterdiff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex 1e595db62..a3e291dfa 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -5738,6 +5738,7 @@ normal pin check, then records the repair on the freeze under the land lock(`REPAIR: #<n>@<sha> admitted under the land lock`) and lands it; the freezestays active. The next main backstop clears it when its gate is green on thatmain (`BACKSTOP: freeze cleared (repair #<n>; backstop <run> green on <sha>)`).+Once main's policy declares `release_gate`, the backstop stands down: `land --pin` only warns (`FREEZE: warn only:`) about a backstop freeze left from before and lands, and `release-cut` lets that freeze go once a green release gate sits on a commit that contains the freeze's main ([release_gate](ship-policy.md#direct-freeze)).A second `--repair` is refused while the admitted one has merged at itsrecorded pin and no backstop has judged it; one that never merged there givesway. Seediff --git a/lib/release-gate.ts b/lib/release-gate.tsindex 9e5b61bfb..0b3749abc 100644--- a/lib/release-gate.ts+++ b/lib/release-gate.ts@@ -36,6 +36,8 @@ import {} from './ship-queue-train-record';export const RELEASE_TRIAL_RESERVATION_USD = 1.5;+/** A bisect case runs one trial and, on a VERDICT failure, its one rule-16 rerun (scripts/train-gate.ts runBisectPrefix). */+export const RELEASE_TRIALS_PER_CASE = 2;/** The gate plus the one re-dispatch EVAL_POLICY.infraRedispatch allows an incomplete census. */export const MAX_RELEASE_ATTEMPTS = 2;/** Cron start jitter the cadence forgives. */@@ -296,7 +298,7 @@ export function runGate(env: GateEnv, o: RunOptions): GateOut {}function finishRed(env: GateEnv, c: Context, rec: ReleaseRecord, lines: string[], out: (a: GateAction, s: string | null) => GateOut): GateOut {- bisectRecord(env, c, rec, { spendCap: c.gate.bisect_spend_cap_usd, dryRun: false }, lines);+ bisectRecord(env, c, rec, { dryRun: false }, lines);lines.push(`RELEASE: red sha=${rec.sha} first_bad=${rec.bisect?.first_bad ?? 'unknown'} run=${rec.run?.id ?? '-'}`,`RELEASE: hold: scripts/release-cut.ts refuses to move ${c.gate.stable_ref} until a gate on a later commit is green (red: ${rec.red_cases.join(', ')}); land the revert or the fix-forward`);return out('held', rec.sha);@@ -304,17 +306,19 @@ function finishRed(env: GateEnv, c: Context, rec: ReleaseRecord, lines: string[]/*** Collect a bisect round's prefix records into its results. Each case on each prefix adds its reported cost to the spend, or- * RELEASE_TRIAL_RESERVATION_USD when the cost is null or the prefix record is missing, so the cap holds across rounds.+ * RELEASE_TRIAL_RESERVATION_USD for each trial it ran when the cost is null: two for a VERDICT failure or a flaky pass (the+ * rule-16 rerun), one otherwise, and two when the prefix record is missing, so the cap holds across rounds.*/function collectRound(env: GateEnv, b: ReleaseBisect, round: ReleaseBisectRound, run: Run): void {for (const p of round.prefixes) {const text = artifactFile(env, run.id, `${RELEASE_BISECT_ARTIFACT}-bisect-${p.sha.slice(0, 12)}`, 'bisect-prefix.json');- let rec: { kind?: string; nonce?: string; prefix_sha?: string; checked_out_sha?: string; panels?: Array<{ case: string; status: string; red_class: string | null; cost_usd: number | null }> } | null = null;+ let rec: { kind?: string; nonce?: string; prefix_sha?: string; checked_out_sha?: string; panels?: Array<{ case: string; status: string; red_class: string | null; cost_usd: number | null; flaky?: unknown }> } | null = null;try { rec = text ? JSON.parse(text) : null; } catch { rec = null; }const valid = rec && rec.kind === 'train-bisect-prefix' && rec.nonce === round.nonce && rec.prefix_sha === p.sha && rec.checked_out_sha === p.sha && Array.isArray(rec.panels);for (const c of b.cases) {const panel = valid ? rec!.panels!.find(x => x.case === c) : undefined;- b.spent_usd = Math.round((b.spent_usd + (typeof panel?.cost_usd === 'number' ? panel.cost_usd : RELEASE_TRIAL_RESERVATION_USD)) * 100) / 100;+ const trials = !panel || panel.flaky || (panel.status === 'FAIL' && panel.red_class === 'VERDICT') ? RELEASE_TRIALS_PER_CASE : 1;+ b.spent_usd = Math.round((b.spent_usd + (typeof panel?.cost_usd === 'number' ? panel.cost_usd : trials * RELEASE_TRIAL_RESERVATION_USD)) * 100) / 100;if (!panel) continue;if (panel.status === 'PASS') p.results[panel.case] = 'green';else if (panel.status === 'FAIL' && panel.red_class === 'VERDICT') p.results[panel.case] = 'red';@@ -326,13 +330,17 @@ function collectRound(env: GateEnv, b: ReleaseBisect, round: ReleaseBisectRound,* Bisect a red record (resumable): finish a round still running, then narrow* (good, bad] with up to MAX_PREFIXES commits a round until they are adjacent,* the pattern is not monotone, the cap is spent, or MAX_BISECT_ROUNDS pass.+ * Without o.spendCap the bisect runs under the policy's current cap (stored as spend_cap), so lowering the policy stops further+ * rounds and raising it lets `bisect` resume; a one-off `bisect --spend-cap` (o.spendCap) applies to that invocation only and is never stored.*/-export function bisectRecord(env: GateEnv, c: Context, rec: ReleaseRecord, o: { spendCap: number; dryRun: boolean }, lines: string[]): void {- const b: ReleaseBisect = rec.bisect ?? { cases: rec.red_cases, good: rec.since, bad: rec.sha, first_bad: null, spend_cap: o.spendCap, spent_usd: 0, state: 'running', detail: '', rounds: [] };- b.spend_cap = Math.max(b.spend_cap, o.spendCap);+export function bisectRecord(env: GateEnv, c: Context, rec: ReleaseRecord, o: { spendCap?: number; dryRun: boolean }, lines: string[]): void {+ const policyCap = c.gate.bisect_spend_cap_usd;+ const b: ReleaseBisect = rec.bisect ?? { cases: rec.red_cases, good: rec.since, bad: rec.sha, first_bad: null, spend_cap: policyCap, spent_usd: 0, state: 'running', detail: '', rounds: [] };+ b.spend_cap = policyCap;+ const cap = o.spendCap ?? policyCap;const stop = (state: ReleaseBisect['state'], detail: string) => { Object.assign(b, { state, detail }); };if (!o.dryRun) rec.bisect = b;- if (b.state === 'running' && o.spendCap <= 0 && !b.rounds.length) stop('unknown', 'bisect_spend_cap_usd is 0: no bisect');+ if (b.state === 'running' && cap <= 0 && !b.rounds.length) stop('unknown', 'bisect_spend_cap_usd is 0: no bisect');else if (b.state === 'running' && (!b.cases.length || b.cases.length > MAX_BISECT_CASES || b.cases.some(id => !CASE_ID.test(id)))) stop('unknown', `the red cases cannot be bisected (${b.cases.length} case ids, at most ${MAX_BISECT_CASES})`);else if (b.state === 'running' && !b.good) stop('unknown', 'no green gate and no stable branch before the red commit to bisect from');while (b.state === 'running') {@@ -355,10 +363,10 @@ export function bisectRecord(env: GateEnv, c: Context, rec: ReleaseRecord, o: {interior.pop();if (!interior.length) { b.first_bad = b.bad; stop('found', `${short(b.bad)} is the first red commit after green ${short(b.good)}`); break; }if (b.rounds.length >= MAX_BISECT_ROUNDS) { stop('unknown', `${MAX_BISECT_ROUNDS} rounds left ${interior.length} commit(s) between ${short(b.good)} and ${short(b.bad)}`); break; }- const perPrefix = b.cases.length * RELEASE_TRIAL_RESERVATION_USD;- const fits = Math.floor((b.spend_cap - b.spent_usd + 1e-9) / perPrefix);+ const perPrefix = b.cases.length * RELEASE_TRIALS_PER_CASE * RELEASE_TRIAL_RESERVATION_USD;+ const fits = Math.max(0, Math.floor((cap - b.spent_usd + 1e-9) / perPrefix));const prefixes = planPrefixes(interior, Math.min(MAX_PREFIXES, fits));- if (!prefixes.length) { stop('capped', `the next round needs $${perPrefix.toFixed(2)} a prefix; $${(b.spend_cap - b.spent_usd).toFixed(2)} of the $${b.spend_cap.toFixed(2)} cap is left`); break; }+ if (!prefixes.length) { stop('capped', `the next round needs $${perPrefix.toFixed(2)} a prefix; $${Math.max(0, cap - b.spent_usd).toFixed(2)} of the $${cap.toFixed(2)} cap is left`); break; }lines.push(`RELEASE: bisect round ${b.rounds.length + 1}: ${b.cases.length} case(s) on ${prefixes.length} of ${interior.length} commit(s) between ${short(b.good)} and ${short(b.bad)}, $${(perPrefix * prefixes.length).toFixed(2)} reserved`);if (o.dryRun) { lines.push('RELEASE: dry run: nothing dispatched'); return; }const nonce = makeNonce('gate', b.bad, b.good!, env.random(), { purpose: 'bisect' });@@ -372,7 +380,7 @@ export function bisectRecord(env: GateEnv, c: Context, rec: ReleaseRecord, o: {}) : `git push ${ref} failed: ${pushed.out.slice(0, 120)}`;if (failed) { round.run = { id: -1, url: '' }; env.git(['push', '-q', env.remote, '--delete', `refs/heads/${ref}`]); stop('unknown', `round ${b.rounds.length} dispatch failed: ${failed}`); }}- lines.push(`RELEASE: bisect ${b.state}: ${b.detail} (spent $${b.spent_usd.toFixed(2)} of $${b.spend_cap.toFixed(2)})`);+ lines.push(`RELEASE: bisect ${b.state}: ${b.detail} (spent $${b.spent_usd.toFixed(2)} of $${cap.toFixed(2)})`);if (!o.dryRun) save(env, rec, lines);}@@ -385,8 +393,8 @@ export function bisectGate(env: GateEnv, o: { gate: ReleaseGatePolicy | null; laconst rec = o.sha ? c.records.find(r => r.sha === o.sha) : c.records.find(r => r.verdict === 'RED');if (!rec || rec.verdict !== 'RED') { lines.push(`RELEASE: no red release record${o.sha ? ` at ${o.sha}` : ''} to bisect`); return { action: 'failed', sha: o.sha ?? null, lines }; }ensureHistory(env, o.gate, rec.sha);- if (rec.bisect?.state === 'capped' && (o.spendCap ?? 0) > rec.bisect.spend_cap) rec.bisect.state = 'running';- bisectRecord(env, c, rec, { spendCap: o.spendCap ?? o.gate.bisect_spend_cap_usd, dryRun: o.dryRun }, lines);+ if (rec.bisect?.state === 'capped' && (o.spendCap ?? o.gate.bisect_spend_cap_usd) > rec.bisect.spent_usd) rec.bisect.state = 'running';+ bisectRecord(env, c, rec, { spendCap: o.spendCap, dryRun: o.dryRun }, lines);lines.push(`RELEASE: red sha=${rec.sha} first_bad=${rec.bisect?.first_bad ?? 'unknown'} run=${rec.run?.id ?? '-'}`);return { action: o.dryRun ? 'dry-run' : 'held', sha: rec.sha, lines };}diff --git a/lib/ship-queue-land-direct.ts b/lib/ship-queue-land-direct.tsindex 741075082..cdd19f9cc 100644--- a/lib/ship-queue-land-direct.ts+++ b/lib/ship-queue-land-direct.ts@@ -163,7 +163,9 @@ export function landDirect(ctx: QueueContext, o: DirectOptions): StepOutput {if (!loadReady(keys, o.pr, o.pin)) return fail(lines, { code: 'QUEUE_NOT_READY', message: `no READY note for #${o.pr} at the pin ${o.pin.slice(0, 12)}`, fix: `the lane runs gstack-ship-queue ready --pr ${o.pr} --no-screen at the pin` });}const freeze = activeFreeze(keys);- if (freeze && !o.repair) return fail(lines, { code: 'QUEUE_TRAIN_FROZEN', message: `main is frozen by train ${freeze.train} (${freeze.reason})`, fix: 'only the one repair PR lands: gstack-ship-queue land --pr <repair-pr> --pin <sha> --repair; the freeze clears when the main backstop is green on a main that contains it (docs/ship-policy.md#direct-freeze)' });+ const standsDown = freeze?.train === 'backstop' && policy.release_gate !== null;+ if (standsDown) lines.push(`FREEZE: warn only: train backstop froze main (${freeze.reason}); the base policy declares release_gate, so the backstop stands down and a red release gate holds release-cut instead of land (docs/ship-policy.md#direct-freeze)`);+ if (freeze && !standsDown && !o.repair) return fail(lines, { code: 'QUEUE_TRAIN_FROZEN', message: `main is frozen by train ${freeze.train} (${freeze.reason})`, fix: 'only the one repair PR lands: gstack-ship-queue land --pr <repair-pr> --pin <sha> --repair; the freeze clears when the main backstop is green on a main that contains it (docs/ship-policy.md#direct-freeze)' });const refused = !o.repair ? null : release ? { code: 'QUEUE_TRAIN_FROZEN' as const, message: `${info.headRefName} is a release PR, which never repairs main`, fix: 'land the revert or fix-forward with --repair; release once the backstop clears the freeze' } : repairRefusal(ctx, freeze, o.pr, o.pin);if (refused) return fail(lines, refused);const lock = o.dryRun ? readLock(root, remote) : null;diff --git a/scripts/release-cut.ts b/scripts/release-cut.tsindex 9dbe1caa0..34cd8f429 100755--- a/scripts/release-cut.ts+++ b/scripts/release-cut.ts@@ -136,7 +136,7 @@ export function gateVerdict(gh: Gh, repo: string, sha: string, o: GateOptions =export interface TrainNotes { error: string | null; freeze: string | null; evidence: TrainEvidence }interface NoteRecord {kind?: string; state?: string; nonce?: string; merged?: Array<{ sha?: string; tree?: string }>; cleared_at?: string | null; reason?: string; train?: string;- sha?: string; verdict?: string; run?: { id?: number } | null; red_cases?: string[];+ sha?: string; verdict?: string; run?: { id?: number } | null; red_cases?: string[]; main?: { sha?: string } | null;}/**@@ -147,7 +147,10 @@ interface NoteRecord {* an error; a missing ref holds nothing. Release-gate records (kind release,* lib/release-gate.ts) add evidence when GREEN, and a RED one with no GREEN* record on a later commit that contains it is the hold: it refuses the cut- * like a freeze (a train freeze, when both exist, is the one named).+ * like a freeze (a train freeze, when both exist, is the one named). A backstop+ * freeze clears for the cut once a GREEN release record sits on a commit that+ * contains its main: under release_gate the backstop stands down and never+ * clears it itself.*/export function readTrainNotes(git: Git, notesRef = NOTES_REF): TrainNotes {const notes: TrainNotes = { error: null, freeze: null, evidence: { bySha: new Map(), byTree: new Map() } };@@ -159,6 +162,7 @@ export function readTrainNotes(git: Git, notesRef = NOTES_REF): TrainNotes {const listed = git(['notes', `--ref=${NOTES_LOCAL}`, 'list']);if (!listed.ok || !listed.out.trim()) return notes;const gates: Array<{ sha: string; verdict: string; red: string[] }> = [];+ let backstopMain: string | null = null;notes.evidence.release = new Map();for (const line of listed.out.split('\n')) {const blob = line.split(' ')[0];@@ -167,7 +171,10 @@ export function readTrainNotes(git: Git, notesRef = NOTES_REF): TrainNotes {try { parsed = JSON.parse(git(['cat-file', 'blob', blob]).out); } catch { continue; }if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) continue;const r = parsed as NoteRecord;- if (r.kind === 'freeze' && !r.cleared_at) notes.freeze = `queue frozen since train ${r.train ?? '?'}: ${r.reason ?? 'red backstop'}`;+ if (r.kind === 'freeze' && !r.cleared_at) {+ notes.freeze = `queue frozen since train ${r.train ?? '?'}: ${r.reason ?? 'red backstop'}`;+ backstopMain = r.train === 'backstop' && typeof r.main?.sha === 'string' && /^[0-9a-f]{40}$/.test(r.main.sha) ? r.main.sha : null;+ }if (r.kind === 'release' && typeof r.sha === 'string' && /^[0-9a-f]{40}$/.test(r.sha)) {gates.push({ sha: r.sha, verdict: String(r.verdict), red: Array.isArray(r.red_cases) ? r.red_cases.filter(c => typeof c === 'string') : [] });if (r.verdict === 'GREEN') notes.evidence.release.set(r.sha, String(r.run?.id ?? '?'));@@ -179,6 +186,8 @@ export function readTrainNotes(git: Git, notesRef = NOTES_REF): TrainNotes {if (typeof m.tree === 'string' && m.tree) notes.evidence.byTree.set(m.tree, r.nonce);}}+ const main = backstopMain;+ if (main && gates.some(g => g.verdict === 'GREEN' && git(['merge-base', '--is-ancestor', main, g.sha]).ok)) notes.freeze = null;const held = gates.find(red => red.verdict === 'RED' && !gates.some(g => g.verdict === 'GREEN' && g.sha !== red.sha && git(['merge-base', '--is-ancestor', red.sha, g.sha]).ok));if (held && !notes.freeze) notes.freeze = `release gate red on ${held.sha.slice(0, 12)} (${held.red.join(', ') || 'red cases not recorded'}) and no gate on a later commit is green; land the revert or fix-forward, then run gstack-release-gate run --ignore-cadence`;return notes;diff --git a/test/release-cut.test.ts b/test/release-cut.test.tsindex 0de0eba80..1d4979a22 100644--- a/test/release-cut.test.ts+++ b/test/release-cut.test.ts@@ -247,6 +247,19 @@ describe('release-cut: planning', () => {expect(thawed.ok, JSON.stringify(thawed)).toBe(true);if (thawed.ok) expect(thawed.plan.via).toBe('train ok1');});++ test('GST-1133: a backstop freeze left from before release_gate stands until a GREEN release gate on a commit that contains its main; a train freeze ignores the gate', () => {+ const f = fixture();+ const add = (record: unknown, on: string) => { git(f.seed, 'notes', '--ref=' + NOTES_REF, 'add', '-f', '-m', JSON.stringify(record), on); git(f.seed, 'push', '-q', '-f', 'origin', NOTES_REF); };+ const freeze = { schema: 1, kind: 'freeze', train: 'backstop', reason: 'backstop red', main: { sha: f.shas['1.0.1'] }, cleared_at: null };+ add(freeze, f.shas['1.0.1']!);+ add({ schema: 1, kind: 'release', sha: f.shas['1.0.0'], verdict: 'GREEN', run: { id: 1 } }, f.shas['1.0.0']!);+ expect(readTrainNotes(f.git).freeze).toBe('queue frozen since train backstop: backstop red');+ add({ schema: 1, kind: 'release', sha: f.shas['1.0.2'], verdict: 'GREEN', run: { id: 2 } }, f.shas['1.0.2']!);+ expect(readTrainNotes(f.git).freeze).toBeNull();+ add({ ...freeze, train: 'ok1' }, f.shas['1.0.1']!);+ expect(readTrainNotes(f.git).freeze).toBe('queue frozen since train ok1: backstop red');+ });});describe('release-cut: the release gate holds and gates (lib/release-gate.ts records)', () => {diff --git a/test/release-gate.test.ts b/test/release-gate.test.tsindex 07e79ab39..b1f211f58 100644--- a/test/release-gate.test.ts+++ b/test/release-gate.test.ts@@ -13,7 +13,7 @@ import * as os from 'node:os';import * as path from 'node:path';import { bunIsolationArgs } from '../lib/bun-isolation';import {- MAX_RELEASE_ATTEMPTS, OPEN_GATE_CADENCES, activeHold, bisectGate, classifyRun, gateStatus, loadReleaseGate, narrow, parseReport, planPrefixes, releaseRecords, runGate,+ MAX_RELEASE_ATTEMPTS, OPEN_GATE_CADENCES, RELEASE_TRIAL_RESERVATION_USD, activeHold, bisectGate, classifyRun, gateStatus, loadReleaseGate, narrow, parseReport, planPrefixes, releaseRecords, runGate,type GateEnv, type Run,} from '../lib/release-gate';import { RELEASE_GATE_SCHEDULE_HOURS, releaseGateErrors, type ReleaseGatePolicy } from '../lib/release-gate-policy';@@ -310,7 +310,7 @@ describe('release gate: red, bisect and the hold', () => {const g = fixture();const fake2 = fakeGh((inputs) => (inputs.prefix_shas ? { conclusion: 'success', artifacts: {} } : { conclusion: 'failure', artifacts: report('RED', ['case-a rule FAIL VERDICT', 'case-b judge FAIL']) }));const capped = runGate(envFor(g, fake2.gh), { gate: { ...GATE, bisect_spend_cap_usd: 2 }, label: 'test', dryRun: false, ignoreCadence: true });- expect(capped.lines.some(l => l.includes('bisect capped: the next round needs $3.00 a prefix'))).toBe(true);+ expect(capped.lines.some(l => l.includes('bisect capped: the next round needs $6.00 a prefix'))).toBe(true);expect(fake2.dispatches).toHaveLength(1);const plan = bisectGate(envFor(g, fake2.gh), { gate: GATE, label: 'test', spendCap: 30, dryRun: true });expect(plan.lines.some(l => l.startsWith('RELEASE: bisect round 1: 2 case(s) on 4 of 4 commit(s)'))).toBe(true);@@ -339,10 +339,91 @@ describe('release gate: the bisect cap with unknown costs', () => {const out = runGate(envFor(f, fake.gh), { gate: { ...GATE, bisect_spend_cap_usd: 4 }, label: 'test', dryRun: false, ignoreCadence: true });expect(out.action, out.lines.join('\n')).toBe('held');const bisect = records(f)[0]!.bisect!;- expect(bisect).toMatchObject({ state: 'capped', spent_usd: 3 });+ expect(bisect).toMatchObject({ state: 'capped', spent_usd: 1.5 });expect(bisect.spent_usd).toBeLessThanOrEqual(4);expect(fake.dispatches).toHaveLength(2);- expect(fake.dispatches[1]!.inputs.prefix_shas!.split(',')).toHaveLength(2);+ expect(fake.dispatches[1]!.inputs.prefix_shas!.split(',')).toHaveLength(1);+ });+ // Value: protects=a red prefix runs its case twice (one trial plus its one rule-16 rerun in scripts/train-gate.ts runBisectPrefix),+ // so each prefix reserves both trials and books the trials it ran, and the bisect ends capped at or under its dollar cap;+ // fails_when=a round reserves one trial a prefix, dispatches more prefixes than the cap pays for once they rerun, and books+ // half of what ran; why_new=GSTA-36 condition before adoption (l1 fix-check open note); seam=fake gh; no_claim=real case prices+ test('a red case and its rule-16 rerun count against the cap: the bisect ends capped at or under bisect_spend_cap_usd', () => {+ const f = fixture();+ [6, 7, 8, 9, 10, 11, 12].forEach(i => f.commit('c' + i));+ const fake = fakeGh((inputs) => {+ if (!inputs.prefix_shas) return { conclusion: 'failure', artifacts: report('RED', ['case-a rule FAIL VERDICT']) };+ const files: Record<string, Record<string, string>> = {};+ for (const sha of inputs.prefix_shas.split(',')) {+ files['gstack-release-record-bisect-' + sha.slice(0, 12)] = { 'bisect-prefix.json': JSON.stringify({ schema: 1, kind: 'train-bisect-prefix', nonce: inputs.nonce, prefix_sha: sha, checked_out_sha: sha,+ panels: [{ case: 'case-a', kind: 'rule', status: 'FAIL', red_class: 'VERDICT', cost_usd: null }] }) };+ }+ return { conclusion: 'success', artifacts: files };+ });+ const cap = 4;+ const out = runGate(envFor(f, fake.gh), { gate: { ...GATE, bisect_spend_cap_usd: cap }, label: 'test', dryRun: false, ignoreCadence: true });+ expect(out.action, out.lines.join('\n')).toBe('held');+ const bisect = records(f)[0]!.bisect!;+ const prefixesRun = fake.dispatches.slice(1).reduce((n, d) => n + d.inputs.prefix_shas!.split(',').length, 0);+ const trialsRun = prefixesRun * 2;+ expect(bisect.state).toBe('capped');+ expect(bisect.spent_usd).toBe(trialsRun * RELEASE_TRIAL_RESERVATION_USD);+ expect(trialsRun * RELEASE_TRIAL_RESERVATION_USD).toBeLessThanOrEqual(cap);+ expect(prefixesRun).toBeGreaterThan(0);+ });+ // Value: protects=a running release bisect never spends past the current policy cap: a scheduled resume takes the current policy cap, so+ // lowering bisect_spend_cap_usd (to 0 here) stops further rounds, and a one-off bisect --spend-cap applies to that invocation only and is not+ // stored as a floor; fails_when=the stored cap only rises (Math.max), so a lowered policy keeps dispatching and a one-off raise keeps+ // spending on every later scheduled run; why_new=GSTA-36 condition before adoption (targeted reader at 598467d); seam=fake gh; no_claim=real case prices+ test('lowering the cap mid-bisect stops further spend, and a one-off --spend-cap is not stored', () => {+ const f = fixture();+ [6, 7, 8, 9, 10, 11, 12].forEach(i => f.commit('c' + i));+ let roundStatus = 'in_progress';+ const fake = fakeGh((inputs) => {+ if (!inputs.prefix_shas) return { conclusion: 'failure', artifacts: report('RED', ['case-a rule FAIL VERDICT']) };+ const files: Record<string, Record<string, string>> = {};+ for (const sha of inputs.prefix_shas.split(',')) {+ files['gstack-release-record-bisect-' + sha.slice(0, 12)] = { 'bisect-prefix.json': JSON.stringify({ schema: 1, kind: 'train-bisect-prefix', nonce: inputs.nonce, prefix_sha: sha, checked_out_sha: sha,+ panels: [{ case: 'case-a', kind: 'rule', status: 'PASS', red_class: null, cost_usd: null }] }) };+ }+ return { conclusion: roundStatus === 'in_progress' ? '' : 'success', status: roundStatus, artifacts: files };+ });+ const env = envFor(f, fake.gh);+ runGate({ ...env, deadline: 0 }, { gate: { ...GATE, bisect_spend_cap_usd: 7 }, label: 'test', dryRun: false, ignoreCadence: true });+ expect(fake.dispatches).toHaveLength(2);+ expect(records(f)[0]!.bisect!.state).toBe('running');+ Object.assign(fake.runs[1]!, { status: 'completed', conclusion: 'success' });+ roundStatus = 'completed';++ const lowered = bisectGate(env, { gate: { ...GATE, bisect_spend_cap_usd: 0 }, label: 'test', dryRun: false });+ const afterLower = records(f)[0]!.bisect!;+ expect(fake.dispatches, lowered.lines.join('\n')).toHaveLength(2);+ expect(afterLower.state).toBe('capped');+ expect(afterLower.spend_cap).toBe(0);++ const oneOff = bisectGate(env, { gate: { ...GATE, bisect_spend_cap_usd: 0 }, label: 'test', spendCap: 40, dryRun: false });+ expect(fake.dispatches.length, oneOff.lines.join('\n')).toBeGreaterThan(2);+ expect(records(f)[0]!.bisect!.spend_cap).toBe(0);+ });+ test('a bisect capped under a lower cap resumes once bisect runs under a raised policy cap above what it spent', () => {+ const f = fixture();+ [6, 7, 8, 9, 10, 11, 12].forEach(i => f.commit('c' + i));+ const fake = fakeGh((inputs) => {+ if (!inputs.prefix_shas) return { conclusion: 'failure', artifacts: report('RED', ['case-a rule FAIL VERDICT']) };+ const files: Record<string, Record<string, string>> = {};+ for (const sha of inputs.prefix_shas.split(',')) {+ files['gstack-release-record-bisect-' + sha.slice(0, 12)] = { 'bisect-prefix.json': JSON.stringify({ schema: 1, kind: 'train-bisect-prefix', nonce: inputs.nonce, prefix_sha: sha, checked_out_sha: sha,+ panels: [{ case: 'case-a', kind: 'rule', status: 'FAIL', red_class: 'VERDICT', cost_usd: null }] }) };+ }+ return { conclusion: 'success', artifacts: files };+ });+ const env = envFor(f, fake.gh);+ runGate(env, { gate: { ...GATE, bisect_spend_cap_usd: 4 }, label: 'test', dryRun: false, ignoreCadence: true });+ expect(records(f)[0]!.bisect!).toMatchObject({ state: 'capped', spent_usd: 3 });+ expect(fake.dispatches).toHaveLength(2);+ const raised = bisectGate(env, { gate: { ...GATE, bisect_spend_cap_usd: 80 }, label: 'test', dryRun: false });+ expect(fake.dispatches.length, raised.lines.join('\n')).toBe(3);+ expect(records(f)[0]!.bisect!.spend_cap).toBe(80);});});diff --git a/test/ship-queue-land-direct.test.ts b/test/ship-queue-land-direct.test.tsindex af76d19e3..cb05adee5 100644--- a/test/ship-queue-land-direct.test.ts+++ b/test/ship-queue-land-direct.test.ts@@ -11,7 +11,7 @@ import * as fs from 'node:fs';import * as os from 'node:os';import * as path from 'node:path';import { EXIT } from '../lib/headless-artifacts';-import { LAND_KEY_VERSION, MERGE_KEY_VERSION, validatePolicy } from '../lib/ship-policy';+import { LAND_KEY_VERSION, MERGE_KEY_VERSION, RELEASE_GATE_KEY_VERSION, validatePolicy } from '../lib/ship-policy';import { BASE_POLICY, cleanup, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/restamp-fixture';import { shippedBody } from './helpers/ship-queue-train-fixture';import { persist, repoIdentity } from '../lib/ship-queue-train-record';@@ -849,6 +849,18 @@ function backstopOn(fx: Fx, gate: 'success' | 'failure' | 'cancelled', run: numbconst DIRECT_TRAIN = { ...POLICY, train: TRAIN_BLOCK };describe('land --pin --repair: the one way through a backstop freeze under merge: direct (GST-1354)', () => {+ test('GST-1133: with release_gate on the base the backstop stands down, so a backstop freeze left from before adoption warns instead of refusing: a plain land merges and the record is left as it was', () => {+ const fx = setup({ ...DIRECT_TRAIN, release_gate: { cadence_hours: 8, gate_workflow: 'evals.yml', branch: 'main', stable_ref: 'stable', check_name: 'main-backstop', on_red: 'hold-release', bisect_spend_cap_usd: 40 }, min_gstack_version: RELEASE_GATE_KEY_VERSION });+ freezeMain(fx);+ const pin = openPr(fx, '7');+ const r = land(fx, '7', pin);+ expect(r.err).toBe('');+ expect(r.status).toBe(EXIT.ok);+ expect(r.out).toMatch(/^FREEZE: warn only: train backstop froze main \(backstop red on main [0-9a-f]{12}: .*\); the base policy declares release_gate/m);+ expect(fx.read().mergeArgs).toEqual(['7', '--squash', '--match-head-commit', pin]);+ expect(freezeOf(fx)).toMatchObject({ train: 'backstop', repair: null, cleared_at: null });+ }, 90_000);+test('a freeze refuses a plain land and names --repair; --repair with no freeze refuses; nothing merges', () => {const fx = setup();const pin8 = openPr(fx, '8');