Skip to content

Assign PR leads from "Part of #N" references and a twice-daily sweep - #14255

Merged
RayBB merged 3 commits into
internetarchive:masterfrom
RayBB:14254/feature/pr-lead-sweep
Nov 3, 2026
Merged

RayBB merged 3 commits into
internetarchive:masterfrom
RayBB:14254/feature/pr-lead-sweep

Conversation

@RayBB

@RayBB RayBB commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #14254

feature: assign PR leads from "Part of #N" references, fall back to the parent epic's lead, and add a twice-daily sweep for PRs that were missed when they opened. Part of #13160.

Technical

  • Finding references (findIssueReferences in new_pr_labeler_core.mjs):
    • Closing keywords come first, then non-closing references: Part of, Refs/References, Related to, Follow-up to, Works on, Towards.
    • A same-repo issue URL works in place of #N.
    • A bare #N is still ignored.
  • Choosing the lead (planForPr in the new pr_lead_resolver.mjs):
    • The labeler and the sweep share this, so they always decide the same way.
    • It looks up each reference with one GraphQL issueOrPullRequest query and skips references that are PRs.
    • It takes the lead from the issue, or else from the issue's parent epic (Issue.parent).
    • The priority label is copied only from a closing reference, because "Part of" usually points at an epic.
  • Visibility: every decision is written to the job summary with its reason, for example #14140 (closing keyword) has no Lead label. A run that assigns nobody no longer looks the same as a success.
  • New pm_pr_lead_sweep.yml:
    • Runs at 0 14 * * * and 0 2 * * * UTC, which is 6 AM / 6 PM PST and an hour later during daylight time. It can also be run by hand.
    • Only considers open PRs that are not drafts, not opened by bots, and have never had an assignee, so it never re-assigns someone a human removed.
    • Adds a priority label only when the PR has none.
    • Scheduled runs are dry runs. A maintainer can run it live from the Actions tab with the live input. Going live on schedule is a one-line change once the reports look right.
  • GraphQL quirk: timelineItems(itemTypes: …).totalCount ignores the filter, so "ever assigned" checks the returned nodes instead.

Testing

  • npx vitest run tests/unit/js/new_pr_labeler.test.js: 54 pass, 40 of them new. They cover phrase matching, the parent fallback, the sweep's skip rules, planForPr, and the sweep loop (runSweep: dry-run vs live, pagination, per-PR and listing failures, a lead GitHub won't assign) against a fake Octokit.

  • After review, checked live with planForPr:

    • Part of #13079 (a Discussion) no longer throws.
    • Closes #13770. Part of #14254 now keeps Priority: 2 while assigning @mekarpeles.
  • A referenced number that isn't an issue (a Discussion or a typo) is skipped, so a bad reference no longer stops the sweep.

  • When GitHub silently drops an assignee (e.g. the user has no repo access), the run reports "could not assign".

  • I ran the sweep locally in dry-run mode against this repo with a personal token. It writes nothing. Result:

  • Not verifiable before merge:

    • whether the workflow's GITHUB_TOKEN can make the GraphQL reads (the permissions match new_pr_labeler.yml, which already reads issues);
    • the cron trigger itself.

    After merge: run pm_pr_lead_sweep by hand with live unchecked and check the job summary. Then open a test PR that says "Part of #N" and confirm it gets assigned.

Stakeholders

@mekarpeles (lead)

new_pr_labeler only read closing keywords, so PRs that say "Part of #N" got
no lead, and PRs whose issue got its Lead label later were never revisited.

- Recognise non-closing references (Part of, Refs, Related to, Follow-up to,
  Works on, Towards) after closing keywords, and same-repo issue URLs.
- Fall back to the parent epic's lead when the issue has none. Inherit the
  priority only from closing references.
- Add pm_pr_lead_sweep, which runs the same decision at 6 AM and 6 PM Pacific
  on open PRs that have never had an assignee. Scheduled runs are dry runs.
- Write the decision and its reason to the job summary.
@RayBB RayBB self-assigned this Nov 2, 2026
@github-project-automation github-project-automation Bot moved this to Waiting Review/Merge from Staff in Ray's Project Nov 2, 2026
@RayBB
RayBB marked this pull request as ready for review November 2, 2026 23:50
@github-actions github-actions Bot added the Priority: 2 Important, as time permits. [managed] label Nov 2, 2026
@RayBB

RayBB commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@mekarpeles since this can really only be tested after merging I'm thinking I might just merge so we can see it works can you can review closer later.

RayBB added 2 commits November 2, 2026 15:58
- Skip referenced numbers that are not issues or PRs (Discussions, typos)
  instead of throwing; GraphQL NOT_FOUND made Octokit throw before the
  type check, aborting the sweep and the labeler.
- Keep the closing issue's priority when a later "Part of" reference
  supplies the lead (regression from master).
- Report "could not assign" when GitHub silently drops the assignee, so the
  sweep doesn't silently retry a lead without repo access.
- Ignore references inside HTML comments.
- Isolate each PR in the sweep so one failure can't stop the run; failures
  are listed in the summary and fail the job.
- Move the sweep loop into runSweep()/formatSweepSummary() in
  pr_lead_resolver.mjs so it can be unit tested with a fake Octokit;
  pr_lead_sweep.mjs is now a thin entry point.
- A failure while listing PRs no longer loses the summary: rows collected so
  far are reported and the run fails.
- Escape newlines and pipes in summary table cells (GraphQL error messages
  are multi-line).
- Only treat NOT_FOUND on the issue itself as "skip"; if only its parent
  can't be read, keep the issue's own labels.
- Ignore parents in another repo.
- Add a 10-minute timeout to the sweep job.
- Fix stale comments and document the 5-reference cap, the self-assignment
  rule and how to make scheduled runs live.
@RayBB
RayBB merged commit 45d67e7 into internetarchive:master Nov 3, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project Nov 3, 2026
@RayBB

RayBB commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Update after merge: it's working in production.

What I ran

  1. Manual dry run (run 41550878660). It checked 236 open PRs, found 13 eligible, would assign 4, and wrote nothing. This was the part we couldn't test before merge: the workflow's own GITHUB_TOKEN can make the GraphQL reads. The new new_pr_labeler code uses the same token and queries. The results matched the local dry run exactly.

  2. Manual live run (run 41551040167) assigned 4 PRs. The event log shows github-actions[bot] as the assigner on each, and all four came from "Part of #N" references, which the old labeler couldn't read:

    No priority labels were added, which is right, because non-closing references don't pass one on.

  3. Second dry run (run 41551136379). It found 9 eligible PRs and would assign 0. PRs the sweep has already assigned are skipped, so it won't touch them again.

The 9 PRs it still can't assign

Next

  • Scheduled runs (02:00 and 14:00 UTC) stay dry runs for now. Once a few reports look right, making them live is a one-line DRY_RUN change.
  • The PR-open path hasn't seen a new PR since the merge. It shares the lookup code and token with the sweep, so it should work. The next PR opened will confirm it.

@mekarpeles a closer review whenever you have time would still be welcome.

marley pushed a commit to marley/openlibrary that referenced this pull request Nov 3, 2026
…nternetarchive#14255)

* Assign PR leads from "Part of #N" references and a twice-daily sweep

new_pr_labeler only read closing keywords, so PRs that say "Part of #N" got
no lead, and PRs whose issue got its Lead label later were never revisited.

- Recognise non-closing references (Part of, Refs, Related to, Follow-up to,
  Works on, Towards) after closing keywords, and same-repo issue URLs.
- Fall back to the parent epic's lead when the issue has none. Inherit the
  priority only from closing references.
- Add pm_pr_lead_sweep, which runs the same decision at 6 AM and 6 PM Pacific
  on open PRs that have never had an assignee. Scheduled runs are dry runs.
- Write the decision and its reason to the job summary.

* Harden PR lead resolution after review

- Skip referenced numbers that are not issues or PRs (Discussions, typos)
  instead of throwing; GraphQL NOT_FOUND made Octokit throw before the
  type check, aborting the sweep and the labeler.
- Keep the closing issue's priority when a later "Part of" reference
  supplies the lead (regression from master).
- Report "could not assign" when GitHub silently drops the assignee, so the
  sweep doesn't silently retry a lead without repo access.
- Ignore references inside HTML comments.
- Isolate each PR in the sweep so one failure can't stop the run; failures
  are listed in the summary and fail the job.

* Make the sweep robust and testable; tighten comments

- Move the sweep loop into runSweep()/formatSweepSummary() in
  pr_lead_resolver.mjs so it can be unit tested with a fake Octokit;
  pr_lead_sweep.mjs is now a thin entry point.
- A failure while listing PRs no longer loses the summary: rows collected so
  far are reported and the run fails.
- Escape newlines and pipes in summary table cells (GraphQL error messages
  are multi-line).
- Only treat NOT_FOUND on the issue itself as "skip"; if only its parent
  can't be read, keep the issue's own labels.
- Ignore parents in another repo.
- Add a 10-minute timeout to the sweep job.
- Fix stale comments and document the 5-reference cap, the self-assignment
  rule and how to make scheduled runs live.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: 2 Important, as time permits. [managed]

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

new_pr_labeler: twice-daily sweep to assign leads on unassigned PRs, and handle "Part of #N" PRs

2 participants