You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
torchci: don't auto-dispatch the AI advisor on closed/draft PRs (#8197)
Follow-up to #8178. The Dr.CI auto-dispatch path fired the AI advisor on
**any** PR with recent NEW failures — including PRs that are
**closed/merged** (won't be worked on) and **draft** (work-in-progress).
Example: it dispatched on
[pytorch/pytorch#187528](pytorch/pytorch#187528)
right as it was closed.
## Fix
Add a PR-state gate in `autoDispatchAdvisorForNewFailures`:
- After dedup, once there's **fresh work** to dispatch, look up the PR
and **skip if it's not open** (closed/merged) or — by default
(`SKIP_DRAFT_PRS = true`) — **draft**.
- The lookup runs **only when there's something to dispatch**
(fully-deduped PRs are never looked up).
- **Fails closed**: a lookup error skips the pass (the next 15-min pass
retries) rather than dispatching on a possibly-closed PR.
## PR state from ClickHouse, not the GitHub API
PR state comes from the **`default.pull_request` CH mirror** via a new
`advisor_pr_state` saved query (`state` + `draft`), not
`octokit.pulls.get`. This is consistent with the rest of the advisor
path (all of its other reads are `queryClickhouseSaved`) and with
`getPRsWithPendingJobInComment`, which already reads
`pull_request.state` from CH — and it keeps the Dr.CI cron off the
GitHub rate limit. The mirror lags GitHub by ~1 min (verified: #187528
closed at 22:04:54Z, CH `updated_at` 22:05:58Z), well within the 15-min
cron cadence. A not-yet-mirrored PR (no row) is treated as **open** so
brand-new PRs aren't dropped.
## Draft PRs
`SKIP_DRAFT_PRS` defaults to **true** (skip drafts — WIP, tend to
churn). One-line flip if advisor feedback on drafts is desirable.
## Test plan
- `tsc --noEmit` clean; local lintrunner clean (incl. SQLFLUFF on the
new saved query).
- Verified the saved query live against CH: `{state: "closed", draft:
false}` for #187528.
- Unit tests: skips a closed PR (no dispatch, no marker write), skips a
draft PR, and does **not** look up PR state when every failure is
already deduped.
Co-authored-by: Ivan <izaitsevfb@meta.com>
0 commit comments