Skip to content

pr_review.py's out-of-scope refusal names "this checkout" when it means the script's own directory #1557

Closed

Description

@ptr727

scripts/pr_review.py refuses a write it cannot scope with a message naming the wrong directory, so an operator reads it as a problem with the checkout they are standing in rather than with where the script itself sits.

The behavior

origin_owner() resolves the owner a write may target from the script file's own directory, which is deliberate and its docstring says why: the helper is reached from a hub checkout while the repository being answered is named on the command line, so the working directory says nothing about who owns either. That part is right and is not what this issue asks to change.

At main (6e859734ddd159a4718a420e5762ae1db73722e2):

# scripts/pr_review.py:1994
    try:
        url = subprocess.run(
            ["git", "-C", str(Path(__file__).resolve().parent), "remote", "get-url", "origin"],
# scripts/pr_review.py:2022
    origin = origin_owner()
    if origin is None:
        return False, (
            "this checkout has no readable `origin`, so the owner a write would stay "
            "within cannot be established, and an unverified scope is not a scope"
        )

The lookup reads Path(__file__).resolve().parent. The message says "this checkout", which an operator reads as the working directory, because that is the checkout they are in and the one the command is about.

Why that costs a round

The two facts the reader needs are that the anchor is the script's directory and that the fix is to run the script from a hub checkout. The message states neither, and the state it describes ("no readable origin") is one the operator can immediately disprove in the directory they are actually standing in:

mkdir -p /tmp/scratch && cp <hub-checkout>/scripts/pr_review.py /tmp/scratch/
cd <a checkout of ptr727/ExampleRepo>
python3 /tmp/scratch/pr_review.py reply 1 --repo ptr727/ExampleRepo \
  --match "some words from the finding" --body "Fixed in abc1234: summary." --resolve
# status=OUT_OF_SCOPE nothing was written: this checkout has no readable `origin`, ...

git remote get-url origin
# https://github.com/ptr727/ExampleRepo.git

The refusal and the git command disagree, and nothing on screen explains why. A copy outside any checkout is the ordinary way to reach this: the helper is hub-hosted rather than carried, so a session working a downstream repository has to fetch it from somewhere, and copying the single file it needs is the obvious move.

Encountered live rather than constructed: a session driving a pull request in a downstream repository hit this on a reply and again on a retry from a different directory, and first misdiagnosed it as the linked-worktree shape (.git as a file) that OPERATIONS.md warns about for other tools, since that also produces a tool that cannot read repository metadata. Running the helper from a hub checkout resolved it immediately. No write was lost, because the refusal is correct and writes nothing, which is the design working.

Suggested fix

Name the anchor and the remedy, and print the path that was actually probed so the message is self-diagnosing:

the directory this script sits in (/tmp/scratch) has no readable `origin`, so the owner a
write would stay within cannot be established, and an unverified scope is not a scope. This
is anchored on the script's own directory rather than the working directory, so run it from a
hub checkout rather than from a copy.

The same wording question applies to the cross-owner branch just below it, which says "this checkout is under {origin}" and means the same script-anchored checkout.

Scope

Message only. The anchoring, the refusal, and the refusal writing nothing are all correct and should stay as they are.

Activity

  1. added a commit that references this issue on Sep 12, 2026
    d49ea0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions