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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ jobs:
- name: Player-facing name check
run: bash scripts/ci/player_facing_names.sh

- name: Workflow policy
run: python3 scripts/ci/test_workflow_policy.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right job. gate checks out, runs this before Rust setup, does not skip it on a docs-only diff, and a failing unittest fails the step. python3 scripts/ci/test_workflow_policy.py -v exited 0 here (16 tests).

Nothing in test_workflow_policy.py reads ci.yml for this command. Deleting the step leaves the unittest green for anyone who runs the file, and the gate stops enforcing it. test_ci_gate_is_required_before_heavy_jobs already loads this workflow. Assert python3 scripts/ci/test_workflow_policy.py there.

The new event test is still a substring check. It stays green if the three event names remain in the file while the boolean around them changes. The expression on nightly-failure-issue.yml lines 40–46 is parenthesized correctly today.


- name: Rust CI setup
if: needs.changes.outputs.docs_only != 'true'
uses: ./.github/actions/rust-ci-setup
Expand Down
131 changes: 113 additions & 18 deletions .github/workflows/nightly-failure-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_run:
workflows:
- Comprehensive CI Pipeline
- Determinism Replay
- determinism-replay
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
- Performance Benchmarks
- Sanitizers
- Code Coverage
Expand All @@ -22,9 +22,11 @@ on:
- Allocation Measurement
types: [completed]

# One workflow_run webhook per upstream failure; key by that run id so the 13
# watched workflows never cancel each other's pending reports (BS-011 / #576).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: ${{ github.workflow }}-${{ github.event.workflow_run.id }}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
cancel-in-progress: false

permissions:
contents: read
Expand All @@ -37,8 +39,11 @@ jobs:
timeout-minutes: 10
if: >-
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
(github.event.workflow_run.event == 'schedule' ||
github.event.workflow_run.head_branch == 'main')
(github.event.workflow_run.head_branch == 'main' &&
(github.event.workflow_run.event == 'push' ||
github.event.workflow_run.event == 'workflow_dispatch')))
steps:
- name: Open or update the issue
uses: actions/github-script@v7
Expand Down Expand Up @@ -77,25 +82,97 @@ jobs:
}
}

const listParams = {
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
per_page: 100,
const listOpenIssues = async () => {
const listParams = {
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
per_page: 100,
};
if (labelReady) {
listParams.labels = "ci-nightly";
}
return github.paginate(github.rest.issues.listForRepo, listParams);
};
if (labelReady) {
listParams.labels = "ci-nightly";
}
const existing = await github.paginate(github.rest.issues.listForRepo, listParams);
const match = existing.find((issue) => issue.title === title);
if (match) {

const commentOnIssue = async (issueNumber) => {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: match.number,
issue_number: issueNumber,
body,
});
core.notice(`Updated issue #${match.number}`);
core.notice(`Updated issue #${issueNumber}`);
};

const REPORTER_MARKER =
"Opened by `.github/workflows/nightly-failure-issue.yml`";

const isReportableIssue = (issue) =>
issue.title === title && !issue.pull_request;

const pickKeeper = (issues) => {
const matches = issues.filter(isReportableIssue);
if (matches.length === 0) {
return undefined;
}
matches.sort((a, b) => a.number - b.number);
return matches[0];
};

const issueBodyMatches = async (issue) => {
if (issue.body && issue.body.includes(REPORTER_MARKER)) {
return true;
}
const full = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
});
return full.data.body.includes(REPORTER_MARKER);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking. issues.get returns body: null when the description was never set. An empty string is fine. null.includes throws.

This call sits after commentOnIssue(keeper.number), and only for a same-title row whose list body did not already contain the marker. A blank issue titled Nightly CI failure: <workflow> makes the reporter job red after the keeper comment is already stored. Rows later in open are then left open. The workflow's own issues always have a body, so this is the manually opened row.

(full.data.body || "").includes(REPORTER_MARKER) treats that row as not ours and does not close it.

};

const closeAsDuplicateOf = async (issueNumber, keeperNumber) => {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `Duplicate of #${keeperNumber}. Closing in favor of the canonical nightly issue.`,
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed",
state_reason: "not_planned",
});
};

const syncKeeper = async () => {
const open = await listOpenIssues();
const keeper = pickKeeper(open);
if (!keeper) {
return undefined;
}
await commentOnIssue(keeper.number);
for (const issue of open) {
if (!isReportableIssue(issue) || issue.number === keeper.number) {
continue;
}
if (!(await issueBodyMatches(issue))) {
continue;
}
await closeAsDuplicateOf(issue.number, keeper.number);
}
return keeper;
};

let keeper = await syncKeeper();
if (!keeper) {
keeper = await syncKeeper();
}
if (keeper) {
core.notice(`Updated issue #${keeper.number}`);
} else {
const created = await github.rest.issues.create({
owner: context.repo.owner,
Expand All @@ -104,5 +181,23 @@ jobs:
body,
labels: labelReady ? ["ci-nightly"] : [],
});
core.notice(`Opened issue #${created.data.number}`);
const open = await listOpenIssues();
const reportable = open.filter(isReportableIssue);
const older = reportable.find(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking. listForRepo defaults to sort=created, direction=desc, and paginate keeps that order. find returns the first lower number, which is the newest older row, not the minimum.

On [{number:100},{number:80},{number:50}], find(number < 100) returns 80. pickKeeper returns 50. This branch then closes only the issue this run just created and comments on 80. It does not call syncKeeper, so 80 stays open beside 50 until a later failure takes the keeper path at the top of the script. The close comment names the wrong issue.

The mutual-close case is fixed. A higher peer is not < created. Created 100 with a re-list that contains only 101 leaves older undefined, and this run does not close itself.

Select the lowest number with pickKeeper, and run the marker close loop against that keeper. Close created only when keeper.number < created.data.number. A lagging list then leaves a duplicate, which is the residual that does not drop the report.

(issue) => issue.number < created.data.number,
);
if (older) {
await closeAsDuplicateOf(created.data.number, older.number);
await commentOnIssue(older.number);
core.notice(
`Closed duplicate #${created.data.number}; kept #${older.number}`,
);
} else {
keeper = await syncKeeper();
if (keeper) {
core.notice(`Opened issue #${keeper.number}`);
} else {
core.notice(`Opened issue #${created.data.number}`);
}
}
}
67 changes: 67 additions & 0 deletions scripts/ci/test_workflow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import re
import unittest
from pathlib import Path

Expand All @@ -17,6 +18,40 @@ def workflow_texts() -> dict[str, str]:
return {path.name: path.read_text(encoding="utf-8") for path in sorted(WORKFLOWS.glob("*.yml"))}


def workflow_display_names() -> set[str]:
names: set[str] = set()
name_re = re.compile(r"^name:\s*(.+?)\s*$")
for text in workflow_texts().values():
for line in text.splitlines():
match = name_re.match(line)
if not match:
continue
value = match.group(1).strip()
if len(value) >= 2 and value[0] == value[-1] and value[0] in "\"'":
value = value[1:-1]
names.add(value)
break
return names


def nightly_failure_watched_workflows(text: str) -> list[str]:
watched: list[str] = []
in_list = False
for line in text.splitlines():
if re.match(r"^\s+workflows:\s*$", line):
in_list = True
continue
if not in_list:
continue
item = re.match(r"^\s+-\s+(.+)\s*$", line)
if item:
watched.append(item.group(1).strip())
continue
if line.strip():
break
return watched


def has_pull_request(text: str) -> bool:
# Quoted "on" (scorecard) and bare on: both count.
in_on = False
Expand Down Expand Up @@ -303,6 +338,38 @@ def test_detect_checks_out_merge_parents_only(self) -> None:
self.assertIn("--head HEAD", changes)
self.assertIn("reason=missing-merge-parent", changes)

def test_nightly_failure_issue_serializes_per_upstream_run(self) -> None:
text = (WORKFLOWS / "nightly-failure-issue.yml").read_text(encoding="utf-8")
self.assertIn(
"group: ${{ github.workflow }}-${{ github.event.workflow_run.id }}",
text,
)
self.assertIn("cancel-in-progress: false", text)
self.assertNotIn("group: ${{ github.workflow }}-${{ github.ref }}", text)

def test_nightly_failure_issue_watched_names_match_workflows(self) -> None:
text = (WORKFLOWS / "nightly-failure-issue.yml").read_text(encoding="utf-8")
watched = nightly_failure_watched_workflows(text)
known = workflow_display_names()
self.assertEqual(len(watched), 13)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
missing = [name for name in watched if name not in known]
self.assertEqual(missing, [])
self.assertIn("determinism-replay", watched)
self.assertNotIn("Determinism Replay", watched)

def test_nightly_failure_issue_job_skips_fork_and_pull_request_runs(self) -> None:
text = (WORKFLOWS / "nightly-failure-issue.yml").read_text(encoding="utf-8")
self.assertIn("head_repository.full_name == github.repository", text)
self.assertIn("github.event.workflow_run.event == 'schedule'", text)
self.assertIn("github.event.workflow_run.event == 'push'", text)
self.assertIn("github.event.workflow_run.event == 'workflow_dispatch'", text)
self.assertNotIn("github.event.workflow_run.event == 'pull_request'", text)
self.assertNotIn(
"github.event.workflow_run.event == 'schedule' ||\n"
" github.event.workflow_run.head_branch == 'main')",
text,
)

def test_allocation_measurement_is_a_real_gate_off_prs(self) -> None:
text = (WORKFLOWS / "allocation-measurement.yml").read_text(encoding="utf-8")
self.assertIn("schedule:", text)
Expand Down
Loading