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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/gstack-docs-candidate
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
* attempt reads one audit child's output and says whether the launch counts
* against Step 14.5's attempt budget. A launch the child's install check refused
* (an `INSTALL: fail` row, its last GSTACK_RESULT line a document-release
* refusal, and no audit JSON) never audited, so it is not counted, once per
* refusal, and no audit JSON beyond a blocked result that reviewed and updated
* no file, CAPY-1) never audited, so it is not counted, once per
* invocation (--state, the invocation's record); a second refusal is counted
* and stops for the install fix (GST-391, gbrain #8084).
*
Expand Down Expand Up @@ -325,7 +326,8 @@ function main(argv: string[]): void {
const lines = fs.readFileSync(file, 'utf8').split('\n').map(l => l.trim()).filter(Boolean);
const last = lines.filter(l => l.startsWith('GSTACK_RESULT: ')).pop();
const install = lines.find(l => /^INSTALL: fail\b/.test(l));
const audited = lines.some(l => { try { const v = JSON.parse(l); return !!v && typeof v === 'object' && 'schema_version' in v; } catch { return false; } });
const empty = (a: unknown) => Array.isArray(a) && a.length === 0;
const audited = lines.some(l => { try { const v = JSON.parse(l); return !!v && typeof v === 'object' && 'schema_version' in v && !(v.status === 'blocked' && empty(v.files_reviewed) && empty(v.files_updated)); } catch { return false; } });
if (!last || !/^GSTACK_RESULT: skill=document-release status=refused\b/.test(last) || !install || audited) { console.log('ATTEMPT: counted'); return; }
let seen = 0;
try { seen = Number(JSON.parse(fs.readFileSync(state, 'utf8')).not_counted) || 0; } catch { seen = fs.existsSync(state) ? 1 : 0; }
Expand Down
31 changes: 21 additions & 10 deletions bin/gstack-install-verdict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
# GSTACK_INSTALL_VERDICT, so a reviewer's install never shadows it (GST-1161).
# Each workflow install also writes its own record, <verdict>.for/<workflow>.json,
# which admission tries when the shared verdict does not admit that workflow, so
# another workflow's later install never drops it (GST-1233).
# another workflow's later install never drops it (GST-1233), then, when a
# review-voice install wrote the shared verdict, /ship's own record, which
# covers the workflows /ship launches (CAPY-1).
#
# Admission (gstack-skill-start, after SESSION_KIND): an unattended session,
# or an explicit GSTACK_SESSION_KIND=spawned session with GSTACK_CAPY=1,
Expand Down Expand Up @@ -192,16 +194,25 @@ gstack_install_admission() {
_gstack_ia_check
# GST-1233: each install also keeps its own verdict per workflow, so when a
# later install for another workflow replaced the shared one, this
# workflow's own record still admits it; never after a failed ./setup, which
# changed the checkout every record certified.
_ia_own="${file%.json}.for/$skill.json"
case "$skill" in ''|*[!A-Za-z0-9._-]*) _ia_own="" ;; esac
case "$trailer" in "gstack: fail setup"*) _ia_own="" ;; esac
if [ -n "$detail" ] && [ -n "$_ia_own" ] && [ -f "$_ia_own" ]; then
# workflow's own record still admits it; when an install profile (a
# reviewer's review-voice install) wrote the shared verdict, so does /ship's
# own record, which a workflow /ship launches (document-release) runs under
# (CAPY-1); never after a failed ./setup, which changed the checkout every
# record certified.
_ia_dir="${file%.json}.for"
_ia_ship=""
gstack_doctor_install_profile "$(gstack_install_verdict_field "$file" for)" && _ia_ship="$_ia_dir/ship.json"
case "$skill" in ''|*[!A-Za-z0-9._-]*) _ia_dir="" ;; esac
case "$trailer" in "gstack: fail setup"*) _ia_dir="" ;; esac
if [ -n "$detail" ] && [ -n "$_ia_dir" ]; then
_ia_m_file=$file _ia_m_detail=$detail _ia_m_fix=$fix _ia_m_code=$code _ia_m_status=$_ia_status _ia_m_trailer=$trailer
file=$_ia_own _ia_status=ok
_gstack_ia_check
[ -z "$detail" ] || { file=$_ia_m_file detail=$_ia_m_detail fix=$_ia_m_fix code=$_ia_m_code _ia_status=$_ia_m_status trailer=$_ia_m_trailer; }
for _ia_own in "$_ia_dir/$skill.json" ${_ia_ship:+"$_ia_ship"}; do
[ -f "$_ia_own" ] || continue
file=$_ia_own _ia_status=ok
_gstack_ia_check
[ -n "$detail" ] || break
file=$_ia_m_file detail=$_ia_m_detail fix=$_ia_m_fix code=$_ia_m_code _ia_status=$_ia_m_status trailer=$_ia_m_trailer
done
fi
[ -n "$detail" ] || { _ia_line="INSTALL_VERDICT: ok $trailer"; return 0; }
[ "$_ia_status" = runtime ] || _ia_status=verdict
Expand Down
3 changes: 2 additions & 1 deletion bin/gstack-ship-receipt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ function noStopArg(raw: string | undefined): ShipReceipt['no_stop'] {
if (raw === undefined) return undefined;
const parsed = JSON.parse(raw.startsWith('@') ? fs.readFileSync(raw.slice(1), 'utf8') : raw);
if (!Array.isArray(parsed)) throw new Error('--no-stop expects a JSON array of {class, reason, evidence}');
const kept = parsed.filter(r => (NO_STOP_CLASSES as readonly string[]).includes(r?.class) || void process.stderr.write(`NO_STOP: dropped ${JSON.stringify(r?.class)} from --no-stop: not a current no-stop class (${NO_STOP_CLASSES.join(', ')}), so the receipt leaves it out (GST-2706)\n`));
const current: readonly string[] = NO_STOP_CLASSES.filter(c => c !== 'scoped-fix-check');
const kept = parsed.filter(r => current.includes(r?.class) || void process.stderr.write(`NO_STOP: dropped ${JSON.stringify(r?.class)} from --no-stop: not a current no-stop class (${current.join(', ')}), so the receipt leaves it out (GST-2706)\n`));
return kept.length ? kept : undefined;
}
function git(args: string[], cwd?: string): string | undefined {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Fixed

- **`gstack-pr-wait` no longer blocks on a cancelled check that a newer passing run of the same check replaced.** In a repository whose workflows use `concurrency: cancel-in-progress`, the older run is cancelled when the next one starts; `gstack-ship-queue ready` already judged the check by the newer pass, but `gstack-pr-wait --until green` stopped with `PR_WAIT_BLOCKED`. It now waits while the newer run is going and goes green when it passes. A failed run beside a newer pass still blocks, and so does a cancel that is the newest run (#4807, reported by exGeni).
- **The `DEPS_MISSING` stop names npm's `allow-git` setting when the lockfile installs a package from git.** npm 12 refuses git packages by default, so the plain `npm ci` the stop suggested failed with `EALLOWGIT`. The hint still suggests `npm ci` and says to add `--allow-git=all` if you trust that source; gstack does not turn it on for you (#4815, reported by exGeni).
- **The docs audit /gstack-ship launches starts after a reviewer's install replaced the shared install verdict.** A `--for review-voice` install rewrote the shared verdict, so the `document-release` child was refused at start even though /gstack-ship's own install had certified the same checkout and HEAD. When a reviewer's install wrote the shared verdict, admission now also tries /gstack-ship's own record, with the same checks. A launch refused this way and reported as an empty blocked result no longer uses up the PR's one re-audit.
- **`gstack-ship-receipt write` leaves a retired `scoped-fix-check` row out of `--no-stop`,** as `gstack-no-stop` already refuses one.
5 changes: 4 additions & 1 deletion docs/capy-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ uses it to refuse a base merge under an open run
verdict does not admit a workflow, admission and the pregate try the
workflow's own record with the same checks, so a later install for another
workflow on a shared machine (a /gstack-ship docs child resolving another Bun, or a
failed child install) never drops /gstack-ship's admission (GST-1233). A new HEAD
failed child install) never drops /gstack-ship's admission (GST-1233). When a
reviewer's review-voice install wrote the shared verdict, admission then tries
/gstack-ship's own record with the same checks, so the docs audit
/gstack-ship launches still starts (CAPY-1). A new HEAD
still invalidates both, and a failed `./setup` (`gstack: fail setup`)
invalidates every workflow's record. `--check --for <workflow>` keeps the
Bun that workflow's own record holds. The launch file and launch directory
Expand Down
4 changes: 4 additions & 0 deletions docs/ship-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ the same workflow replaced it; a run cancelled before any job is not counted.
An unreadable list is unknown, never green. `gstack-pr-wait`, `gstack-ci-gate`
and the release cut read CI through the same helper (`lib/ci-head-checks.ts`),
on top of what they read before, so none of them calls such a head green.
The one row they drop from before is a cancelled run that a newer run of the
same check replaced while that run passed or still runs, which `ci:` already
judges by that newer run (`gstack-pr-wait`, #4807); any other older red run
still gates.

When a check counts as passing only because a newer run from another check
suite replaced a red one (a branch-only `free-tests.yml` dispatch beside the red
Expand Down
5 changes: 4 additions & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8180,7 +8180,10 @@ attempt of each check suite as `gstack-ship-queue ready` does: a failed check
whose rerun attempt created no jobs (GitHub's default list then hides it) and a
workflow run that failed before creating any job (`check failed: <workflow>
(run <id>, no jobs)`) block `green`, and a rerun that passed clears its
failure. A check the base
failure. `gstack-pr-wait` also judges a check by its newer run when that run
replaced a cancelled one (a workflow with `concurrency: cancel-in-progress`):
passing, or pending while it runs, as `ready` does; a failed run beside a newer
pass still blocks. A check the base
branch requires (rulesets and classic branch protection) counts as pending
until it appears. `--exclude <check,...>` leaves a named non-required check
out of the verdict, as `gstack-ci-gate --exclude` does: it neither holds
Expand Down
14 changes: 10 additions & 4 deletions lib/install-verdict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ export function verdictProblem(skill: string, gstackRoot: string, env: Env, bunP
/**
* The verdict file that admits `skill`: `file` itself, else the workflow's own record
* <verdict>.for/<skill>.json that every install also writes, so a later install for another
* workflow never drops this one (GST-1233), except after a failed ./setup, which changed the
* checkout every record certified. When neither admits, `file` with its problem.
* workflow never drops this one (GST-1233), and when an install profile (a reviewer's
* review-voice install) wrote `file`, /ship's own record, which a workflow /ship launches
* (document-release) runs under (CAPY-1); each record is checked for `skill` in full. Never after a failed ./setup, which changed the
* checkout every record certified. When none admits, `file` with its problem.
*/
export function admittedVerdict(skill: string, src: string, file: string, project: string | null, bunPath: string, bunVersion: string): { file: string; problem: VerdictProblem | null } {
const problem = verdictFileProblem(file, skill, src, project, bunPath, bunVersion);
const own = file.replace(/\.json$/, `.for/${skill}.json`);
if (problem && /^[A-Za-z0-9._-]+$/.test(skill) && !readInstallVerdict(file)?.trailer?.startsWith('gstack: fail setup') && fs.existsSync(own) && !verdictFileProblem(own, skill, src, project, bunPath, bunVersion)) return { file: own, problem: null };
if (!problem || !/^[A-Za-z0-9._-]+$/.test(skill) || readInstallVerdict(file)?.trailer?.startsWith('gstack: fail setup')) return { file, problem };
const records = INSTALL_PROFILES.includes(readInstallVerdict(file)?.for ?? '') ? new Set([skill, 'ship']) : [skill];
for (const name of records) {
const own = file.replace(/\.json$/, `.for/${name}.json`);
if (fs.existsSync(own) && !verdictFileProblem(own, skill, src, project, bunPath, bunVersion)) return { file: own, problem: null };
}
return { file, problem };
}

Expand Down
9 changes: 7 additions & 2 deletions lib/pr-wait-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import type { GhResult, GhRunner } from './ci-gate';
import { headCheckRows } from './ci-head-checks';
import { parseHeadChecks, parsePullState, rateLimitKind, type PullState } from './gh-poll';
import { replacedCancels } from './ship-queue';

export class GhError extends Error {
constructor(message: string, readonly transient: boolean) {
Expand Down Expand Up @@ -183,12 +184,16 @@ function restList(env: GhEnv, path: string, key: string): unknown[] {
* statuses (the same rows `gh pr checks` reads through GraphQL) plus CI at the
* head as gstack-ship-queue ready reads it (lib/ci-head-checks.ts: a failed
* check whose rerun attempt created no jobs, a workflow run that failed with
* no jobs), duplicates collapsed to the worst bucket. An unknown read is a
* no jobs), duplicates collapsed to the worst bucket. A cancelled run that a
* newer passing or still-running run of the same app and check name replaced is left out first,
* as that reader leaves it out (replacedCancels, #4807). An unknown read is a
* transient GhError, so the poll loop tries again.
*/
export function fetchChecks(env: GhEnv, repo: string, head: string): Map<string, Check> {
const runs = restList(env, `repos/${repo}/commits/${head}/check-runs?per_page=100`, 'check_runs') as Array<Record<string, unknown>>;
const replaced = replacedCancels(runs);
const listed = parseHeadChecks(
restList(env, `repos/${repo}/commits/${head}/check-runs?per_page=100`, 'check_runs'),
runs.filter(r => !replaced.has(r)),
restList(env, `repos/${repo}/commits/${head}/status?per_page=100`, 'statuses'),
);
const ci = headCheckRows(args => runGh(env, args), repo, head);
Expand Down
10 changes: 9 additions & 1 deletion lib/ship-preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,15 @@ function depsInstall(root: string): string | null {
try { pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); } catch { return null; }
const has = (f: string) => fs.existsSync(path.join(root, f));
if (!Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }).length || has('node_modules') || has('.pnp.cjs') || has('.pnp.loader.mjs') || has('.pnp.js')) return null;
return has('bun.lock') || has('bun.lockb') ? 'bun install --frozen-lockfile' : has('pnpm-lock.yaml') ? 'pnpm install --frozen-lockfile' : has('yarn.lock') ? 'yarn install --frozen-lockfile' : has('package-lock.json') || has('npm-shrinkwrap.json') ? 'npm ci' : 'bun install';
return has('bun.lock') || has('bun.lockb') ? 'bun install --frozen-lockfile' : has('pnpm-lock.yaml') ? 'pnpm install --frozen-lockfile' : has('yarn.lock') ? 'yarn install --frozen-lockfile' : has('npm-shrinkwrap.json') ? npmCi(root, 'npm-shrinkwrap.json') : has('package-lock.json') ? npmCi(root, 'package-lock.json') : 'bun install';
}

/** npm ci, with a note naming npm's allow-git setting when the lockfile resolves a package from git, which npm 12 refuses by default (#4815). */
function npmCi(root: string, lock: string): string {
let text = '';
try { text = fs.readFileSync(path.join(root, lock), 'utf8'); } catch { /* plain npm ci */ }
if (!/"(?:resolved|version)"\s*:\s*"(?:git\+|git:\/\/|github:)/.test(text)) return 'npm ci';
return `npm ci (${lock} resolves a package from git, which npm 12 and later install only when npm's allow-git setting permits it: add --allow-git=all if you trust that source)`;
}

async function tests(cwd: string, base: string, list: { label: string; command: string }[], policyFrom: string, timeout: string | undefined, step: { seconds: number; source: string }, run: { concurrency: number; line: string; hold: boolean; testsOnly: boolean }, r: Report): Promise<void> {
Expand Down
15 changes: 15 additions & 0 deletions lib/ship-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ export function latestRunPerName<T extends CheckRun>(runs: T[]): T[] {
const suiteOf = (r: Record<string, unknown>) => String((r.check_suite as { id?: unknown } | null | undefined)?.id ?? '');
const PASSING = ['success', 'skipped', 'neutral'];

/**
* The cancelled runs latestRunPerName judges by a newer run of the same app and check name that passed or is still
* running, such as a pull_request run that concurrency: cancel-in-progress cancelled when the next run on the same head
* started (#4807). gstack-pr-wait leaves these out before keeping the worst bucket per name, so the check reads as that
* newer run (pass or pending), as ready reads it; every other older run still gates there.
*/
export function replacedCancels<T extends CheckRun & { conclusion?: unknown }>(runs: T[]): Set<T> {
const winners = new Map(latestRunPerName(runs).map(r => [checkKey(r), r] as const).filter(([k]) => k !== null));
return new Set(runs.filter(r => {
const key = checkKey(r);
const by = key === null ? undefined : winners.get(key);
return r.status === 'completed' && r.conclusion === 'cancelled' && !!by && by !== r && (by.status !== 'completed' || PASSING.includes(String(by.conclusion)));
}));
}

/**
* A CI_SUPERSEDED line for each red run whose check counts by a passing newer run from another check suite, such as a
* branch-only dispatch that replaced a red pull_request run, which tested the merge with the base (reports/GSTA-461.md
Expand Down
19 changes: 18 additions & 1 deletion test/gh-poll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import type { GhResult } from '../lib/ci-gate';
import { MAX_LIMIT_WAITS, MIN_POLL_MS, parseHeadChecks, parsePullState, pollDelayMs, rateLimitKind, rateLimitWaitMs, withRateLimit } from '../lib/gh-poll';
import { GhError, fetchChecks, runGh } from '../lib/pr-wait-github';
import { GhError, bucketClass, fetchChecks, runGh } from '../lib/pr-wait-github';
import { waitForRun } from '../lib/ci-carry';
import { ciRest } from './helpers/ci-attempts-fixture';

Expand Down Expand Up @@ -188,6 +188,23 @@ describe('REST replies parse from recorded fixtures', () => {
]);
expect(calls.some(c => c[0] === 'pr' || c[1] === 'graphql')).toBe(false);
});

// Value: protects=gstack-pr-wait agrees with gstack-ship-queue ready on a cancelled run that a newer passing run of the same app and
// check name replaced (concurrency: cancel-in-progress), pending while that run is still going, and every other duplicate keeps
// the worst bucket (#4807, exGeni's repro); fails_when=the replaced cancel blocks with PR_WAIT_BLOCKED, or a cancel that is newest, a failure, or another app's pass stops
// gating; seam=fetchChecks over the shared REST fake; no_claim=the CLI exit
test("fetchChecks drops a cancelled run that a newer passing or running run of the same check replaced, and nothing else (#4807)", () => {
const app = { id: 15368 };
const run = (id: number, suite: number, conclusion: string, done: string, appId = app): Record<string, unknown> =>
({ id, name: 'title-check', status: 'completed', conclusion, completed_at: done, check_suite: { id: suite }, app: appId });
const bucket = (check_runs: Array<Record<string, unknown>>) => fetchChecks({ gh: (args: string[]) => ciRest(args, { check_runs }) ?? ok(''), sleep: () => {}, log: () => {} }, 'owner/repo', 'a'.repeat(40)).get('title-check')!.bucket;
expect(bucket([run(1, 100, 'cancelled', '2026-01-01T10:00:10Z'), run(2, 200, 'success', '2026-01-01T10:00:50Z')])).toBe('pass');
expect(bucketClass(bucket([run(1, 100, 'cancelled', '2026-01-01T10:00:50Z'), run(2, 200, 'success', '2026-01-01T10:00:10Z')]))).toBe('fail');
expect(bucketClass(bucket([run(1, 100, 'failure', '2026-01-01T10:00:10Z'), run(2, 200, 'success', '2026-01-01T10:00:50Z')]))).toBe('fail');
expect(bucketClass(bucket([run(1, 100, 'cancelled', '2026-01-01T10:00:10Z'), run(2, 200, 'success', '2026-01-01T10:00:50Z', { id: 99 })]))).toBe('fail');
expect(bucketClass(bucket([run(1, 100, 'cancelled', '2026-01-01T10:00:10Z'), run(2, 200, 'failure', '2026-01-01T10:00:50Z')]))).toBe('fail');
expect(bucketClass(bucket([run(1, 100, 'cancelled', '2026-01-01T10:00:10Z'), { ...run(2, 200, 'success', '2026-01-01T10:00:50Z'), status: 'in_progress', conclusion: null, completed_at: null }]))).toBe('pending');
});
});

describe('waits sleep at least the floor', () => {
Expand Down
Loading
Loading