fix(pr-review): fleet PRs are ours by branch ownership, not author identity (#668)

With a GitHub App bound, fleet PRs are authored by <app-slug>[bot] whose
author_association is NONE — the inbound classifier's author heuristics
read that as an outsider and ingested the org's own dev-stream PR as
external_pr for adversarial review (2026-07-23 live: PR #667). The
repo-owner author check only ever covered the PAT era.

_ingest_pr_if_reviewable now skips any same-repo PR whose head branch an
active task owns BEFORE the author-based classification, and
active_task_owns_branch widens from the single polled project to every
project sharing its git_url (the poll collapses a monorepo's
cell-projects to one canonical project, so a sibling cell's ownership
must count — the same sibling scope external_review_task_exists already
uses, now shared via _repo_sibling_project_ids). A deleted-fork head
(GitHub sends head.repo=null) now classifies as fork, failing closed to
review instead of risking a silent ownership skip on a branch-name
collision. Residual, documented: an org PR whose task went terminal with
the PR left open falls through to the author heuristics.

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
Renzo F
2026-07-23 21:54:45 +02:00
committed by GitHub
co-authored by Renn F
parent a036c97985
commit f8b4a6755c
6 changed files with 187 additions and 53 deletions
@@ -104,6 +104,22 @@ async def test_list_open_prs_normalizes_and_flags_fork() -> None:
assert internal["author_is_owner"] is False
def test_normalize_deleted_fork_head_is_fork() -> None:
"""GitHub sends head.repo=null when a fork was deleted — that head is NOT
ours, so it must classify as a fork (fail-closed to review) rather than
fall into the same-repo path where a branch-name collision could skip it."""
pr = {
"number": 11,
"html_url": "https://github.com/acme/repo/pull/11",
"title": "ghost fork",
"head": {"ref": "feature-x", "sha": "cafebabe", "repo": None},
"user": {"login": "ghost"},
"author_association": "NONE",
}
out = GitService._normalize_open_pr(pr, "acme/repo")
assert out["is_fork"] is True
@pytest.mark.asyncio
async def test_list_open_prs_flags_owner_authored_pr() -> None:
"""A PR opened by the repo-owner account is flagged author_is_owner."""