Skip to content
Merged
12 changes: 9 additions & 3 deletions .agents/skills/merge-and-release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ skill covers all of it, scoped down by what the maintainer actually asks for.
--jq .headRefOid`. Then, from a hub checkout, `scripts/` is not carried into downstream repos,
run `uv run --no-project --script scripts/pr_review.py status [number] --repo owner/repo` on it and confirm the
pr-review-conduct Merge Gate. Stop and report exactly what is missing rather than merging on a
partial gate. A digest reading `coverage=none` is not a partial gate where the promotion meets the
partial gate. A digest carrying `state=MERGED` is a promotion merged since step 1 found it
open, whose `merge=UNKNOWN` never clears, so stop re-reading it. Confirm its `merge_commit=` per
step 4, run the ready-report comparison below against its `head=`, and report both. Dispatch no
release from here, since whoever merged it may have released it already. The merge has landed
all the same, so go on to step 7 where a release scope was chosen, and then step 8. A digest carrying
`state=CLOSED` is a stop to report. A digest reading `coverage=none` is not a partial gate where the promotion meets the
one case that skill's Merge Gate item 2 states. Check that case again on every re-run below, and record
its evidence for the head step 3 merges, as that item says.
Confirm the digest's `head=` is a prefix of the recorded SHA, re-running both where it is not.
Expand Down Expand Up @@ -157,8 +162,9 @@ skill covers all of it, scoped down by what the maintainer actually asks for.
`docs/host-setup.md` "Fleet Skills Install" cadence.
8. Run cleanup regardless of how steps 5 through 7 ended. No release configured, a dispatch
failure, an ambiguous run match, a timeout, a failed run, or a hub Skills refresh all still
reach this step. The merge in step 3 already landed by then. Every part below is required:
- The promotion PR's own worktree: fetch and prune, remove the worktree, then bring the base
reach this step. So does step 2 finding the promotion already merged. The merge already landed
by then, in step 3 or before step 2 read it. Every part below is required:
- The promotion PR's own worktree, where one exists: fetch and prune, remove the worktree, then bring the base
clone to current `develop`. To do so, check `develop` out first only where it sits on another
branch, and fast-forward it with `git merge --ff-only origin/develop`. Where that checkout
is needed, removing first, not after, matters. The reason is that the base clone cannot check out `develop`
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cfb35b46f54071bd
87702aa214211aee
12 changes: 9 additions & 3 deletions .claude-plugin/fleet-skills/skills/merge-and-release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ skill covers all of it, scoped down by what the maintainer actually asks for.
--jq .headRefOid`. Then, from a hub checkout, `scripts/` is not carried into downstream repos,
run `uv run --no-project --script scripts/pr_review.py status [number] --repo owner/repo` on it and confirm the
pr-review-conduct Merge Gate. Stop and report exactly what is missing rather than merging on a
partial gate. A digest reading `coverage=none` is not a partial gate where the promotion meets the
partial gate. A digest carrying `state=MERGED` is a promotion merged since step 1 found it
open, whose `merge=UNKNOWN` never clears, so stop re-reading it. Confirm its `merge_commit=` per
step 4, run the ready-report comparison below against its `head=`, and report both. Dispatch no
release from here, since whoever merged it may have released it already. The merge has landed
all the same, so go on to step 7 where a release scope was chosen, and then step 8. A digest carrying
`state=CLOSED` is a stop to report. A digest reading `coverage=none` is not a partial gate where the promotion meets the
one case that skill's Merge Gate item 2 states. Check that case again on every re-run below, and record
its evidence for the head step 3 merges, as that item says.
Confirm the digest's `head=` is a prefix of the recorded SHA, re-running both where it is not.
Expand Down Expand Up @@ -157,8 +162,9 @@ skill covers all of it, scoped down by what the maintainer actually asks for.
`docs/host-setup.md` "Fleet Skills Install" cadence.
8. Run cleanup regardless of how steps 5 through 7 ended. No release configured, a dispatch
failure, an ambiguous run match, a timeout, a failed run, or a hub Skills refresh all still
reach this step. The merge in step 3 already landed by then. Every part below is required:
- The promotion PR's own worktree: fetch and prune, remove the worktree, then bring the base
reach this step. So does step 2 finding the promotion already merged. The merge already landed
by then, in step 3 or before step 2 read it. Every part below is required:
- The promotion PR's own worktree, where one exists: fetch and prune, remove the worktree, then bring the base
clone to current `develop`. To do so, check `develop` out first only where it sits on another
branch, and fast-forward it with `git merge --ff-only origin/develop`. Where that checkout
is needed, removing first, not after, matters. The reason is that the base clone cannot check out `develop`
Expand Down
12 changes: 9 additions & 3 deletions .github/skills/merge-and-release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ skill covers all of it, scoped down by what the maintainer actually asks for.
--jq .headRefOid`. Then, from a hub checkout, `scripts/` is not carried into downstream repos,
run `uv run --no-project --script scripts/pr_review.py status [number] --repo owner/repo` on it and confirm the
pr-review-conduct Merge Gate. Stop and report exactly what is missing rather than merging on a
partial gate. A digest reading `coverage=none` is not a partial gate where the promotion meets the
partial gate. A digest carrying `state=MERGED` is a promotion merged since step 1 found it
open, whose `merge=UNKNOWN` never clears, so stop re-reading it. Confirm its `merge_commit=` per
step 4, run the ready-report comparison below against its `head=`, and report both. Dispatch no
release from here, since whoever merged it may have released it already. The merge has landed
all the same, so go on to step 7 where a release scope was chosen, and then step 8. A digest carrying
`state=CLOSED` is a stop to report. A digest reading `coverage=none` is not a partial gate where the promotion meets the
one case that skill's Merge Gate item 2 states. Check that case again on every re-run below, and record
its evidence for the head step 3 merges, as that item says.
Confirm the digest's `head=` is a prefix of the recorded SHA, re-running both where it is not.
Expand Down Expand Up @@ -157,8 +162,9 @@ skill covers all of it, scoped down by what the maintainer actually asks for.
`docs/host-setup.md` "Fleet Skills Install" cadence.
8. Run cleanup regardless of how steps 5 through 7 ended. No release configured, a dispatch
failure, an ambiguous run match, a timeout, a failed run, or a hub Skills refresh all still
reach this step. The merge in step 3 already landed by then. Every part below is required:
- The promotion PR's own worktree: fetch and prune, remove the worktree, then bring the base
reach this step. So does step 2 finding the promotion already merged. The merge already landed
by then, in step 3 or before step 2 read it. Every part below is required:
- The promotion PR's own worktree, where one exists: fetch and prune, remove the worktree, then bring the base
clone to current `develop`. To do so, check `develop` out first only where it sits on another
branch, and fast-forward it with `git merge --ff-only origin/develop`. Where that checkout
is needed, removing first, not after, matters. The reason is that the base clone cannot check out `develop`
Expand Down
67 changes: 47 additions & 20 deletions scripts/pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
round covering the head states beside the threads that round opened, `?` where it
states no count. A count it cannot believe reads `?` too. `FINDINGS WITH NO THREAD`
names findings the round names that no thread on the pull request carries. Each of these is owed the triage a suppressed
finding gets, and none decides an exit code.
finding gets, and none decides an exit code. On a pull request no longer open, `pr=` is
followed by `state=` with `merged_at=` and `merge_commit=`, or with `closed_at=`. Its
`merge=UNKNOWN` never clears.
reply Answer one thread selected by its text, and resolve it on request. Exists
because the hand-run form keeps failing the same way. The failure is a node id typed
into a mutation. Such an id resolves globally and so writes to a real thread somewhere
Expand Down Expand Up @@ -134,7 +136,9 @@
The bot id is read from the repository's most recently updated pull requests, the last
HISTORY_PRS, widened once to HISTORY_PRS_WIDE. Nothing is requested where neither
carries any Copilot activity. The loop runs in-process, so a 45-minute wait costs one
agent turn, not 90.
agent turn, not 90. A pull request found no longer open, on the first read or on any
poll, is neither requested nor polled further. `wait` then prints its digest and exits
as `status` does, so a 0 there says nothing about review coverage, and `state=` says why.
Exit 0 = review present, or on a held head an attested local pass whose checks no longer
hold the poll, with no thread open where the pull request is open. Exit 0 on a review
present does not poll the checks, so it does not prove the required checks ran. On an open attested held head whose commit the payload carries,
Expand Down Expand Up @@ -247,11 +251,13 @@
head_reviews,
history_entry,
holds,
is_open,
local_cover,
matching_threads,
newest_first,
newest_of,
newest_request_event,
null_node,
open_threads,
possible_quota,
quota_refusal,
Expand Down Expand Up @@ -318,7 +324,7 @@
Q_LIVE = """
query($o:String!,$r:String!,$n:Int!){
repository(owner:$o,name:$r){ pullRequest(number:$n){
id headRefOid
id headRefOid state
reviews(last:100){ nodes{ author{login} state commit{oid} submittedAt } pageInfo{ hasPreviousPage } }
comments(last:100){ nodes{ author{login} createdAt } pageInfo{ hasPreviousPage } }
reviewRequests(first:10){ nodes{ requestedReviewer{ __typename ... on Bot{login} ... on User{login} } } }
Expand Down Expand Up @@ -355,7 +361,7 @@

# The rollup rides this query and hangs off the last commit, which a case holds equal to `headRefOid`.
HELD_FIELDS = """
headRefOid baseRefName state mergeable mergeStateStatus
headRefOid baseRefName state mergeable mergeStateStatus mergedAt closedAt mergeCommit{ oid }
baseRepository{ defaultBranchRef{ name } }
reviews(last:100){ nodes{ id author{login} state commit{oid} submittedAt body } pageInfo{ hasPreviousPage } }
comments(last:100){ nodes{ author{login} authorAssociation createdAt body isMinimized } pageInfo{ hasPreviousPage } }
Expand Down Expand Up @@ -467,13 +473,26 @@ def gh_graphql(query: str, **variables) -> dict:
"""Run one GraphQL document and return its `data`, ending the run on a failed read.

The transport raises `GraphQLError` and never exits, so a failed read prints its detail and
ends the run at exit 1. Only an error set made of `workflowRun` paths is tolerated.
ends the run at exit 1. Only an error set made of `workflowRun` paths is tolerated. A response
holding a null node ends the run too, and only that case is retried first. A query is read
again on `READ_RETRY_DELAYS`, and a mutation is never sent twice.
"""
try:
response = shared.request(query, variables, tolerate=_is_workflow_run_error)
except shared.GraphQLError as exc:
sys.stderr.write(exc.detail)
raise SystemExit(str(exc)) from exc

def send() -> shared.Response:
try:
return shared.request(query, variables, tolerate=_is_workflow_run_error)
except shared.GraphQLError as exc:
sys.stderr.write(exc.detail)
raise SystemExit(str(exc)) from exc

reads = query.lstrip().startswith("query")
delays = READ_RETRY_DELAYS if reads else ()
response = backoff(send(), send, lambda r: null_node(r.data) is not None, delays=delays)
if (where := null_node(response.data)) is not None:
raise SystemExit(
f"gh graphql returned a null node GitHub could not resolve under {where}, so the "
"response is unread" + ("" if reads else ", though the write it answers was sent")
)
data = response.data
if response.tolerated:
sys.stderr.write("gh graphql: workflowRun unreadable, checks are not deduped by workflow\n")
Expand Down Expand Up @@ -781,7 +800,7 @@ def required_for(
pr: dict, owner: str, repo: str, gated: frozenset[str] = frozenset({"BLOCKED"})
) -> frozenset[tuple[str, int | None]]:
"""The required entries a merge in `gated` can be short of, empty wherever none can matter."""
if pr.get("state", "OPEN") != "OPEN" or pr.get("mergeStateStatus") not in gated:
if not is_open(pr) or pr.get("mergeStateStatus") not in gated:
return frozenset()
return required_contexts(owner, repo, pr.get("baseRefName") or "") or frozenset()

Expand Down Expand Up @@ -838,9 +857,10 @@ def liveness(pr: dict, min_rounds: int = 0) -> tuple[bool, dict | None, list[str

The three readings `wait`'s Copilot poll stops on, shared by its first evaluation and every
re-read. `Q_LIVE` carries the authors, so drift costs no extra call. A `min_rounds` of 0 reads
as `reviewed_head`.
as `reviewed_head`. A pull request no longer open reads as done, which ends the poll.
"""
return head_review_done(pr, min_rounds), answered_outside_review(pr), reviewer_login_drift(pr)
done = head_review_done(pr, min_rounds) or not is_open(pr)
return done, answered_outside_review(pr), reviewer_login_drift(pr)


def live_state(
Expand Down Expand Up @@ -1168,7 +1188,7 @@ def await_registered_head(
"""
meta = gql(Q_ATTEST_BRANCH, owner, repo, num) or {}
ref, source = meta.get("headRefName") or "", (meta.get("headRepository") or {}).get("url") or ""
if meta.get("state") != "OPEN" or not ref or not source or not safe_ref(ref):
if not is_open(meta) or not ref or not source or not safe_ref(ref):
return head, True
tip = _git(checkout, "ls-remote", source, f"refs/heads/{ref}")
if tip.returncode != 0 or tip.stdout.split()[:1] != [local]:
Expand Down Expand Up @@ -1540,6 +1560,13 @@ def utf8_console() -> None:
reconfigure(encoding="utf-8", errors="replace")


def run_status(owner: str, repo: str, a: argparse.Namespace, pr: dict | None = None) -> int:
"""Print the digest and return the verdict's code, both off one payload, read where not given."""
pr = full_read(owner, repo, a.number) if pr is None else pr
print(digest(owner, repo, a.number, pr=pr, grace=a.check_grace, stall=a.check_stall)[0])
return report_verdict(pr)


def run_wait(owner: str, repo: str, a: argparse.Namespace) -> int:
"""Request a review where one is owed, poll until it lands or the timeout, and return the code."""
# `wait` mutates through the auto-request, so a cross-owner target is refused before the read as well.
Expand All @@ -1548,6 +1575,8 @@ def run_wait(owner: str, repo: str, a: argparse.Namespace) -> int:

start = time.monotonic()
pr = gql(Q_LIVE, owner, repo, a.number)
if not is_open(pr):
return run_status(owner, repo, a)
rounds_before = len(reviewer_nodes(pr, "reviews"))
done, answer, drift = liveness(pr, a.min_rounds)
if done and a.ignore_quota_signal:
Expand Down Expand Up @@ -1699,6 +1728,8 @@ def read_live() -> tuple[bool, dict | None, list[str], bool]:

# One payload decides the digest and the exit code together, and the digest also prints at the timeout.
final = full_read(owner, repo, a.number, final)
if not is_open(final):
return run_status(owner, repo, a, final)
now = datetime.now(UTC)
# Parsed here and handed down so the digest and the exit code share one read of the rollup.
checks = check_nodes(final)
Expand Down Expand Up @@ -1732,7 +1763,7 @@ def read_live() -> tuple[bool, dict | None, list[str], bool]:
if verdict:
return verdict
opened = covered and open_on_head(owner, repo, a.number, final)
if opened and final.get("state", "OPEN") == "OPEN":
if opened:
who = ", ".join(sorted({thread_author(t) or "an unnamed author" for t in opened}))
print(
f"status=THREADS_UNRESOLVED an attested local pass covers this head, and "
Expand Down Expand Up @@ -2097,11 +2128,7 @@ def refuse_foreign(late: bool) -> None:
return comment_on_pr(owner, repo, a.number, a.body.strip() + marker)

if a.cmd == "status":
# One payload renders the digest and decides the code, as in `wait`.
pr = full_read(owner, repo, a.number)
out, _ = digest(owner, repo, a.number, pr=pr, grace=a.check_grace, stall=a.check_stall)
print(out)
return report_verdict(pr)
return run_status(owner, repo, a)

if a.cmd == "reply":
return reply_to_thread(
Expand Down
11 changes: 11 additions & 0 deletions scripts/pr_review_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
first_comment,
head_nodes,
head_reviews,
is_open,
newest_of,
open_threads,
opened_by,
Expand Down Expand Up @@ -75,6 +76,15 @@ def digest_refusal(pr: dict) -> dict | None:
return stopping_refusal(pr) or (None if head_reviews(pr) else refusing_review(pr))


def state_fields(pr: dict) -> list[tuple[str, object]]:
"""`state=` and when it changed, where the pull request is no longer open, else nothing."""
if is_open(pr):
return []
merged, commit = pr.get("mergedAt"), (pr.get("mergeCommit") or {}).get("oid")
stamp = ("merged_at", merged) if merged else ("closed_at", pr.get("closedAt"))
return [("state", pr["state"]), stamp, ("merge_commit", commit[:8] if commit else None)]


def header(fields: list[tuple[str, object]]) -> str:
"""Join each `key=value` pair by one space, leaving out a field whose value is None."""
return " ".join(f"{key}={value}" for key, value in fields if value is not None)
Expand Down Expand Up @@ -174,6 +184,7 @@ def render(
fields: list[tuple[str, object]] = [
("repo", f"{owner}/{repo}"),
("pr", num),
*state_fields(pr),
("head", head[:8]),
("rounds", len(revs)),
("review_on_head", "yes" if on_head else "local" if cover == "local" else "NO"),
Expand Down
23 changes: 23 additions & 0 deletions scripts/pr_review_rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ def reviewer_nodes(pr: dict, field: str, login: str = REVIEWER) -> list[dict]:
]


def is_open(pr: dict) -> bool:
"""True where the pull request is open, a payload naming no state read as open."""
return pr.get("state", "OPEN") == "OPEN"


def null_node(data: object, path: str = "") -> str | None:
"""The path of the first connection under `data` whose `nodes` holds a null, else None.

GraphQL can return null for a list item it could not resolve at read time, with no entry in
`errors`. Any connection can hold one, the threads and checks a gate decides on included. So
no reading off such a response can be trusted, and the response reads as unread.
"""
if isinstance(data, list):
items = [(path, value) for value in data]
elif isinstance(data, dict):
if isinstance(nodes := data.get("nodes"), list) and None in nodes:
return path or "nodes"
items = [(f"{path}.{key}".lstrip("."), value) for key, value in data.items()]
else:
return None
return next((found for key, value in items if (found := null_node(value, key))), None)


def commit_oid(node: dict) -> str | None:
"""The oid of the commit this node carries, or None where the payload names none."""
return (node.get("commit") or {}).get("oid")
Expand Down
Loading
Loading