Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(ci): harden nightly failure reporter guards and dedupe
Require same-repo head and schedule or main push/dispatch so fork and
pull_request workflow_run completions do not open nightly issues.

Always comment on the lowest-number open issue, close reporter duplicates,
and only close a just-created issue when a strictly older sibling exists.

Run test_workflow_policy.py in the CI gate and assert the job guard.
Rebased onto main (includes #599 Windows rate-limit flake fix).

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 30, 2026
commit 56e15d4afd350c5e9591e38b96277b96c52d4639
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
130 changes: 92 additions & 38 deletions .github/workflows/nightly-failure-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,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 @@ -102,46 +105,97 @@ jobs:
core.notice(`Updated issue #${issueNumber}`);
};

const findByTitle = (issues) => issues.find((issue) => issue.title === title);
const REPORTER_MARKER =
"Opened by `.github/workflows/nightly-failure-issue.yml`";

let match = findByTitle(await listOpenIssues());
if (match) {
await commentOnIssue(match.number);
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 {
match = findByTitle(await listOpenIssues());
if (match) {
await commentOnIssue(match.number);
} else {
const created = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: labelReady ? ["ci-nightly"] : [],
});
const sameTitle = (await listOpenIssues()).filter(
(issue) => issue.title === title,
const created = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: labelReady ? ["ci-nightly"] : [],
});
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}`,
);
sameTitle.sort((a, b) => a.number - b.number);
const keep = sameTitle[0] ?? created.data;
if (keep.number !== created.data.number) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: created.data.number,
body: `Duplicate of #${keep.number}. Closing in favor of the earlier open issue.`,
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: created.data.number,
state: "closed",
state_reason: "not_planned",
});
await commentOnIssue(keep.number);
core.notice(
`Closed duplicate #${created.data.number}; kept #${keep.number}`,
);
} else {
keeper = await syncKeeper();
if (keeper) {
core.notice(`Opened issue #${keeper.number}`);
} else {
core.notice(`Opened issue #${created.data.number}`);
}
Expand Down
13 changes: 13 additions & 0 deletions scripts/ci/test_workflow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ def test_nightly_failure_issue_watched_names_match_workflows(self) -> None:
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