From ee022b290705687c6a479d17edc0ac6f7765991d Mon Sep 17 00:00:00 2001 From: mavrick Date: Sat, 21 Nov 2026 23:53:44 -0600 Subject: [PATCH 1/9] ci: a reply can't leave a defect the review found for the release quality pass The Claude review now ends each inline finding with its category as a hidden comment. A new `Review deferrals` job in CI, part of `Tests pass`, fails when a `` reply answers a bug, security or AGENTS.md finding, or one edited since the review posted it. It runs on each push and again in the merge queue, which sees replies posted after the last push. A maintainer other than the pull request's author settles a misclassified finding by replying ``. AGENTS.md and the contributing guide name the usual excuses as no reason to defer a defect, and say a defect too large for the pull request gets a filed issue linked from the reply instead of the marker. --- .github/scripts/review-deferrals.py | 189 +++++++++++++++++++++++ .github/scripts/test_review_deferrals.py | 118 ++++++++++++++ .github/workflows/ci.yml | 25 ++- .github/workflows/claude-code-review.yml | 2 + AGENTS.md | 8 +- docs/contributing.md | 13 +- 6 files changed, 352 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/review-deferrals.py create mode 100644 .github/scripts/test_review_deferrals.py diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py new file mode 100644 index 0000000000..a6cab4ae04 --- /dev/null +++ b/.github/scripts/review-deferrals.py @@ -0,0 +1,189 @@ +"""Fails a pull request that leaves a defect for the release quality pass. + +A review point may wait for the release quality pass when the reply to it ends with +``, but only a quality point may (AGENTS.md, "Review comments"). The Claude +review (claude-code-review.yml, posting as github-actions) ends each inline finding with its +category, `` and so on, so the reviewer classifies a finding and the +author doesn't. This check refuses a deferral reply in a thread that the reviewer opened with a +`bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited. + +Threads opened by anyone else (CodeRabbit, people) or by a review from before categories carry no +category and are let through: a reviewer there can answer the reply. They are listed in a notice. + +A maintainer settles a misclassified finding by replying in its thread with +``; a reply from the pull request's author doesn't count. + +CI runs this on each push and again in the merge queue, which sees replies posted after the last +push. It needs GH_TOKEN (read access to pull requests), GITHUB_REPOSITORY, and PR_NUMBER or, in the +merge queue, MERGE_GROUP_REF. +""" + +import json +import os +import re +import subprocess +import sys + +DEFER = "" +APPROVE = "" +CATEGORY = re.compile(r"") +MUST_FIX = {"bug", "security", "agents-md"} +REVIEWER = "github-actions" +MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} +QUEUE_REF = re.compile(r"/pr-(\d+)-[0-9a-f]{40}$") + +THREADS = """ +query($owner: String!, $name: String!, $number: Int!, $endCursor: String) { + repository(owner: $owner, name: $name) { + pullRequest(number: $number) { + author { login } + reviewThreads(first: 50, after: $endCursor) { + pageInfo { hasNextPage endCursor } + nodes { id path line originalLine comments(first: 100) { %s } } + } + } + } +} +""" +COMMENTS = """pageInfo { hasNextPage endCursor } + nodes { url body authorAssociation lastEditedAt author { login __typename } editor { login } }""" +MORE_COMMENTS = """ +query($id: ID!, $endCursor: String) { + node(id: $id) { ... on PullRequestReviewThread { comments(first: 100, after: $endCursor) { %s } } } +} +""" + + +def is_reviewer(comment): + """Whether a comment was posted by the Claude review workflow's bot account.""" + author = comment.get("author") or {} + return author.get("login") == REVIEWER and author.get("__typename") == "Bot" + + +def category(opening): + """The category a reviewer finding gives itself: the most serious of its markers, or None.""" + if not is_reviewer(opening): + return None + found = CATEGORY.findall(opening.get("body") or "") + serious = [c for c in found if c in MUST_FIX] + return (serious or found or [None])[0] + + +def edited_by_someone_else(opening): + """Whether a human or other account edited the reviewer's comment, which may have changed its category.""" + if not opening.get("lastEditedAt"): + return False + return ((opening.get("editor") or {}).get("login")) != REVIEWER + + +def approved(replies, pr_author): + """Whether a maintainer other than the pull request's author settled the thread's deferral.""" + for reply in replies: + author = reply.get("author") or {} + if ( + APPROVE in (reply.get("body") or "") + and author.get("__typename") != "Bot" + and reply.get("authorAssociation") in MAINTAINERS + and author.get("login") != pr_author + ): + return True + return False + + +def check(threads, pr_author): + """Sorts the threads that hold a deferral reply into (refused, unclassified) lists of messages.""" + refused, unclassified = [], [] + for thread in threads: + comments = thread.get("comments") or [] + if not comments: + continue + opening, replies = comments[0], comments[1:] + deferral = next((r for r in replies if DEFER in (r.get("body") or "")), None) + if deferral is None: + continue + where = f"{thread.get('path')}:{thread.get('line') or thread.get('originalLine') or '?'}" + if not is_reviewer(opening): + unclassified.append(f"{where} ({(opening.get('author') or {}).get('login', 'ghost')}): {deferral.get('url')}") + continue + kind = category(opening) + if edited_by_someone_else(opening): + reason = "its finding was edited after the review posted it" + elif kind in MUST_FIX: + reason = f"the reviewer classed it as {kind}" + else: + if kind is None: + unclassified.append(f"{where} (review without a category): {deferral.get('url')}") + continue + if not approved(replies, pr_author): + refused.append(f"{where}: left for the release quality pass, but {reason}. {deferral.get('url')}") + return refused, unclassified + + +def graphql(query, **variables): + """Runs one GraphQL query through the gh CLI and returns its data.""" + args = ["gh", "api", "graphql", "-f", f"query={query}"] + for key, value in variables.items(): + args += ["-F" if isinstance(value, int) else "-f", f"{key}={value}"] + out = subprocess.run(args, check=True, capture_output=True, text=True).stdout + return json.loads(out)["data"] + + +def fetch(repo, number): + """The pull request's author and its review threads, every comment of each in order.""" + owner, name = repo.split("/", 1) + threads, cursor, author = [], None, None + while True: + extra = {"endCursor": cursor} if cursor else {} + pr = graphql(THREADS % COMMENTS, owner=owner, name=name, number=number, **extra)["repository"]["pullRequest"] + author = (pr.get("author") or {}).get("login") + page = pr["reviewThreads"] + for node in page["nodes"]: + comments, more = node["comments"]["nodes"], node["comments"]["pageInfo"] + while more["hasNextPage"]: + rest = graphql(MORE_COMMENTS % COMMENTS, id=node["id"], endCursor=more["endCursor"])["node"]["comments"] + comments, more = comments + rest["nodes"], rest["pageInfo"] + threads.append({**node, "comments": comments}) + if not page["pageInfo"]["hasNextPage"]: + return author, threads + cursor = page["pageInfo"]["endCursor"] + + +def pr_number(): + """The pull request to check, from PR_NUMBER or the merge queue's branch name.""" + if os.environ.get("PR_NUMBER"): + return int(os.environ["PR_NUMBER"]) + match = QUEUE_REF.search(os.environ.get("MERGE_GROUP_REF", "")) + if match is None: + raise SystemExit("::error::No PR_NUMBER, and MERGE_GROUP_REF names no pull request.") + return int(match.group(1)) + + +def escape(text): + """Text for a workflow command line: a path with a newline must not start a command of its own.""" + return text.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A") + + +def main(): + """Checks the pull request and exits 1 if it defers a finding that must be fixed.""" + number = pr_number() + author, threads = fetch(os.environ["GITHUB_REPOSITORY"], number) + refused, unclassified = check(threads, author) + for line in unclassified: + print(f"::notice::Deferred without a review category, not checked: {escape(line)}") + for line in refused: + print(f"::error::{escape(line)}") + if refused: + print( + f"#{number} leaves {len(refused)} finding(s) that must be fixed for the release quality pass. " + "Fix each in the pull request and take the marker out of the reply; for a defect too large " + "for it, link a filed issue in the reply instead of the marker. If the reviewer misclassified " + "one, a maintainer other than the author replies in its thread with . " + "Then run the checks again (re-run the job, or queue the pull request again)." + ) + return 1 + print(f"#{number}: no deferral to the release quality pass is on a finding that must be fixed.") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py new file mode 100644 index 0000000000..6eb376c8d8 --- /dev/null +++ b/.github/scripts/test_review_deferrals.py @@ -0,0 +1,118 @@ +"""Checks for review-deferrals.py on review threads recorded from pull requests, cut down to the fields it reads.""" + +import importlib.util +from pathlib import Path +import unittest +import unittest.mock + +SPEC = importlib.util.spec_from_file_location("review_deferrals", Path(__file__).with_name("review-deferrals.py")) +MODULE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) + +AUTHOR = "contributor" +REVIEWER = {"login": "github-actions", "__typename": "Bot"} +CODERABBIT = {"login": "coderabbitai", "__typename": "Bot"} + + +def comment(author, body, association="CONTRIBUTOR", editor=None): + return { + "url": f"https://github.com/o/r/pull/1#discussion_r{abs(hash(body)) % 10**9}", + "body": body, + "authorAssociation": association, + "lastEditedAt": "2026-11-16T03:39:59Z" if editor else None, + "author": author, + "editor": {"login": editor} if editor else None, + } + + +def thread(*comments, path="crates/data/src/dbf.rs"): + return {"path": path, "line": 120, "comments": list(comments)} + + +def finding(text, kind=None, editor=None): + marker = f"\n\n" if kind else "" + return comment(REVIEWER, text + marker, editor=editor) + + +def reply(text, author=AUTHOR, association="MEMBER"): + return comment({"login": author, "__typename": "User"}, text, association) + + +DEFER = reply("The reader skipping deleted records predates this PR; left for the release quality pass. ") +BUG = "**Bug:** a deleted record shifts every later row's attributes by one." + + +class ReviewDeferrals(unittest.TestCase): + def check(self, *threads): + return MODULE.check(list(threads), AUTHOR) + + def test_a_deferred_bug_is_refused(self): + refused, unclassified = self.check(thread(finding(BUG, "bug"), DEFER)) + self.assertEqual(len(refused), 1) + self.assertIn("classed it as bug", refused[0]) + self.assertEqual(unclassified, []) + + def test_a_deferred_quality_point_passes(self): + quality = finding("**Quality:** appending `dbf` keeps the fuzz corpus's extension indexes.", "quality") + self.assertEqual(self.check(thread(quality, DEFER)), ([], [])) + + def test_an_undeferred_bug_is_not_this_checks_business(self): + answer = reply("Fixed in d3eda9c78.") + self.assertEqual(self.check(thread(finding(BUG, "bug"), answer)), ([], [])) + + def test_a_grouped_comment_takes_its_most_serious_category(self): + both = finding(BUG + "\n", "agents-md") + refused, _ = self.check(thread(both, DEFER)) + self.assertIn("classed it as agents-md", refused[0]) + + def test_only_a_maintainer_other_than_the_author_settles_a_misclassified_finding(self): + rule = finding("**Never silent:** the deleted-record notice has no test.", "agents-md") + by_author = reply("Misclassified. ") + by_outsider = reply("Agreed. ", author="drive-by", association="CONTRIBUTOR") + by_maintainer = reply("An extra test for working code. ", author="maintainer") + self.assertEqual(len(self.check(thread(rule, DEFER, by_author, by_outsider))[0]), 1) + self.assertEqual(self.check(thread(rule, DEFER, by_maintainer)), ([], [])) + + def test_an_edited_finding_counts_as_must_fix(self): + edited = finding(BUG, "quality", editor=AUTHOR) + refused, _ = self.check(thread(edited, DEFER)) + self.assertIn("edited after the review posted it", refused[0]) + + def test_threads_without_a_category_pass_with_a_notice(self): + rabbit = thread(comment(CODERABBIT, "_Potential issue_ | **Major** Record the uppercase DBF sidecar."), DEFER) + person = thread(reply("Should this clamp?", author="maintainer"), DEFER) + old_review = thread(finding("**Bug risk (low):** every non-I/O record error is counted."), DEFER) + refused, unclassified = self.check(rabbit, person, old_review) + self.assertEqual(refused, []) + self.assertEqual(len(unclassified), 3) + + def test_a_marker_in_the_opening_comment_is_not_a_deferral(self): + self.assertEqual(self.check(thread(finding(BUG + " ", "bug"))), ([], [])) + + def test_the_merge_queue_branch_names_the_pull_request(self): + ref = "refs/heads/gh-readonly-queue/main/pr-2655-76a6cd2823b4431c363e30a8023c7f69bccae938" + with unittest.mock.patch.dict(MODULE.os.environ, {"PR_NUMBER": "", "MERGE_GROUP_REF": ref}): + self.assertEqual(MODULE.pr_number(), 2655) + + def test_fetch_reads_every_page_of_threads_and_comments(self): + def page(nodes, cursor=None): + return {"pageInfo": {"hasNextPage": cursor is not None, "endCursor": cursor}, "nodes": nodes} + + first, second, third = finding(BUG, "bug"), reply("a"), DEFER + answers = iter([ + {"repository": {"pullRequest": {"author": {"login": AUTHOR}, "reviewThreads": page( + [{"id": "T1", "path": "a.rs", "line": 1, "comments": page([first], "c1")}], "t1")}}}, + {"node": {"comments": page([second], "c2")}}, + {"node": {"comments": page([third])}}, + {"repository": {"pullRequest": {"author": {"login": AUTHOR}, "reviewThreads": page( + [{"id": "T2", "path": "b.rs", "line": 2, "comments": page([])}])}}}, + ]) + with unittest.mock.patch.object(MODULE, "graphql", lambda *a, **k: next(answers)): + author, threads = MODULE.fetch("o/r", 1) + self.assertEqual(author, AUTHOR) + self.assertEqual([t["id"] for t in threads], ["T1", "T2"]) + self.assertEqual(threads[0]["comments"], [first, second, third]) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fec00ec253..2358fb980c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -292,6 +292,29 @@ jobs: - name: Count direct row uses run: cargo run --locked -q -p xtask -- rows + # A review point left for the release quality pass must be a quality point + # (.github/scripts/review-deferrals.py). The merge queue's run sees replies posted after the last + # push. It runs the checkout with a read-only token and no secrets, like every job here. + deferrals: + name: Review deferrals + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - name: Test the check + run: python3 -m unittest discover -s .github/scripts -p 'test_review_deferrals.py' + - name: No defect left for the release quality pass + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + MERGE_GROUP_REF: ${{ github.event.merge_group.head_ref }} + run: python3 .github/scripts/review-deferrals.py + # The packages whose tests this run needs, for `test` (.github/scripts/test-selection.sh). Only # tests are narrowed: lint, the wasm build, licences and the schema check run whole every time. select: @@ -395,7 +418,7 @@ jobs: # unless their conditions below hold (the same as on the jobs), and every other job always runs. tests_pass: name: Tests pass - needs: [lint, wasm, ios, android, licenses, schema, rows, plan, select, test] + needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, plan, select, test] if: ${{ always() }} runs-on: ubuntu-latest steps: diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index a231820ab5..bc27600e3d 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -499,6 +499,8 @@ jobs: Post specific findings as inline review comments on the relevant lines using the create_inline_comment tool. For each comment, briefly explain the issue and, when the fix is small and self-contained, include a committable suggestion block. Group minor nits together rather than posting many separate inline comments. + End every inline comment with its category, on a line of its own, as one of ``, ``, ``, `` or ``, the same groups as the summary. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one marker, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category decides what may wait: CI refuses a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. + After posting inline comments, end your run by writing the summary as your FINAL MESSAGE. Do not try to post it yourself — you have no tool that can, and a workflow step publishes your final message as the PR comment verbatim. So your final message must be the comment body and nothing else: no preamble, no "I've completed the review", no meta-commentary about the tools you used. That final message must start with the heading "## Code review" and list the findings grouped by category (Bugs, Security, Performance, Quality, AGENTS.md), each with a one-line description and confidence. If you genuinely find nothing worth raising, say so and note what you checked. diff --git a/AGENTS.md b/AGENTS.md index 76a5649243..32d33b55f8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -169,11 +169,17 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. ## Review comments - Fix in the pull request what a review finds wrong: bugs, crash paths, silent data loss, a broken - rule from this file. + rule from this file. None of these makes a defect a quality point: it predates the pull request, + the input is rare, the fix needs a wider change, earlier code does the same. A defect too large + for the pull request gets an issue, filed and linked from the reply, not the marker below. - A quality point (style, naming, wording, a refactor, an extra test for code that works) may wait for the **release quality pass**, where maintainers handle them together before each release. Reply that it's left for the release quality pass, end the reply with ``, and leave it out of the next push. +- The Claude review ends each inline finding with its category (``). + CI's `Review deferrals` job fails, on each push and in the merge queue, when the marker answers + a `bug`, `security` or `agents-md` finding, or one edited since it was posted. A maintainer + other than the author settles a misclassified one by replying ``. ## Looking at the app - `cargo run --release -p rustgis` (opens the World Atlas sample). diff --git a/docs/contributing.md b/docs/contributing.md index 658278366d..3eb3dd4183 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -34,7 +34,18 @@ naming, wording, a refactor, an extra test for code that works) can be left for quality pass**: before each release, maintainers gather these from the merged pull requests and fix them together. Reply on the comment that it's left for the release quality pass (agents end the reply with ``), so it can be found. Bugs, crashes, silent data loss and -breaks of the rules in AGENTS.md are fixed in the pull request. +breaks of the rules in AGENTS.md are fixed in the pull request, even when the problem predates it, +the input that triggers it is rare, the fix needs a wider change or earlier code does the same. A +defect too large for the pull request gets an issue, filed and linked from the reply, instead of +the marker. + +The Claude review gives each inline comment a hidden category (bug, security, performance, +quality or AGENTS.md). CI's **Review deferrals** check, which runs on each push and again in the +merge queue, fails when a reply leaves a bug, security or AGENTS.md finding for the release quality +pass. If the review misclassified a finding, a maintainer other than the pull request's author +replies in its thread with `` and runs the check again. Comments from +other reviewers carry no category, so the check lets them through: those reviewers answer the +reply themselves. Changes to saved or generated output must classify each new owning field: address, executable parameters, generated text or user data. Use the shared durable-output transaction and keep From 492e401f62c9b8adc3a71e310e62772d6978d161 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:31:20 -0600 Subject: [PATCH 2/9] ci: the review deferrals check warns instead of failing A maintainer who merges decides whether a deferred finding may wait; the check lists deferred bug, security and AGENTS.md findings as warnings and in the job summary, and is no longer part of Tests pass. The maintainer approval reply is dropped with it. --- .github/scripts/review-deferrals.py | 78 +++++++++--------------- .github/scripts/test_review_deferrals.py | 44 ++++++------- .github/workflows/ci.yml | 11 ++-- .github/workflows/claude-code-review.yml | 2 +- AGENTS.md | 6 +- docs/contributing.md | 9 ++- 6 files changed, 60 insertions(+), 90 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index a6cab4ae04..e7c7f0c668 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -1,17 +1,15 @@ -"""Fails a pull request that leaves a defect for the release quality pass. +"""Warns when a pull request leaves a defect for the release quality pass. A review point may wait for the release quality pass when the reply to it ends with ``, but only a quality point may (AGENTS.md, "Review comments"). The Claude review (claude-code-review.yml, posting as github-actions) ends each inline finding with its category, `` and so on, so the reviewer classifies a finding and the -author doesn't. This check refuses a deferral reply in a thread that the reviewer opened with a -`bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited. +author doesn't. This check warns about a deferral reply in a thread that the reviewer opened with +a `bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited. +It never fails: whoever merges reads the warnings and decides. Threads opened by anyone else (CodeRabbit, people) or by a review from before categories carry no -category and are let through: a reviewer there can answer the reply. They are listed in a notice. - -A maintainer settles a misclassified finding by replying in its thread with -``; a reply from the pull request's author doesn't count. +category, so they are only listed in a notice: a reviewer there can answer the reply. CI runs this on each push and again in the merge queue, which sees replies posted after the last push. It needs GH_TOKEN (read access to pull requests), GITHUB_REPOSITORY, and PR_NUMBER or, in the @@ -25,18 +23,15 @@ import sys DEFER = "" -APPROVE = "" CATEGORY = re.compile(r"") MUST_FIX = {"bug", "security", "agents-md"} REVIEWER = "github-actions" -MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} QUEUE_REF = re.compile(r"/pr-(\d+)-[0-9a-f]{40}$") THREADS = """ query($owner: String!, $name: String!, $number: Int!, $endCursor: String) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { - author { login } reviewThreads(first: 50, after: $endCursor) { pageInfo { hasNextPage endCursor } nodes { id path line originalLine comments(first: 100) { %s } } @@ -46,7 +41,7 @@ } """ COMMENTS = """pageInfo { hasNextPage endCursor } - nodes { url body authorAssociation lastEditedAt author { login __typename } editor { login } }""" + nodes { url body lastEditedAt author { login __typename } editor { login } }""" MORE_COMMENTS = """ query($id: ID!, $endCursor: String) { node(id: $id) { ... on PullRequestReviewThread { comments(first: 100, after: $endCursor) { %s } } } @@ -76,23 +71,9 @@ def edited_by_someone_else(opening): return ((opening.get("editor") or {}).get("login")) != REVIEWER -def approved(replies, pr_author): - """Whether a maintainer other than the pull request's author settled the thread's deferral.""" - for reply in replies: - author = reply.get("author") or {} - if ( - APPROVE in (reply.get("body") or "") - and author.get("__typename") != "Bot" - and reply.get("authorAssociation") in MAINTAINERS - and author.get("login") != pr_author - ): - return True - return False - - -def check(threads, pr_author): - """Sorts the threads that hold a deferral reply into (refused, unclassified) lists of messages.""" - refused, unclassified = [], [] +def check(threads): + """Sorts the threads that hold a deferral reply into (flagged, unclassified) lists of messages.""" + flagged, unclassified = [], [] for thread in threads: comments = thread.get("comments") or [] if not comments: @@ -114,9 +95,8 @@ def check(threads, pr_author): if kind is None: unclassified.append(f"{where} (review without a category): {deferral.get('url')}") continue - if not approved(replies, pr_author): - refused.append(f"{where}: left for the release quality pass, but {reason}. {deferral.get('url')}") - return refused, unclassified + flagged.append(f"{where}: left for the release quality pass, but {reason}. {deferral.get('url')}") + return flagged, unclassified def graphql(query, **variables): @@ -129,13 +109,12 @@ def graphql(query, **variables): def fetch(repo, number): - """The pull request's author and its review threads, every comment of each in order.""" + """The pull request's review threads, every comment of each in order.""" owner, name = repo.split("/", 1) - threads, cursor, author = [], None, None + threads, cursor = [], None while True: extra = {"endCursor": cursor} if cursor else {} pr = graphql(THREADS % COMMENTS, owner=owner, name=name, number=number, **extra)["repository"]["pullRequest"] - author = (pr.get("author") or {}).get("login") page = pr["reviewThreads"] for node in page["nodes"]: comments, more = node["comments"]["nodes"], node["comments"]["pageInfo"] @@ -144,7 +123,7 @@ def fetch(repo, number): comments, more = comments + rest["nodes"], rest["pageInfo"] threads.append({**node, "comments": comments}) if not page["pageInfo"]["hasNextPage"]: - return author, threads + return threads cursor = page["pageInfo"]["endCursor"] @@ -164,24 +143,25 @@ def escape(text): def main(): - """Checks the pull request and exits 1 if it defers a finding that must be fixed.""" + """Lists the pull request's deferrals of findings that must be fixed, as warnings. Never fails for them.""" number = pr_number() - author, threads = fetch(os.environ["GITHUB_REPOSITORY"], number) - refused, unclassified = check(threads, author) + flagged, unclassified = check(fetch(os.environ["GITHUB_REPOSITORY"], number)) for line in unclassified: print(f"::notice::Deferred without a review category, not checked: {escape(line)}") - for line in refused: - print(f"::error::{escape(line)}") - if refused: - print( - f"#{number} leaves {len(refused)} finding(s) that must be fixed for the release quality pass. " - "Fix each in the pull request and take the marker out of the reply; for a defect too large " - "for it, link a filed issue in the reply instead of the marker. If the reviewer misclassified " - "one, a maintainer other than the author replies in its thread with . " - "Then run the checks again (re-run the job, or queue the pull request again)." + for line in flagged: + print(f"::warning::{escape(line)}") + if flagged: + report = ( + f"#{number} leaves {len(flagged)} finding(s) for the release quality pass that the review classed as " + "must-fix. Fix each in the pull request, or link a filed issue in the reply for a defect too large " + "for it. If the review misclassified one, say so in its thread." ) - return 1 - print(f"#{number}: no deferral to the release quality pass is on a finding that must be fixed.") + else: + report = f"#{number}: no deferral to the release quality pass is on a finding that must be fixed." + print(report) + if os.environ.get("GITHUB_STEP_SUMMARY"): + with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary: + summary.write("\n".join([report, "", *(f"- {line}" for line in flagged)]) + "\n") return 0 diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index 6eb376c8d8..815d2b6c53 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -14,11 +14,10 @@ CODERABBIT = {"login": "coderabbitai", "__typename": "Bot"} -def comment(author, body, association="CONTRIBUTOR", editor=None): +def comment(author, body, editor=None): return { "url": f"https://github.com/o/r/pull/1#discussion_r{abs(hash(body)) % 10**9}", "body": body, - "authorAssociation": association, "lastEditedAt": "2026-11-16T03:39:59Z" if editor else None, "author": author, "editor": {"login": editor} if editor else None, @@ -34,8 +33,8 @@ def finding(text, kind=None, editor=None): return comment(REVIEWER, text + marker, editor=editor) -def reply(text, author=AUTHOR, association="MEMBER"): - return comment({"login": author, "__typename": "User"}, text, association) +def reply(text, author=AUTHOR): + return comment({"login": author, "__typename": "User"}, text) DEFER = reply("The reader skipping deleted records predates this PR; left for the release quality pass. ") @@ -44,12 +43,12 @@ def reply(text, author=AUTHOR, association="MEMBER"): class ReviewDeferrals(unittest.TestCase): def check(self, *threads): - return MODULE.check(list(threads), AUTHOR) + return MODULE.check(list(threads)) - def test_a_deferred_bug_is_refused(self): - refused, unclassified = self.check(thread(finding(BUG, "bug"), DEFER)) - self.assertEqual(len(refused), 1) - self.assertIn("classed it as bug", refused[0]) + def test_a_deferred_bug_is_flagged(self): + flagged, unclassified = self.check(thread(finding(BUG, "bug"), DEFER)) + self.assertEqual(len(flagged), 1) + self.assertIn("classed it as bug", flagged[0]) self.assertEqual(unclassified, []) def test_a_deferred_quality_point_passes(self): @@ -62,28 +61,20 @@ def test_an_undeferred_bug_is_not_this_checks_business(self): def test_a_grouped_comment_takes_its_most_serious_category(self): both = finding(BUG + "\n", "agents-md") - refused, _ = self.check(thread(both, DEFER)) - self.assertIn("classed it as agents-md", refused[0]) - - def test_only_a_maintainer_other_than_the_author_settles_a_misclassified_finding(self): - rule = finding("**Never silent:** the deleted-record notice has no test.", "agents-md") - by_author = reply("Misclassified. ") - by_outsider = reply("Agreed. ", author="drive-by", association="CONTRIBUTOR") - by_maintainer = reply("An extra test for working code. ", author="maintainer") - self.assertEqual(len(self.check(thread(rule, DEFER, by_author, by_outsider))[0]), 1) - self.assertEqual(self.check(thread(rule, DEFER, by_maintainer)), ([], [])) + flagged, _ = self.check(thread(both, DEFER)) + self.assertIn("classed it as agents-md", flagged[0]) def test_an_edited_finding_counts_as_must_fix(self): edited = finding(BUG, "quality", editor=AUTHOR) - refused, _ = self.check(thread(edited, DEFER)) - self.assertIn("edited after the review posted it", refused[0]) + flagged, _ = self.check(thread(edited, DEFER)) + self.assertIn("edited after the review posted it", flagged[0]) def test_threads_without_a_category_pass_with_a_notice(self): rabbit = thread(comment(CODERABBIT, "_Potential issue_ | **Major** Record the uppercase DBF sidecar."), DEFER) person = thread(reply("Should this clamp?", author="maintainer"), DEFER) old_review = thread(finding("**Bug risk (low):** every non-I/O record error is counted."), DEFER) - refused, unclassified = self.check(rabbit, person, old_review) - self.assertEqual(refused, []) + flagged, unclassified = self.check(rabbit, person, old_review) + self.assertEqual(flagged, []) self.assertEqual(len(unclassified), 3) def test_a_marker_in_the_opening_comment_is_not_a_deferral(self): @@ -100,16 +91,15 @@ def page(nodes, cursor=None): first, second, third = finding(BUG, "bug"), reply("a"), DEFER answers = iter([ - {"repository": {"pullRequest": {"author": {"login": AUTHOR}, "reviewThreads": page( + {"repository": {"pullRequest": {"reviewThreads": page( [{"id": "T1", "path": "a.rs", "line": 1, "comments": page([first], "c1")}], "t1")}}}, {"node": {"comments": page([second], "c2")}}, {"node": {"comments": page([third])}}, - {"repository": {"pullRequest": {"author": {"login": AUTHOR}, "reviewThreads": page( + {"repository": {"pullRequest": {"reviewThreads": page( [{"id": "T2", "path": "b.rs", "line": 2, "comments": page([])}])}}}, ]) with unittest.mock.patch.object(MODULE, "graphql", lambda *a, **k: next(answers)): - author, threads = MODULE.fetch("o/r", 1) - self.assertEqual(author, AUTHOR) + threads = MODULE.fetch("o/r", 1) self.assertEqual([t["id"] for t in threads], ["T1", "T2"]) self.assertEqual(threads[0]["comments"], [first, second, third]) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2358fb980c..c6a863d004 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -292,9 +292,10 @@ jobs: - name: Count direct row uses run: cargo run --locked -q -p xtask -- rows - # A review point left for the release quality pass must be a quality point - # (.github/scripts/review-deferrals.py). The merge queue's run sees replies posted after the last - # push. It runs the checkout with a read-only token and no secrets, like every job here. + # Warns when a review point left for the release quality pass isn't a quality point + # (.github/scripts/review-deferrals.py); it never fails for one, so `Tests pass` doesn't need it. + # The merge queue's run sees replies posted after the last push. It runs the checkout with a + # read-only token and no secrets, like every job here. deferrals: name: Review deferrals runs-on: ubuntu-latest @@ -307,7 +308,7 @@ jobs: persist-credentials: false - name: Test the check run: python3 -m unittest discover -s .github/scripts -p 'test_review_deferrals.py' - - name: No defect left for the release quality pass + - name: Warn about defects left for the release quality pass if: github.event_name == 'pull_request' || github.event_name == 'merge_group' env: GH_TOKEN: ${{ github.token }} @@ -418,7 +419,7 @@ jobs: # unless their conditions below hold (the same as on the jobs), and every other job always runs. tests_pass: name: Tests pass - needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, plan, select, test] + needs: [lint, wasm, ios, android, licenses, schema, rows, plan, select, test] if: ${{ always() }} runs-on: ubuntu-latest steps: diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index bc27600e3d..743c844b56 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -499,7 +499,7 @@ jobs: Post specific findings as inline review comments on the relevant lines using the create_inline_comment tool. For each comment, briefly explain the issue and, when the fix is small and self-contained, include a committable suggestion block. Group minor nits together rather than posting many separate inline comments. - End every inline comment with its category, on a line of its own, as one of ``, ``, ``, `` or ``, the same groups as the summary. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one marker, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category decides what may wait: CI refuses a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. + End every inline comment with its category, on a line of its own, as one of ``, ``, ``, `` or ``, the same groups as the summary. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one marker, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category says what may wait: CI warns about a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. After posting inline comments, end your run by writing the summary as your FINAL MESSAGE. Do not try to post it yourself — you have no tool that can, and a workflow step publishes your final message as the PR comment verbatim. So your final message must be the comment body and nothing else: no preamble, no "I've completed the review", no meta-commentary about the tools you used. diff --git a/AGENTS.md b/AGENTS.md index 32d33b55f8..9c082b9a96 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -177,9 +177,9 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. release. Reply that it's left for the release quality pass, end the reply with ``, and leave it out of the next push. - The Claude review ends each inline finding with its category (``). - CI's `Review deferrals` job fails, on each push and in the merge queue, when the marker answers - a `bug`, `security` or `agents-md` finding, or one edited since it was posted. A maintainer - other than the author settles a misclassified one by replying ``. + CI's `Review deferrals` job warns, on each push and in the merge queue, when the marker answers + a `bug`, `security` or `agents-md` finding, or one edited since it was posted. It doesn't block + the merge: read its warnings before merging. ## Looking at the app - `cargo run --release -p rustgis` (opens the World Atlas sample). diff --git a/docs/contributing.md b/docs/contributing.md index 3eb3dd4183..1b7235edc4 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -41,11 +41,10 @@ the marker. The Claude review gives each inline comment a hidden category (bug, security, performance, quality or AGENTS.md). CI's **Review deferrals** check, which runs on each push and again in the -merge queue, fails when a reply leaves a bug, security or AGENTS.md finding for the release quality -pass. If the review misclassified a finding, a maintainer other than the pull request's author -replies in its thread with `` and runs the check again. Comments from -other reviewers carry no category, so the check lets them through: those reviewers answer the -reply themselves. +merge queue, warns when a reply leaves a bug, security or AGENTS.md finding for the release quality +pass. It doesn't block the merge; whoever merges reads the warnings first. If the review +misclassified a finding, say so in its thread. Comments from other reviewers carry no category, so +the check only lists them: those reviewers answer the reply themselves. Changes to saved or generated output must classify each new owning field: address, executable parameters, generated text or user data. Use the shared durable-output transaction and keep From 01864241cf408acca10842dbe4643b2983cedff7 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:32:29 -0600 Subject: [PATCH 3/9] ci: the review deferrals check blocks again, and any maintainer can override it A warning is easy to miss, most of all for a reply posted after the last push. The check fails as before, and a maintainer's reply in the thread overrides it for that finding; the pull request's author may be that maintainer. --- .github/scripts/review-deferrals.py | 67 +++++++++++++++--------- .github/scripts/test_review_deferrals.py | 35 ++++++++----- .github/workflows/ci.yml | 11 ++-- .github/workflows/claude-code-review.yml | 2 +- AGENTS.md | 7 +-- docs/contributing.md | 10 ++-- 6 files changed, 80 insertions(+), 52 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index e7c7f0c668..47ef7b35b1 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -1,15 +1,18 @@ -"""Warns when a pull request leaves a defect for the release quality pass. +"""Fails a pull request that leaves a defect for the release quality pass. A review point may wait for the release quality pass when the reply to it ends with ``, but only a quality point may (AGENTS.md, "Review comments"). The Claude review (claude-code-review.yml, posting as github-actions) ends each inline finding with its category, `` and so on, so the reviewer classifies a finding and the -author doesn't. This check warns about a deferral reply in a thread that the reviewer opened with -a `bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited. -It never fails: whoever merges reads the warnings and decides. +author doesn't. This check refuses a deferral reply in a thread that the reviewer opened with a +`bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited. Threads opened by anyone else (CodeRabbit, people) or by a review from before categories carry no -category, so they are only listed in a notice: a reviewer there can answer the reply. +category and are let through: a reviewer there can answer the reply. They are listed in a notice. + +A maintainer overrides the check for a finding, misclassified or accepted as it is, by replying in +its thread with ``. The pull request's author may be that maintainer: the +override is a deliberate, recorded decision, not a second opinion. CI runs this on each push and again in the merge queue, which sees replies posted after the last push. It needs GH_TOKEN (read access to pull requests), GITHUB_REPOSITORY, and PR_NUMBER or, in the @@ -23,9 +26,11 @@ import sys DEFER = "" +APPROVE = "" CATEGORY = re.compile(r"") MUST_FIX = {"bug", "security", "agents-md"} REVIEWER = "github-actions" +MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} QUEUE_REF = re.compile(r"/pr-(\d+)-[0-9a-f]{40}$") THREADS = """ @@ -41,7 +46,7 @@ } """ COMMENTS = """pageInfo { hasNextPage endCursor } - nodes { url body lastEditedAt author { login __typename } editor { login } }""" + nodes { url body authorAssociation lastEditedAt author { login __typename } editor { login } }""" MORE_COMMENTS = """ query($id: ID!, $endCursor: String) { node(id: $id) { ... on PullRequestReviewThread { comments(first: 100, after: $endCursor) { %s } } } @@ -71,9 +76,22 @@ def edited_by_someone_else(opening): return ((opening.get("editor") or {}).get("login")) != REVIEWER +def approved(replies): + """Whether a maintainer overrode the check for the thread's deferral.""" + for reply in replies: + author = reply.get("author") or {} + if ( + APPROVE in (reply.get("body") or "") + and author.get("__typename") != "Bot" + and reply.get("authorAssociation") in MAINTAINERS + ): + return True + return False + + def check(threads): - """Sorts the threads that hold a deferral reply into (flagged, unclassified) lists of messages.""" - flagged, unclassified = [], [] + """Sorts the threads that hold a deferral reply into (refused, unclassified) lists of messages.""" + refused, unclassified = [], [] for thread in threads: comments = thread.get("comments") or [] if not comments: @@ -95,8 +113,9 @@ def check(threads): if kind is None: unclassified.append(f"{where} (review without a category): {deferral.get('url')}") continue - flagged.append(f"{where}: left for the release quality pass, but {reason}. {deferral.get('url')}") - return flagged, unclassified + if not approved(replies): + refused.append(f"{where}: left for the release quality pass, but {reason}. {deferral.get('url')}") + return refused, unclassified def graphql(query, **variables): @@ -143,25 +162,23 @@ def escape(text): def main(): - """Lists the pull request's deferrals of findings that must be fixed, as warnings. Never fails for them.""" + """Checks the pull request and exits 1 if it defers a finding that must be fixed.""" number = pr_number() - flagged, unclassified = check(fetch(os.environ["GITHUB_REPOSITORY"], number)) + refused, unclassified = check(fetch(os.environ["GITHUB_REPOSITORY"], number)) for line in unclassified: print(f"::notice::Deferred without a review category, not checked: {escape(line)}") - for line in flagged: - print(f"::warning::{escape(line)}") - if flagged: - report = ( - f"#{number} leaves {len(flagged)} finding(s) for the release quality pass that the review classed as " - "must-fix. Fix each in the pull request, or link a filed issue in the reply for a defect too large " - "for it. If the review misclassified one, say so in its thread." + for line in refused: + print(f"::error::{escape(line)}") + if refused: + print( + f"#{number} leaves {len(refused)} finding(s) that must be fixed for the release quality pass. " + "Fix each in the pull request and take the marker out of the reply; for a defect too large " + "for it, link a filed issue in the reply instead of the marker. To let one wait all the same, " + "a maintainer replies in its thread with . " + "Then run the checks again (re-run the job, or queue the pull request again)." ) - else: - report = f"#{number}: no deferral to the release quality pass is on a finding that must be fixed." - print(report) - if os.environ.get("GITHUB_STEP_SUMMARY"): - with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary: - summary.write("\n".join([report, "", *(f"- {line}" for line in flagged)]) + "\n") + return 1 + print(f"#{number}: no deferral to the release quality pass is on a finding that must be fixed.") return 0 diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index 815d2b6c53..d4e09aca76 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -14,10 +14,11 @@ CODERABBIT = {"login": "coderabbitai", "__typename": "Bot"} -def comment(author, body, editor=None): +def comment(author, body, association="CONTRIBUTOR", editor=None): return { "url": f"https://github.com/o/r/pull/1#discussion_r{abs(hash(body)) % 10**9}", "body": body, + "authorAssociation": association, "lastEditedAt": "2026-11-16T03:39:59Z" if editor else None, "author": author, "editor": {"login": editor} if editor else None, @@ -33,8 +34,8 @@ def finding(text, kind=None, editor=None): return comment(REVIEWER, text + marker, editor=editor) -def reply(text, author=AUTHOR): - return comment({"login": author, "__typename": "User"}, text) +def reply(text, author=AUTHOR, association="MEMBER"): + return comment({"login": author, "__typename": "User"}, text, association) DEFER = reply("The reader skipping deleted records predates this PR; left for the release quality pass. ") @@ -45,10 +46,10 @@ class ReviewDeferrals(unittest.TestCase): def check(self, *threads): return MODULE.check(list(threads)) - def test_a_deferred_bug_is_flagged(self): - flagged, unclassified = self.check(thread(finding(BUG, "bug"), DEFER)) - self.assertEqual(len(flagged), 1) - self.assertIn("classed it as bug", flagged[0]) + def test_a_deferred_bug_is_refused(self): + refused, unclassified = self.check(thread(finding(BUG, "bug"), DEFER)) + self.assertEqual(len(refused), 1) + self.assertIn("classed it as bug", refused[0]) self.assertEqual(unclassified, []) def test_a_deferred_quality_point_passes(self): @@ -61,20 +62,28 @@ def test_an_undeferred_bug_is_not_this_checks_business(self): def test_a_grouped_comment_takes_its_most_serious_category(self): both = finding(BUG + "\n", "agents-md") - flagged, _ = self.check(thread(both, DEFER)) - self.assertIn("classed it as agents-md", flagged[0]) + refused, _ = self.check(thread(both, DEFER)) + self.assertIn("classed it as agents-md", refused[0]) + + def test_only_a_maintainer_overrides_the_check(self): + rule = finding("**Never silent:** the deleted-record notice has no test.", "agents-md") + by_contributor = reply("Misclassified. ", association="CONTRIBUTOR") + by_bot = comment(CODERABBIT, "", "MEMBER") + by_maintainer_author = reply("An extra test for working code. ") + self.assertEqual(len(self.check(thread(rule, DEFER, by_contributor, by_bot))[0]), 1) + self.assertEqual(self.check(thread(rule, DEFER, by_maintainer_author)), ([], [])) def test_an_edited_finding_counts_as_must_fix(self): edited = finding(BUG, "quality", editor=AUTHOR) - flagged, _ = self.check(thread(edited, DEFER)) - self.assertIn("edited after the review posted it", flagged[0]) + refused, _ = self.check(thread(edited, DEFER)) + self.assertIn("edited after the review posted it", refused[0]) def test_threads_without_a_category_pass_with_a_notice(self): rabbit = thread(comment(CODERABBIT, "_Potential issue_ | **Major** Record the uppercase DBF sidecar."), DEFER) person = thread(reply("Should this clamp?", author="maintainer"), DEFER) old_review = thread(finding("**Bug risk (low):** every non-I/O record error is counted."), DEFER) - flagged, unclassified = self.check(rabbit, person, old_review) - self.assertEqual(flagged, []) + refused, unclassified = self.check(rabbit, person, old_review) + self.assertEqual(refused, []) self.assertEqual(len(unclassified), 3) def test_a_marker_in_the_opening_comment_is_not_a_deferral(self): diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6a863d004..2358fb980c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -292,10 +292,9 @@ jobs: - name: Count direct row uses run: cargo run --locked -q -p xtask -- rows - # Warns when a review point left for the release quality pass isn't a quality point - # (.github/scripts/review-deferrals.py); it never fails for one, so `Tests pass` doesn't need it. - # The merge queue's run sees replies posted after the last push. It runs the checkout with a - # read-only token and no secrets, like every job here. + # A review point left for the release quality pass must be a quality point + # (.github/scripts/review-deferrals.py). The merge queue's run sees replies posted after the last + # push. It runs the checkout with a read-only token and no secrets, like every job here. deferrals: name: Review deferrals runs-on: ubuntu-latest @@ -308,7 +307,7 @@ jobs: persist-credentials: false - name: Test the check run: python3 -m unittest discover -s .github/scripts -p 'test_review_deferrals.py' - - name: Warn about defects left for the release quality pass + - name: No defect left for the release quality pass if: github.event_name == 'pull_request' || github.event_name == 'merge_group' env: GH_TOKEN: ${{ github.token }} @@ -419,7 +418,7 @@ jobs: # unless their conditions below hold (the same as on the jobs), and every other job always runs. tests_pass: name: Tests pass - needs: [lint, wasm, ios, android, licenses, schema, rows, plan, select, test] + needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, plan, select, test] if: ${{ always() }} runs-on: ubuntu-latest steps: diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index 743c844b56..bc27600e3d 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -499,7 +499,7 @@ jobs: Post specific findings as inline review comments on the relevant lines using the create_inline_comment tool. For each comment, briefly explain the issue and, when the fix is small and self-contained, include a committable suggestion block. Group minor nits together rather than posting many separate inline comments. - End every inline comment with its category, on a line of its own, as one of ``, ``, ``, `` or ``, the same groups as the summary. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one marker, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category says what may wait: CI warns about a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. + End every inline comment with its category, on a line of its own, as one of ``, ``, ``, `` or ``, the same groups as the summary. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one marker, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category decides what may wait: CI refuses a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. After posting inline comments, end your run by writing the summary as your FINAL MESSAGE. Do not try to post it yourself — you have no tool that can, and a workflow step publishes your final message as the PR comment verbatim. So your final message must be the comment body and nothing else: no preamble, no "I've completed the review", no meta-commentary about the tools you used. diff --git a/AGENTS.md b/AGENTS.md index 9c082b9a96..4050655445 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -177,9 +177,10 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. release. Reply that it's left for the release quality pass, end the reply with ``, and leave it out of the next push. - The Claude review ends each inline finding with its category (``). - CI's `Review deferrals` job warns, on each push and in the merge queue, when the marker answers - a `bug`, `security` or `agents-md` finding, or one edited since it was posted. It doesn't block - the merge: read its warnings before merging. + CI's `Review deferrals` job fails, on each push and in the merge queue, when the marker answers + a `bug`, `security` or `agents-md` finding, or one edited since it was posted. A maintainer + overrides it for one finding by replying `` in its thread; agents + never post that reply. ## Looking at the app - `cargo run --release -p rustgis` (opens the World Atlas sample). diff --git a/docs/contributing.md b/docs/contributing.md index 1b7235edc4..3ed38f8b66 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -41,10 +41,12 @@ the marker. The Claude review gives each inline comment a hidden category (bug, security, performance, quality or AGENTS.md). CI's **Review deferrals** check, which runs on each push and again in the -merge queue, warns when a reply leaves a bug, security or AGENTS.md finding for the release quality -pass. It doesn't block the merge; whoever merges reads the warnings first. If the review -misclassified a finding, say so in its thread. Comments from other reviewers carry no category, so -the check only lists them: those reviewers answer the reply themselves. +merge queue, fails when a reply leaves a bug, security or AGENTS.md finding for the release quality +pass. A maintainer can override it for one finding, because the review misclassified it or because +it can wait all the same, by replying in its thread with `` and running +the check again. The pull request's author may be that maintainer. Comments from +other reviewers carry no category, so the check lets them through: those reviewers answer the +reply themselves. Changes to saved or generated output must classify each new owning field: address, executable parameters, generated text or user data. Use the shared durable-output transaction and keep From ab284adbb87c01b50e2a4bf924c4412929966e71 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:35:45 -0600 Subject: [PATCH 4/9] ci: a visible category line, and the deferral marker must end the reply The review's inline-comment tool strips HTML comments, so a hidden category never reached the thread. A mention of the marker mid-reply is no deferral. The docs say who counts as a maintainer for the override. --- .github/scripts/review-deferrals.py | 13 ++++++++----- .github/scripts/test_review_deferrals.py | 14 ++++++++++++-- .github/workflows/claude-code-review.yml | 2 +- AGENTS.md | 2 +- docs/contributing.md | 7 ++++--- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index 47ef7b35b1..92247eddd1 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -3,7 +3,7 @@ A review point may wait for the release quality pass when the reply to it ends with ``, but only a quality point may (AGENTS.md, "Review comments"). The Claude review (claude-code-review.yml, posting as github-actions) ends each inline finding with its -category, `` and so on, so the reviewer classifies a finding and the +category, a last line `Category: bug` and so on, so the reviewer classifies a finding and the author doesn't. This check refuses a deferral reply in a thread that the reviewer opened with a `bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited. @@ -11,7 +11,8 @@ category and are let through: a reviewer there can answer the reply. They are listed in a notice. A maintainer overrides the check for a finding, misclassified or accepted as it is, by replying in -its thread with ``. The pull request's author may be that maintainer: the +its thread with ``. A maintainer here is the repository's owner, a member +of its organization or a collaborator, as GitHub labels the reply. The author may be that maintainer: the override is a deliberate, recorded decision, not a second opinion. CI runs this on each push and again in the merge queue, which sees replies posted after the last @@ -25,9 +26,11 @@ import subprocess import sys -DEFER = "" +# The marker ends the reply; only other hidden comments (a tool's own bookkeeping) may follow it. +DEFER = re.compile(r"(?:\s|)*\Z", re.S) APPROVE = "" -CATEGORY = re.compile(r"") +# Visible text on a line of its own: the review's inline-comment tool strips hidden comments. +CATEGORY = re.compile(r"^Category:[ \t]*([a-z-]+)[ \t]*$", re.M) MUST_FIX = {"bug", "security", "agents-md"} REVIEWER = "github-actions" MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} @@ -97,7 +100,7 @@ def check(threads): if not comments: continue opening, replies = comments[0], comments[1:] - deferral = next((r for r in replies if DEFER in (r.get("body") or "")), None) + deferral = next((r for r in replies if DEFER.search(r.get("body") or "")), None) if deferral is None: continue where = f"{thread.get('path')}:{thread.get('line') or thread.get('originalLine') or '?'}" diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index d4e09aca76..53858847f9 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -30,7 +30,7 @@ def thread(*comments, path="crates/data/src/dbf.rs"): def finding(text, kind=None, editor=None): - marker = f"\n\n" if kind else "" + marker = f"\n\nCategory: {kind}" if kind else "" return comment(REVIEWER, text + marker, editor=editor) @@ -61,7 +61,7 @@ def test_an_undeferred_bug_is_not_this_checks_business(self): self.assertEqual(self.check(thread(finding(BUG, "bug"), answer)), ([], [])) def test_a_grouped_comment_takes_its_most_serious_category(self): - both = finding(BUG + "\n", "agents-md") + both = finding(BUG + "\nCategory: quality", "agents-md") refused, _ = self.check(thread(both, DEFER)) self.assertIn("classed it as agents-md", refused[0]) @@ -86,6 +86,16 @@ def test_threads_without_a_category_pass_with_a_notice(self): self.assertEqual(refused, []) self.assertEqual(len(unclassified), 3) + def test_the_marker_ends_the_reply_apart_from_other_hidden_comments(self): + mention = reply("No here; fixed in this push.") + tracked = reply("Left for the release quality pass. \n\n") + self.assertEqual(self.check(thread(finding(BUG, "bug"), mention)), ([], [])) + self.assertEqual(len(self.check(thread(finding(BUG, "bug"), tracked))[0]), 1) + + def test_a_category_is_a_line_of_its_own(self): + prose = finding("The Category: bug label in the legend is cut short.\n\nCategory: quality") + self.assertEqual(self.check(thread(prose, DEFER)), ([], [])) + def test_a_marker_in_the_opening_comment_is_not_a_deferral(self): self.assertEqual(self.check(thread(finding(BUG + " ", "bug"))), ([], [])) diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index bc27600e3d..a0e53ea832 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -499,7 +499,7 @@ jobs: Post specific findings as inline review comments on the relevant lines using the create_inline_comment tool. For each comment, briefly explain the issue and, when the fix is small and self-contained, include a committable suggestion block. Group minor nits together rather than posting many separate inline comments. - End every inline comment with its category, on a line of its own, as one of ``, ``, ``, `` or ``, the same groups as the summary. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one marker, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category decides what may wait: CI refuses a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. + End every inline comment with its category as the last line, on a line of its own, as one of `Category: bug`, `Category: security`, `Category: performance`, `Category: quality` or `Category: agents-md`, the same groups as the summary. Write it as plain visible text: the comment tool removes hidden HTML comments. `bug` is wrong results, crashes and lost or corrupted data; `agents-md` is a break of a rule in `pr-context/AGENTS.md`; `quality` is style, naming, wording, a refactor or an extra test for code that works. Give a comment one category line, the most serious of what it holds (bug, security, agents-md, performance, quality), and post a bug on its own rather than among nits. The category decides what may wait: CI refuses a reply that leaves a bug, security or agents-md finding for the release quality pass, so classify by what the finding is, neither softening a defect into quality nor raising a quality point to a bug. After posting inline comments, end your run by writing the summary as your FINAL MESSAGE. Do not try to post it yourself — you have no tool that can, and a workflow step publishes your final message as the PR comment verbatim. So your final message must be the comment body and nothing else: no preamble, no "I've completed the review", no meta-commentary about the tools you used. diff --git a/AGENTS.md b/AGENTS.md index 4050655445..701b38350e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -176,7 +176,7 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. wait for the **release quality pass**, where maintainers handle them together before each release. Reply that it's left for the release quality pass, end the reply with ``, and leave it out of the next push. -- The Claude review ends each inline finding with its category (``). +- The Claude review ends each inline finding with its category (a last line such as `Category: bug`). CI's `Review deferrals` job fails, on each push and in the merge queue, when the marker answers a `bug`, `security` or `agents-md` finding, or one edited since it was posted. A maintainer overrides it for one finding by replying `` in its thread; agents diff --git a/docs/contributing.md b/docs/contributing.md index 3ed38f8b66..5dbc10ff5e 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -39,12 +39,13 @@ the input that triggers it is rare, the fix needs a wider change or earlier code defect too large for the pull request gets an issue, filed and linked from the reply, instead of the marker. -The Claude review gives each inline comment a hidden category (bug, security, performance, -quality or AGENTS.md). CI's **Review deferrals** check, which runs on each push and again in the +The Claude review ends each inline comment with its category (`Category: bug`, security, +performance, quality or agents-md). CI's **Review deferrals** check, which runs on each push and again in the merge queue, fails when a reply leaves a bug, security or AGENTS.md finding for the release quality pass. A maintainer can override it for one finding, because the review misclassified it or because it can wait all the same, by replying in its thread with `` and running -the check again. The pull request's author may be that maintainer. Comments from +the check again. A maintainer here is the repository's owner, a member of its organization or a +collaborator, and the pull request's author may be that maintainer. Comments from other reviewers carry no category, so the check lets them through: those reviewers answer the reply themselves. From 54d05b8f6c35bde5d5f648d6020fc7342c7b2def Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:43:59 -0600 Subject: [PATCH 5/9] ci: read the deferral marker in linear time and accept a formatted category line The marker pattern backtracked exponentially over hidden comments. A category written with emphasis, code marks or capitals now counts. gh's stderr reaches the job log. The two rules move from AGENTS.md to the pull request's suggested additions, leaving the check's line. --- .github/scripts/review-deferrals.py | 24 ++++++++++++++++++------ .github/scripts/test_review_deferrals.py | 13 +++++++++++++ AGENTS.md | 7 ++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index 92247eddd1..1101221a13 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -9,6 +9,11 @@ Threads opened by anyone else (CodeRabbit, people) or by a review from before categories carry no category and are let through: a reviewer there can answer the reply. They are listed in a notice. +An edited review finding is refused whatever category it now shows, since the edit may have +removed or changed it; the override below settles a harmless edit. + +`performance` is left out on purpose: a faster path may wait. A performance finding that is also a +crash path or breaks "Size for real data" carries `bug` or `agents-md`, the more serious category. A maintainer overrides the check for a finding, misclassified or accepted as it is, by replying in its thread with ``. A maintainer here is the repository's owner, a member @@ -26,11 +31,12 @@ import subprocess import sys -# The marker ends the reply; only other hidden comments (a tool's own bookkeeping) may follow it. -DEFER = re.compile(r"(?:\s|)*\Z", re.S) +DEFER = "" +HIDDEN = re.compile(r"", re.S) APPROVE = "" # Visible text on a line of its own: the review's inline-comment tool strips hidden comments. -CATEGORY = re.compile(r"^Category:[ \t]*([a-z-]+)[ \t]*$", re.M) +# Markdown emphasis and code marks around the label or the value, and capitals, are let through. +CATEGORY = re.compile(r"^[*_`]*Category[*_`]*:[*_` \t]*([A-Za-z-]+)[*_`]*[ \t]*$", re.M) MUST_FIX = {"bug", "security", "agents-md"} REVIEWER = "github-actions" MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} @@ -67,11 +73,17 @@ def category(opening): """The category a reviewer finding gives itself: the most serious of its markers, or None.""" if not is_reviewer(opening): return None - found = CATEGORY.findall(opening.get("body") or "") + found = [c.lower() for c in CATEGORY.findall(opening.get("body") or "")] serious = [c for c in found if c in MUST_FIX] return (serious or found or [None])[0] +def defers(reply): + """Whether a reply ends with the deferral marker; only other hidden comments (a tool's bookkeeping) may follow it.""" + _, marker, after = (reply.get("body") or "").rpartition(DEFER) + return bool(marker) and not HIDDEN.sub("", after).strip() + + def edited_by_someone_else(opening): """Whether a human or other account edited the reviewer's comment, which may have changed its category.""" if not opening.get("lastEditedAt"): @@ -100,7 +112,7 @@ def check(threads): if not comments: continue opening, replies = comments[0], comments[1:] - deferral = next((r for r in replies if DEFER.search(r.get("body") or "")), None) + deferral = next((r for r in replies if defers(r)), None) if deferral is None: continue where = f"{thread.get('path')}:{thread.get('line') or thread.get('originalLine') or '?'}" @@ -126,7 +138,7 @@ def graphql(query, **variables): args = ["gh", "api", "graphql", "-f", f"query={query}"] for key, value in variables.items(): args += ["-F" if isinstance(value, int) else "-f", f"{key}={value}"] - out = subprocess.run(args, check=True, capture_output=True, text=True).stdout + out = subprocess.run(args, check=True, stdout=subprocess.PIPE, text=True).stdout return json.loads(out)["data"] diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index 53858847f9..c6b95bddb3 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -92,6 +92,19 @@ def test_the_marker_ends_the_reply_apart_from_other_hidden_comments(self): self.assertEqual(self.check(thread(finding(BUG, "bug"), mention)), ([], [])) self.assertEqual(len(self.check(thread(finding(BUG, "bug"), tracked))[0]), 1) + def test_many_hidden_comments_after_the_marker_are_read_in_linear_time(self): + crowded = reply("Left. " + "" * 5000 + "x") + self.assertEqual(self.check(thread(finding(BUG, "bug"), crowded)), ([], [])) + + def test_a_category_line_may_be_emphasised_or_capitalised(self): + for line in ("**Category:** bug", "Category: `bug`", "Category: Bug", "_Category_: BUG"): + refused, _ = self.check(thread(comment(REVIEWER, BUG + "\n\n" + line), DEFER)) + self.assertEqual(len(refused), 1, line) + + def test_an_edited_finding_without_a_category_is_refused_too(self): + refused, unclassified = self.check(thread(finding(BUG, editor=AUTHOR), DEFER)) + self.assertEqual((len(refused), unclassified), (1, [])) + def test_a_category_is_a_line_of_its_own(self): prose = finding("The Category: bug label in the legend is cut short.\n\nCategory: quality") self.assertEqual(self.check(thread(prose, DEFER)), ([], [])) diff --git a/AGENTS.md b/AGENTS.md index 701b38350e..15ba62cbb0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -169,9 +169,7 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. ## Review comments - Fix in the pull request what a review finds wrong: bugs, crash paths, silent data loss, a broken - rule from this file. None of these makes a defect a quality point: it predates the pull request, - the input is rare, the fix needs a wider change, earlier code does the same. A defect too large - for the pull request gets an issue, filed and linked from the reply, not the marker below. + rule from this file. - A quality point (style, naming, wording, a refactor, an extra test for code that works) may wait for the **release quality pass**, where maintainers handle them together before each release. Reply that it's left for the release quality pass, end the reply with @@ -179,8 +177,7 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. - The Claude review ends each inline finding with its category (a last line such as `Category: bug`). CI's `Review deferrals` job fails, on each push and in the merge queue, when the marker answers a `bug`, `security` or `agents-md` finding, or one edited since it was posted. A maintainer - overrides it for one finding by replying `` in its thread; agents - never post that reply. + overrides it for one finding by replying `` in its thread. ## Looking at the app - `cargo run --release -p rustgis` (opens the World Atlas sample). From 59a6c1c3070c030c97d557ee95bb593449933df2 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:47:24 -0600 Subject: [PATCH 6/9] ci: the override marker must end its reply, like the deferral marker --- .github/scripts/review-deferrals.py | 12 ++++++------ .github/scripts/test_review_deferrals.py | 3 ++- AGENTS.md | 2 +- docs/contributing.md | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index 1101221a13..5f7651a55f 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -78,10 +78,10 @@ def category(opening): return (serious or found or [None])[0] -def defers(reply): - """Whether a reply ends with the deferral marker; only other hidden comments (a tool's bookkeeping) may follow it.""" - _, marker, after = (reply.get("body") or "").rpartition(DEFER) - return bool(marker) and not HIDDEN.sub("", after).strip() +def ends_with(reply, marker): + """Whether a reply ends with a marker; only other hidden comments (a tool's bookkeeping) may follow it.""" + _, found, after = (reply.get("body") or "").rpartition(marker) + return bool(found) and not HIDDEN.sub("", after).strip() def edited_by_someone_else(opening): @@ -96,7 +96,7 @@ def approved(replies): for reply in replies: author = reply.get("author") or {} if ( - APPROVE in (reply.get("body") or "") + ends_with(reply, APPROVE) and author.get("__typename") != "Bot" and reply.get("authorAssociation") in MAINTAINERS ): @@ -112,7 +112,7 @@ def check(threads): if not comments: continue opening, replies = comments[0], comments[1:] - deferral = next((r for r in replies if defers(r)), None) + deferral = next((r for r in replies if ends_with(r, DEFER)), None) if deferral is None: continue where = f"{thread.get('path')}:{thread.get('line') or thread.get('originalLine') or '?'}" diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index c6b95bddb3..28ba12eb3c 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -70,7 +70,8 @@ def test_only_a_maintainer_overrides_the_check(self): by_contributor = reply("Misclassified. ", association="CONTRIBUTOR") by_bot = comment(CODERABBIT, "", "MEMBER") by_maintainer_author = reply("An extra test for working code. ") - self.assertEqual(len(self.check(thread(rule, DEFER, by_contributor, by_bot))[0]), 1) + mention = reply("I won't reply `` to this one.") + self.assertEqual(len(self.check(thread(rule, DEFER, by_contributor, by_bot, mention))[0]), 1) self.assertEqual(self.check(thread(rule, DEFER, by_maintainer_author)), ([], [])) def test_an_edited_finding_counts_as_must_fix(self): diff --git a/AGENTS.md b/AGENTS.md index 15ba62cbb0..e88446c6f3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -177,7 +177,7 @@ immediately; label-gated build jobs in `ci.yml` start from the next push. - The Claude review ends each inline finding with its category (a last line such as `Category: bug`). CI's `Review deferrals` job fails, on each push and in the merge queue, when the marker answers a `bug`, `security` or `agents-md` finding, or one edited since it was posted. A maintainer - overrides it for one finding by replying `` in its thread. + overrides it for one finding by ending a reply in its thread with ``. ## Looking at the app - `cargo run --release -p rustgis` (opens the World Atlas sample). diff --git a/docs/contributing.md b/docs/contributing.md index 5dbc10ff5e..9943bf1df1 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -43,7 +43,7 @@ The Claude review ends each inline comment with its category (`Category: bug`, s performance, quality or agents-md). CI's **Review deferrals** check, which runs on each push and again in the merge queue, fails when a reply leaves a bug, security or AGENTS.md finding for the release quality pass. A maintainer can override it for one finding, because the review misclassified it or because -it can wait all the same, by replying in its thread with `` and running +it can wait all the same, by ending a reply in its thread with `` and running the check again. A maintainer here is the repository's owner, a member of its organization or a collaborator, and the pull request's author may be that maintainer. Comments from other reviewers carry no category, so the check lets them through: those reviewers answer the From 6cf9a127f0fd824144504d62faba2d2a419b1312 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:49:56 -0600 Subject: [PATCH 7/9] ci: the deferral marker counts wherever it sits, as the release quality pass collects it Text after the marker let a deferral past the check while the pass still collected it. With no comment stripping left there is no pattern to run slowly. The override must still end its reply. --- .github/scripts/review-deferrals.py | 19 ++++++++----------- .github/scripts/test_review_deferrals.py | 14 +++++--------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index 5f7651a55f..3a36834a59 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -15,6 +15,10 @@ `performance` is left out on purpose: a faster path may wait. A performance finding that is also a crash path or breaks "Size for real data" carries `bug` or `agents-md`, the more serious category. +Both markers err towards refusing. The deferral marker counts wherever it sits in a reply, as the +release quality pass collects it, so a reply that only mentions it is refused too: reword it. The +override counts only when it ends its reply, so a mention doesn't approve. + A maintainer overrides the check for a finding, misclassified or accepted as it is, by replying in its thread with ``. A maintainer here is the repository's owner, a member of its organization or a collaborator, as GitHub labels the reply. The author may be that maintainer: the @@ -32,11 +36,10 @@ import sys DEFER = "" -HIDDEN = re.compile(r"", re.S) APPROVE = "" # Visible text on a line of its own: the review's inline-comment tool strips hidden comments. # Markdown emphasis and code marks around the label or the value, and capitals, are let through. -CATEGORY = re.compile(r"^[*_`]*Category[*_`]*:[*_` \t]*([A-Za-z-]+)[*_`]*[ \t]*$", re.M) +CATEGORY = re.compile(r"^[*_`]*Category[*_`]*:[*_` \t]*([A-Za-z-]+)[*_`]*\.?[ \t\r]*$", re.M) MUST_FIX = {"bug", "security", "agents-md"} REVIEWER = "github-actions" MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} @@ -78,12 +81,6 @@ def category(opening): return (serious or found or [None])[0] -def ends_with(reply, marker): - """Whether a reply ends with a marker; only other hidden comments (a tool's bookkeeping) may follow it.""" - _, found, after = (reply.get("body") or "").rpartition(marker) - return bool(found) and not HIDDEN.sub("", after).strip() - - def edited_by_someone_else(opening): """Whether a human or other account edited the reviewer's comment, which may have changed its category.""" if not opening.get("lastEditedAt"): @@ -96,7 +93,7 @@ def approved(replies): for reply in replies: author = reply.get("author") or {} if ( - ends_with(reply, APPROVE) + (reply.get("body") or "").rstrip().endswith(APPROVE) and author.get("__typename") != "Bot" and reply.get("authorAssociation") in MAINTAINERS ): @@ -112,7 +109,7 @@ def check(threads): if not comments: continue opening, replies = comments[0], comments[1:] - deferral = next((r for r in replies if ends_with(r, DEFER)), None) + deferral = next((r for r in replies if DEFER in (r.get("body") or "")), None) if deferral is None: continue where = f"{thread.get('path')}:{thread.get('line') or thread.get('originalLine') or '?'}" @@ -138,7 +135,7 @@ def graphql(query, **variables): args = ["gh", "api", "graphql", "-f", f"query={query}"] for key, value in variables.items(): args += ["-F" if isinstance(value, int) else "-f", f"{key}={value}"] - out = subprocess.run(args, check=True, stdout=subprocess.PIPE, text=True).stdout + out = subprocess.run(args, check=True, stdout=subprocess.PIPE, text=True, timeout=120).stdout return json.loads(out)["data"] diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index 28ba12eb3c..24ac006594 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -87,18 +87,14 @@ def test_threads_without_a_category_pass_with_a_notice(self): self.assertEqual(refused, []) self.assertEqual(len(unclassified), 3) - def test_the_marker_ends_the_reply_apart_from_other_hidden_comments(self): - mention = reply("No here; fixed in this push.") + def test_the_marker_counts_wherever_it_sits_as_the_sweep_collects_it(self): + trailing = reply("Left for the release quality pass. Will do after the merge.") tracked = reply("Left for the release quality pass. \n\n") - self.assertEqual(self.check(thread(finding(BUG, "bug"), mention)), ([], [])) - self.assertEqual(len(self.check(thread(finding(BUG, "bug"), tracked))[0]), 1) - - def test_many_hidden_comments_after_the_marker_are_read_in_linear_time(self): - crowded = reply("Left. " + "" * 5000 + "x") - self.assertEqual(self.check(thread(finding(BUG, "bug"), crowded)), ([], [])) + for deferral in (trailing, tracked): + self.assertEqual(len(self.check(thread(finding(BUG, "bug"), deferral))[0]), 1) def test_a_category_line_may_be_emphasised_or_capitalised(self): - for line in ("**Category:** bug", "Category: `bug`", "Category: Bug", "_Category_: BUG"): + for line in ("**Category:** bug", "Category: `bug`", "Category: Bug", "_Category_: BUG", "Category: bug.", "Category: bug\r"): refused, _ = self.check(thread(comment(REVIEWER, BUG + "\n\n" + line), DEFER)) self.assertEqual(len(refused), 1, line) From 72c71ffbe17bbbf1dd12498fec1486d2d08c4e13 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:56:00 -0600 Subject: [PATCH 8/9] ci: an unknown category word is no category, and the check's tests run once --- .github/scripts/review-deferrals.py | 2 ++ .github/scripts/test_review_deferrals.py | 5 +++-- .github/workflows/ci.yml | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/scripts/review-deferrals.py b/.github/scripts/review-deferrals.py index 3a36834a59..92e4168a09 100644 --- a/.github/scripts/review-deferrals.py +++ b/.github/scripts/review-deferrals.py @@ -41,6 +41,7 @@ # Markdown emphasis and code marks around the label or the value, and capitals, are let through. CATEGORY = re.compile(r"^[*_`]*Category[*_`]*:[*_` \t]*([A-Za-z-]+)[*_`]*\.?[ \t\r]*$", re.M) MUST_FIX = {"bug", "security", "agents-md"} +MAY_WAIT = {"performance", "quality"} REVIEWER = "github-actions" MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"} QUEUE_REF = re.compile(r"/pr-(\d+)-[0-9a-f]{40}$") @@ -77,6 +78,7 @@ def category(opening): if not is_reviewer(opening): return None found = [c.lower() for c in CATEGORY.findall(opening.get("body") or "")] + found = [c for c in found if c in MUST_FIX | MAY_WAIT] # an unknown word is no category serious = [c for c in found if c in MUST_FIX] return (serious or found or [None])[0] diff --git a/.github/scripts/test_review_deferrals.py b/.github/scripts/test_review_deferrals.py index 24ac006594..53d16125ef 100644 --- a/.github/scripts/test_review_deferrals.py +++ b/.github/scripts/test_review_deferrals.py @@ -83,9 +83,10 @@ def test_threads_without_a_category_pass_with_a_notice(self): rabbit = thread(comment(CODERABBIT, "_Potential issue_ | **Major** Record the uppercase DBF sidecar."), DEFER) person = thread(reply("Should this clamp?", author="maintainer"), DEFER) old_review = thread(finding("**Bug risk (low):** every non-I/O record error is counted."), DEFER) - refused, unclassified = self.check(rabbit, person, old_review) + unknown = thread(finding(BUG, "bugs"), DEFER) + refused, unclassified = self.check(rabbit, person, old_review, unknown) self.assertEqual(refused, []) - self.assertEqual(len(unclassified), 3) + self.assertEqual(len(unclassified), 4) def test_the_marker_counts_wherever_it_sits_as_the_sweep_collects_it(self): trailing = reply("Left for the release quality pass. Will do after the merge.") diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2358fb980c..ab900db48a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -305,8 +305,6 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - - name: Test the check - run: python3 -m unittest discover -s .github/scripts -p 'test_review_deferrals.py' - name: No defect left for the release quality pass if: github.event_name == 'pull_request' || github.event_name == 'merge_group' env: From aee6a1703d58828a9843032fad0f9ff47320ef5b Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:59:54 -0600 Subject: [PATCH 9/9] ci: a change to the deferrals script alone runs its tests; the docs say what an override records --- .github/workflows/ci.yml | 2 +- docs/contributing.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab900db48a..902ecf4082 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -177,7 +177,7 @@ jobs: echo "run=true" >> "$GITHUB_OUTPUT" exit 0 fi - if grep -qE '^(Cargo\.lock|(.*/)?Cargo\.toml|deny\.toml|about\.toml|xtask/src/(main|notices)\.rs|(.*/)?THIRD-PARTY-LICENSES\.txt|\.github/scripts/(check-cargo-sources|test_[^/]+)\.py|\.github/workflows/ci\.yml|crates/map/src/color/(scientific|matplotlib)\.rs|crates/tiles/src/(symbols|style)\.rs|crates/data/src/(raster/crs|esripbf)\.rs)$|^(third-party/|\.cargo/)' <<<"$changed"; then + if grep -qE '^(Cargo\.lock|(.*/)?Cargo\.toml|deny\.toml|about\.toml|xtask/src/(main|notices)\.rs|(.*/)?THIRD-PARTY-LICENSES\.txt|\.github/scripts/(check-cargo-sources|review-deferrals|test_[^/]+)\.py|\.github/workflows/ci\.yml|crates/map/src/color/(scientific|matplotlib)\.rs|crates/tiles/src/(symbols|style)\.rs|crates/data/src/(raster/crs|esripbf)\.rs)$|^(third-party/|\.cargo/)' <<<"$changed"; then echo "run=true" >> "$GITHUB_OUTPUT" else echo "No dependency, licence or notice files changed; skipping." diff --git a/docs/contributing.md b/docs/contributing.md index 9943bf1df1..755fe0030e 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -42,9 +42,9 @@ the marker. The Claude review ends each inline comment with its category (`Category: bug`, security, performance, quality or agents-md). CI's **Review deferrals** check, which runs on each push and again in the merge queue, fails when a reply leaves a bug, security or AGENTS.md finding for the release quality -pass. A maintainer can override it for one finding, because the review misclassified it or because -it can wait all the same, by ending a reply in its thread with `` and running -the check again. A maintainer here is the repository's owner, a member of its organization or a +pass. A maintainer can override it for one finding by ending a reply in its thread with +`` and running the check again. The override isn't a reason: it records +that a maintainer accepts the finding for the release quality pass, or judges it misclassified. A maintainer here is the repository's owner, a member of its organization or a collaborator, and the pull request's author may be that maintainer. Comments from other reviewers carry no category, so the check lets them through: those reviewers answer the reply themselves.