Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

nightly-watch: master-red issues for push-to-master Test and E2E Tests

garrytancb35f2276941
diff --git a/.github/workflows/nightly-watch.yml b/.github/workflows/nightly-watch.yml
index 5a6087c279..fd72a0afed 100644
--- a/.github/workflows/nightly-watch.yml
+++ b/.github/workflows/nightly-watch.yml
@@ -1,21 +1,46 @@
name: Nightly watch
-# Keeps one `nightly-red` issue per scheduled workflow (scripts/nightly-issue.ts;
-# owner and 24-hour response: docs/RELEASING.md#nightly-red-issues). Opens it on
-# a red scheduled run, updates it while red, reopens it on a flap, and closes
-# it only when a later scheduled run is green and every previously failing job
-# executed. Cells listed in .github/nightly-known-red.tsv keep the issue open
-# with the `known-red` label instead of counting as green.
+# Two incident tracks (scripts/nightly-issue.ts; owner, response times and
+# labels: docs/RELEASING.md#nightly-red-issues, #master-red-issues and
+# docs/ci-red-runbook.md#ci-issue-labels):
#
-# Security: runs only for scheduled runs of this repository, checks out the
-# default branch (never the triggering run's code), passes every event field
-# through env (no expression interpolation inside run:), and holds only
-# issues: write, actions: read and checks: read (for error annotations).
+# - Scheduled runs of every watched workflow keep one `nightly-red` issue per
+# workflow: open on red, update while red, reopen on a flap, close only when
+# a later scheduled run is green with complete evidence and every
+# previously failing job executed. Cells listed in
+# .github/nightly-known-red.tsv keep the issue open with the `known-red`
+# label instead of counting as green.
+# - Push-to-master runs of Test and E2E Tests (the allowlist below and in
+# scripts/lib/master-red.ts) keep one `master-red` issue per workflow with
+# the suspect range (last green push SHA -> first red SHA + merged PRs).
+# Every watch reconciles every unevaluated completed push run in
+# (run_number, run_attempt) order, so a dropped pending watch loses nothing.
+#
+# Triggers: `branches: [master]` drops every pull-request completion before a
+# run is created. The job guard then admits scheduled runs and push runs of
+# the allowlisted workflows whose head branch is master, from this repository
+# only (the head repository check keeps a fork branch named master out).
+# Push runs of other watched workflows on master still create a skipped
+# watch run (no trigger-level event filter exists); CI health counts them.
+#
+# Serialization: `resolve` turns every entry path (automatic or dispatch)
+# into its target workflow id and state track (schedule or push; a replay
+# writes the push track). `watch` queues on one group per repository +
+# workflow + track (never cancelled), so a dispatch and an automatic watch of
+# the same target cannot race; the script also re-reads the issue before it
+# writes and retries when it moved. A newer queued watch may replace an older
+# pending one; reconciliation covers the dropped run.
+#
+# Security: checks out the default branch (never the triggering run's code),
+# passes every event field through env (no expression interpolation inside
+# run:), and holds only issues: write plus read scopes (actions, checks,
+# contents for compare, pull-requests for commit-to-PR lookups).
#
# Every workflow with a schedule trigger must be listed below
-# (test/scripts/nightly-issue.test.ts enforces it). A new workflow file can
-# only be dispatched from the default branch, so `run_id` dispatch is for
-# post-merge checks: gh workflow run nightly-watch.yml -f run_id=<scheduled run id>
+# (test/scripts/nightly-issue.test.ts enforces it). Dispatch is for
+# post-merge checks:
+# gh workflow run nightly-watch.yml -f run_id=<scheduled or push-to-master run id>
+# gh workflow run nightly-watch.yml -f run_id=<E2E dispatch run id> -f replay_issue=<master-red issue>
on:
workflow_run:
@@ -29,12 +54,18 @@ on:
- OSV-Scanner
- CI health
types: [completed]
+ branches: [master]
workflow_dispatch:
inputs:
run_id:
- description: Scheduled run id to evaluate
+ description: Scheduled or push-to-master run id to evaluate
required: true
type: string
+ replay_issue:
+ description: Open master-red issue an E2E Tests dispatch run on master replays (optional)
+ required: false
+ type: string
+ default: ''
dry_run:
description: Print the issue it would write instead of writing it
type: boolean
@@ -42,21 +73,67 @@ on:
permissions: {}
-# One group per watched workflow, queued (never cancelled), so two runs of the
-# same workflow cannot race on its issue.
-concurrency:
- group: nightly-watch-${{ github.event.workflow_run.workflow_id || inputs.run_id }}
- cancel-in-progress: false
-
jobs:
+ resolve:
+ if: >-
+ github.event_name == 'workflow_dispatch' ||
+ (github.event.workflow_run.head_repository.full_name == github.repository &&
+ (github.event.workflow_run.event == 'schedule' ||
+ (github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'master' &&
+ contains(fromJSON('["Test","E2E Tests"]'), github.event.workflow_run.name))))
+ runs-on: ubicloud-standard-2-ubuntu-2404
+ timeout-minutes: 5
+ permissions:
+ actions: read
+ outputs:
+ workflow_id: ${{ steps.target.outputs.workflow_id }}
+ track: ${{ steps.target.outputs.track }}
+ run_id: ${{ steps.target.outputs.run_id }}
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ with:
+ persist-credentials: false
+ sparse-checkout: |
+ scripts
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
+ with:
+ bun-version: 1.4.2
+ - id: target
+ name: Resolve the target workflow and track
+ env:
+ GH_TOKEN: ${{ github.token }}
+ RUN_ID: ${{ github.event.workflow_run.id || inputs.run_id }}
+ REPLAY_ISSUE: ${{ inputs.replay_issue }}
+ run: |
+ set -euo pipefail
+ if ! [[ "$RUN_ID" =~ ^[0-9]+$ ]]; then
+ echo "::error::run_id '$RUN_ID' is not a numeric run id. Why: nightly-watch reads one workflow run. Fix: gh workflow run nightly-watch.yml -f run_id=<id from gh run list>. Docs: docs/RELEASING.md#master-red-issues"
+ exit 1
+ fi
+ if [ -n "$REPLAY_ISSUE" ] && ! [[ "$REPLAY_ISSUE" =~ ^[0-9]+$ ]]; then
+ echo "::error::replay_issue '$REPLAY_ISSUE' is not an issue number. Fix: pass the number of the open master-red issue. Docs: docs/RELEASING.md#master-red-issues"
+ exit 1
+ fi
+ args=(--run-id "$RUN_ID" --repo "$GITHUB_REPOSITORY" --resolve)
+ [ -z "$REPLAY_ISSUE" ] || args+=(--replay-issue "$REPLAY_ISSUE")
+ bun scripts/nightly-issue.ts "${args[@]}" | tee "$RUNNER_TEMP/target.txt"
+ grep -E '^(workflow_id=[0-9]+|track=(schedule|push|refused))$' "$RUNNER_TEMP/target.txt" >> "$GITHUB_OUTPUT"
+ echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
+
watch:
- if: github.event_name == 'workflow_dispatch' || (github.event.workflow_run.event == 'schedule' && github.event.workflow_run.head_repository.full_name == github.repository)
+ needs: resolve
runs-on: ubicloud-standard-2-ubuntu-2404
- timeout-minutes: 10
+ timeout-minutes: 15
+ # One queue per repository + target workflow + track; queued, never cancelled.
+ concurrency:
+ group: nightly-watch-${{ github.repository }}-${{ needs.resolve.outputs.workflow_id }}-${{ needs.resolve.outputs.track }}
+ cancel-in-progress: false
permissions:
issues: write
actions: read
checks: read
+ contents: read
+ pull-requests: read
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
@@ -68,11 +145,15 @@ jobs:
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: 1.4.2
- - name: Upsert the nightly-red issue
+ - name: Upsert the nightly-red or master-red issue
env:
GH_TOKEN: ${{ github.token }}
- RUN_ID: ${{ github.event.workflow_run.id || inputs.run_id }}
+ RUN_ID: ${{ needs.resolve.outputs.run_id }}
+ REPLAY_ISSUE: ${{ inputs.replay_issue }}
DRY_RUN: ${{ inputs.dry_run && '--dry-run' || '' }}
run: |
- # shellcheck disable=SC2086 # DRY_RUN is empty or one flag
- bun scripts/nightly-issue.ts --run-id "$RUN_ID" --repo "$GITHUB_REPOSITORY" $DRY_RUN
+ set -euo pipefail
+ args=(--run-id "$RUN_ID" --repo "$GITHUB_REPOSITORY")
+ [ -z "$REPLAY_ISSUE" ] || args+=(--replay-issue "$REPLAY_ISSUE")
+ [ -z "$DRY_RUN" ] || args+=("$DRY_RUN")
+ bun scripts/nightly-issue.ts "${args[@]}"
diff --git a/scripts/lib/master-red.ts b/scripts/lib/master-red.ts
new file mode 100644
index 0000000000..20ffdf4e6c
--- /dev/null
+++ b/scripts/lib/master-red.ts
@@ -0,0 +1,564 @@
+/**
+ * Master-red incidents (green master wave, Lane 4 + E4): one `master-red`
+ * issue per workflow (Test, E2E Tests) for push-to-master runs only;
+ * scheduled runs stay in nightly-red (scripts/nightly-issue.ts).
+ *
+ * Reconciliation: every watch reads the completed push-to-master runs of its
+ * workflow and evaluates, in (run_number, run_attempt) order, every run above
+ * the high-water mark stored in the JSON block of the newest master-red issue
+ * of that workflow (open or closed). A dropped watch therefore loses nothing,
+ * an out-of-order completion is ignored, a successful re-run is a newer
+ * attempt, and a run cancelled by a newer push changes no state. A missing or
+ * malformed block is rebuilt from the actions API (fold from the last green
+ * run before the newest red one), never guessed.
+ *
+ * Open on red (suspect range: last green push SHA -> first red SHA plus the
+ * PRs merged in it), update while red, close on a green run where every
+ * previously failing job ran and passed with complete evidence (E2E Tests
+ * also needs every previously failing test file among the files that run
+ * executed and passed; the scheduled full run or an issue-bound replay also
+ * satisfies it). A failing job that has not run since keeps the issue open
+ * with the manual-close next step. Closing without a merged repair PR linked
+ * opens one `flake` issue per previously failing test; a flake closes after
+ * its repair PR merged and a later complete run passed that test's file and
+ * arm (platform-only flakes: the job that failed passed).
+ *
+ * Writes are compare-and-retry: before the first write the issue is re-read,
+ * and the plan is recomputed when its updated_at or high-water mark moved.
+ * Docs: docs/RELEASING.md#master-red-issues, docs/ci-red-runbook.md#ci-issue-labels.
+ */
+import {
+ commentIssue, createIssue, ensureLabel, getIssue, inert, inertBlock, jsonBlock, linkedPulls, listLabeled, readJsonBlock, updateIssue,
+ type GitHubClient, type Issue,
+} from './gh-issue.ts';
+import { collectEvidence, reproduceCommand, verdictOf, workflowFile, type EvidenceOptions, type FailedJob, type FailedTest, type RunEvidence, type RunInfo } from './ci-run.ts';
+
+export const MR_LABEL = 'master-red';
+export const FLAKE_LABEL = 'flake';
+export const MR_MARKER = 'master-red:json';
+export const FLAKE_MARKER = 'flake:json';
+export const MR_SCHEMA = 'master-red/v1';
+export const FLAKE_SCHEMA = 'flake/v1';
+export const MR_DOCS = 'docs/RELEASING.md#master-red-issues';
+export const FLAKE_DOCS = 'docs/ci-red-runbook.md#flake-issues';
+export const PUSH_ALLOWLIST: Record<string, string> = { Test: 'test.yml', 'E2E Tests': 'e2e.yml' };
+export const MAX_FOLD = 30;
+export const MAX_FLAKES_PER_CLOSE = 10;
+export const MAX_PR_LOOKUPS = 40;
+export const FLAKE_EXPIRY_DAYS = 14;
+const RETRIES = 3;
+
+export interface RunRef { run_id: number; run_number: number; run_attempt: number; sha: string }
+export interface Suspect { from_sha: string | null; to_sha: string; prs: number[]; complete: boolean; note: string }
+export interface MasterRedState {
+ schema: typeof MR_SCHEMA;
+ workflow: string;
+ workflow_file: string;
+ evaluated: RunRef | null;
+ status: 'red' | 'green';
+ first_red: RunRef | null;
+ latest_red: RunRef | null;
+ last_green: RunRef | null;
+ suspect: Suspect | null;
+ open_jobs: FailedJob[];
+ open_files: string[];
+ failed_jobs: FailedJob[];
+ tests: FailedTest[];
+ evidence: { run_id: number; complete: boolean; problems: string[] } | null;
+ blocked: string[];
+ rebuilt?: string;
+}
+export interface FlakeRecord {
+ schema: typeof FLAKE_SCHEMA;
+ workflow: string;
+ file: string;
+ test: string;
+ lane: string;
+ arm: string;
+ platform: 'linux' | 'windows' | 'macos';
+ job: string;
+ signature: string;
+ first_seen: RunRef;
+ master_red_issue: number;
+ owner: string;
+ opened: string;
+ expires: string;
+ reproduce: string | null;
+}
+export interface MasterRedStep {
+ action: 'create' | 'update' | 'close' | 'record-closed';
+ issue?: number;
+ state: MasterRedState;
+ comment?: string;
+ flakes: Array<{ title: string; body: string; record: FlakeRecord }>;
+}
+export interface MasterRedPlan {
+ /** Summary of the last step ('none' when nothing is written). */
+ action: MasterRedStep['action'] | 'none';
+ title: string;
+ issue?: number;
+ body?: string;
+ comment?: string;
+ state: MasterRedState;
+ steps: MasterRedStep[];
+ evaluated: number[];
+ flakes: MasterRedStep['flakes'];
+ reason: string;
+ /** Evidence of the triggering run when this watch evaluated it (not persisted). */
+ evidence?: RunEvidence;
+}
+
+const refOf = (run: RunInfo): RunRef => ({ run_id: run.id, run_number: run.run_number, run_attempt: run.run_attempt, sha: run.head_sha });
+const order = (a: Pick<RunRef, 'run_number' | 'run_attempt'>, b: Pick<RunRef, 'run_number' | 'run_attempt'>) => a.run_number - b.run_number || a.run_attempt - b.run_attempt;
+const runUrl = (repo: string, id: number) => `https://github.com/${repo}/actions/runs/${id}`;
+const testKey = (t: Pick<FailedTest, 'file' | 'test' | 'arm'>) => `${t.file}\u001f${t.test}\u001f${t.arm}`;
+export const masterRedTitle = (workflow: string) => `Master red: ${inert(workflow, 100)}`;
+const isE2E = (state: Pick<MasterRedState, 'workflow_file'>) => state.workflow_file === 'e2e.yml';
+
+export function blankState(run: RunInfo): MasterRedState {
+ return {
+ schema: MR_SCHEMA, workflow: inert(run.name, 100), workflow_file: workflowFile(run), evaluated: null, status: 'green',
+ first_red: null, latest_red: null, last_green: null, suspect: null, open_jobs: [], open_files: [], failed_jobs: [], tests: [], evidence: null, blocked: [],
+ };
+}
+
+export function validState(value: unknown, workflowFileName: string): MasterRedState | undefined {
+ const s = value as Partial<MasterRedState> | undefined;
+ if (!s || s.schema !== MR_SCHEMA || s.workflow_file !== workflowFileName) return undefined;
+ if (!Array.isArray(s.open_jobs) || !Array.isArray(s.open_files) || !Array.isArray(s.tests) || (s.status !== 'red' && s.status !== 'green')) return undefined;
+ if (s.evaluated !== null && (typeof s.evaluated?.run_number !== 'number' || typeof s.evaluated?.run_attempt !== 'number')) return undefined;
+ return { blocked: [], failed_jobs: [], ...s } as MasterRedState;
+}
+
+/** Clear what this evidence proves passed; returns the names still open. Incomplete evidence clears nothing. */
+function clear(state: MasterRedState, ev: RunEvidence): void {
+ if (!ev.complete) return;
+ state.open_jobs = state.open_jobs.filter(j => !ev.succeeded.includes(j.job));
+ if (isE2E(state)) state.open_files = state.open_files.filter(f => !ev.passed.includes(f));
+}
+
+/** Fold one evaluated run into the incident state (pure). */
+export function applyRun(prev: MasterRedState, run: RunInfo, ev: RunEvidence): MasterRedState {
+ const state: MasterRedState = structuredClone(prev);
+ const ref = refOf(run);
+ state.evaluated = ref;
+ state.evidence = { run_id: run.id, complete: ev.complete, problems: ev.problems };
+ if (ev.verdict === 'red') {
+ if (state.status !== 'red') {
+ state.status = 'red';
+ state.first_red = ref;
+ state.suspect = { from_sha: state.last_green?.sha ?? null, to_sha: run.head_sha, prs: [], complete: false, note: 'not looked up yet' };
+ state.open_jobs = [];
+ state.open_files = [];
+ state.failed_jobs = [];
+ state.tests = [];
+ }
+ state.latest_red = ref;
+ clear(state, ev);
+ for (const job of ev.failed) {
+ state.open_jobs = [...state.open_jobs.filter(j => j.job !== job.job), job];
+ state.failed_jobs = [...state.failed_jobs.filter(j => j.job !== job.job), job];
+ }
+ if (isE2E(state)) state.open_files = [...new Set([...state.open_files, ...ev.files])].sort();
+ const seen = new Set(state.tests.map(testKey));
+ for (const t of ev.tests) if (!seen.has(testKey(t))) { state.tests.push(t); seen.add(testKey(t)); }
+ state.blocked = [];
+ return state;
+ }
+ if (state.status === 'red') {
+ clear(state, ev);
+ if (state.open_jobs.length || state.open_files.length) {
+ state.blocked = [...state.open_jobs.map(j => j.job), ...state.open_files];
+ return state;
+ }
+ state.status = 'green';
+ state.blocked = [];
+ }
+ state.last_green = ref;
+ return state;
+}
+
+/** A scheduled full run or an issue-bound replay that ran at or after the latest red SHA (pure). */
+export function applyExternalPass(prev: MasterRedState, ev: RunEvidence): MasterRedState {
+ const state: MasterRedState = structuredClone(prev);
+ if (state.status !== 'red' || ev.verdict !== 'green') return state;
+ clear(state, ev);
+ if (!state.open_jobs.length && !state.open_files.length) {
+ state.status = 'green';
+ state.blocked = [];
+ } else {
+ state.blocked = [...state.open_jobs.map(j => j.job), ...state.open_files];
+ }
+ return state;
+}
+
+export async function suspectRange(client: GitHubClient, from: string | null, to: string): Promise<Suspect> {
+ if (!from) return { from_sha: null, to_sha: to, prs: [], complete: false, note: 'no green push run of this workflow was found before the first red run' };
+ try {
+ const cmp = await client.request<{ commits: Array<{ sha: string }>; total_commits: number }>('GET', `repos/{repo}/compare/${from}...${to}`);
+ const shas = cmp.commits.map(c => c.sha);
+ const prs = new Set<number>();
+ for (const sha of shas.slice(-MAX_PR_LOOKUPS)) {
+ const pulls = await client.request<Array<{ number: number; merged_at: string | null; base?: { ref: string } }>>('GET', `repos/{repo}/commits/${sha}/pulls`);
+ for (const p of pulls) if (p.merged_at && (!p.base || p.base.ref === 'master')) prs.add(p.number);
+ }
+ const complete = cmp.total_commits === shas.length && shas.length <= MAX_PR_LOOKUPS;
+ return {
+ from_sha: from, to_sha: to, prs: [...prs].sort((a, b) => a - b), complete,
+ note: complete ? `${shas.length} commit(s) in range` : `${cmp.total_commits} commits in range; PRs looked up for the newest ${Math.min(shas.length, MAX_PR_LOOKUPS)}`,
+ };
+ } catch (e) {
+ return { from_sha: from, to_sha: to, prs: [], complete: false, note: `compare or commit-to-PR lookup failed (${inert(e instanceof Error ? e.message : String(e), 120)})` };
+ }
+}
+
+function filesList(state: MasterRedState): string[] {
+ const lines: string[] = [];
+ const byFile = new Map<string, FailedTest[]>();
+ for (const t of state.tests) byFile.set(t.file, [...(byFile.get(t.file) ?? []), t]);
+ for (const [file, tests] of [...byFile].sort(([a], [b]) => a.localeCompare(b))) {
+ const repro = reproduceCommand(file, tests.some(t => t.postgres));
+ const names = tests.filter(t => t.test).map(t => `\`${inert(t.test, 160)}\`${t.arm ? ` [${inert(t.arm, 40)}]` : ''}`);
+ const open = isE2E(state) ? (state.open_files.includes(file) ? ' (not yet passed since)' : ' (passed since)') : '';
+ lines.push(`- \`${file}\`${open}: ${names.length ? names.join(', ') : 'failing (test names in the job log)'}; reproduce: ${repro ? `\`${repro}\`` : '(path failed validation; read the job log)'}`);
+ }
+ return lines;
+}
+
+function nextStep(state: MasterRedState, repo: string, issue: number | undefined): string {
+ const ref = issue ? `#${issue}` : 'this issue';
+ if (state.status === 'green') return 'None: every previously failing job ran and passed on a later run.';
+ const lines: string[] = [];
+ const owner = state.open_jobs.filter(j => j.owner_signal);
+ if (owner.length && owner.length === state.open_jobs.length) {
+ lines.push(`**Owner action (not a code fix).** A setting only the repository owner can change is missing (see the errors above, e.g. an empty secret). Ask the owner to apply the named fix; the next green push run closes ${ref}.`);
+ } else {
+ lines.push(`**Repair PR.** Read the failing log (\`gh run view ${state.latest_red?.run_id ?? state.evaluated?.run_id} --log-failed\`), reproduce each failing file with its command above, find the cause in the suspect range, and open a repair PR whose body says \`Fixes ${ref}\`. Ask Garry to fast-track it. A \`.github/nightly-known-red.tsv\` row is not a response: known-red rows never apply to push runs.`);
+ if (owner.length) lines.push(`Also an **owner action** for ${owner.map(j => `\`${j.job}\``).join(', ')}: ask the repository owner to apply the fix its error names.`);
+ }
+ if (state.blocked.length) {
+ lines.push(`**Not run since:** ${state.blocked.map(b => `\`${inert(b, 160)}\``).join(', ')} failed and has not run and passed on a later run with complete evidence, so ${ref} stays open. `
+ + `If a job was renamed or removed, close ${ref} by hand with a comment naming its replacement. `
+ + (isE2E(state) ? `For an E2E file the selection skipped, dispatch a replay: \`gh workflow run e2e.yml --ref master -f full_corpus=true\`, then \`gh workflow run nightly-watch.yml -f run_id=<that run id> -f replay_issue=${issue ?? '<this issue>'}\`; the nightly scheduled run also counts.`
+ : 'The next push run or the nightly scheduled run that runs it closes this issue.'));
+ }
+ if (state.evidence && !state.evidence.complete) {
+ lines.push(`**Incomplete evidence** for run ${runUrl(repo, state.evidence.run_id)}: ${state.evidence.problems.map(p => inert(p, 200)).join('; ')}. Nothing was cleared from that run. Re-check after the next push run, or re-evaluate a run with \`gh workflow run nightly-watch.yml -f run_id=<run id>\`. Docs: docs/ci-red-runbook.md#ci-failure-manifest`);
+ }
+ lines.push(`Owner: the agent on release duty; first response (a comment or a linked repair PR) within 1 hour, measured by CI health, not enforced. Docs: ${MR_DOCS}`);
+ return lines.join('\n\n');
+}
+
+export function renderMasterRed(state: MasterRedState, repo: string, issue?: number): string {
+ const s = state.suspect;
+ const short = (sha: string | null | undefined) => (sha ? `\`${sha.slice(0, 12)}\`` : 'unknown');
+ const lines = [
+ `Workflow **${state.workflow}** (\`.github/workflows/${state.workflow_file}\`) on master push runs — state: **${state.status}**. Scheduled runs report in \`nightly-red\` issues.`,
+ '',
+ `- Latest evaluated run: ${state.evaluated ? `${runUrl(repo, state.evaluated.run_id)} (run ${state.evaluated.run_number}, attempt ${state.evaluated.run_attempt}, ${short(state.evaluated.sha)})` : 'none'}`,
+ `- First red run: ${state.first_red ? `${runUrl(repo, state.first_red.run_id)} (${short(state.first_red.sha)})` : 'unknown'}`,
+ `- Suspect range: last green ${short(s?.from_sha)} → first red ${short(s?.to_sha)}${s?.from_sha ? ` (https://github.com/${repo}/compare/${s.from_sha}...${s.to_sha})` : ''}; PRs merged in range: ${s?.prs.length ? s.prs.map(n => `#${n}`).join(', ') : 'none found'} (${s ? inert(s.note, 200) : 'not computed'}${s && !s.complete ? '; partial' : ''})`,
+ `- Re-check: \`gh workflow run nightly-watch.yml -f run_id=${state.evaluated?.run_id ?? '<run id>'}\``,
+ ...(state.rebuilt ? [`- State rebuilt from the actions API: ${inert(state.rebuilt, 200)}`] : []),
+ '',
+ ];
+ if (state.open_jobs.length) {
+ lines.push('| failing job | step | result | test files |', '|---|---|---|---|');
+ for (const j of state.open_jobs) lines.push(`| \`${j.job}\` | \`${j.step}\` | ${j.conclusion} | ${j.files.length ? j.files.map(f => `\`${f}\``).join(', ') : '—'} |`);
+ lines.push('');
+ }
+ if (state.tests.length) {
+ lines.push(`<details><summary>Every failing test file this incident (${new Set(state.tests.map(t => t.file)).size})</summary>`, '', ...filesList(state), '', '</details>', '');
+ }
+ for (const j of state.open_jobs.filter(x => x.excerpt.length)) lines.push(`Errors in \`${j.job}\` (sanitized excerpts):`, '~~~text', inertBlock(j.excerpt.join('\n')), '~~~', '');
+ lines.push('### Next step for the agent', '', nextStep(state, repo, issue), '', jsonBlock(MR_MARKER, state), '');
+ return lines.join('\n');
+}
+
+export function flakeFor(state: MasterRedState, t: FailedTest, issue: number, today: string): { title: string; body: string; record: FlakeRecord } {
+ const job = state.failed_jobs.find(j => (t.job ? j.job === t.job : j.files.includes(t.file))) ?? state.failed_jobs[0];
+ const jobName = t.job ?? job?.job ?? '';
+ const platform: FlakeRecord['platform'] = /windows/i.test(jobName) ? 'windows' : /macos|darwin/i.test(jobName) ? 'macos' : 'linux';
+ const expires = new Date(Date.parse(`${today}T00:00:00Z`) + FLAKE_EXPIRY_DAYS * 86_400_000).toISOString().slice(0, 10);
+ const reproduce = reproduceCommand(t.file, t.postgres) ?? null;
+ const record: FlakeRecord = {
+ schema: FLAKE_SCHEMA, workflow: state.workflow, file: t.file, test: t.test, lane: t.lane, arm: t.arm, platform, job: jobName,
+ signature: inert(job?.excerpt[0] ?? '', 200), first_seen: state.first_red!, master_red_issue: issue,
+ owner: 'agent on release duty', opened: today, expires, reproduce,
+ };
+ const title = `Flake: ${inert(`${t.file}${t.test ? ` › ${t.test}` : ''}`, 200)}`;
+ const owner = /runner|no space left|lost communication|secret/i.test(record.signature);
+ const body = [
+ `\`${t.file}\`${t.test ? ` › \`${inert(t.test, 200)}\`` : ''}${t.arm ? ` [${inert(t.arm, 40)}]` : ''} failed on master (${state.workflow}, first seen in https://github.com/{repo}/actions/runs/${record.first_seen.run_id}) and passed later without a repair PR, so master-red #${issue} closed on green. The failure is intermittent.`,
+ '',
+ `- Reproduce: ${reproduce ? `\`${reproduce}\`` : '(path failed validation; read the job log)'}`,
+ `- Failure signature: ${record.signature ? `\`${record.signature}\`` : 'see the master-red issue'}`,
+ `- Owner: ${record.owner}; review by ${expires}.`,
+ '',
+ '### Next step for the agent',
+ '',
+ owner
+ ? '**Owner action (not a code fix).** The signature names a runner, disk or secret problem: ask the repository owner to fix the runner or setting, then close this issue with the evidence.'
+ : `**Root-cause it.** Run the reproduce command until it fails, find the race, and open a repair PR whose body says \`Fixes #<this issue>\`. Never widen a timeout or weaken an assertion. This issue closes after that PR merges and the next complete run passes this test's file and arm${platform === 'linux' ? '' : ` (the \`${inert(jobName, 80)}\` job passes)`}.`,
+ '',
+ `Docs: ${FLAKE_DOCS}`,
+ '',
+ jsonBlock(FLAKE_MARKER, record),
+ '',
+ ].join('\n');
+ return { title, body, record };
+}
+
+export interface ReconcileOptions extends EvidenceOptions { dryRun: boolean; today: string; triggering?: RunInfo }
+
+/** The open incident issue (the oldest open one wins a create race), else the newest closed issue that carries the state block. */
+async function newestIssue(client: GitHubClient, title: string): Promise<Issue | undefined> {
+ const mine = (await listLabeled(client, MR_LABEL, 'all')).filter(i => i.title === title);
+ return mine.filter(i => i.state === 'open').sort((a, b) => a.number - b.number)[0] ?? mine.find(i => (i.body ?? '').includes(`<!-- ${MR_MARKER} -->`)) ?? mine[0];
+}
+
+class CreateRace extends Error {}
+
+async function pushRuns(client: GitHubClient, run: RunInfo): Promise<RunInfo[]> {
+ const r = await client.request<{ workflow_runs: RunInfo[] }>('GET', `repos/{repo}/actions/workflows/${run.workflow_id}/runs?event=push&branch=master&per_page=100`);
+ const runs = r.workflow_runs.filter(x => x.event === 'push' && x.head_branch === 'master' && x.status === 'completed');
+ const listed = runs.findIndex(x => x.id === run.id);
+ if (run.event === 'push' && run.head_branch === 'master' && run.status === 'completed') {
+ if (listed < 0) runs.push(run);
+ else if (runs[listed]!.run_attempt < run.run_attempt) runs[listed] = run;
+ }
+ return runs.sort((a, b) => order(a, b));
+}
+
+/** Pending runs above the high-water mark, or a rebuilt base state plus its pending runs. */
+export function pendingRuns(state: MasterRedState | undefined, runs: RunInfo[], blank: MasterRedState, rebuildReason: string): { state: MasterRedState; pending: RunInfo[] } {
+ const sorted = [...runs].sort((a, b) => order(a, b));
+ if (state) return { state, pending: sorted.filter(r => !state.evaluated || order(r, state.evaluated) > 0) };
+ const counted = sorted.filter(r => verdictOf(r.conclusion) !== 'ignored');
+ const lastRed = counted.map(r => verdictOf(r.conclusion)).lastIndexOf('red');
+ if (lastRed < 0) {
+ const newest = counted.at(-1);
+ return { state: { ...blank, evaluated: newest ? refOf(newest) : null, last_green: newest ? refOf(newest) : null, rebuilt: rebuildReason }, pending: [] };
+ }
+ const green = counted.slice(0, lastRed).map(r => verdictOf(r.conclusion)).lastIndexOf('green');
+ if (green < 0) return { state: { ...blank, rebuilt: `${rebuildReason}; no green run among the ${runs.length} newest, so the first red run may be older` }, pending: sorted };
+ const g = counted[green]!;
+ return { state: { ...blank, evaluated: refOf(g), last_green: refOf(g), rebuilt: rebuildReason }, pending: sorted.filter(r => order(r, g) > 0) };
+}
+
+function failingKey(state: MasterRedState): string {
+ return [...state.open_jobs.map(j => `${j.job}>${j.step}`), ...state.open_files, ...state.tests.map(testKey)].sort().join('\n');
+}
+
+export async function planMasterRed(client: GitHubClient, repo: string, run: RunInfo, opts: ReconcileOptions, cache = new Map<number, RunEvidence>()): Promise<{ plan: MasterRedPlan; issue?: Issue }> {
+ const title = masterRedTitle(run.name);
+ const issue = await newestIssue(client, title);
+ const blank = blankState(run);
+ const stored = issue ? validState(readJsonBlock(issue.body, MR_MARKER), blank.workflow_file) : undefined;
+ const reason = !issue ? 'no master-red issue for this workflow yet' : 'the JSON block of the newest master-red issue was missing or malformed';
+ const runs = await pushRuns(client, run);
+ const { state: base, pending } = pendingRuns(stored, runs, blank, reason);
+ let state = base;
+ const evaluated: number[] = [];
+ const closed: MasterRedState[] = [];
+ const counted = pending.filter(r => verdictOf(r.conclusion) !== 'ignored');
+ const window = counted.slice(-MAX_FOLD);
+ if (counted.length > window.length) state.rebuilt = `${counted.length - window.length} older unevaluated run(s) were not read (more than ${MAX_FOLD} pending)`;
+ for (const r of window) {
+ const key = r.id * 1000 + r.run_attempt;
+ const ev = cache.get(key) ?? await collectEvidence(client, r, opts);
+ cache.set(key, ev);
+ const before = state.status;
+ state = applyRun(state, r, ev);
+ if (before === 'red' && state.status === 'green') closed.push(state);
+ evaluated.push(r.id);
+ }
+ for (const s of [...closed, state]) {
+ if (s.first_red && s.suspect?.note === 'not looked up yet') s.suspect = await suspectRange(client, s.suspect.from_sha, s.suspect.to_sha);
+ }
+ const plan = decide(stored, state, closed, issue, repo, title, evaluated, opts.today);
+ plan.evidence = cache.get(run.id * 1000 + run.run_attempt);
+ return { plan, issue };
+}
+
+function changeComment(prev: MasterRedState | undefined, state: MasterRedState, repo: string): string | undefined {
+ const latest = state.evaluated ? runUrl(repo, state.evaluated.run_id) : 'the latest run';
+ if (!prev || failingKey(prev) !== failingKey(state)) return `Failing set changed (latest run ${latest}); the body has every failing job, test file and reproduce command.`;
+ if (state.blocked.length && state.blocked.join('\n') !== (prev.blocked ?? []).join('\n')) {
+ return `Run ${latest} is green, but ${state.blocked.map(b => `\`${inert(b, 120)}\``).join(', ')} has not run and passed since it failed. Keeping this open; see "Not run since" in the body.`;
+ }
+ if (state.evidence && !state.evidence.complete && state.evidence.run_id !== prev.evidence?.run_id) return `Run ${runUrl(repo, state.evidence.run_id)} has incomplete evidence, so nothing was cleared from it (see the body).`;
+ return undefined;
+}
+
+function closeComment(state: MasterRedState, repo: string, dropped: boolean): string {
+ const g = state.last_green!;
+ return `Green: ${runUrl(repo, g.run_id)} (run ${g.run_number}, attempt ${g.run_attempt}) passed and every previously failing job${isE2E(state) ? ' and test file' : ''} ran and passed with complete evidence. Closing.`
+ + (dropped ? ' This incident started and ended between two watches (the red run\'s own watch was dropped or superseded), so it is recorded here for its suspect range and flake follow-up.' : '');
+}
+
+function decide(prev: MasterRedState | undefined, state: MasterRedState, closed: MasterRedState[], issue: Issue | undefined, repo: string, title: string, evaluated: number[], today: string): MasterRedPlan {
+ let open = issue?.state === 'open' ? issue : undefined;
+ const steps: MasterRedStep[] = [];
+ const flakesOf = (s: MasterRedState, n: number | undefined) => s.tests.slice(0, MAX_FLAKES_PER_CLOSE).map(t => flakeFor(s, t, n ?? 0, today));
+ for (const c of closed) {
+ if (open) {
+ steps.push({ action: 'close', issue: open.number, state: c, comment: closeComment(c, repo, false), flakes: flakesOf(c, open.number) });
+ open = undefined;
+ } else {
+ steps.push({ action: 'record-closed', state: c, comment: closeComment(c, repo, true), flakes: flakesOf(c, undefined) });
+ }
+ }
+ const last = closed.at(-1);
+ if (state.status === 'red') {
+ if (open) {
+ if (evaluated.length || !prev) steps.push({ action: 'update', issue: open.number, state, comment: changeComment(prev?.status === 'red' ? prev : undefined, state, repo), flakes: [] });
+ } else {
+ steps.push({ action: 'create', state, flakes: [] });
+ }
+ } else if (!closed.length && issue && (evaluated.length || !prev)) {
+ steps.push({ action: 'update', issue: issue.number, state, flakes: [] });
+ } else if (last && last !== state) {
+ steps[steps.length - 1]!.state = state;
+ }
+ const final = steps.at(-1);
+ const reason = !final ? (issue ? 'no unevaluated push runs' : 'green and no master-red issue')
+ : final.action === 'create' ? `new master-red incident (first red run ${state.first_red?.run_id})`
+ : final.action === 'close' ? 'green and every previously failing job passed'
+ : final.action === 'record-closed' ? 'an incident opened and closed between watches'
+ : state.status === 'red' ? (state.blocked.length ? 'green but failing jobs not re-run' : 'still red') : 'green; high-water mark recorded on the newest issue';
+ return {
+ action: final?.action ?? 'none', title, issue: final?.issue, steps, state, evaluated, reason,
+ body: final ? renderMasterRed(final.state, repo, final.issue) : undefined, comment: final?.comment, flakes: steps.flatMap(st => st.flakes),
+ };
+}
+
+/** Re-read before writing; true when the issue moved since it was planned. */
+async function moved(client: GitHubClient, title: string, planned: Issue | undefined): Promise<boolean> {
+ const fresh = await newestIssue(client, title);
+ if (!planned || !fresh) return fresh?.number !== planned?.number;
+ const current = fresh.number === planned.number ? await getIssue(client, planned.number) : fresh;
+ const hw = (i: Issue) => JSON.stringify(readJsonBlock<MasterRedState>(i.body, MR_MARKER)?.evaluated ?? null);
+ return current.number !== planned.number || current.updated_at !== planned.updated_at || hw(current) !== hw(planned) || current.state !== planned.state;
+}
+
+export async function openFlakes(client: GitHubClient, repo: string, step: MasterRedStep): Promise<{ opened: number[]; skipped: string[]; note?: string }> {
+ if (!step.issue || !step.flakes.length) return { opened: [], skipped: [] };
+ let linked;
+ try {
+ linked = await linkedPulls(client, step.issue);
+ } catch (e) {
+ return { opened: [], skipped: [], note: `Could not read the PRs linked to #${step.issue} (${inert(e instanceof Error ? e.message : String(e), 120)}), so no flake issue was opened. Check by hand: \`gh api repos/${repo}/issues/${step.issue}/timeline\`. Docs: ${FLAKE_DOCS}` };
+ }
+ const merged = linked.filter(p => p.merged_at);
+ if (merged.length) return { opened: [], skipped: [], note: `Repair PR(s) ${merged.map(p => `#${p.number}`).join(', ')} merged; no flake follow-up.` };
+ const existing = (await listLabeled(client, FLAKE_LABEL, 'open')).map(i => readJsonBlock<FlakeRecord>(i.body, FLAKE_MARKER)).filter(Boolean) as FlakeRecord[];
+ const have = new Set(existing.map(r => testKey(r)));
+ const opened: number[] = [];
+ await ensureLabel(client, FLAKE_LABEL, 'd93f0b', 'An intermittent master failure that passed without a repair (nightly-watch)');
+ for (const f of step.flakes) {
+ if (have.has(testKey(f.record))) continue;
+ const record = { ...f.record, master_red_issue: step.issue };
+ const body = f.body.replaceAll('{repo}', repo).replace(/master-red #0\b/g, `master-red #${step.issue}`).replace(jsonBlock(FLAKE_MARKER, f.record), jsonBlock(FLAKE_MARKER, record));
+ opened.push((await createIssue(client, f.title, body, [FLAKE_LABEL])).number);
+ have.add(testKey(f.record));
+ }
+ const skipped = step.state.tests.slice(MAX_FLAKES_PER_CLOSE).map(t => `${t.file}${t.test ? ` › ${t.test}` : ''}`);
+ return { opened, skipped, note: `No merged repair PR is linked, so this closed as intermittent: flake issue(s) ${opened.map(n => `#${n}`).join(', ') || '(already open)'}${skipped.length ? `; ${skipped.length} more failing test(s) were not given their own issue (open them by hand if they recur): ${skipped.slice(0, 10).map(x => `\`${inert(x, 120)}\``).join(', ')}` : ''}. Docs: ${FLAKE_DOCS}` };
+}
+
+export async function watchMasterRed(client: GitHubClient, repo: string, run: RunInfo, opts: ReconcileOptions): Promise<MasterRedPlan> {
+ const cache = new Map<number, RunEvidence>();
+ for (let attempt = 1; ; attempt++) {
+ const { plan, issue } = await planMasterRed(client, repo, run, opts, cache);
+ if (opts.dryRun || plan.action === 'none') return plan;
+ if (await moved(client, plan.title, issue)) {
+ if (attempt >= RETRIES) throw new Error(`the master-red issue for ${run.name} kept moving while this watch planned (${RETRIES} attempts); another watch is writing it. Re-check with: gh workflow run nightly-watch.yml -f run_id=${run.id}`);
+ continue;
+ }
+ try {
+ await writePlan(client, repo, plan);
+ } catch (e) {
+ if (!(e instanceof CreateRace) || attempt >= RETRIES) throw e;
+ continue;
+ }
+ return plan;
+ }
+}
+
+async function writePlan(client: GitHubClient, repo: string, plan: MasterRedPlan): Promise<void> {
+ await ensureLabel(client, MR_LABEL, 'b60205', 'A push-to-master run of Test or E2E Tests is red (nightly-watch)');
+ for (const step of plan.steps) {
+ if (step.action === 'create' || step.action === 'record-closed') {
+ step.issue = (await createIssue(client, plan.title, renderMasterRed(step.state, repo), [MR_LABEL])).number;
+ const older = step.action === 'create' && (await listLabeled(client, MR_LABEL, 'open')).filter(i => i.title === plan.title && i.number < step.issue!).sort((a, b) => a.number - b.number)[0];
+ if (older) {
+ await updateIssue(client, step.issue, { body: `Duplicate of #${older.number}: two watches created this incident at the same time; #${older.number} carries the state. Nothing to do here.`, state: 'closed', labels: [] });
+ throw new CreateRace(`#${step.issue} duplicated #${older.number}`);
+ }
+ }
+ await updateIssue(client, step.issue!, { body: renderMasterRed(step.state, repo, step.issue) });
+ if (step.action === 'update') {
+ if (step.comment) await commentIssue(client, step.issue!, step.comment);
+ continue;
+ }
+ if (step.action === 'create') continue;
+ const flakes = await openFlakes(client, repo, step);
+ await commentIssue(client, step.issue!, [step.comment, flakes.note].filter(Boolean).join('\n\n'));
+ await updateIssue(client, step.issue!, { state: 'closed' });
+ }
+ plan.issue = plan.steps.at(-1)?.issue;
+}
+
+/** Close open flake issues whose repair PR merged before this run and whose test this complete run passed. */
+export async function closeFlakes(client: GitHubClient, repo: string, run: RunInfo, evidence: RunEvidence | (() => Promise<RunEvidence>), dryRun: boolean): Promise<number[]> {
+ const open = (await listLabeled(client, FLAKE_LABEL, 'open')).map(issue => ({ issue, rec: readJsonBlock<FlakeRecord>(issue.body, FLAKE_MARKER) })).filter(x => x.rec?.schema === FLAKE_SCHEMA);
+ if (!open.length) return [];
+ const ev = typeof evidence === 'function' ? await evidence() : evidence;
+ if (!ev.complete || ev.verdict === 'ignored') return [];
+ const closed: number[] = [];
+ for (const { issue, rec: found } of open) {
+ const rec = found!;
+ const passed = rec.platform === 'linux'
+ ? ev.passed.includes(rec.file) && !ev.tests.some(t => t.file === rec.file && t.arm === rec.arm)
+ : ev.succeeded.includes(rec.job);
+ if (!passed) continue;
+ const pulls = await linkedPulls(client, issue.number).catch(() => []);
+ const merged = pulls.find(p => p.merged_at && (!run.created_at || p.merged_at < run.created_at));
+ if (!merged) continue;
+ closed.push(issue.number);
+ if (dryRun) continue;
+ await commentIssue(client, issue.number, `Repair PR #${merged.number} merged and ${runUrl(repo, run.id)} (${run.event}, \`${run.head_sha.slice(0, 12)}\`) passed \`${rec.file}\`${rec.arm ? ` [${inert(rec.arm, 40)}]` : ''}${rec.platform === 'linux' ? '' : ` (job \`${inert(rec.job, 80)}\`)`} with complete evidence. Closing.`);
+ await updateIssue(client, issue.number, { state: 'closed' });
+ }
+ return closed;
+}
+
+/** Feed a scheduled full run or an issue-bound replay into the open master-red issue of the same workflow. */
+export async function externalPass(client: GitHubClient, repo: string, run: RunInfo, ev: RunEvidence, opts: { dryRun: boolean; today: string; issueNumber?: number }): Promise<MasterRedPlan | undefined> {
+ const title = masterRedTitle(run.name);
+ const issue = opts.issueNumber ? await getIssue(client, opts.issueNumber) : await newestIssue(client, title);
+ if (!issue || issue.state !== 'open' || issue.title !== title) return undefined;
+ const prev = validState(readJsonBlock(issue.body, MR_MARKER), workflowFile(run));
+ if (!prev || prev.status !== 'red' || !prev.latest_red) return undefined;
+ const kind = run.event === 'schedule' ? 'scheduled full run' : 'issue-bound replay';
+ const plan = (state: MasterRedState, step: MasterRedStep | undefined, reason: string): MasterRedPlan => ({
+ action: step?.action ?? 'none', title, issue: issue.number, state, steps: step ? [step] : [], evaluated: [run.id], flakes: step?.flakes ?? [], reason,
+ body: step ? renderMasterRed(state, repo, issue.number) : undefined, comment: step?.comment, evidence: ev,
+ });
+ let contains = false;
+ try {
+ const cmp = await client.request<{ status: string }>('GET', `repos/{repo}/compare/${prev.latest_red.sha}...${run.head_sha}`);
+ contains = cmp.status === 'ahead' || cmp.status === 'identical';
+ } catch { contains = false; }
+ if (!contains) return plan(prev, undefined, `run ${run.id} does not contain the latest red commit ${prev.latest_red.sha.slice(0, 12)}`);
+ const state = applyExternalPass(prev, ev);
+ const result = state.status === 'green'
+ ? plan(state, { action: 'close', issue: issue.number, state, flakes: prev.tests.slice(0, MAX_FLAKES_PER_CLOSE).map(t => flakeFor(prev, t, issue.number, opts.today)),
+ comment: `Green: ${kind} ${runUrl(repo, run.id)} (\`${run.head_sha.slice(0, 12)}\`) ran and passed every previously failing job and test file with complete evidence. Closing.` }, `${kind} cleared every failure`)
+ : plan(state, { action: 'update', issue: issue.number, state, flakes: [],
+ comment: ev.complete ? `${kind} ${runUrl(repo, run.id)} cleared what it ran; still open: ${state.blocked.map(b => `\`${inert(b, 120)}\``).join(', ')}.`
+ : `${kind} ${runUrl(repo, run.id)} has incomplete evidence (${ev.problems.map(p => inert(p, 160)).join('; ')}), so nothing was cleared.` }, `${kind} did not clear every failure`);
+ if (!opts.dryRun) await writePlan(client, repo, result);
+ return result;
+}
diff --git a/scripts/nightly-issue.ts b/scripts/nightly-issue.ts
index 3881a27a35..0895fb6024 100644
--- a/scripts/nightly-issue.ts
+++ b/scripts/nightly-issue.ts
@@ -30,9 +30,15 @@
import { readFileSync } from 'node:fs';
import { basename, join, resolve } from 'node:path';
import {
- commentIssue, createIssue, ensureLabel, findIssueByTitle, inert, inertBlock, jsonBlock, labelNames, readJsonBlock, restClient, updateIssue,
+ commentIssue, createIssue, ensureLabel, findIssueByTitle, inert, inertBlock, jsonBlock, labelNames, readJsonBlock, redactCredentials, restClient, updateIssue,
type GitHubClient, type Issue,
} from './lib/gh-issue.ts';
+import {
+ annotationFiles, collectEvidence, FAILING, OWNER_SIGNAL, pagedJobs, reproduceCommand, type Annotation, type EvidenceOptions, type JobInfo, type RunEvidence, type RunInfo,
+} from './lib/ci-run.ts';
+import { closeFlakes, externalPass, PUSH_ALLOWLIST, watchMasterRed, type MasterRedPlan } from './lib/master-red.ts';
+
+export type { Annotation, JobInfo, RunInfo } from './lib/ci-run.ts';
const REPO_ROOT = resolve(import.meta.dir, '..');
export const KNOWN_RED_FILE = '.github/nightly-known-red.tsv';
@@ -42,30 +48,8 @@ export const KNOWN_LABEL = 'known-red';
export const JSON_MARKER = 'nightly-watch:json';
export const DOCS = 'docs/RELEASING.md#nightly-red-issues';
-export interface RunInfo {
- id: number;
- name: string;
- event: string;
- conclusion: string | null;
- run_attempt: number;
- path: string;
- workflow_id: number;
- head_branch: string;
- head_sha: string;
- html_url: string;
- head_repository?: { full_name: string };
- repository?: { full_name: string };
-}
-export interface JobInfo {
- id: number;
- name: string;
- conclusion: string | null;
- html_url?: string;
- steps?: Array<{ number: number; name: string; conclusion: string | null }>;
-}
-export interface Annotation { annotation_level: string; title?: string | null; message: string }
export interface KnownRow { workflow: string; job: string; signature: string; kind: 'known-red' | 'known-skipped'; todo: string; review_by: string }
-export interface Failure { job: string; job_id: number; job_url?: string; conclusion: string; step: string; errors: string[] }
+export interface Failure { job: string; job_id: number; job_url?: string; conclusion: string; step: string; errors: string[]; files: string[] }
export interface Assessment {
state: 'green' | 'red' | 'known-red' | 'known-skipped';
failures: Failure[];
@@ -82,13 +66,15 @@ export interface IncidentRecord {
run_attempt: number;
run_url: string;
head_sha: string;
- failing: Array<{ job: string; job_id: number; step: string; errors: string[] }>;
+ failing: Array<{ job: string; job_id: number; step: string; errors: string[]; files?: string[] }>;
known: Array<{ job: string; signature: string; kind: string; todo: string; review_by: string }>;
first_red: { run_id: number; sha: string };
last_green_sha: string | null;
dispatch_argv: string[];
next_step: 'code_fix' | 'owner_action' | 'known_red_wait' | 'review_by_passed' | 'none';
review_by_notified?: string[];
+ files?: string[];
+ evidence?: { complete: boolean; problems: string[] };
}
export interface Plan {
action: 'create' | 'update' | 'reopen' | 'close' | 'none';
@@ -101,9 +87,9 @@ export interface Plan {
reason: string;
}
-const FAILING = new Set(['failure', 'timed_out', 'cancelled', 'startup_failure']);
const GENERIC_ERROR = /^Process completed with exit code \d+\.?$/;
-const OWNER_SIGNAL = /gh secret set|secret is empty|secrets? (?:is |are )?(?:empty|missing|not configured)/i;
+/** Jobs whose reds must be repaired, never parked as known-red (the race hunt reports races in product or test code). */
+export const NO_KNOWN_RED_JOBS = /^race[- ]hunt\b/i;
export function parseKnownRed(text: string): { rows: KnownRow[]; problems: string[] } {
const rows: KnownRow[] = [];
@@ -129,6 +115,7 @@ export function validateKnownRed(text: string, todosText: string): string[] {
const { rows, problems } = parseKnownRed(text);
for (const row of rows) {
if (!todosText.includes(row.todo)) problems.push(`row '${row.job}': todo '${row.todo}' is not in TODOS.md; every known-red row needs the TODO that owns its fix`);
+ if (NO_KNOWN_RED_JOBS.test(row.job)) problems.push(`row '${row.job}': race-hunt failures cannot be known-red; delete the row and open a repair PR for each file the race hunt lists (docs/ci-red-runbook.md#ci-issue-labels)`);
}
return problems.map(p => `${KNOWN_RED_FILE}: ${p}. Fix: edit the row, then run bun test --timeout=60000 test/scripts/nightly-issue.test.ts. Docs: ${DOCS}`);
}
@@ -138,9 +125,9 @@ export function assessRun(run: RunInfo, jobs: JobInfo[], annotations: Record<num
const step = j.steps?.find(s => FAILING.has(s.conclusion ?? ''));
const errors = (annotations[j.id] ?? []).filter(a => a.annotation_level === 'failure' && !GENERIC_ERROR.test(a.message.trim()))
.map(a => [a.title, a.message].filter(Boolean).join(': '));
- return { job: j.name, job_id: j.id, job_url: j.html_url, conclusion: j.conclusion!, step: step?.name ?? '(job-level)', errors };
+ return { job: j.name, job_id: j.id, job_url: j.html_url, conclusion: j.conclusion!, step: step?.name ?? '(job-level)', errors, files: annotationFiles(annotations[j.id] ?? []) };
});
- const mine = rows.filter(r => r.workflow === run.name);
+ const mine = rows.filter(r => r.workflow === run.name && !NO_KNOWN_RED_JOBS.test(r.job));
const matched: Assessment['matched'] = [];
const stale: KnownRow[] = [];
const unmatched = failures.filter(f => {
@@ -217,8 +204,18 @@ export function renderBody(rec: IncidentRecord, assessment: Assessment): string
lines.push(`| \`${inert(f.job)}\` | \`${inert(f.step)}\` | ${inert(f.conclusion, 20)} | ${row ? `known-red (TODO: ${inert(row.todo)}, review by ${row.review_by})` : 'no'} |`);
}
lines.push('');
+ const files = [...new Set([...(rec.files ?? []), ...rec.failing.flatMap(f => f.files ?? [])])].sort();
+ if (files.length) {
+ lines.push(`<details><summary>Every failing test file (${files.length})</summary>`, '');
+ for (const file of files) {
+ const jobs = rec.failing.filter(f => (f.files ?? []).includes(file));
+ const repro = reproduceCommand(file, jobs.some(f => /postgres/i.test(`${f.job} ${f.errors.join(' ')}`)));
+ lines.push(`- \`${file}\`${jobs.length ? ` (${jobs.map(f => `\`${f.job}\``).join(', ')})` : ''}; reproduce: ${repro ? `\`${repro}\`` : '(path failed validation; read the job log)'}`);
+ }
+ lines.push('', '</details>', '');
+ }
for (const f of assessment.failures.filter(x => x.errors.length)) {
- lines.push(`Errors in \`${inert(f.job)}\`:`, '~~~text', inertBlock(f.errors.slice(0, 3).join('\n')), '~~~', '');
+ lines.push(`Errors in \`${inert(f.job)}\` (sanitized excerpts):`, '~~~text', inertBlock(f.errors.slice(0, 3).map(redactCredentials).join('\n')), '~~~', '');
}
}
for (const m of assessment.matched.filter(x => x.row.kind === 'known-skipped')) {
@@ -227,11 +224,14 @@ export function renderBody(rec: IncidentRecord, assessment: Assessment): string
for (const r of assessment.stale) {
lines.push(`- Stale row: \`${inert(r.job)}\` / \`${inert(r.signature)}\` no longer matches (the cell ran). Delete it from \`${KNOWN_RED_FILE}\`.`);
}
+ if (rec.evidence && !rec.evidence.complete) {
+ lines.push(`- Incomplete evidence: ${rec.evidence.problems.join('; ')}. This run's failures may be under-reported and it cannot close an incident. Docs: docs/ci-red-runbook.md#ci-failure-manifest`);
+ }
lines.push('', '### Next step for the agent', '', nextStepText(rec, assessment), '', jsonBlock(JSON_MARKER, rec), '');
return lines.join('\n');
}
-export function planIncident(run: RunInfo, assessment: Assessment, existing: Issue | undefined, lastGreenSha: string | null, repo: string, succeededJobs: string[]): Plan {
+export function planIncident(run: RunInfo, assessment: Assessment, existing: Issue | undefined, lastGreenSha: string | null, repo: string, succeededJobs: string[], evidence?: RunEvidence): Plan {
const title = `Nightly red: ${inert(run.name, 100)}`;
const previous = existing ? readJsonBlock<IncidentRecord>(existing.body, JSON_MARKER) : undefined;
const keepLabels = existing ? labelNames(existing).filter(l => l !== KNOWN_LABEL && l !== LABEL) : [];
@@ -249,6 +249,14 @@ export function planIncident(run: RunInfo, assessment: Assessment, existing: Iss
reason: 'green but previously failing jobs did not run',
};
}
+ if (evidence && !evidence.complete) {
+ return {
+ action: 'none', title, labels: [], issue: existing.number,
+ comment: `Run ${runUrl} is green, but its evidence is incomplete (${evidence.problems.map(p => inert(p, 200)).join('; ')}), so this incident stays open. `
+ + `The next complete scheduled run closes it, or re-check with \`gh workflow run nightly-watch.yml -f run_id=<run id>\`. Docs: docs/ci-red-runbook.md#ci-failure-manifest`,
+ reason: 'green but evidence incomplete',
+ };
+ }
return {
action: 'close', title, labels: [], issue: existing.number,
comment: `Green: scheduled run ${runUrl} (attempt ${run.run_attempt}) passed and every previously failing job executed. Closing.`,
@@ -268,7 +276,7 @@ export function planIncident(run: RunInfo, assessment: Assessment, existing: Iss
run_attempt: run.run_attempt,
run_url: runUrl,
head_sha: run.head_sha,
- failing: assessment.failures.map(f => ({ job: inert(f.job), job_id: f.job_id, step: inert(f.step), errors: f.errors.slice(0, 3).map(e => inert(e, 400)) })),
+ failing: assessment.failures.map(f => ({ job: inert(f.job), job_id: f.job_id, step: inert(f.step), errors: f.errors.slice(0, 3).map(e => inert(redactCredentials(e), 400)), files: f.files })),
known: assessment.matched.map(m => ({ job: inert(m.row.job), signature: inert(m.row.signature), kind: m.row.kind, todo: inert(m.row.todo), review_by: m.row.review_by })),
first_red: continuing ? previous!.first_red : { run_id: run.id, sha: run.head_sha },
last_green_sha: lastGreenSha,
@@ -278,6 +286,7 @@ export function planIncident(run: RunInfo, assessment: Assessment, existing: Iss
: assessment.reviewPassed.length ? 'review_by_passed'
: assessment.state === 'known-skipped' ? 'owner_action' : 'known_red_wait',
review_by_notified: [...notified, ...newlyPassed.map(r => `${r.job}|${r.review_by}`)],
+ ...(evidence ? { files: evidence.files, evidence: { complete: evidence.complete, problems: evidence.problems.map(p => inert(p, 300)) } } : {}),
};
const body = renderBody(record, assessment).replaceAll('{repo}', repo);
const labels = [LABEL, ...(assessment.state === 'red' ? [] : [KNOWN_LABEL]), ...keepLabels];
@@ -299,39 +308,33 @@ export function planIncident(run: RunInfo, assessment: Assessment, existing: Iss
return { action: 'update', title, labels, body, record, issue: existing.number, comment, reason: changed ? 'failing set changed' : 'same failing set' };
}
-async function pagedJobs(client: GitHubClient, run: RunInfo): Promise<JobInfo[]> {
- const jobs: JobInfo[] = [];
- for (let page = 1; page <= 5; page++) {
- const r = await client.request<{ jobs: JobInfo[]; total_count: number }>('GET', `repos/{repo}/actions/runs/${run.id}/attempts/${run.run_attempt}/jobs?per_page=100&page=${page}`);
- jobs.push(...r.jobs);
- if (jobs.length >= r.total_count || r.jobs.length < 100) break;
- }
- return jobs;
-}
+export interface WatchResult { plan: Plan; assessment: Assessment; run: RunInfo; evidence: RunEvidence; masterRed?: MasterRedPlan; flakesClosed: number[] }
+export interface WatchOptions extends EvidenceOptions { client: GitHubClient; repo: string; runId: number; rows: KnownRow[]; today: string; dryRun: boolean; run?: RunInfo }
-export interface WatchResult { plan: Plan; assessment: Assessment; run: RunInfo }
-
-export async function watchRun(opts: { client: GitHubClient; repo: string; runId: number; rows: KnownRow[]; today: string; dryRun: boolean }): Promise<WatchResult> {
- const { client, repo } = opts;
- const run = await client.request<RunInfo>('GET', `repos/{repo}/actions/runs/${opts.runId}`);
+const sameRepoCheck = (run: RunInfo) => {
if (run.head_repository?.full_name && run.repository?.full_name && run.head_repository.full_name !== run.repository.full_name) {
throw new Error(`run ${run.id} comes from fork ${run.head_repository.full_name}; nightly-watch never reads fork runs.`);
}
+};
+
+/** The nightly-red path: one scheduled run (a scheduled Test or E2E Tests run also feeds that workflow's open master-red issue). */
+export async function watchRun(opts: WatchOptions): Promise<WatchResult> {
+ const { client, repo } = opts;
+ const run = opts.run ?? await client.request<RunInfo>('GET', `repos/{repo}/actions/runs/${opts.runId}`);
+ sameRepoCheck(run);
if (run.event !== 'schedule' && !opts.dryRun) {
- throw new Error(`run ${run.id} is a ${run.event} run; nightly-watch only tracks scheduled runs. Fix: pass a scheduled run id, or add --dry-run to preview.`);
+ throw new Error(`run ${run.id} is a ${run.event} run; the nightly-red path only tracks scheduled runs. Fix: pass a scheduled run id, or add --dry-run to preview.`);
}
- const jobs = await pagedJobs(client, run);
- const annotations: Record<number, Annotation[]> = {};
- for (const job of jobs.filter(j => FAILING.has(j.conclusion ?? ''))) {
- annotations[job.id] = await client.request<Annotation[]>('GET', `repos/{repo}/check-runs/${job.id}/annotations?per_page=50`).catch(() => []);
- }
- const assessment = assessRun(run, jobs, annotations, opts.rows, opts.today);
+ const evidence = await collectEvidence(client, run, opts);
+ const assessment = assessRun(run, evidence.jobs, evidence.annotations, opts.rows, opts.today);
const greens = await client.request<{ workflow_runs: Array<{ head_sha: string }> }>('GET',
`repos/{repo}/actions/workflows/${run.workflow_id}/runs?event=schedule&status=success&per_page=1`).catch(() => ({ workflow_runs: [] }));
const existing = await findIssueByTitle(client, LABEL, `Nightly red: ${inert(run.name, 100)}`);
- const succeeded = jobs.filter(j => j.conclusion === 'success').map(j => j.name);
- const plan = planIncident(run, assessment, existing, greens.workflow_runs[0]?.head_sha ?? null, repo, succeeded);
- if (opts.dryRun) return { plan, assessment, run };
+ const succeeded = evidence.jobs.filter(j => j.conclusion === 'success').map(j => j.name);
+ const plan = planIncident(run, assessment, existing, greens.workflow_runs[0]?.head_sha ?? null, repo, succeeded, evidence);
+ const fed = run.event === 'schedule' && PUSH_ALLOWLIST[run.name] ? await externalPass(client, repo, run, evidence, { dryRun: opts.dryRun, today: opts.today }) : undefined;
+ const flakesClosed = run.event === 'schedule' ? await closeFlakes(client, repo, run, evidence, opts.dryRun) : [];
+ if (opts.dryRun) return { plan, assessment, run, evidence, masterRed: fed, flakesClosed };
if (plan.action === 'create' || plan.action === 'reopen' || plan.action === 'update') {
await ensureLabel(client, LABEL, 'b60205', 'A scheduled workflow is red (nightly-watch)');
@@ -344,34 +347,114 @@ export async function watchRun(opts: { client: GitHubClient; repo: string; runId
}
if (plan.comment && plan.issue) await commentIssue(client, plan.issue, plan.comment);
if (plan.action === 'close') await updateIssue(client, plan.issue!, { state: 'closed' });
- return { plan, assessment, run };
+ return { plan, assessment, run, evidence, masterRed: fed, flakesClosed };
+}
+
+export type Route = { track: 'schedule' | 'push' | 'replay' } | { refuse: string };
+
+/** Which state track a run feeds; every refusal names what nightly-watch accepts and the next command. */
+export function routeRun(run: RunInfo, repo: string, replayIssue?: number): Route {
+ const fix = 'Fix: pass a scheduled run id, a push-to-master run id of Test or E2E Tests (gh run list --workflow test.yml --event push --branch master --limit 5), or an E2E Tests dispatch run on master with replay_issue. Docs: docs/RELEASING.md#master-red-issues';
+ if (run.repository?.full_name && run.repository.full_name !== repo) return { refuse: `run ${run.id} belongs to ${run.repository.full_name}, not ${repo}. ${fix}` };
+ if (run.event === 'schedule') return replayIssue ? { refuse: `run ${run.id} is a scheduled run; replay_issue applies only to E2E Tests dispatch runs. ${fix}` } : { track: 'schedule' };
+ if (run.event === 'push') {
+ if (run.head_branch !== 'master') return { refuse: `run ${run.id} is a push to '${inert(run.head_branch, 80)}'; only push-to-master runs open master-red issues. ${fix}` };
+ if (!PUSH_ALLOWLIST[run.name]) return { refuse: `run ${run.id} is a push run of '${inert(run.name, 80)}', which master-red does not watch (allowlist: ${Object.keys(PUSH_ALLOWLIST).join(', ')}). ${fix}` };
+ return replayIssue ? { refuse: `run ${run.id} is a push run; replay_issue applies only to E2E Tests dispatch runs. ${fix}` } : { track: 'push' };
+ }
+ if (run.event === 'workflow_dispatch' && replayIssue) {
+ if (run.name !== 'E2E Tests' || run.head_branch !== 'master') return { refuse: `run ${run.id} is a dispatch of '${inert(run.name, 80)}' on '${inert(run.head_branch, 80)}'; an issue-bound replay must be an E2E Tests dispatch on master (gh workflow run e2e.yml --ref master -f full_corpus=true). ${fix}` };
+ return { track: 'replay' };
+ }
+ return { refuse: `run ${run.id} is a ${inert(run.event, 40)} run; nightly-watch evaluates scheduled runs, push-to-master runs of Test and E2E Tests, and issue-bound E2E replays only (pull-request and other runs are refused). ${fix}` };
+}
+
+export type RoutedResult =
+ | { track: 'schedule'; run: RunInfo; nightly: WatchResult; masterRed?: MasterRedPlan; flakesClosed: number[] }
+ | { track: 'push' | 'replay'; run: RunInfo; masterRed?: MasterRedPlan; flakesClosed: number[] };
+
+/** Entry point: route one run id to the nightly-red, master-red or replay path. */
+export async function watch(opts: WatchOptions & { replayIssue?: number }): Promise<RoutedResult> {
+ const { client, repo } = opts;
+ const run = await client.request<RunInfo>('GET', `repos/{repo}/actions/runs/${opts.runId}`);
+ sameRepoCheck(run);
+ const route = routeRun(run, repo, opts.replayIssue);
+ if ('refuse' in route) throw new Error(route.refuse);
+ if (route.track === 'schedule') {
+ const nightly = await watchRun({ ...opts, run });
+ return { track: 'schedule', run, nightly, masterRed: nightly.masterRed, flakesClosed: nightly.flakesClosed };
+ }
+ if (route.track === 'push') {
+ const masterRed = await watchMasterRed(client, repo, run, { dryRun: opts.dryRun, today: opts.today, manifest: opts.manifest });
+ const flakesClosed = await closeFlakes(client, repo, run, () => masterRed.evidence ? Promise.resolve(masterRed.evidence) : collectEvidence(client, run, opts), opts.dryRun);
+ return { track: 'push', run, masterRed, flakesClosed };
+ }
+ if (run.status && run.status !== 'completed') throw new Error(`replay run ${run.id} is ${run.status}; wait for it (gh run watch ${run.id}), then dispatch nightly-watch again.`);
+ const ev = await collectEvidence(client, run, opts);
+ const masterRed = await externalPass(client, repo, run, ev, { dryRun: opts.dryRun, today: opts.today, issueNumber: opts.replayIssue });
+ if (!masterRed) throw new Error(`issue #${opts.replayIssue} is not the open master-red issue of ${run.name} (or it is not red); nothing to replay against. Fix: pass the number of the open "Master red: ${run.name}" issue.`);
+ return { track: 'replay', run, masterRed, flakesClosed: [] };
+}
+
+/** The serialization key every entry path shares: target workflow id and state track (schedule, push; a replay writes the push track). */
+export async function resolveTarget(client: GitHubClient, repo: string, runId: number, replayIssue?: number): Promise<{ workflow_id: number; track: string; refuse?: string }> {
+ const run = await client.request<RunInfo>('GET', `repos/{repo}/actions/runs/${runId}`);
+ const route = routeRun(run, repo, replayIssue);
+ if ('refuse' in route) return { workflow_id: run.workflow_id, track: 'refused', refuse: route.refuse };
+ return { workflow_id: run.workflow_id, track: route.track === 'replay' ? 'push' : route.track };
+}
+
+function printNightly(r: WatchResult, dryRun: boolean) {
+ const { plan, assessment, run } = r;
+ console.log(`[nightly-watch] ${run.name} run ${run.id} attempt ${run.run_attempt}: ${assessment.state}; action ${plan.action}${plan.issue ? ` #${plan.issue}` : ''} (${plan.reason})${dryRun ? ' [dry run]' : ''}`);
+ if (dryRun) {
+ console.log(`--- title: ${plan.title}\n--- labels: ${plan.labels.join(', ') || '(none)'}`);
+ if (plan.comment) console.log(`--- comment:\n${plan.comment}`);
+ if (plan.body) console.log(`--- body:\n${plan.body}`);
+ }
+}
+
+function printMasterRed(plan: MasterRedPlan | undefined, run: RunInfo, dryRun: boolean) {
+ if (!plan) return;
+ console.log(`[nightly-watch] master-red ${run.name}: ${plan.state.status}; action ${plan.action}${plan.issue ? ` #${plan.issue}` : ''} (${plan.reason}); evaluated runs: ${plan.evaluated.join(', ') || 'none'}${dryRun ? ' [dry run]' : ''}`);
+ if (dryRun) {
+ console.log(`--- title: ${plan.title}`);
+ if (plan.comment) console.log(`--- comment:\n${plan.comment}`);
+ if (plan.body) console.log(`--- body:\n${plan.body}`);
+ for (const f of plan.flakes) console.log(`--- flake issue (opened only when no merged repair PR is linked): ${f.title}`);
+ }
}
if (import.meta.main) {
const flag = (name: string) => { const i = process.argv.indexOf(name); return i >= 0 ? process.argv[i + 1] : undefined; };
const runId = Number(flag('--run-id'));
+ const replayRaw = flag('--replay-issue');
+ const replayIssue = replayRaw ? Number(replayRaw) : undefined;
const repo = flag('--repo') ?? process.env.GITHUB_REPOSITORY ?? 'garrytan/gbrain';
const dryRun = process.argv.includes('--dry-run');
- if (!Number.isInteger(runId) || runId <= 0) {
- console.log('Usage: bun scripts/nightly-issue.ts --run-id <id> [--repo owner/name] [--dry-run]');
+ if (!Number.isInteger(runId) || runId <= 0 || (replayIssue !== undefined && (!Number.isInteger(replayIssue) || replayIssue <= 0))) {
+ console.log('Usage: bun scripts/nightly-issue.ts --run-id <id> [--replay-issue <n>] [--repo owner/name] [--dry-run] [--resolve]');
process.exit(2);
}
try {
+ if (process.argv.includes('--resolve')) {
+ const target = await resolveTarget(restClient(repo), repo, runId, replayIssue);
+ console.log(`workflow_id=${target.workflow_id}\ntrack=${target.track}`);
+ if (target.refuse) console.log(`::notice::nightly-watch will refuse run ${runId}: ${target.refuse}`);
+ process.exit(0);
+ }
const tsv = readFileSync(join(REPO_ROOT, KNOWN_RED_FILE), 'utf8');
const problems = validateKnownRed(tsv, readFileSync(join(REPO_ROOT, 'TODOS.md'), 'utf8'));
for (const p of problems) console.log(`::warning::${p}`);
const { rows } = parseKnownRed(tsv);
const today = new Date().toISOString().slice(0, 10);
- const { plan, assessment, run } = await watchRun({ client: restClient(repo), repo, runId, rows, today, dryRun });
- console.log(`[nightly-watch] ${run.name} run ${run.id} attempt ${run.run_attempt}: ${assessment.state}; action ${plan.action}${plan.issue ? ` #${plan.issue}` : ''} (${plan.reason})${dryRun ? ' [dry run]' : ''}`);
- if (dryRun) {
- console.log(`--- title: ${plan.title}\n--- labels: ${plan.labels.join(', ') || '(none)'}`);
- if (plan.comment) console.log(`--- comment:\n${plan.comment}`);
- if (plan.body) console.log(`--- body:\n${plan.body}`);
- }
+ const result = await watch({ client: restClient(repo), repo, runId, rows, today, dryRun, replayIssue });
+ if (result.track === 'schedule') printNightly(result.nightly, dryRun);
+ printMasterRed(result.masterRed, result.run, dryRun);
+ if (result.flakesClosed.length) console.log(`[nightly-watch] flake issue(s) ${dryRun ? 'that would close' : 'closed'}: ${result.flakesClosed.map(n => `#${n}`).join(', ')}`);
} catch (e) {
console.log(`[nightly-watch] FAIL: ${e instanceof Error ? e.message : String(e)}`);
- console.log(`[nightly-watch] Fix: check the run id and the token's actions:read / issues:write scopes, then rerun: bun scripts/nightly-issue.ts --run-id ${runId} --dry-run. Docs: ${DOCS}`);
+ console.log(`[nightly-watch] Fix: check the run id and the token's actions:read / issues:write / contents:read / pull-requests:read scopes, then rerun: bun scripts/nightly-issue.ts --run-id ${runId} --dry-run. Docs: ${DOCS}`);
process.exit(1);
}
}
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111876367226.json b/test/fixtures/nightly-watch/master-red/annotations-111876367226.json
new file mode 100644
index 0000000000..d447524142
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111876367226.json
@@ -0,0 +1,26 @@
+[
+ {
+ "annotation_level": "warning",
+ "path": ".github",
+ "title": "",
+ "message": "Node.js 20 is deprecated. The following actions target Node.js 20 but are being forced to run on Node.js 24: actions/checkout@11d5960a326750d5838078e36cf38b85af677262. For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/"
+ },
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ },
+ {
+ "annotation_level": "failure",
+ "path": "test/persistence-history-fixture.test.ts",
+ "title": "",
+ "message": "PostgreSQL arm failed. Reproduce: DATABASE_URL=<pgvector test database> GBRAIN_TEST_ALLOW_DATABASE_URL=1 bun test --timeout=120000 test/persistence-history-fixture.test.ts"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "test/persistence-history-fixture.test.ts",
+ "title": "error: expect(received).toEqual(expected)",
+ "message": " {\n- \"future\": true,\n+ \"future\": false,\n \"state\": \"queued\",\n }\n\n- Expected - 1\n+ Received + 1\n\n at <anonymous> (/home/runner/work/gbrain/gbrain/test/persistence-history-fixture.test.ts:55:28)"
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111882475890.json b/test/fixtures/nightly-watch/master-red/annotations-111882475890.json
new file mode 100644
index 0000000000..82f8f9fdde
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111882475890.json
@@ -0,0 +1,8 @@
+[
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111902484298.json b/test/fixtures/nightly-watch/master-red/annotations-111902484298.json
new file mode 100644
index 0000000000..3cae8b06d1
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111902484298.json
@@ -0,0 +1,68 @@
+[
+ {
+ "annotation_level": "warning",
+ "path": ".github",
+ "title": "",
+ "message": "Node.js 20 is deprecated. The following actions target Node.js 20 but are being forced to run on Node.js 24: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684, actions/checkout@11d5960a326750d5838078e36cf38b85af677262, actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02. For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:232:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:213:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:199:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:162:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:152:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:143:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:131:28)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:120:27)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/embed-facts.ts",
+ "title": "error: Facts embedding dimensions differ from the configured model; inspect migrate embeddings --status first",
+ "message": "\n at embedStaleFacts (/home/runner/work/gbrain/gbrain/src/core/embed-facts.ts:106:15)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/e2e/fact-embedding-backfill-parity.test.ts:98:27)"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "vendor/postgres/src/connection.js",
+ "title": "PostgresError: expected 8 dimensions, not 1536",
+ "message": "\n at ErrorResponse (/home/runner/work/gbrain/gbrain/vendor/postgres/src/connection.js:833:30)\n at handle (/home/runner/work/gbrain/gbrain/vendor/postgres/src/connection.js:503:7)\n at data (/home/runner/work/gbrain/gbrain/vendor/postgres/src/connection.js:330:9)\n at emit (node:events:100:22)\n at addChunk (internal:streams/readable:267:47)\n at readableAddChunkPushByteMode (internal:streams/readable:245:18)\n at data (node:net:633:72)"
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111902768521.json b/test/fixtures/nightly-watch/master-red/annotations-111902768521.json
new file mode 100644
index 0000000000..f5766cbb28
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111902768521.json
@@ -0,0 +1,26 @@
+[
+ {
+ "annotation_level": "warning",
+ "path": ".github",
+ "title": "",
+ "message": "Node.js 20 is deprecated. The following actions target Node.js 20 but are being forced to run on Node.js 24: actions/checkout@11d5960a326750d5838078e36cf38b85af677262. For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/"
+ },
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ },
+ {
+ "annotation_level": "failure",
+ "path": "test/managed-lint.test.ts",
+ "title": "",
+ "message": "PostgreSQL arm failed. Reproduce: DATABASE_URL=<pgvector test database> GBRAIN_TEST_ALLOW_DATABASE_URL=1 bun test --timeout=120000 test/managed-lint.test.ts"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/commands/lint.ts",
+ "title": "error: ENOENT: no such file or directory, open '/tmp/gbrain-managed-lint-R0xjr9/brain/people/jane-doe.md'",
+ "message": "\n at runLintCore (/home/runner/work/gbrain/gbrain/src/commands/lint.ts:757:21)\n at async lintCollecting (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:199:24)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:284:41)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:61:15)\n at async withEnv (/home/runner/work/gbrain/gbrain/test/helpers/with-env.ts:68:18)\n at async fixture (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:56:13)\n at async <anonymous> (/home/runner/work/gbrain/gb"
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111909257450.json b/test/fixtures/nightly-watch/master-red/annotations-111909257450.json
new file mode 100644
index 0000000000..82f8f9fdde
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111909257450.json
@@ -0,0 +1,8 @@
+[
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111909670183.json b/test/fixtures/nightly-watch/master-red/annotations-111909670183.json
new file mode 100644
index 0000000000..82f8f9fdde
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111909670183.json
@@ -0,0 +1,8 @@
+[
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111914484195.json b/test/fixtures/nightly-watch/master-red/annotations-111914484195.json
new file mode 100644
index 0000000000..6a5d9871bb
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111914484195.json
@@ -0,0 +1,26 @@
+[
+ {
+ "annotation_level": "warning",
+ "path": ".github",
+ "title": "",
+ "message": "Node.js 20 is deprecated. The following actions target Node.js 20 but are being forced to run on Node.js 24: actions/checkout@11d5960a326750d5838078e36cf38b85af677262. For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/"
+ },
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ },
+ {
+ "annotation_level": "failure",
+ "path": "test/pack-relation-direction-engine.test.ts",
+ "title": "",
+ "message": "PostgreSQL arm failed. Reproduce: DATABASE_URL=<pgvector test database> GBRAIN_TEST_ALLOW_DATABASE_URL=1 bun test --timeout=120000 test/pack-relation-direction-engine.test.ts"
+ },
+ {
+ "annotation_level": "failure",
+ "path": "src/core/page-state/projections.ts",
+ "title": "PageProjectionConflictError: The page projection changed during preparation. Read its current snapshot before retrying.",
+ "message": "\n at <anonymous> (/home/runner/work/gbrain/gbrain/src/core/page-state/projections.ts:146:13)"
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111921205893.json b/test/fixtures/nightly-watch/master-red/annotations-111921205893.json
new file mode 100644
index 0000000000..82f8f9fdde
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/annotations-111921205893.json
@@ -0,0 +1,8 @@
+[
+ {
+ "annotation_level": "failure",
+ "path": ".github",
+ "title": "",
+ "message": "Process completed with exit code 1."
+ }
+]
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json b/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json
new file mode 100644
index 0000000000..858a2ed906
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json
@@ -0,0 +1,174 @@
+{
+ "schema": "gbrain-ci-manifest/v1",
+ "workflow": "",
+ "event": "",
+ "sha": "17c5765ba425a724ba92c6563c3b81562c83025e",
+ "run_id": 37351182593,
+ "run_attempt": 1,
+ "complete": false,
+ "problems": [
+ "lane backend-matrix: test/e2e/embedding-recovery-parity.test.ts [postgres-direct] has no valid receipt from any attempt (receipts-tier1-backend-matrix-2/backend-matrix--s2of2-f4-direct--primary [primary, exit 124]: no JUnit report)"
+ ],
+ "files": [
+ {
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "postgres-direct",
+ "executed": 44,
+ "failed": 17,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-vector-repair-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "pgbouncer",
+ "executed": 18,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-vector-repair-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "postgres-direct",
+ "executed": 18,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-withdrawal-scope-postgres.test.ts",
+ "lane": "e2e",
+ "arm": "",
+ "executed": 1,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/legacy-fact-extraction-dedup-postgres.test.ts",
+ "lane": "e2e",
+ "arm": "",
+ "executed": 1,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/loops-close-fact-postgres.test.ts",
+ "lane": "e2e",
+ "arm": "",
+ "executed": 10,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/mechanical.test.ts",
+ "lane": "tier1",
+ "arm": "",
+ "executed": 77,
+ "failed": 0,
+ "skipped": 0
+ }
+ ],
+ "failures": [
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > a zero budget cannot admit a paid request for an empty legacy fact",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > abort after provider response installs nothing",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > an engine off-switch changed during provider work prevents installation",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > an incomplete provider result writes no partial batch",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > BIGSERIAL fact IDs retain exact identity and JSON-safe results",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > bounded runs bank progress, restart from remaining nulls, and are idempotent",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > concurrent text and visibility edits never receive a stale vector",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > cost cap rejects before any provider request",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > managed repair refuses installing a vector after the model changes",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > managed repair updates only physical vectors and preserves canonical rows and guards",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > missing valid provider usage retains a conservative reported charge",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > preview is read-only and scoped; null active facts only, with zero provider calls",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > provider failure samples redact connection credentials and bearer tokens",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > source incarnation changes prevent installing vectors into a new identity",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > stops after a failed batch and resumes without re-embedding completed facts",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > unexpected billed usage cannot silently exceed the cap on the final batch",
+ "arm": "postgres-direct"
+ },
+ {
+ "lane": "backend-matrix",
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "test": "postgres explicit fact embedding backfill > withdrawals recorded during embedding remain unembedded",
+ "arm": "postgres-direct"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json b/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json
new file mode 100644
index 0000000000..1b5622e666
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json
@@ -0,0 +1,93 @@
+{
+ "schema": "gbrain-ci-manifest/v1",
+ "workflow": "",
+ "event": "",
+ "sha": "67c4ff27bd0a5a8a02ccb66cd663d3aa1daf9969",
+ "run_id": 37354832141,
+ "run_attempt": 1,
+ "complete": true,
+ "problems": [],
+ "files": [
+ {
+ "file": "test/e2e/embedding-recovery-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "pgbouncer",
+ "executed": 155,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/embedding-recovery-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "postgres-direct",
+ "executed": 155,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "pgbouncer",
+ "executed": 44,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-embedding-backfill-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "postgres-direct",
+ "executed": 44,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-vector-repair-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "pgbouncer",
+ "executed": 18,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-vector-repair-parity.test.ts",
+ "lane": "backend-matrix",
+ "arm": "postgres-direct",
+ "executed": 18,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/fact-withdrawal-scope-postgres.test.ts",
+ "lane": "e2e",
+ "arm": "",
+ "executed": 1,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/legacy-fact-extraction-dedup-postgres.test.ts",
+ "lane": "e2e",
+ "arm": "",
+ "executed": 1,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/loops-close-fact-postgres.test.ts",
+ "lane": "e2e",
+ "arm": "",
+ "executed": 10,
+ "failed": 0,
+ "skipped": 0
+ },
+ {
+ "file": "test/e2e/mechanical.test.ts",
+ "lane": "tier1",
+ "arm": "",
+ "executed": 77,
+ "failed": 0,
+ "skipped": 0
+ }
+ ],
+ "failures": []
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/commit-pulls.json b/test/fixtures/nightly-watch/master-red/commit-pulls.json
new file mode 100644
index 0000000000..24b6139998
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/commit-pulls.json
@@ -0,0 +1,38 @@
+{
+ "b6fef31e0815010b95f9a57490b3c8cbcf03fd76": [
+ {
+ "number": 6067,
+ "merged_at": "2026-10-05T16:47:39Z",
+ "base": {
+ "ref": "master"
+ }
+ }
+ ],
+ "f607c2eec3ad16714c0dc9f9fe44f5ab77482cdc": [
+ {
+ "number": 6067,
+ "merged_at": "2026-10-05T16:47:39Z",
+ "base": {
+ "ref": "master"
+ }
+ }
+ ],
+ "65aeef84807223dad15c62096ec5d80e901d124d": [
+ {
+ "number": 6067,
+ "merged_at": "2026-10-05T16:47:39Z",
+ "base": {
+ "ref": "master"
+ }
+ }
+ ],
+ "df34c67af680052dbfb612a994e2d56aaee61cb8": [
+ {
+ "number": 6067,
+ "merged_at": "2026-10-05T16:47:39Z",
+ "base": {
+ "ref": "master"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json b/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json
new file mode 100644
index 0000000000..f9ef3f5c09
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json
@@ -0,0 +1,18 @@
+{
+ "status": "ahead",
+ "total_commits": 4,
+ "commits": [
+ {
+ "sha": "b6fef31e0815010b95f9a57490b3c8cbcf03fd76"
+ },
+ {
+ "sha": "f607c2eec3ad16714c0dc9f9fe44f5ab77482cdc"
+ },
+ {
+ "sha": "65aeef84807223dad15c62096ec5d80e901d124d"
+ },
+ {
+ "sha": "df34c67af680052dbfb612a994e2d56aaee61cb8"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37343551740.json b/test/fixtures/nightly-watch/master-red/jobs-37343551740.json
new file mode 100644
index 0000000000..d496b199f3
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/jobs-37343551740.json
@@ -0,0 +1,485 @@
+{
+"total_count": 78,
+"jobs": [
+{
+"id": 111876366848,
+"name": "dependency-audit",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366851,
+"name": "brainbench",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366872,
+"name": "admin-browser",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366878,
+"name": "test (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366894,
+"name": "slow-brainbench-e2e",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366899,
+"name": "verify",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366912,
+"name": "shared-skills-compatibility",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366927,
+"name": "serial-tests (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366960,
+"name": "gitleaks",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876366974,
+"name": "changes",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367008,
+"name": "serial-tests (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367033,
+"name": "serial-tests (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367042,
+"name": "slow-entity-resolve-perf",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367050,
+"name": "test (5)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367069,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367072,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367083,
+"name": "test (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367085,
+"name": "serial-tests (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367090,
+"name": "security-regressions (windows-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367101,
+"name": "security-regressions (ubuntu-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367136,
+"name": "security-regressions (macos-26, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367152,
+"name": "security-regressions (macos-26, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367155,
+"name": "security-regressions (windows-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367208,
+"name": "test (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367226,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.0",
+"conclusion": "failure",
+"steps": [
+{
+"number": 7,
+"name": "Require PostgreSQL arms of unit-lane suites",
+"conclusion": "failure"
+}
+]
+},
+{
+"id": 111876367254,
+"name": "security-regressions (ubuntu-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367268,
+"name": "test (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367271,
+"name": "test (7)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367301,
+"name": "test (6)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367311,
+"name": "test (8)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367317,
+"name": "persistence-validation / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367350,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367352,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367355,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367356,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367392,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367448,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367450,
+"name": "persistence-validation / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367454,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367483,
+"name": "persistence-validation / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367485,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367512,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367527,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367528,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367565,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367582,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367732,
+"name": "persistence-validation / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367867,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876367897,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587249,
+"name": "native-locks / OpenClaw 2026.9.4 native context-engine startup",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587299,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587304,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587413,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587420,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587421,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587456,
+"name": "native-locks / linux-x64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587468,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587542,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587665,
+"name": "native-locks / linux-x64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587679,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587716,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587727,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587731,
+"name": "native-locks / win32-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587735,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587743,
+"name": "native-locks / darwin-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587761,
+"name": "native-locks / darwin-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587811,
+"name": "native-locks / win32-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587846,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587851,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587920,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587960,
+"name": "native-locks / win32-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876587989,
+"name": "native-locks / win32-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876588020,
+"name": "native-locks / darwin-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111876588250,
+"name": "native-locks / darwin-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111880419143,
+"name": "Native-only result (full CI not run)",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111881647178,
+"name": "coverage-report",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111881647354,
+"name": "executed-receipts",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111882475890,
+"name": "test-status",
+"conclusion": "failure",
+"steps": [
+{
+"number": 3,
+"name": "Aggregate result",
+"conclusion": "failure"
+}
+]
+}
+]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37351182593.json b/test/fixtures/nightly-watch/master-red/jobs-37351182593.json
new file mode 100644
index 0000000000..030a41a3d9
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/jobs-37351182593.json
@@ -0,0 +1,143 @@
+{
+"total_count": 21,
+"jobs": [
+{
+"id": 111902483748,
+"name": "prepare-e2e",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902483888,
+"name": "JSONB parity (#2339 regression guard)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902483904,
+"name": "Tier 1 backend matrix (direct + PgBouncer) 1/2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902484180,
+"name": "Tier 1 (Mechanical)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902484298,
+"name": "Tier 1 backend matrix (direct + PgBouncer) 2/2",
+"conclusion": "failure",
+"steps": [
+{
+"number": 9,
+"name": "Run backend matrix (direct Postgres, then PgBouncer)",
+"conclusion": "failure"
+}
+]
+},
+{
+"id": 111902484906,
+"name": "coverage-full-e2e",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111902485457,
+"name": "coverage-full-slow",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111902486720,
+"name": "coverage-full-report",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111902520670,
+"name": "coverage-full-unit",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111902545650,
+"name": "coverage-full-serial",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111902658547,
+"name": "Selected E2E (diff-relevant) 3",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658552,
+"name": "Selected E2E (diff-relevant) 5",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658576,
+"name": "Selected E2E (diff-relevant) 4",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658581,
+"name": "Selected E2E (diff-relevant) 2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658583,
+"name": "Selected E2E (diff-relevant) 6",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658614,
+"name": "Selected E2E (diff-relevant) 8",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658615,
+"name": "Selected E2E (diff-relevant) 7",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902658764,
+"name": "Selected E2E (diff-relevant) 1",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902982972,
+"name": "Tier 2 (LLM Skills)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111909670138,
+"name": "executed-receipts",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111909670183,
+"name": "e2e-status",
+"conclusion": "failure",
+"steps": [
+{
+"number": 3,
+"name": "Aggregate result",
+"conclusion": "failure"
+}
+]
+}
+]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37351183194.json b/test/fixtures/nightly-watch/master-red/jobs-37351183194.json
new file mode 100644
index 0000000000..2924105c3f
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/jobs-37351183194.json
@@ -0,0 +1,485 @@
+{
+"total_count": 78,
+"jobs": [
+{
+"id": 111902767415,
+"name": "slow-entity-resolve-perf",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767594,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767636,
+"name": "test (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767643,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767654,
+"name": "verify",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767686,
+"name": "security-regressions (macos-26, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767720,
+"name": "brainbench",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767726,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767734,
+"name": "gitleaks",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767737,
+"name": "test (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767738,
+"name": "changes",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767795,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767820,
+"name": "persistence-validation / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767829,
+"name": "security-regressions (windows-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767830,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767831,
+"name": "test (5)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767834,
+"name": "serial-tests (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767848,
+"name": "slow-brainbench-e2e",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767857,
+"name": "test (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767871,
+"name": "security-regressions (ubuntu-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767895,
+"name": "serial-tests (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767897,
+"name": "serial-tests (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767911,
+"name": "security-regressions (ubuntu-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767935,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767940,
+"name": "dependency-audit",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767943,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902767998,
+"name": "security-regressions (windows-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768014,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768035,
+"name": "test (7)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768040,
+"name": "test (6)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768044,
+"name": "admin-browser",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768046,
+"name": "test (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768047,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768048,
+"name": "persistence-validation / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768057,
+"name": "security-regressions (macos-26, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768060,
+"name": "test (8)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768089,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768106,
+"name": "persistence-validation / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768158,
+"name": "serial-tests (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768190,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768192,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768244,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768301,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768324,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768426,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768444,
+"name": "persistence-validation / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768498,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902768521,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.2",
+"conclusion": "failure",
+"steps": [
+{
+"number": 7,
+"name": "Require PostgreSQL arms of unit-lane suites",
+"conclusion": "failure"
+}
+]
+},
+{
+"id": 111902768903,
+"name": "shared-skills-compatibility",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862426,
+"name": "native-locks / OpenClaw 2026.9.4 native context-engine startup",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862458,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862500,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862544,
+"name": "native-locks / linux-x64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862581,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862585,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862593,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862602,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862624,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862628,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862680,
+"name": "native-locks / linux-x64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862720,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902862908,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863031,
+"name": "native-locks / darwin-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863041,
+"name": "native-locks / win32-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863051,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863067,
+"name": "native-locks / darwin-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863076,
+"name": "native-locks / darwin-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863084,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863116,
+"name": "native-locks / win32-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863117,
+"name": "native-locks / win32-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863125,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863138,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863189,
+"name": "native-locks / win32-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111902863194,
+"name": "native-locks / darwin-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111906497341,
+"name": "Native-only result (full CI not run)",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111908599510,
+"name": "executed-receipts",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111908599512,
+"name": "coverage-report",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111909257450,
+"name": "test-status",
+"conclusion": "failure",
+"steps": [
+{
+"number": 3,
+"name": "Aggregate result",
+"conclusion": "failure"
+}
+]
+}
+]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37354832141.json b/test/fixtures/nightly-watch/master-red/jobs-37354832141.json
new file mode 100644
index 0000000000..861a856c57
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/jobs-37354832141.json
@@ -0,0 +1,131 @@
+{
+"total_count": 21,
+"jobs": [
+{
+"id": 111914482094,
+"name": "JSONB parity (#2339 regression guard)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914482103,
+"name": "Tier 1 backend matrix (direct + PgBouncer) 2/2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914482160,
+"name": "Tier 1 backend matrix (direct + PgBouncer) 1/2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914482263,
+"name": "Tier 1 (Mechanical)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914482719,
+"name": "prepare-e2e",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483688,
+"name": "coverage-full-slow",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111914484064,
+"name": "coverage-full-serial",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111914484112,
+"name": "coverage-full-e2e",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111914484435,
+"name": "coverage-full-report",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111914485257,
+"name": "coverage-full-unit",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111914650722,
+"name": "Selected E2E (diff-relevant) 2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650741,
+"name": "Selected E2E (diff-relevant) 5",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650770,
+"name": "Selected E2E (diff-relevant) 1",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650780,
+"name": "Selected E2E (diff-relevant) 3",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650803,
+"name": "Selected E2E (diff-relevant) 8",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650852,
+"name": "Selected E2E (diff-relevant) 4",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650969,
+"name": "Selected E2E (diff-relevant) 6",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914650995,
+"name": "Selected E2E (diff-relevant) 7",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914936918,
+"name": "Tier 2 (LLM Skills)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111922042682,
+"name": "e2e-status",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111922043400,
+"name": "executed-receipts",
+"conclusion": "success",
+"steps": []
+}
+]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37354832822.json b/test/fixtures/nightly-watch/master-red/jobs-37354832822.json
new file mode 100644
index 0000000000..a1312fb0d6
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/jobs-37354832822.json
@@ -0,0 +1,485 @@
+{
+"total_count": 78,
+"jobs": [
+{
+"id": 111914483571,
+"name": "changes",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483861,
+"name": "slow-brainbench-e2e",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483942,
+"name": "brainbench",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483963,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483978,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483981,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914483987,
+"name": "serial-tests (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484013,
+"name": "serial-tests (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484017,
+"name": "slow-entity-resolve-perf",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484037,
+"name": "verify",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484063,
+"name": "serial-tests (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484073,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484123,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484156,
+"name": "gitleaks",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484179,
+"name": "test (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484195,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.0",
+"conclusion": "failure",
+"steps": [
+{
+"number": 7,
+"name": "Require PostgreSQL arms of unit-lane suites",
+"conclusion": "failure"
+}
+]
+},
+{
+"id": 111914484201,
+"name": "admin-browser",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484210,
+"name": "dependency-audit",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484211,
+"name": "test (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484218,
+"name": "test (5)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484244,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484288,
+"name": "shared-skills-compatibility",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484306,
+"name": "serial-tests (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484320,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484338,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484357,
+"name": "test (6)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484384,
+"name": "persistence-validation / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484440,
+"name": "persistence-validation / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484445,
+"name": "security-regressions (ubuntu-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484467,
+"name": "test (8)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484469,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484480,
+"name": "test (7)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484482,
+"name": "persistence-validation / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484503,
+"name": "security-regressions (macos-26, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484522,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484545,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484555,
+"name": "security-regressions (macos-26, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484557,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484567,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484571,
+"name": "test (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484578,
+"name": "security-regressions (windows-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484579,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484580,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484590,
+"name": "security-regressions (windows-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484605,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484645,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484663,
+"name": "security-regressions (ubuntu-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914484724,
+"name": "persistence-validation / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914485413,
+"name": "test (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666079,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666083,
+"name": "native-locks / OpenClaw 2026.9.4 native context-engine startup",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666087,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666106,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666117,
+"name": "native-locks / linux-x64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666123,
+"name": "native-locks / linux-x64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666133,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666135,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666142,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666152,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666165,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666209,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666301,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666355,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666380,
+"name": "native-locks / win32-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666383,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666392,
+"name": "native-locks / win32-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666400,
+"name": "native-locks / darwin-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666436,
+"name": "native-locks / win32-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666449,
+"name": "native-locks / darwin-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666475,
+"name": "native-locks / win32-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666507,
+"name": "native-locks / darwin-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666517,
+"name": "native-locks / darwin-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666675,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111914666789,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111918327520,
+"name": "Native-only result (full CI not run)",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111920042853,
+"name": "coverage-report",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111920042989,
+"name": "executed-receipts",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111921205893,
+"name": "test-status",
+"conclusion": "failure",
+"steps": [
+{
+"number": 3,
+"name": "Aggregate result",
+"conclusion": "failure"
+}
+]
+}
+]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37358088371.json b/test/fixtures/nightly-watch/master-red/jobs-37358088371.json
new file mode 100644
index 0000000000..c186fb5d22
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/jobs-37358088371.json
@@ -0,0 +1,473 @@
+{
+"total_count": 78,
+"jobs": [
+{
+"id": 111925509010,
+"name": "changes",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509334,
+"name": "dependency-audit",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509388,
+"name": "security-regressions (ubuntu-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509422,
+"name": "shared-skills-compatibility",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509432,
+"name": "gitleaks",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509445,
+"name": "test (6)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509498,
+"name": "security-regressions (windows-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509516,
+"name": "verify",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509517,
+"name": "security-regressions (ubuntu-latest, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509558,
+"name": "test (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509591,
+"name": "slow-brainbench-e2e",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509600,
+"name": "security-regressions (windows-latest, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509612,
+"name": "test (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509638,
+"name": "serial-tests (3)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509699,
+"name": "security-regressions (macos-26, 1.4.2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509700,
+"name": "serial-tests (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509734,
+"name": "test (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509747,
+"name": "test (8)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509751,
+"name": "serial-tests (1)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509758,
+"name": "test (7)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509769,
+"name": "security-regressions (macos-26, 1.4.0)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509786,
+"name": "test (4)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509816,
+"name": "slow-entity-resolve-perf",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509823,
+"name": "brainbench",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509906,
+"name": "admin-browser",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925509994,
+"name": "serial-tests (2)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510112,
+"name": "test (5)",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510307,
+"name": "persistence-validation / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510337,
+"name": "persistence-validation / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510410,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510420,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510465,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510494,
+"name": "persistence-validation / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510495,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510511,
+"name": "persistence-validation / Crash robot / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510519,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510534,
+"name": "persistence-validation / Read latency / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510550,
+"name": "persistence-validation / Read latency / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510571,
+"name": "persistence-validation / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510589,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510592,
+"name": "persistence-validation / PgBouncer, RLS and pool capacity / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510623,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510641,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510651,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510669,
+"name": "persistence-validation / Reconciliation crashes / pglite / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510721,
+"name": "persistence-validation / Crash robot / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510753,
+"name": "persistence-validation / Reconciliation crashes / postgres / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510879,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 1/2 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925510909,
+"name": "persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721186,
+"name": "native-locks / OpenClaw 2026.9.4 native context-engine startup",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721304,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721319,
+"name": "native-locks / linux-x64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721375,
+"name": "native-locks / linux-x64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721430,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721477,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721500,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721505,
+"name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721521,
+"name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721550,
+"name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721712,
+"name": "native-locks / linux-arm64-musl / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721734,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721786,
+"name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721989,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925721999,
+"name": "native-locks / linux-x64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722002,
+"name": "native-locks / win32-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722009,
+"name": "native-locks / win32-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722064,
+"name": "native-locks / darwin-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722074,
+"name": "native-locks / darwin-x64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722078,
+"name": "native-locks / win32-x64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722092,
+"name": "native-locks / darwin-arm64 / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722105,
+"name": "native-locks / darwin-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722158,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722159,
+"name": "native-locks / win32-arm64 / Bun 1.4.0",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111925722252,
+"name": "native-locks / linux-arm64-glibc / Bun 1.4.2",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111928881455,
+"name": "Native-only result (full CI not run)",
+"conclusion": "skipped",
+"steps": []
+},
+{
+"id": 111930298118,
+"name": "coverage-report",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111930298141,
+"name": "executed-receipts",
+"conclusion": "success",
+"steps": []
+},
+{
+"id": 111931838782,
+"name": "test-status",
+"conclusion": "success",
+"steps": []
+}
+]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/runs-e2e-push.json b/test/fixtures/nightly-watch/master-red/runs-e2e-push.json
new file mode 100644
index 0000000000..9fa46ef80a
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/runs-e2e-push.json
@@ -0,0 +1,173 @@
+{
+ "total_count": 8,
+ "workflow_runs": [
+ {
+ "id": 37358088065,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8502,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "4022fd7c5587448390dfeb83458fb8c0bfd21702",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37358088065",
+ "created_at": "2026-10-05T18:43:24Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37354832141,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8493,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "67c4ff27bd0a5a8a02ccb66cd663d3aa1daf9969",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37354832141",
+ "created_at": "2026-10-05T18:17:28Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37351182593,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "failure",
+ "run_number": 8486,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "17c5765ba425a724ba92c6563c3b81562c83025e",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37351182593",
+ "created_at": "2026-10-05T17:48:27Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37349359638,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "cancelled",
+ "run_number": 8481,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "c9ba778235fb2da921acd22dc3f92527f5072258",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37349359638",
+ "created_at": "2026-10-05T17:33:51Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37343551181,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8470,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "df34c67af680052dbfb612a994e2d56aaee61cb8",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37343551181",
+ "created_at": "2026-10-05T16:47:43Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37341267230,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8465,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "cab092f5cd7ec14153155fc85061927d57649668",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37341267230",
+ "created_at": "2026-10-05T16:29:46Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37322618654,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8441,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "8c9a8e9a480c388cf7a87dc0c48dd0d56e6c4bb3",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37322618654",
+ "created_at": "2026-10-05T14:10:49Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37295204829,
+ "name": "E2E Tests",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8427,
+ "run_attempt": 1,
+ "path": ".github/workflows/e2e.yml",
+ "workflow_id": 258366165,
+ "head_branch": "master",
+ "head_sha": "2142119298dd7fc7200245f155e93fe8b99e24b5",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37295204829",
+ "created_at": "2026-10-05T10:13:36Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/test/fixtures/nightly-watch/master-red/runs-test-push.json b/test/fixtures/nightly-watch/master-red/runs-test-push.json
new file mode 100644
index 0000000000..8ed19581be
--- /dev/null
+++ b/test/fixtures/nightly-watch/master-red/runs-test-push.json
@@ -0,0 +1,173 @@
+{
+ "total_count": 8,
+ "workflow_runs": [
+ {
+ "id": 37358088371,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8352,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "4022fd7c5587448390dfeb83458fb8c0bfd21702",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37358088371",
+ "created_at": "2026-10-05T18:43:24Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37354832822,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "failure",
+ "run_number": 8343,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "67c4ff27bd0a5a8a02ccb66cd663d3aa1daf9969",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37354832822",
+ "created_at": "2026-10-05T18:17:29Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37351183194,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "failure",
+ "run_number": 8336,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "17c5765ba425a724ba92c6563c3b81562c83025e",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37351183194",
+ "created_at": "2026-10-05T17:48:28Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37349360236,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "cancelled",
+ "run_number": 8331,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "c9ba778235fb2da921acd22dc3f92527f5072258",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37349360236",
+ "created_at": "2026-10-05T17:33:51Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37343551740,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "failure",
+ "run_number": 8320,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "df34c67af680052dbfb612a994e2d56aaee61cb8",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37343551740",
+ "created_at": "2026-10-05T16:47:43Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37341267966,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8315,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "cab092f5cd7ec14153155fc85061927d57649668",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37341267966",
+ "created_at": "2026-10-05T16:29:46Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37322619090,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8291,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "8c9a8e9a480c388cf7a87dc0c48dd0d56e6c4bb3",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37322619090",
+ "created_at": "2026-10-05T14:10:50Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ },
+ {
+ "id": 37295205094,
+ "name": "Test",
+ "event": "push",
+ "status": "completed",
+ "conclusion": "success",
+ "run_number": 8277,
+ "run_attempt": 1,
+ "path": ".github/workflows/test.yml",
+ "workflow_id": 258320022,
+ "head_branch": "master",
+ "head_sha": "2142119298dd7fc7200245f155e93fe8b99e24b5",
+ "html_url": "https://github.com/garrytan/gbrain/actions/runs/37295205094",
+ "created_at": "2026-10-05T10:13:36Z",
+ "head_repository": {
+ "full_name": "garrytan/gbrain"
+ },
+ "repository": {
+ "full_name": "garrytan/gbrain"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/test/scripts/nightly-issue.test.ts b/test/scripts/nightly-issue.test.ts
index 16ab37cdb1..a6cd790ad1 100644
--- a/test/scripts/nightly-issue.test.ts
+++ b/test/scripts/nightly-issue.test.ts
@@ -6,12 +6,17 @@
* validation and the "every scheduled workflow is watched" ratchet.
*/
import { describe, expect, test } from 'bun:test';
-import { readdirSync, readFileSync } from 'node:fs';
+import { existsSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { deflateRawSync } from 'node:zlib';
import { safeLoad } from 'js-yaml';
-import { inert, readJsonBlock, type GitHubClient, type Issue } from '../../scripts/lib/gh-issue.ts';
+import { loadReceiptDir } from '../../scripts/ci-executed-counts.ts';
+import { buildManifest, checkManifest, MANIFEST_ARTIFACT, MANIFEST_SCHEMA, type CiManifest } from '../../scripts/ci-manifest.ts';
+import { inert, jsonBlock, labelNames, readJsonBlock, readZipEntry, type GitHubClient, type Issue } from '../../scripts/lib/gh-issue.ts';
+import { FLAKE_MARKER, MR_MARKER, PUSH_ALLOWLIST, type FlakeRecord, type MasterRedState } from '../../scripts/lib/master-red.ts';
import {
- JSON_MARKER, parseKnownRed, validateKnownRed, watchRun, type IncidentRecord, type JobInfo, type KnownRow, type RunInfo,
+ JSON_MARKER, parseKnownRed, resolveTarget, routeRun, validateKnownRed, watch, watchRun, type IncidentRecord, type JobInfo, type KnownRow, type RunInfo,
} from '../../scripts/nightly-issue.ts';
const ROOT = join(import.meta.dir, '../..');
@@ -235,3 +240,524 @@ describe('nightly-watch coverage ratchet', () => {
expect(missing, `Add ${missing.join(', ')} to .github/workflows/nightly-watch.yml on.workflow_run.workflows`).toEqual([]);
});
});
+
+// ── master-red (push-to-master runs of Test and E2E Tests) ────────────────
+// Recorded API JSON from master runs on 2026-10-05: Test runs 8315 (green,
+// cab092f5cd) → 8320 red (persistence-history-fixture) → 8331 cancelled →
+// 8336 red (managed-lint) → 8343 red (pack-relation-direction-engine) → 8352
+// green; E2E Tests run 8486 red (fact-embedding-backfill-parity, a killed
+// shard makes its manifest incomplete) → 8493 green.
+
+const MR = join(FIX, 'master-red');
+const mr = <T>(name: string): T => JSON.parse(readFileSync(join(MR, name), 'utf8')) as T;
+const testRuns = mr<{ workflow_runs: RunInfo[] }>('runs-test-push.json').workflow_runs;
+const e2eRuns = mr<{ workflow_runs: RunInfo[] }>('runs-e2e-push.json').workflow_runs;
+const byNumber = (runs: RunInfo[], n: number) => runs.find(r => r.run_number === n)!;
+const T = { g8315: byNumber(testRuns, 8315), r8320: byNumber(testRuns, 8320), c8331: byNumber(testRuns, 8331), r8336: byNumber(testRuns, 8336), r8343: byNumber(testRuns, 8343), g8352: byNumber(testRuns, 8352) };
+const E = { g8470: byNumber(e2eRuns, 8470), r8486: byNumber(e2eRuns, 8486), g8493: byNumber(e2eRuns, 8493) };
+
+/** A stored-method zip (or deflated), enough for readZipEntry. */
+function zipOf(name: string, content: string, deflate = true): Uint8Array {
+ const data = Buffer.from(content);
+ const body = deflate ? deflateRawSync(data) : data;
+ const file = Buffer.from(name);
+ const local = Buffer.alloc(30);
+ local.writeUInt32LE(0x04034b50, 0); local.writeUInt16LE(deflate ? 8 : 0, 8); local.writeUInt32LE(body.length, 18); local.writeUInt32LE(data.length, 22); local.writeUInt16LE(file.length, 26);
+ const central = Buffer.alloc(46);
+ central.writeUInt32LE(0x02014b50, 0); central.writeUInt16LE(deflate ? 8 : 0, 10); central.writeUInt32LE(body.length, 20); central.writeUInt32LE(data.length, 24); central.writeUInt16LE(file.length, 28); central.writeUInt32LE(0, 42);
+ const end = Buffer.alloc(22);
+ end.writeUInt32LE(0x06054b50, 0); end.writeUInt16LE(1, 8); end.writeUInt16LE(1, 10); end.writeUInt32LE(46 + file.length, 12); end.writeUInt32LE(30 + file.length + body.length, 16);
+ return new Uint8Array(Buffer.concat([local, file, body, central, file, end]));
+}
+
+const completeManifest = (run: RunInfo, extra: Partial<CiManifest> = {}): CiManifest => ({
+ schema: MANIFEST_SCHEMA, workflow: run.name, event: run.event, sha: run.head_sha, run_id: run.id, run_attempt: run.run_attempt,
+ complete: true, problems: [], files: [{ file: 'test/unit-only.test.ts', lane: 'unit', arm: '', executed: 3, failed: 0, skipped: 0 }], failures: [], ...extra,
+});
+
+interface WorldIssue extends Issue { created: number; comments: string[] }
+class World {
+ runs = new Map<number, RunInfo>();
+ jobs = new Map<string, { jobs: JobInfo[]; total_count: number }>();
+ annotations = new Map<number, unknown[]>();
+ manifests = new Map<string, unknown>();
+ issues: WorldIssue[] = [];
+ timeline = new Map<number, unknown[]>();
+ compares = new Map<string, unknown>();
+ pulls = mr<Record<string, unknown[]>>('commit-pulls.json');
+ calls: Call[] = [];
+ clock = 1;
+ failGet?: (path: string) => boolean;
+ onGet?: (path: string, world: World) => void;
+
+ addRun(run: RunInfo, jobsFile?: string, manifest: unknown | null = completeManifest(run)) {
+ this.runs.set(run.id, run);
+ const jobs = jobsFile ? mr<{ jobs: JobInfo[]; total_count: number }>(jobsFile) : { total_count: 1, jobs: [{ id: run.id + 1, name: 'test (1)', conclusion: run.conclusion === 'success' ? 'success' : 'failure', steps: [] }] };
+ this.jobs.set(`${run.id}/${run.run_attempt}`, jobs);
+ for (const j of jobs.jobs) {
+ if (j.conclusion === 'failure' && !this.annotations.has(j.id)) {
+ try { this.annotations.set(j.id, mr<unknown[]>(`annotations-${j.id}.json`)); } catch { this.annotations.set(j.id, []); }
+ }
+ }
+ if (manifest !== null) this.manifests.set(`${run.id}/${run.run_attempt}`, manifest);
+ return this;
+ }
+ issue(n: number) { return this.issues.find(i => i.number === n)!; }
+ labeled(label: string) { return this.issues.filter(i => labelNames(i).includes(label)); }
+
+ client(): GitHubClient {
+ const world = this;
+ const touch = (i: WorldIssue) => { i.updated_at = `t${world.clock++}`; };
+ return {
+ async request<R>(method: 'GET' | 'POST' | 'PATCH', path: string, body?: unknown): Promise<R> {
+ world.calls.push({ method, path, body: body as Record<string, unknown> });
+ const b = body as Record<string, unknown>;
+ if (method === 'GET') {
+ world.onGet?.(path, world);
+ if (world.failGet?.(path)) throw Object.assign(new Error(`HTTP 502 on ${path}`), { status: 502 });
+ }
+ let m: RegExpExecArray | null;
+ if (method === 'POST' && path === 'repos/{repo}/labels') return {} as R;
+ if (method === 'POST' && path === 'repos/{repo}/issues') {
+ const issue: WorldIssue = { number: 100 + world.issues.length, title: String(b.title), state: 'open', body: String(b.body), labels: (b.labels as string[]).map(name => ({ name })), created: world.clock, comments: [] };
+ touch(issue);
+ world.issues.push(issue);
+ return issue as R;
+ }
+ if ((m = /^repos\/\{repo\}\/issues\/(\d+)\/comments$/.exec(path)) && method === 'POST') { const i = world.issue(Number(m[1])); i.comments.push(String(b.body)); touch(i); return {} as R; }
+ if ((m = /^repos\/\{repo\}\/issues\/(\d+)$/.exec(path))) {
+ const i = world.issue(Number(m[1]));
+ if (method === 'PATCH') { Object.assign(i, b.labels ? { ...b, labels: (b.labels as string[]).map(name => ({ name })) } : b); touch(i); }
+ return { ...i } as R;
+ }
+ if ((m = /^repos\/\{repo\}\/issues\/(\d+)\/timeline/.exec(path))) return (world.timeline.get(Number(m[1])) ?? []) as R;
+ if ((m = /^repos\/\{repo\}\/issues\?labels=([^&]+)&state=(\w+)/.exec(path))) {
+ const label = decodeURIComponent(m[1]!);
+ return world.issues.filter(i => labelNames(i).includes(label) && (m![2] === 'all' || i.state === m![2])).sort((x, y) => y.number - x.number).map(i => ({ ...i })) as R;
+ }
+ if ((m = /^repos\/\{repo\}\/actions\/runs\/(\d+)$/.exec(path))) { const r = world.runs.get(Number(m[1])); if (!r) throw Object.assign(new Error('404'), { status: 404 }); return r as R; }
+ if ((m = /^repos\/\{repo\}\/actions\/runs\/(\d+)\/attempts\/(\d+)\/jobs/.exec(path))) return (world.jobs.get(`${m[1]}/${m[2]}`) ?? { jobs: [], total_count: 0 }) as R;
+ if ((m = /^repos\/\{repo\}\/check-runs\/(\d+)\/annotations/.exec(path))) return (world.annotations.get(Number(m[1])) ?? []) as R;
+ if ((m = /^repos\/\{repo\}\/actions\/runs\/(\d+)\/artifacts\?name=ci-manifest/.exec(path))) {
+ const run = world.runs.get(Number(m[1]))!;
+ return { artifacts: world.manifests.has(`${run.id}/${run.run_attempt}`) ? [{ id: run.id * 10 + run.run_attempt, name: 'ci-manifest', expired: false }] : [] } as R;
+ }
+ if ((m = /^repos\/\{repo\}\/actions\/workflows\/(\d+)\/runs\?event=(\w+)/.exec(path))) {
+ const runs = [...world.runs.values()].filter(r => r.workflow_id === Number(m![1]) && r.event === m![2] && (m![2] !== 'push' || r.head_branch === 'master'))
+ .filter(r => !path.includes('status=success') || r.conclusion === 'success').sort((x, y) => y.run_number - x.run_number);
+ return { workflow_runs: runs } as R;
+ }
+ if ((m = /^repos\/\{repo\}\/compare\/(\w+)\.\.\.(\w+)$/.exec(path))) {
+ const key = `${m[1]}...${m[2]}`;
+ const known = [...world.compares.entries()].find(([k]) => { const [a, c] = k.split('...'); return m![1]!.startsWith(a!) && m![2]!.startsWith(c!); });
+ return (known?.[1] ?? { status: 'ahead', total_commits: 1, commits: [{ sha: m[2] }], key }) as R;
+ }
+ if ((m = /^repos\/\{repo\}\/commits\/(\w+)\/pulls$/.exec(path))) return (world.pulls[m[1]!] ?? []) as R;
+ throw new Error(`unexpected ${method} ${path}`);
+ },
+ async download(path: string): Promise<Uint8Array> {
+ world.calls.push({ method: 'DOWNLOAD', path });
+ const id = Number(/artifacts\/(\d+)\/zip/.exec(path)![1]);
+ const run = world.runs.get(Math.floor(id / 10))!;
+ return zipOf('ci-manifest.json', JSON.stringify(world.manifests.get(`${run.id}/${id % 10}`)));
+ },
+ };
+ }
+}
+
+const testWorld = (...runs: RunInfo[]) => {
+ const w = new World();
+ w.compares.set('cab092f5cd...df34c67af6', mr('compare-cab092f5cd...df34c67af6.json'));
+ for (const r of runs) w.addRun(r, existsSync(join(MR, `jobs-${r.id}.json`)) ? `jobs-${r.id}.json` : undefined);
+ return w;
+};
+const mrState = (issue: Issue) => readJsonBlock<MasterRedState>(issue.body, MR_MARKER)!;
+const go = (w: World, run: RunInfo, extra: { dryRun?: boolean; replayIssue?: number } = {}) =>
+ watch({ client: w.client(), repo: REPO, runId: run.id, rows: realRows, today: TODAY, dryRun: extra.dryRun ?? false, replayIssue: extra.replayIssue });
+const masterIssue = (w: World, workflow = 'Test') => w.labeled('master-red').filter(i => i.title === `Master red: ${workflow}`).sort((a, b) => b.number - a.number)[0];
+
+describe('master-red: push-to-master runs', () => {
+ test('a red push-to-master run opens one master-red issue with the suspect range, every failing file and its reproduce line', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ const r = await go(w, T.r8320);
+ expect(r.track).toBe('push');
+ expect(r.masterRed!.action).toBe('create');
+ const issue = masterIssue(w)!;
+ expect(labelNames(issue)).toEqual(['master-red']);
+ const state = mrState(issue);
+ expect(state.status).toBe('red');
+ expect(state.first_red).toMatchObject({ run_id: T.r8320.id, sha: T.r8320.head_sha });
+ expect(state.suspect).toMatchObject({ from_sha: T.g8315.head_sha, to_sha: T.r8320.head_sha, prs: [6067], complete: true });
+ expect(state.open_jobs.map(j => j.job)).toEqual(['persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.0']);
+ const body = issue.body!;
+ expect(body).toContain(`https://github.com/${REPO}/compare/${T.g8315.head_sha}...${T.r8320.head_sha}`);
+ expect(body).toContain('PRs merged in range: #6067');
+ expect(body).toContain('`bun run test:stress test/persistence-history-fixture.test.ts --iterations 10 --postgres`');
+ expect(body).toContain(`Fixes #${issue.number}`);
+ expect(body).toContain('known-red rows never apply to push runs');
+ expect(body).toContain('within 1 hour');
+ expect(body).not.toMatch(/nightly-known-red\.tsv` row \(at most/);
+ });
+
+ test('a run cancelled by a newer push changes no state', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ const before = JSON.stringify(w.issues);
+ w.addRun(T.c8331);
+ const r = await go(w, T.c8331);
+ expect(r.masterRed!.action).toBe('none');
+ expect(r.masterRed!.evaluated).toEqual([]);
+ expect(JSON.stringify(w.issues)).toBe(before);
+ });
+
+ test('a dropped pending watch is recovered: later watches evaluate every unevaluated run in order and close on green with flake follow-ups', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ for (const r of [T.c8331, T.r8336, T.r8343, T.g8352]) w.addRun(r, existsSync(join(MR, `jobs-${r.id}.json`)) ? `jobs-${r.id}.json` : undefined);
+ const r = await go(w, T.g8352);
+ expect(r.masterRed!.evaluated).toEqual([T.r8336.id, T.r8343.id, T.g8352.id]);
+ expect(r.masterRed!.action).toBe('close');
+ const issue = masterIssue(w)!;
+ expect(issue.state).toBe('closed');
+ const state = mrState(issue);
+ expect(state.evaluated).toMatchObject({ run_id: T.g8352.id, run_number: 8352 });
+ expect([...new Set(state.tests.map(t => t.file))].sort()).toEqual(['test/managed-lint.test.ts', 'test/pack-relation-direction-engine.test.ts', 'test/persistence-history-fixture.test.ts']);
+ expect(issue.comments.at(-1)).toContain('Green:');
+ expect(issue.comments.at(-1)).toContain('No merged repair PR is linked');
+ const flakes = w.labeled('flake');
+ expect(flakes.map(f => f.title).sort()).toEqual(['Flake: test/managed-lint.test.ts', 'Flake: test/pack-relation-direction-engine.test.ts', 'Flake: test/persistence-history-fixture.test.ts']);
+ const rec = readJsonBlock<FlakeRecord>(flakes[0]!.body, FLAKE_MARKER)!;
+ expect(rec).toMatchObject({ schema: 'flake/v1', master_red_issue: issue.number, owner: 'agent on release duty', platform: 'linux' });
+ expect(rec.reproduce).toMatch(/^bun run test:stress test\/[\w./-]+\.test\.ts --iterations 10 --postgres$/);
+ expect(rec.expires).toBe('2026-10-19');
+ expect(flakes[0]!.body).toContain(`master-red #${issue.number}`);
+ });
+
+ test('red then green with the red run\'s watch dropped still records the incident, its suspect range and flake follow-ups', async () => {
+ const w = testWorld(T.g8315, T.r8320, T.g8352);
+ const r = await go(w, T.g8352);
+ expect(r.masterRed!.action).toBe('record-closed');
+ const issue = masterIssue(w)!;
+ expect(issue.state).toBe('closed');
+ expect(mrState(issue).suspect!.prs).toEqual([6067]);
+ expect(issue.comments.at(-1)).toContain('started and ended between two watches');
+ expect(w.labeled('flake').map(f => f.title)).toEqual(['Flake: test/persistence-history-fixture.test.ts']);
+ });
+
+ test('an out-of-order red (completing after a newer run was evaluated) is ignored', async () => {
+ const w = testWorld(T.g8315, T.r8320, T.g8352);
+ await go(w, T.g8352);
+ const before = JSON.stringify(w.issues);
+ w.addRun(T.r8343, `jobs-${T.r8343.id}.json`);
+ const r = await go(w, T.r8343);
+ expect(r.masterRed!.action).toBe('none');
+ expect(JSON.stringify(w.issues)).toBe(before);
+ });
+
+ test('a failure and then a successful rerun of the same run: the newer attempt is evaluated and closes; the older attempt never reverses it', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ const rerun: RunInfo = { ...T.r8320, run_attempt: 2, conclusion: 'success' };
+ const greenJobs = mr<{ jobs: JobInfo[]; total_count: number }>(`jobs-${T.r8320.id}.json`);
+ w.runs.set(rerun.id, rerun);
+ w.jobs.set(`${rerun.id}/2`, { ...greenJobs, jobs: greenJobs.jobs.map(j => ({ ...j, conclusion: j.conclusion === 'failure' ? 'success' : j.conclusion })) });
+ w.manifests.set(`${rerun.id}/2`, completeManifest(rerun));
+ const r = await go(w, rerun);
+ expect(r.masterRed!.action).toBe('close');
+ expect(mrState(masterIssue(w)!).evaluated).toMatchObject({ run_number: 8320, run_attempt: 2 });
+ w.runs.set(rerun.id, T.r8320);
+ const again = await go(w, T.r8320);
+ expect(again.masterRed!.action).toBe('none');
+ expect(masterIssue(w)!.state).toBe('closed');
+ });
+
+ test('a green run where a previously failing job did not run keeps the issue open and names the manual-close step', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ const green: RunInfo = { ...T.g8352 };
+ w.addRun(green, `jobs-${green.id}.json`);
+ const jobs = w.jobs.get(`${green.id}/1`)!;
+ w.jobs.set(`${green.id}/1`, { ...jobs, jobs: jobs.jobs.filter(j => j.name !== 'persistence-validation / Unit-lane PostgreSQL arms 2/2 / Bun 1.4.0') });
+ const r = await go(w, green);
+ expect(r.masterRed!.action).toBe('update');
+ const issue = masterIssue(w)!;
+ expect(issue.state).toBe('open');
+ expect(issue.body).toContain('**Not run since:**');
+ expect(issue.body).toContain('close #');
+ expect(issue.comments.at(-1)).toContain('has not run and passed since it failed');
+ });
+
+ test('incomplete evidence (unreadable manifest or annotations) never closes and is reported, never read as zero failures', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ w.addRun(T.g8352, `jobs-${T.g8352.id}.json`, null);
+ const r = await go(w, T.g8352);
+ expect(r.masterRed!.action).toBe('update');
+ const issue = masterIssue(w)!;
+ expect(issue.state).toBe('open');
+ expect(issue.body).toContain('**Incomplete evidence**');
+ expect(issue.body).toContain("has no 'ci-manifest' artifact");
+
+ const red = testWorld(T.g8315, T.r8320);
+ red.failGet = p => p.includes('/annotations');
+ await go(red, T.r8320);
+ const opened = masterIssue(red)!;
+ expect(mrState(opened).evidence!.complete).toBe(false);
+ expect(opened.body).toContain('could not be read');
+ });
+
+ test('a corrupted JSON block is rebuilt from the actions API; an unreadable API never opens or closes on a guess', async () => {
+ const w = testWorld(T.g8315, T.r8320, T.r8336);
+ await go(w, T.r8320);
+ const issue = masterIssue(w)!;
+ issue.body = `${issue.body!.split('<!-- master-red:json -->')[0]}<!-- master-red:json -->\n\`\`\`json\n{"schema": "master-red/v1", "broken\n\`\`\``;
+ const r = await go(w, T.r8336);
+ expect(r.masterRed!.action).toBe('update');
+ expect(w.labeled('master-red')).toHaveLength(1);
+ const state = mrState(masterIssue(w)!);
+ expect(state.rebuilt).toContain('missing or malformed');
+ expect(state.first_red!.run_id).toBe(T.r8320.id);
+ expect(state.evaluated!.run_id).toBe(T.r8336.id);
+
+ const blind = testWorld(T.g8315, T.r8320);
+ await go(blind, T.r8320);
+ blind.addRun(T.g8352, `jobs-${T.g8352.id}.json`);
+ masterIssue(blind)!.body = 'no block';
+ blind.failGet = p => p.includes('/actions/workflows/');
+ const writes = () => blind.calls.filter(c => c.method !== 'GET' && c.method !== 'DOWNLOAD').length;
+ const before = writes();
+ await expect(go(blind, T.g8352)).rejects.toThrow('HTTP 502');
+ expect(writes()).toBe(before);
+ expect(masterIssue(blind)!.state).toBe('open');
+ });
+
+ test('more than three failures are all listed; a database URL in run text is redacted and never reaches a reproduce command', async () => {
+ const run: RunInfo = { ...T.r8320, id: 999001, run_number: 8321, head_sha: 'b'.repeat(40) };
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ const files = ['a', 'b', 'c', 'd', 'e'].map(x => `test/many-${x}.test.ts`);
+ w.runs.set(run.id, run);
+ w.jobs.set(`${run.id}/1`, { total_count: 1, jobs: [{ id: 555, name: 'test (3)', conclusion: 'failure', steps: [{ number: 4, name: 'Run test shard 3/8', conclusion: 'failure' }] }] });
+ w.annotations.set(555, files.map(f => ({ annotation_level: 'failure', path: f, title: 'error: boom', message: 'DATABASE_URL=postgresql://postgres:[email protected]:5432/gbrain_test bun test failed' })));
+ w.manifests.set(`${run.id}/1`, completeManifest(run));
+ await go(w, run);
+ const body = masterIssue(w)!.body!;
+ for (const f of files) expect(body).toContain(`\`bun run test:stress ${f} --iterations 10 --postgres\``);
+ expect(body).not.toContain('hunter2');
+ expect(body).toContain('postgresql:\u200b//‹redacted›@');
+ expect(body).not.toMatch(/test:stress[^`]*postgres(ql)?:/);
+ });
+
+ test('a push watch and a scheduled watch of the same workflow are both evaluated, each on its own issue', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ const scheduled: RunInfo = { ...T.r8320, id: 999002, event: 'schedule', run_number: 8322 };
+ w.addRun(scheduled, `jobs-${T.r8320.id}.json`);
+ const [push, nightly] = await Promise.all([go(w, T.r8320), go(w, scheduled)]);
+ expect(push.track).toBe('push');
+ expect(nightly.track).toBe('schedule');
+ expect(w.labeled('master-red').map(i => i.title)).toEqual(['Master red: Test']);
+ expect(w.labeled('nightly-red').map(i => i.title)).toEqual(['Nightly red: Test']);
+ });
+
+ test('a dispatch and an automatic watch of the same target resolve to one serialization key; a write that moved the issue makes the watch re-plan', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ w.addRun(T.r8336, `jobs-${T.r8336.id}.json`);
+ const auto = await resolveTarget(w.client(), REPO, T.r8336.id);
+ const dispatched = await resolveTarget(w.client(), REPO, T.r8336.id);
+ expect(auto).toEqual({ workflow_id: T.r8336.workflow_id, track: 'push' });
+ expect(dispatched).toEqual(auto);
+ expect(await resolveTarget(w.client(), REPO, T.r8336.id, undefined)).toEqual(auto);
+
+ w.runs.delete(T.r8336.id);
+ await go(w, T.r8320);
+ w.addRun(T.r8336, `jobs-${T.r8336.id}.json`);
+ const issue = masterIssue(w)!;
+ let interfered = false;
+ w.onGet = (path, world) => {
+ if (!interfered && path === `repos/{repo}/issues/${issue.number}`) {
+ interfered = true;
+ const i = world.issue(issue.number);
+ i.updated_at = `t${world.clock++}`;
+ }
+ };
+ const r = await go(w, T.r8336);
+ expect(interfered).toBe(true);
+ const plans = w.calls.filter(c => c.path.startsWith('repos/{repo}/issues?labels=master-red')).length;
+ expect(plans).toBeGreaterThanOrEqual(3);
+ expect(r.masterRed!.action).toBe('update');
+ expect(mrState(masterIssue(w)!).evaluated!.run_id).toBe(T.r8336.id);
+ expect(w.labeled('master-red')).toHaveLength(1);
+
+ const both = testWorld(T.g8315, T.r8320);
+ await Promise.all([go(both, T.r8320), go(both, T.r8320)]);
+ const open = both.issues.filter(i => i.title === 'Master red: Test' && i.state === 'open');
+ expect(open).toHaveLength(1);
+ expect(both.labeled('master-red')).toHaveLength(1);
+ for (const twin of both.issues.filter(i => i.title === 'Master red: Test' && i.state === 'closed')) expect(twin.body).toContain(`Duplicate of #${open[0]!.number}`);
+ });
+
+ test('E2E Tests closes only when every previously failing test file was among the files a run executed and passed', async () => {
+ const w = new World();
+ w.addRun(E.g8470).addRun(E.r8486, `jobs-${E.r8486.id}.json`, mr('ci-manifest-37351182593.json'));
+ await go(w, E.r8486);
+ const issue = masterIssue(w, 'E2E Tests')!;
+ const opened = mrState(issue);
+ expect(opened.open_files).toContain('test/e2e/fact-embedding-backfill-parity.test.ts');
+ expect(opened.tests.filter(t => t.file === 'test/e2e/fact-embedding-backfill-parity.test.ts')).toHaveLength(17);
+ expect(opened.evidence!.complete).toBe(false);
+
+ const skippedSelection = { ...mr<CiManifest>('ci-manifest-37354832141.json') };
+ skippedSelection.files = skippedSelection.files.filter(f => !f.file.includes('fact-embedding-backfill'));
+ w.addRun(E.g8493, `jobs-${E.g8493.id}.json`, skippedSelection);
+ const kept = await go(w, E.g8493);
+ expect(kept.masterRed!.action).toBe('update');
+ expect(masterIssue(w, 'E2E Tests')!.body).toContain('**Not run since:**');
+ expect(masterIssue(w, 'E2E Tests')!.body).toContain('replay_issue=');
+
+ const scheduled: RunInfo = { ...E.g8493, id: 999003, event: 'schedule', run_number: 8499 };
+ w.addRun(scheduled, `jobs-${E.g8493.id}.json`, { ...mr<CiManifest>('ci-manifest-37354832141.json'), run_id: scheduled.id, event: 'schedule' });
+ const nightly = await go(w, scheduled);
+ expect(nightly.masterRed!.action).toBe('close');
+ expect(masterIssue(w, 'E2E Tests')!.state).toBe('closed');
+ expect(masterIssue(w, 'E2E Tests')!.comments.join('\n')).toContain('scheduled full run');
+ });
+
+ test('an issue-bound E2E replay dispatch on master clears the files it passed; the green push run with the full selection closes directly', async () => {
+ const w = new World();
+ w.addRun(E.g8470).addRun(E.r8486, `jobs-${E.r8486.id}.json`, mr('ci-manifest-37351182593.json'));
+ await go(w, E.r8486);
+ const n = masterIssue(w, 'E2E Tests')!.number;
+ const replay: RunInfo = { ...E.g8493, id: 999004, event: 'workflow_dispatch', run_number: 8500 };
+ w.addRun(replay, `jobs-${E.g8493.id}.json`, { ...mr<CiManifest>('ci-manifest-37354832141.json'), run_id: replay.id, event: 'workflow_dispatch' });
+ const r = await go(w, replay, { replayIssue: n });
+ expect(r.track).toBe('replay');
+ expect(r.masterRed!.action).toBe('close');
+ expect(w.issue(n).comments.at(-1)).toContain('issue-bound replay');
+
+ const direct = new World();
+ direct.addRun(E.g8470).addRun(E.r8486, `jobs-${E.r8486.id}.json`, mr('ci-manifest-37351182593.json'));
+ await go(direct, E.r8486);
+ direct.addRun(E.g8493, `jobs-${E.g8493.id}.json`, mr('ci-manifest-37354832141.json'));
+ expect((await go(direct, E.g8493)).masterRed!.action).toBe('close');
+ });
+
+ test('a merged repair PR linked to the issue means no flake follow-up', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ const n = masterIssue(w)!.number;
+ w.timeline.set(n, [{ event: 'cross-referenced', created_at: '2026-10-05T17:00:00Z', source: { issue: { number: 6079, state: 'closed', pull_request: { merged_at: '2026-10-05T17:30:00Z' } } } }]);
+ w.addRun(T.g8352, `jobs-${T.g8352.id}.json`);
+ await go(w, T.g8352);
+ expect(w.issue(n).state).toBe('closed');
+ expect(w.issue(n).comments.at(-1)).toContain('Repair PR(s) #6079 merged; no flake follow-up.');
+ expect(w.labeled('flake')).toHaveLength(0);
+ });
+
+ test('a flake outside the Postgres arms closes after its repair PR merged and a later complete run passed its file and arm', async () => {
+ const w = testWorld(T.g8352);
+ const rec: FlakeRecord = {
+ schema: 'flake/v1', workflow: 'Test', file: 'test/unit-only.test.ts', test: 'ordering', lane: 'unit', arm: '', platform: 'linux', job: 'test (2)', signature: 'expected 7',
+ first_seen: { run_id: 1, run_number: 1, run_attempt: 1, sha: 'c'.repeat(40) }, master_red_issue: 1, owner: 'agent on release duty', opened: TODAY, expires: '2026-10-19', reproduce: null,
+ };
+ const flake: WorldIssue = { number: 50, title: 'Flake: test/unit-only.test.ts › ordering', state: 'open', labels: [{ name: 'flake' }], body: jsonBlock(FLAKE_MARKER, rec), created: 0, comments: [] };
+ w.issues.push(flake);
+ const unmerged = await go(w, T.g8352);
+ expect(unmerged.flakesClosed).toEqual([]);
+ w.timeline.set(50, [{ event: 'cross-referenced', created_at: '2026-10-05T12:00:00Z', source: { issue: { number: 6090, state: 'closed', pull_request: { merged_at: '2026-10-05T12:30:00Z' } } } }]);
+ const closed = await go(w, T.g8352);
+ expect(closed.flakesClosed).toEqual([50]);
+ expect(w.issue(50).state).toBe('closed');
+ expect(w.issue(50).comments.at(-1)).toContain('Repair PR #6090 merged');
+ });
+});
+
+describe('nightly-watch routing and guard', () => {
+ const pr = { ...load<RunInfo>('run-heavy.json'), event: 'pull_request', head_branch: 'capy/x' };
+ const refuse = async (run: RunInfo, msg: string, replayIssue?: number) => {
+ const w = new World();
+ w.runs.set(run.id, run);
+ await expect(watch({ client: w.client(), repo: REPO, runId: run.id, rows: realRows, today: TODAY, dryRun: false, replayIssue })).rejects.toThrow(msg);
+ expect(w.calls.filter(c => c.method !== 'GET')).toEqual([]);
+ };
+ test('schedule accepted; push-to-master of Test and E2E Tests accepted, including by dispatch with a push-to-master run id', () => {
+ expect(routeRun(load<RunInfo>('run-heavy.json'), REPO)).toEqual({ track: 'schedule' });
+ expect(routeRun(T.r8320, REPO)).toEqual({ track: 'push' });
+ expect(routeRun(E.r8486, REPO)).toEqual({ track: 'push' });
+ });
+ test('PR run refused', () => refuse(pr, 'pull-request and other runs are refused'));
+ test('fork run refused', () => refuse({ ...T.r8320, head_repository: { full_name: 'someone/fork' } }, 'fork'));
+ test('push to another branch refused', () => refuse({ ...T.r8320, head_branch: 'capy/topic' }, "push to 'capy/topic'"));
+ test('push run of a non-allowlisted workflow refused', () => refuse({ ...T.r8320, name: 'Heavy Tests', path: '.github/workflows/heavy-tests.yml' }, 'which master-red does not watch'));
+ test('a replay must be an E2E Tests dispatch on master', () => refuse({ ...T.r8320, event: 'workflow_dispatch' }, 'issue-bound replay must be an E2E Tests dispatch', 7));
+
+ const yaml = (f: string) => safeLoad(readFileSync(join(ROOT, '.github/workflows', f), 'utf8')) as Record<string, any>;
+ test('nightly-watch.yml: master-only workflow_run, guard for schedule + allowlisted push-to-master from this repo, one queue per repo + workflow + track', () => {
+ const w = yaml('nightly-watch.yml');
+ expect(w.on.workflow_run.branches).toEqual(['master']);
+ expect(w.on.workflow_dispatch.inputs.run_id.description).toBe('Scheduled or push-to-master run id to evaluate');
+ expect(w.on.workflow_dispatch.inputs.replay_issue).toBeDefined();
+ const guard: string = w.jobs.resolve.if;
+ for (const part of ["github.event_name == 'workflow_dispatch'", 'head_repository.full_name == github.repository', "workflow_run.event == 'schedule'", "workflow_run.event == 'push'", "head_branch == 'master'", '["Test","E2E Tests"]']) expect(guard).toContain(part);
+ expect(Object.keys(PUSH_ALLOWLIST).sort()).toEqual(['E2E Tests', 'Test']);
+ expect(w.concurrency).toBeUndefined();
+ expect(w.jobs.watch.needs).toBe('resolve');
+ expect(w.jobs.watch.concurrency).toEqual({ group: 'nightly-watch-${{ github.repository }}-${{ needs.resolve.outputs.workflow_id }}-${{ needs.resolve.outputs.track }}', 'cancel-in-progress': false });
+ expect(w.jobs.watch.permissions).toEqual({ issues: 'write', actions: 'read', checks: 'read', contents: 'read', 'pull-requests': 'read' });
+ for (const job of Object.values(w.jobs) as Array<{ steps: Array<{ run?: string }> }>) for (const s of job.steps) expect(s.run ?? '').not.toContain('${{');
+ });
+ test('test.yml and e2e.yml upload the versioned ci-manifest from executed-receipts', () => {
+ for (const f of ['test.yml', 'e2e.yml']) {
+ const steps = yaml(f).jobs['executed-receipts'].steps as Array<{ run?: string; with?: { name?: string } }>;
+ expect(steps.some(s => s.run?.includes('bun scripts/ci-manifest.ts --receipts-dir'))).toBe(true);
+ expect(steps.some(s => s.with?.name === MANIFEST_ARTIFACT)).toBe(true);
+ }
+ });
+ test('a known-red row for the race-hunt job is refused', () => {
+ const row = ['Test', 'race-hunt (1)', 'x', 'known-red', 'Set the ANTHROPIC_API_KEY and OPENAI_API_KEY repo secrets', '2026-10-25'].join('\t');
+ expect(validateKnownRed(`# h\n${row}`, readFileSync(join(ROOT, 'TODOS.md'), 'utf8')).join('\n')).toContain('race-hunt failures cannot be known-red');
+ });
+});
+
+describe('ci-manifest', () => {
+ test('a manifest is bound to its run: schema, SHA, run id and attempt mismatches are problems', () => {
+ const m = completeManifest(T.g8352);
+ const bind = { sha: T.g8352.head_sha, run_id: T.g8352.id, run_attempt: 1 };
+ expect(checkManifest(m, bind).manifest).toBeDefined();
+ expect(checkManifest({ ...m, schema: 'v0' }, bind).problem).toContain('schema');
+ expect(checkManifest({ ...m, sha: 'f'.repeat(40) }, bind).problem).toContain('describes run');
+ expect(checkManifest(m, { ...bind, run_attempt: 2 }).problem).toContain('re-run all jobs');
+ });
+ test('readZipEntry reads deflated and stored entries', () => {
+ expect(new TextDecoder().decode(readZipEntry(zipOf('ci-manifest.json', '{"a":1}'), 'ci-manifest.json'))).toBe('{"a":1}');
+ expect(new TextDecoder().decode(readZipEntry(zipOf('x.json', 'plain', false), 'x.json'))).toBe('plain');
+ expect(readZipEntry(zipOf('x.json', 'plain'), 'missing.json')).toBeUndefined();
+ });
+ test('buildManifest lists failing identities, counts executed files and flags missing receipts as incomplete', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'ci-manifest-'));
+ writeFileSync(join(dir, 'unit--s1--primary.receipt'), `version=1\nlane=unit\nkind=primary\nshard=1\nof=1\narm=\nsha=${'a'.repeat(40)}\nroot=\nrun_id=5\nrun_attempt=1\nstarted=1\nexit=1\n`);
+ writeFileSync(join(dir, 'unit--s1--primary.files'), 'test/a.test.ts\n');
+ writeFileSync(join(dir, 'unit--s1--primary.junit.xml'), '<?xml version="1.0"?><testsuites tests="2"><testsuite name="test/a.test.ts" file="test/a.test.ts" tests="2"><testcase name="ok" file="test/a.test.ts"/><testcase name="bad" file="test/a.test.ts"><failure message="x"/></testcase></testsuite></testsuites>');
+ const bind = { workflow: 'Test', event: 'push', sha: 'a'.repeat(40), run_id: 5, run_attempt: 1 };
+ const m = buildManifest(loadReceiptDir(dir), bind);
+ expect(m.complete).toBe(true);
+ expect(m.failures).toEqual([{ lane: 'unit', file: 'test/a.test.ts', test: 'bad', arm: '' }]);
+ expect(m.files).toEqual([{ file: 'test/a.test.ts', lane: 'unit', arm: '', executed: 2, failed: 1, skipped: 0 }]);
+ expect(buildManifest([], bind).complete).toBe(false);
+ });
+});
+
+describe('operator messages carry docs anchors that resolve', () => {
+ const slug = (h: string) => h.trim().toLowerCase().replace(/[^\w\- ]/g, '').replace(/ /g, '-');
+ const anchors = (doc: string) => new Set(readFileSync(join(ROOT, doc), 'utf8').split('\n').filter(l => /^#{1,6} /.test(l)).map(l => slug(l.replace(/^#+ /, ''))));
+ test('every docs/*.md#anchor named by the CI watchers exists', () => {
+ const files = ['scripts/nightly-issue.ts', 'scripts/lib/master-red.ts', 'scripts/lib/ci-run.ts', 'scripts/ci-manifest.ts', 'scripts/ci-health-report.ts', 'scripts/release-gate.ts', '.github/workflows/nightly-watch.yml', '.github/workflows/release.yml'];
+ const cache = new Map<string, Set<string>>();
+ const refs = files.flatMap(f => [...readFileSync(join(ROOT, f), 'utf8').matchAll(/(docs\/[\w./-]+\.md)#([\w-]+)/g)].map(m => [f, m[1]!, m[2]!] as const));
+ expect(refs.length).toBeGreaterThan(5);
+ const missing = refs.filter(([, doc, anchor]) => {
+ if (!cache.has(doc)) cache.set(doc, anchors(doc));
+ return !cache.get(doc)!.has(anchor);
+ });
+ expect(missing).toEqual([]);
+ });
+});