From a342cb70d62b9eb74e8c60805ed19ae646794813 Mon Sep 17 00:00:00 2001 From: M4n0x Date: Thu, 3 Dec 2026 15:54:53 +0100 Subject: [PATCH 1/2] ci: keep outsiders' review threads from closing community pull requests An unresolved review thread whose newest reply came from anyone but the author counted against the author. Another contributor could leave a thread open on someone else's pull request, reply after the author, get a bot to reply, or comment from an account deleted later, and get the pull request nudged and then closed, where it would otherwise wait on maintainers and never close. Only the author's and the team's comments, and a bot's that opened the thread, now decide whose court a thread is in. --- .github/scripts/community-pr-followup.mjs | 21 ++++++++-- .../scripts/community-pr-followup.test.mjs | 41 +++++++++++++++++++ .github/workflows/community-pr-followup.yml | 2 +- CONTRIBUTING.md | 2 +- DECISIONS.md | 2 +- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/.github/scripts/community-pr-followup.mjs b/.github/scripts/community-pr-followup.mjs index 6704f172..00da683d 100644 --- a/.github/scripts/community-pr-followup.mjs +++ b/.github/scripts/community-pr-followup.mjs @@ -85,6 +85,11 @@ export function isBotUser(user) { return login === "" || /\[bot\]$/i.test(login); } +/** A bot account that is still there: a deleted account's comments have no author and prove nothing. */ +function isReviewBot(user) { + return Boolean(user?.login) && isBotUser(user); +} + /** Community contributors are non-bot accounts outside OWNER, MEMBER and COLLABORATOR. */ export function isCommunityAuthor(author, authorAssociation) { if (isBotUser(author)) return false; @@ -261,7 +266,11 @@ export function evaluatePullRequest(pr, { now, policy = POLICY, fallbackReviewer } } - // Pick each unresolved thread's newest reply by createdAt rather than array order. + // An unresolved thread waits on the author when the newest comment that counts came from the team + // or a review bot, and on maintainers when it came from the author, picked by createdAt rather + // than array order. The author's and the team's comments count, and a bot's only when it opened + // the thread: anyone can get a bot to reply. Nobody outside the team can put a pull request on + // its author and get it closed. let unresolvedAuthorThreads = 0; let unresolvedMaintainerThreads = 0; let lastAuthorThreadAt = null; @@ -269,17 +278,21 @@ export function evaluatePullRequest(pr, { now, policy = POLICY, fallbackReviewer for (const thread of pr.reviewThreads ?? []) { const threadComments = thread.comments ?? []; + const opener = threadComments.reduce((first, c) => (first === null + || (parseTime(c.createdAt) ?? Infinity) < (parseTime(first.createdAt) ?? Infinity) ? c : first), null); let latestComment = null; let latestCommentAt = null; for (const c of threadComments) { const at = parseTime(c.createdAt); + const fromAuthor = isAuthor(c.author); + if (!isBotUser(c.author)) lastHumanThreadAt = maxTime(lastHumanThreadAt, at); + if (fromAuthor) lastAuthorThreadAt = maxTime(lastAuthorThreadAt, at); + const counts = fromAuthor || isTeamMember(c.author, c.authorAssociation) || (c === opener && isReviewBot(c.author)); + if (!counts) continue; if (latestComment === null || (at ?? -Infinity) >= (latestCommentAt ?? -Infinity)) { latestComment = c; latestCommentAt = at; } - if (isBotUser(c.author)) continue; - lastHumanThreadAt = maxTime(lastHumanThreadAt, at); - if (isAuthor(c.author)) lastAuthorThreadAt = maxTime(lastAuthorThreadAt, at); } if (thread.isResolved || !latestComment) continue; if (isAuthor(latestComment.author)) { diff --git a/.github/scripts/community-pr-followup.test.mjs b/.github/scripts/community-pr-followup.test.mjs index d7021b8b..1e181763 100644 --- a/.github/scripts/community-pr-followup.test.mjs +++ b/.github/scripts/community-pr-followup.test.mjs @@ -420,6 +420,47 @@ test("review threads, CHANGES_REQUESTED, and DISMISSED reviews classify ownershi assert.deepEqual(waitingMaintainer.labelsToRemove, [LABELS.waitingForAuthor.name]); }); +test("review threads from outsiders don't put a PR on its author, while the team's and review bots' still do", () => { + const thread = (...comments) => ({ isResolved: false, comments }); + const outsider = { author: { __typename: "User", login: "mallory" }, authorAssociation: "CONTRIBUTOR", createdAt: daysAgo(9) }; + const bot = { author: { __typename: "Bot", login: "coderabbitai" }, authorAssociation: "NONE", createdAt: daysAgo(9) }; + const maintainer = { author: { __typename: "User", login: "Seb-GRAF" }, authorAssociation: "OWNER", createdAt: daysAgo(9) }; + const outsiderPlusOne = { ...outsider, createdAt: daysAgo(8) }; + + const fromOutsider = evaluatePullRequest(makePR({ reviewThreads: [thread(outsider)] }), { now: BASE_TIME }); + assert.equal(fromOutsider.court, "maintainer"); + assert.equal(fromOutsider.action, "remind-maintainers"); + + // Review bots are installed by the team, and their threads have to be answered before merging. + const fromBot = evaluatePullRequest(makePR({ reviewThreads: [thread(bot)] }), { now: BASE_TIME }); + assert.equal(fromBot.action, "nudge-author"); + assert.deepEqual(fromBot.blockers, [{ kind: "unresolved-threads", count: 1 }]); + + // Anyone can get a bot to reply, so a bot's reply after the author's doesn't count. + const botReply = { ...bot, createdAt: daysAgo(7) }; + const answeredThenBot = evaluatePullRequest(makePR({ + reviewThreads: [thread(bot, { author: { __typename: "User", login: "alice" }, authorAssociation: "FIRST_TIME_CONTRIBUTOR", createdAt: daysAgo(8) }, botReply)], + }), { now: BASE_TIME }); + assert.equal(answeredThenBot.court, "maintainer"); + + // A deleted account's comment has no author and doesn't pass for a bot. + const fromDeleted = evaluatePullRequest(makePR({ reviewThreads: [thread({ ...outsider, author: null })] }), { now: BASE_TIME }); + assert.equal(fromDeleted.court, "maintainer"); + + // An outsider's reply after the author's doesn't hand the thread back to the author either. + const authorReply = { author: { __typename: "User", login: "alice" }, authorAssociation: "FIRST_TIME_CONTRIBUTOR", createdAt: daysAgo(8) }; + const answeredThenOutsider = evaluatePullRequest(makePR({ + reviewThreads: [thread(maintainer, authorReply, { ...outsider, createdAt: daysAgo(7) })], + }), { now: BASE_TIME }); + assert.equal(answeredThenOutsider.court, "maintainer"); + assert.deepEqual(answeredThenOutsider.maintainerReasons, ["thread-reply"]); + + // An outsider's reply after a maintainer's request doesn't take the thread off the author. + const maintainerThenOutsider = evaluatePullRequest(makePR({ reviewThreads: [thread(maintainer, outsiderPlusOne)] }), { now: BASE_TIME }); + assert.equal(maintainerThenOutsider.action, "nudge-author"); + assert.deepEqual(maintainerThenOutsider.blockers, [{ kind: "unresolved-threads", count: 1 }]); +}); + test("PRs waiting on maintainers remind once after 4 days (including workflow approval and visual-ok) and never close", () => { const day3 = evaluatePullRequest(makePR({ createdAt: daysAgo(3), diff --git a/.github/workflows/community-pr-followup.yml b/.github/workflows/community-pr-followup.yml index b5e9f017..635760ff 100644 --- a/.github/workflows/community-pr-followup.yml +++ b/.github/workflows/community-pr-followup.yml @@ -1,7 +1,7 @@ name: Community PR follow-up # Follows up on open community pull requests so they don't sit idle without action: -# - Waiting on contributor (failing checks, conflicts, requested changes, unresolved threads): +# - Waiting on contributor (failing checks, conflicts, requested changes, unresolved team or bot threads): # labels waiting-for-author and nudges after 7 days, then closes 7 days later if still silent. # - Draft PRs get a longer window: nudge after 14 days, close 14 days later. # - Waiting on maintainers (ready for review, visual-ok, or first-time CI approval): diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2d6450d..b0b886a9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -102,7 +102,7 @@ Reviews are requested automatically from the people listed in [CODEOWNERS](.gith [cubic](https://cubic.dev) also reviews every pull request once it is out of draft. [CodeRabbit](https://coderabbit.ai) reviews pull requests labeled `deep-review`: the label is added automatically when a pull request changes more than 400 lines or a file listed in [.github/deep-review-paths](.github/deep-review-paths), and you can add it yourself, or ask a maintainer to, when a change is risky. Fix each comment from either or reply why not, then resolve its thread: unresolved conversations block merging. Their rules come from [AGENTS.md](AGENTS.md), [cubic.yaml](cubic.yaml) and [.coderabbit.yaml](.coderabbit.yaml). CodeRabbit allows each pull request author only a few reviews per hour. When its limit holds a review back, the Deep review workflow asks it again every hour, so there's no need to ask with `@coderabbitai review`. -Open community pull requests are followed up on daily by [Community PR follow-up](.github/workflows/community-pr-followup.yml). A pull request waiting on its author (failing checks, merge conflicts, requested changes or unresolved threads) gets `waiting-for-author` and a check-in after 7 days, and closes automatically 7 days later without an update (drafts get 14 days before a check-in and 14 days after). A ready pull request waiting on maintainers (review, `visual-ok` or first-time CI approval) never closes automatically; after 4 days it gets `needs-review` and reminds maintainers. Add `keep-open` to pause follow-ups on a pull request. +Open community pull requests are followed up on daily by [Community PR follow-up](.github/workflows/community-pr-followup.yml). A pull request waiting on its author (failing checks, merge conflicts, requested changes or unresolved review threads from the team or a review bot) gets `waiting-for-author` and a check-in after 7 days, and closes automatically 7 days later without an update (drafts get 14 days before a check-in and 14 days after). A ready pull request waiting on maintainers (review, `visual-ok` or first-time CI approval) never closes automatically; after 4 days it gets `needs-review` and reminds maintainers. Add `keep-open` to pause follow-ups on a pull request. The contributors' avatars in the [README](README.md#contributing) come from GitHub's contributors list. Every Monday, [README contributors](.github/workflows/readme-contributors.yml) compares them and, when the list changed, opens a pull request from the `readme-contributors` branch. To count a second account under someone's first, or leave out an automation account, edit `ALIASES` or `EXCLUDED` in [readme-contributors.mjs](.github/scripts/readme-contributors.mjs) rather than the README. diff --git a/DECISIONS.md b/DECISIONS.md index 86172b4d..1840d0c7 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -26,7 +26,7 @@ Add an entry when a pull request sets a rule, a policy or a choice not to do som - **Screens are drawn once they hold still, each scene in a process of its own** (2026-11-20, [#794]). A drawing is kept once three in a row match, held for two seconds while a spinner shows, instead of after a fixed two seconds. Watching the process's threads and run loop instead of its drawings missed changes that only a drawing showed. Scenes draw a few at once, each in a process of its own: several at once in one process shared its main thread and drew pages still loading on CI's three cores, and what a process has drawn changes what it draws later, such as which version of the app's icon an image gets. - **Scenes draw only dark unless appearance is what they show** (2026-11-24). Every scene drew light and dark, 326 images taking about five minutes on each side of a pull request's comparison. In November's pull requests, about 395 changed screens changed in both appearances, and no scene changed in only one: the five screens that did were docs images, which still draw both. Scenes about contrast, transparency, text that follows its background, themes and their tokens, tinted images, color editors and shadows keep both. - **A flaky test doesn't block a pull request** (2026-11-17). When up to five Swift Testing tests fail, the Test job runs them once more on their own and passes with a warning naming those that pass then. They still get fixed, in a pull request of their own. A test that fails twice, an XCTest failure, a crash, a hang or more failures fail the job. -- **Community pull requests get state-aware follow-ups** (2026-11-26). [Community PR follow-up](.github/workflows/community-pr-followup.yml) checks open pull requests from outside the team once a day and distinguishes whose court the ball is in. Ready pull requests waiting on their author (failing checks, merge conflicts, requested changes or unresolved threads) get `waiting-for-author` and a nudge after 7 days and close 7 days later if still silent; drafts get 14 days to nudge and 14 days to close. Ready pull requests waiting on maintainers (review, `visual-ok` or first-time CI approval) never go stale or close, and remind maintainers with `needs-review` after 4 days. `keep-open` pauses follow-ups. +- **Community pull requests get state-aware follow-ups** (2026-11-26). [Community PR follow-up](.github/workflows/community-pr-followup.yml) checks open pull requests from outside the team once a day and distinguishes whose court the ball is in. Ready pull requests waiting on their author (failing checks, merge conflicts, requested changes or unresolved review threads from the team or a review bot) get `waiting-for-author` and a nudge after 7 days and close 7 days later if still silent; drafts get 14 days to nudge and 14 days to close. Ready pull requests waiting on maintainers (review, `visual-ok` or first-time CI approval) never go stale or close, and remind maintainers with `needs-review` after 4 days. `keep-open` pauses follow-ups. - **The README's contributors come from GitHub's list** (2026-12-02). [README contributors](.github/workflows/readme-contributors.yml) rewrites the avatars weekly and proposes them in a pull request, opened with the release app so its required checks run. It keeps the README's own avatars, leaves out bots and merges second accounts, which a contributors image service such as contrib.rocks couldn't, and adds no outside service. all-contributors was too heavy for a list of code contributors. ## Code From e3301b59ee06d6cdaccf671cb7860ddcc6e69de6 Mon Sep 17 00:00:00 2001 From: M4n0x Date: Thu, 3 Dec 2026 16:30:22 +0100 Subject: [PATCH 2/2] ci: trust a follow-up marker only from the workflow itself Anyone can get a bot such as CodeRabbit to repeat text, and the sweep read a follow-up marker from any bot's comment, so a repeated check-in could start the closing countdown. Only GitHub Actions' markers count now. Outsiders' recent thread comments are also tested to delay a follow-up. --- .github/scripts/community-pr-followup.mjs | 5 ++++- .github/scripts/community-pr-followup.test.mjs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/scripts/community-pr-followup.mjs b/.github/scripts/community-pr-followup.mjs index 00da683d..b322342c 100644 --- a/.github/scripts/community-pr-followup.mjs +++ b/.github/scripts/community-pr-followup.mjs @@ -32,6 +32,9 @@ const FAILING_CHECK_CONCLUSIONS = new Set(["FAILURE", "TIMED_OUT", "STARTUP_FAIL const FAILING_STATUS_STATES = new Set(["FAILURE", "ERROR"]); const MARKER_PREFIX = "\s*$/; +// The workflow comments as GitHub Actions (its GraphQL and REST logins). Only its markers count: +// anyone can get another bot, such as CodeRabbit, to repeat text. +const FOLLOWUP_BOT_LOGINS = new Set(["github-actions", "github-actions[bot]"]); const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`; @@ -124,7 +127,7 @@ export function defaultCodeowners(codeownersText) { /** Parses our own follow-up marker from a bot comment, preferring GitHub's publication timestamp. */ export function readFollowupMarker(comment) { const actor = comment?.author ?? comment?.user; - if (!actor || !isBotUser(actor)) return null; + if (!actor || !isBotUser(actor) || !FOLLOWUP_BOT_LOGINS.has(actor.login)) return null; const match = String(comment.body ?? "").match(MARKER_PATTERN); if (!match) return null; try { diff --git a/.github/scripts/community-pr-followup.test.mjs b/.github/scripts/community-pr-followup.test.mjs index 1e181763..7fa2449f 100644 --- a/.github/scripts/community-pr-followup.test.mjs +++ b/.github/scripts/community-pr-followup.test.mjs @@ -72,7 +72,7 @@ test("defaultCodeowners parses wildcard user owners and matches the repository f assert.deepEqual(owners, defaultCodeowners(repoCodeowners)); }); -test("readFollowupMarker trusts only bot comments and prefers publication createdAt", () => { +test("readFollowupMarker trusts only the workflow's own comments and prefers publication createdAt", () => { const body = formatAuthorNudgeComment({ authorLogin: "alice", headSha: "abc1234", @@ -94,6 +94,9 @@ test("readFollowupMarker trusts only bot comments and prefers publication create assert.equal(fallbackParsed?.at, BASE_TIME - 60_000); assert.equal(readFollowupMarker({ author: { __typename: "User", login: "alice" }, body, createdAt: daysAgo(1) }), null); + // Anyone can get another bot to repeat text, so only the workflow's own markers count. + assert.equal(readFollowupMarker({ author: { __typename: "Bot", login: "coderabbitai" }, body, createdAt: daysAgo(1) }), null); + assert.equal(readFollowupMarker({ user: { type: "Bot", login: "github-actions[bot]" }, body, created_at: publishedAt })?.kind, "author-nudge"); }); test("analyzeChecks deduplicates reruns and classifies Visual review statuses", () => { @@ -459,6 +462,16 @@ test("review threads from outsiders don't put a PR on its author, while the team const maintainerThenOutsider = evaluatePullRequest(makePR({ reviewThreads: [thread(maintainer, outsiderPlusOne)] }), { now: BASE_TIME }); assert.equal(maintainerThenOutsider.action, "nudge-author"); assert.deepEqual(maintainerThenOutsider.blockers, [{ kind: "unresolved-threads", count: 1 }]); + + // Outsiders' recent comments still delay a follow-up in either court. + const recentOutsider = evaluatePullRequest(makePR({ reviewThreads: [thread({ ...outsider, createdAt: daysAgo(2) })] }), { now: BASE_TIME }); + assert.equal(recentOutsider.court, "maintainer"); + assert.equal(recentOutsider.action, "none"); + const maintainerThenRecentOutsider = evaluatePullRequest(makePR({ + reviewThreads: [thread(maintainer, { ...outsider, createdAt: daysAgo(2) })], + }), { now: BASE_TIME }); + assert.equal(maintainerThenRecentOutsider.court, "author"); + assert.equal(maintainerThenRecentOutsider.action, "none"); }); test("PRs waiting on maintainers remind once after 4 days (including workflow approval and visual-ok) and never close", () => {