Skip to content

[Dr. CI] Prefer a successful run when a workflow ran twice on the PR head - #9616

Merged
albanD merged 1 commit into
mainfrom
cc_drci_duplicate_runs
Nov 26, 2026
Merged

albanD merged 1 commit into
mainfrom
cc_drci_duplicate_runs

Conversation

@albanD

@albanD albanD commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Author Notes

Making the (rare) case where a single workflow running on a single hash work better. In particular, when you rerun the older run, it doesn't become the "newer" because it's ID doesn't change. And so reruning cannot clear a other workflow being cancelled or failed for flaky reason. Making it so that success > fail > most recent.

Agent Notes

reorganizeWorkflows keeps one run per workflow file (workflowUniqueId) on the PR head and drops every job of the other runs. It used to keep the run with the highest ID. A re-run keeps its run ID (only run_attempt changes), so re-running the older run never makes it win, and a newer cancelled or flakily failed run keeps blocking. Example: pytorch/pytorch#206339 got two Lint runs in the same second; concurrency cancelled the newer one (45427672193) while the older one (45427672059) passed every job, yet Dr. CI dropped the passing run and listed 4 cancelled jobs, keeping the PR from being promoted to "ready for review".

The run is now picked by rank, then by highest ID within a rank: success > anything else (failure, in progress, ...) > cancelled.

Runs on the same head commit Before After
older success, newer cancelled cancelled success
older success, newer failed failed success
older failed, newer success success success
older failed, newer cancelled cancelled failed
all cancelled / no success or cancellation highest ID highest ID

Behavior change vs #5038: the existing test "test new failed workflow overrides old succeeding workflow" asserted that a newer failed run beats an older successful run of the same workflow on the same commit. This PR deliberately reverses that: the successful run wins, and the test is flipped to "test old succeeding workflow overrides new failed workflow" (expects 0 failed jobs). Trade-off: if two events run the same workflow file with different job sets (e.g. label-gated jobs), an older green run can now hide a newer red one.

No SQL change: workflow rows from recent_pr_workflows_query already carry conclusion. Added table-driven reorganizeWorkflows tests (3 of the 4 fail on the old logic). npx jest --no-watchman on drci, drciStatus, drciAuth and crcrComment tests: 157/157 pass; prettier clean; tsc error count unchanged from main.

This PR was written by Claude Code on behalf of albanD.

…head

When the same workflow ran more than once on a PR's head commit, Dr. CI kept
only the run with the highest ID and dropped every job of the others. Re-runs
keep their run ID, so re-running the older run could never clear a newer run
that was cancelled or failed for a flaky reason. For example, two Lint runs
started in the same second on pytorch/pytorch#206339; concurrency cancelled the
newer one, the older one passed, and Dr. CI still reported the cancelled jobs.

Pick a successful run, else one that wasn't cancelled, else the most recent.

This reverses the behavior pinned by "test new failed workflow overrides old
succeeding workflow" (#5038): an older successful run of the same workflow on
the same commit now wins over a newer failed one, and the test is flipped.

This commit was written by Claude Code on behalf of albanD.
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
torchci Ignored Ignored Nov 25, 2026 8:12pm UTC

Request Review

@albanD
albanD marked this pull request as ready for review November 25, 2026 20:13
@albanD
albanD requested a review from jeanschmidt November 25, 2026 20:13
@huydhn

huydhn commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

I dig into this a bit more and realize that this is an exclusive behaviour coming from ghstack 0.16.0+ to having the same workflows triggered twice on the same commit. The data so far supports this:

┌──────────────────────────────────────────────────────┬─────────────────────────────────┐
│                Latest ghstack update                 │ Same-second duplicate Lint runs │
├──────────────────────────────────────────────────────┼─────────────────────────────────┤
│ Stack created ([INITIAL])                            │ No                              │
├──────────────────────────────────────────────────────┼─────────────────────────────────┤
│ Update with newer ghstack (0.16.0+), base also moved │ Yes                             │
├──────────────────────────────────────────────────────┼─────────────────────────────────┤
│ Update with newer ghstack, base not moved            │ No                              │
├──────────────────────────────────────────────────────┼─────────────────────────────────┤
│ Update with older ghstack, base also moved           │ No                              │
├──────────────────────────────────────────────────────┼─────────────────────────────────┤
│ Other updates with older ghstack                     │ No                              │
└──────────────────────────────────────────────────────┴─────────────────────────────────┘

I have submitted a PR to restore the old behaviour ezyang/ghstack#370 and will try to see if it fix this issue at the root.

@huydhn huydhn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@huydhn

huydhn commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up: I confirmed the root cause on a test ghstack stack (pytorch/pytorch#206700, pytorch/pytorch#206701). On 4 updates that moved the base branch, ghstack main (single batched push) started every pull_request workflow twice on 8 of 8 PR updates. On 4 more such updates, ezyang/ghstack#370 (base pushed before head again) gave 0 of 8. Details: ezyang/ghstack#370

This PR is still worth landing. People will stay on ghstack 0.16–0.18 until they upgrade, and duplicate runs can come from other sources too.

@albanD
albanD merged commit a1a8f07 into main Nov 26, 2026
6 checks passed
@albanD
albanD deleted the cc_drci_duplicate_runs branch November 26, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants