Stacked PR Planning Now Requires Same-Repository Branch Ownership
My PR delivery planner resolves a stacked pull request by looking for the pull that owns its base branch, and until this push it accepted any pull whose branch name matched. That meant a fork with a coincidentally named branch could stand in for the real parent. This change makes ownership explicit: a branch counts as stacked only when an open pull in this repository owns it, with merge history as the fallback.
How the stacked base lookup changed in pr-delivery.py
I extracted the ownership test into a single helper, repository_branch_pulls, which keeps a pull only when its head ref equals the target branch and its head repository is this repository. Both call sites now use it. The dependencies function resolves a stacked parent through the helper, so the same-repository rule that already applied mid-stack now applies everywhere. The live_snapshot path previously short-circuited on a bare branch-name match across all open pulls; it now asks the helper, and when no open pull in the repository owns the branch it falls back to paginated history and filters those candidates with the identical function. That symmetry is the point: the open and historical lookups can no longer disagree about what qualifies as the parent.
What the synthetic stack test establishes about fork collisions
The new inspect_stack case in scripts/ci/pr-delivery-test.py builds a three-pull stack: a parent, a child whose base is the parent’s branch, and a fork pull that reuses that branch name from a different repository. It asserts that the history lookup is issued with an explicit head filter scoped to this repository, and it counts the lookups so a silent extra call would be visible. What this establishes is the planner’s behavior under synthetic API responses, not a live run against the real pull list. The pending check is to plan an actual stacked branch and confirm the parent chosen matches the one the helper would pick. I am treating the merged logic and the passing synthetic case as evidence about the resolver, not as proof that a real stack resolves correctly end to end.
Documenting the same-repository rule alongside the code
I updated docs/pr-delivery.md to state that the planner matches pulls that own the base branch in this repository, and that it consults history when no open pull owns the branch, including the case where a fork holds an open pull with the same branch name. The agent workflow note now says the planner resolves stacked base branches through same-repository open pulls or their merge history. Writing the rule down next to the change matters because the failure mode was invisible: the planner produced a plausible plan from the wrong parent rather than erroring.
Where same-repository branch ownership matters for a platform team
A team running stacked changes through a planner of this kind hits the same ambiguity as soon as contributors work from forks. Any tool that infers dependency order from branch names alone is trusting a namespace it does not control. The technique here is small and portable: reduce the ownership predicate to one function, require both the ref and the repository to match, and reuse that function for both live and historical lookups so a fallback path cannot quietly relax the check. A team could apply it when a stacked-branch automation starts misordering changes, or before the first external contributor arrives.