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
The factory scorecard counts each merge batch once in its red rate, not every re-run (GST-4128) (#4880)
Garry Tane8319ea59a54
diff --git a/changelog.d/scorecard-red-rate-counts-each-batch-once.md b/changelog.d/scorecard-red-rate-counts-each-batch-once.mdnew file mode 100644index 000000000..01e124bc9--- /dev/null+++ b/changelog.d/scorecard-red-rate-counts-each-batch-once.md@@ -0,0 +1 @@+The factory scorecard's red-train rate now counts each train (one batch of PRs tested together) once per report, by its branch, so re-testing the same batch inside the report's window no longer moves the rate. It used to divide red runs by every non-cancelled run on a train branch, so a red batch that was bisected and rebuilt added extra runs to the count. A train is now red when any of its non-cancelled runs in the window did not succeed, even if a later rebuild passed, and a branch whose runs were all cancelled is left out. A rebuild that lands after the window closes still counts in the next report. The published week in `crew/docs/recommended-harness.md` recounts the same (1 red of 22 trains). Rebuilt from #4864 by @mvanhorn (#4767).diff --git a/crew/docs/recommended-harness.md b/crew/docs/recommended-harness.mdindex 014c8d84d..134bb4fdf 100644--- a/crew/docs/recommended-harness.md+++ b/crew/docs/recommended-harness.md@@ -288,7 +288,7 @@ measured later does not count anything that happened after that week.| Review passes per PR | the largest count `--pass-marker` captures in the PR body (the ship receipt's `"passes": N` once /gstack-ship writes it) or a PR comment (`passes=N`, `REVIEW_PASSES: N`), median and p90, plus how many PRs reached `--pass-cap` (2, the [review policy](../../docs/review-policy.md)'s cap of two rounds, a fix-check included: pass 1 reviews the whole diff, pass 2 only the range since, and a pass that finds nothing blocking is the exit) | median 1 pass; few at the cap || Gate runs green / red / cancelled | completed runs of the gate workflow (`workflow_dispatch` by default; `--gate-event any`); cost from the run's `report-verdict-a*` artifact (`collector-outcomes.json` `.verdict.costUsd`), else the `**$N** rule/judge cost` or `cost=$N` line of the PR's verdict comment | green on 95%+ of runs, cancelled near 0, cost known for every run || Known gate cost per merged PR | known cost / merged PRs; unknown-cost runs make it a floor | known, stable or falling week over week |-| Red-train rate | runs whose head branch starts with `--train-prefix`, cancelled excluded; red = conclusion other than success; red backstops and screens shown beside it | under 5% (each red train is a bisect plus a rebuild, about two gates) |+| Red-train rate | distinct head branches starting with `--train-prefix`, each counted once, since a train's bisect and rebuild run on its own `train/<nonce>` branch; cancelled runs excluded, and a branch with only cancelled runs left out; a train is red when any of its non-cancelled runs did not succeed, even if a later rebuild did; red backstops and screens shown beside it | under 5% (each red train is a bisect plus a rebuild, about two gates) || Flaky events | `flake-records-a*` records of the newest gate runs (count, known rerun spend) and `flake-ledger-*` entries of free runs on the default branch; a run whose artifacts cannot be read is counted and named, never scored 0, and a main push that reused its pull request's run (no shard artifacts, `reuse` job green) is left out and named | 0 repeat cases; under 1 flaky case per 10 gates; free retries under 1% of runs || Issues opened / closed | GitHub search, created and closed in the window | closed ≥ opened; nothing severe older than a week || Releases cut | releases published in the window, drafts excluded | at least one tagged release a week, on schedule |diff --git a/lib/factory-scorecard.ts b/lib/factory-scorecard.tsindex 6d0a18a2f..346ff34da 100644--- a/lib/factory-scorecard.ts+++ b/lib/factory-scorecard.ts@@ -425,7 +425,9 @@ export function scorecardRows(card: Scorecard): ScorecardRow[] {const by = (outcome: GateOutcome, kind?: GateKind) => gates.filter(g => g.outcome === outcome && (!kind || g.kind === kind)).length;const known = gates.filter(g => g.costUsd !== null);const knownUsd = known.reduce((s, g) => s + g.costUsd!, 0);- const trains = gates.filter(g => g.kind === 'train' && g.outcome !== 'cancelled');+ const trainRed = new Map<string, boolean>();+ for (const g of gates) if (g.kind === 'train' && g.outcome !== 'cancelled') trainRed.set(g.branch, trainRed.get(g.branch) || g.outcome === 'red');+ const redTrains = [...trainRed.values()].filter(Boolean).length;const flakes = gates.reduce((s, g) => s + g.flakes, 0);const flakeUsd = gates.reduce((s, g) => s + g.flakeRerunUsd, 0);const retries = card.freeRuns.reduce((s, r) => s + (r.retries ?? 0), 0);@@ -453,8 +455,8 @@ export function scorecardRows(card: Scorecard): ScorecardRow[] {'completed runs of the gate workflow in the window; cost from the verdict artifact, else the PR verdict comment (one run per PR)'),row('cost_per_merge', 'Known gate cost per merged PR', ['gate runs', 'merged PRs'], () => (card.prs.length ? `${usd(knownUsd / card.prs.length)} (${gates.length - known.length} runs without a known cost)` : 'n/a (no merges)'),'known gate cost divided by merged PRs; unknown-cost runs make this a floor'),- row('red_train', 'Red-train rate', 'gate runs', () => `${pct(trains.filter(t => t.outcome === 'red').length, trains.length)} (${trains.filter(t => t.outcome === 'red').length} red of ${trains.length} trains; ${by('red', 'backstop')} red backstop, ${by('red', 'screen')} red screens)`,- `runs whose head branch starts with the train prefix, cancelled runs excluded; red means the run's conclusion was not success`),+ row('red_train', 'Red-train rate', 'gate runs', () => `${pct(redTrains, trainRed.size)} (${redTrains} red of ${trainRed.size} trains; ${by('red', 'backstop')} red backstop, ${by('red', 'screen')} red screens)`,+ 'distinct head branches starting with the train prefix, each counted once; cancelled runs excluded, and a branch with only cancelled runs left out; a train is red when any of its non-cancelled runs did not succeed, even if a later rebuild did'),row('flaky', 'Flaky events', [], () => `${unavailable('gate runs') ? unavailableText('gate runs') : paidFlakes()}; ${unavailable('free retries') ? unavailableText('free retries') : freeRetries()}`,`flake-records artifacts of the newest ${card.artifactRunsRead} gate runs and flake-ledger artifacts of free runs on the base branch, reused main pushes left out`),row('issues', 'Issues opened / closed', 'issues', () => `${card.issuesOpened ?? 'n/a'} / ${card.issuesClosed ?? 'n/a'}`, 'GitHub search: created, closed inside the window'),diff --git a/test/factory-scorecard.test.ts b/test/factory-scorecard.test.tsindex 14e84f5ca..8f84fbb84 100644--- a/test/factory-scorecard.test.ts+++ b/test/factory-scorecard.test.ts@@ -68,6 +68,29 @@ describe('factory-scorecard: recorded window', () => {expect(values.releases).toBe('1 (v1.0.0)');});+ test('red-train rate counts each train branch once, red when any of its non-cancelled runs was red (#4767)', () => {+ // Value: protects=a train's bisect and rebuild runs, which reuse its train/<nonce> branch, count as one train, a red gate stays red after a green rebuild, and a branch with only cancelled runs is left out; fails_when=scorecardRows divides red runs by all non-cancelled train runs again; why_new=#4767, a bisect plus a rebuild added runs to the denominator and could swing the rate without a new train; seam=fixtureSource; no_claim=gated trains, whose prefix refs sit outside the train prefix+ const fx = fixture();+ const gateRuns = (fx.responses[Object.keys(fx.responses).find(k => k.includes('/evals.yml/runs?'))!] as { workflow_runs: any[] }).workflow_runs;+ const base = gateRuns.find(r => r.id === 9002)!;+ const run = (id: number, branch: string, conclusion: string, hour: number) => ({ ...base, id, head_branch: branch, conclusion, created_at: `2026-10-23T${String(hour).padStart(2, '0')}:00:00Z` });+ const red = base.head_branch as string;+ const twice = 'train/gate.train-dddddddddddd-cccccccccccc-dddddd';+ const cancelled = 'train/gate.train-eeeeeeeeeeee-cccccccccccc-eeeeee';+ gateRuns.unshift(+ run(9020, cancelled, 'cancelled', 17),+ run(9019, twice, 'failure', 16),+ run(9018, twice, 'timed_out', 15),+ run(9017, red, 'success', 13),+ run(9016, red, 'cancelled', 12),+ run(9015, red, 'success', 11),+ );+ const rows = scorecardRows(collectScorecard(fixtureSource(fx, scratch()), options()));+ const row = rows.find(r => r.id === 'red_train')!;+ expect(row.value).toBe('67% (2 red of 3 trains; 0 red backstop, 0 red screens)');+ expect(row.rule).toBe('distinct head branches starting with the train prefix, each counted once; cancelled runs excluded, and a branch with only cancelled runs left out; a train is red when any of its non-cancelled runs did not succeed, even if a later rebuild did');+ });+test('free runs that ran no shards (reused main pushes) stay out of the free-retry count and its denominator (#3725)', () => {// Value: protects=the free-retry rate is read over runs that executed shards only; fails_when=a reused run (no artifacts, reuse job green) counts as a zero-retry run again; why_new=#3725, after #3709 a main push that reuses its PR's run uploads nothing; seam=fixtureSource; no_claim=runs past --max-artifact-runs, which are not readconst fx = fixture();