From d4082adff6131421fed5805e3d10bd291989e215 Mon Sep 17 00:00:00 2001 From: Yi Hu Date: Thu, 10 Sep 2026 12:45:35 -0400 Subject: [PATCH 1/5] [CI] Stop infinite reviewer reassignment, batch state commits, and clean up stale state * Stop infinite reviewer reassignment loops: label with "awaiting triage" if a PR has both "reassigned-reviewers" and "Next Action: Reviewers", and review started >60 days ago. * Track initial reviewer assignment timestamp (reviewersAssignedAt) in persistent PR state, falling back to PR creation time for legacy PRs. * Skip reviewer assignment for PRs labeled "awaiting triage" across new PR processing and daily reminder workflows. * Batch persistent state updates into a single commit and push per workflow execution instead of committing on every file write. * Incrementally prune closed PR state files (oldest 100 per daily run) from the pr-bot-state branch. * Document core PR bot logic in scripts/ci/pr-bot/README.md. --- scripts/ci/pr-bot/README.md | 28 +++++ scripts/ci/pr-bot/findPrsNeedingAttention.ts | 62 +++++++--- scripts/ci/pr-bot/processNewPrs.ts | 33 ++++-- scripts/ci/pr-bot/processPrUpdate.ts | 2 + scripts/ci/pr-bot/shared/commentStrings.ts | 5 +- scripts/ci/pr-bot/shared/constants.ts | 4 + scripts/ci/pr-bot/shared/githubUtils.ts | 8 ++ scripts/ci/pr-bot/shared/persistentState.ts | 118 ++++++++++++++----- scripts/ci/pr-bot/shared/pr.ts | 5 + scripts/ci/pr-bot/shared/userCommand.ts | 4 +- scripts/ci/pr-bot/test/githubUtilsTest.ts | 63 ++++++++++ scripts/ci/pr-bot/test/prTest.ts | 13 ++ 12 files changed, 288 insertions(+), 57 deletions(-) create mode 100644 scripts/ci/pr-bot/test/githubUtilsTest.ts diff --git a/scripts/ci/pr-bot/README.md b/scripts/ci/pr-bot/README.md index d6a55d45e9f1..ccc9a57804d6 100644 --- a/scripts/ci/pr-bot/README.md +++ b/scripts/ci/pr-bot/README.md @@ -23,6 +23,34 @@ This directory holds all the code (except for Actions Workflows) for our PR bot For a list of commands to use when interacting with the bot, see [Commands.md](./Commands.md). For a design doc explaining the design and implementation, see [Automate Reviewer Assignment](https://docs.google.com/document/d/1FhRPRD6VXkYlLAPhNfZB7y2Yese2FCWBzjx67d3TjBo/edit#) +## PR Bot Logic + +The bot consists of three core workflows and a persistent state tracking system: + +### 1. New PR Processing (`processNewPrs.ts`) +* Runs periodically on a schedule (every 30 minutes). +* Checks eligible open PRs (skips WIP, drafts, closed, PRs < 20 minutes old, PRs with notifications silenced, or PRs labeled `awaiting triage`). +* Once CI checks pass, assigns reviewers based on configured label mappings in `.github/REVIEWERS.yml` (prioritizing least-recently-assigned reviewers). +* If a non-committer reviewer approves, automatically assigns a committer for final review and merge. +* Sets `Next Action: Reviewers` label. + +### 2. PR Updates & Commands (`processPrUpdate.ts`) +* Triggered on PR pushes (`synchronize`) and comments (`issue_comment: created`). +* Shifts attention back to reviewers (`Next Action: Reviewers`) when author pushes new commits or posts comments. +* Removes `slow-review` label upon receiving a comment from a non-author reviewer. +* Processes commands like `assign to next reviewer`, `waiting on author`, `stop reviewer notifications`, `assign set of reviewers`, and `remind me after tests pass`. + +### 3. Reviewer Reminders & Stale PRs (`findPrsNeedingAttention.ts`) +* Runs daily to identify PRs needing action. +* Flags PRs awaiting reviewer response as `slow-review` if inactive for ≥ 7 days (or ≥ 2 weekdays without comments). +* If still no response after 2 more weekdays, reassigns to new reviewers, removes `slow-review`, and adds `reassigned-reviewers`. +* **Stale PR Cutoff**: If a PR has both `reassigned-reviewers` and `Next Action: Reviewers` labels and review started > 60 days ago, it stops reviewer assignment loops and adds `awaiting triage`. PRs labeled `awaiting triage` are skipped. +* **Stale State Cleanup**: Cleans up the oldest 100 state files for PRs that are no longer open to incrementally prune closed PR metadata from the state branch. + +### 4. Persistent State (`PersistentState`) +* Stores PR review progress and label assignment rotations on the `pr-bot-state` Git branch under `state/pr-state/pr-.json` and `state/reviewers-for-label-