You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(ci): drive draft pull requests to Ready behind four gates - #287
Automates the team convention — open as draft, get a Copilot review, work through every thread, promote to Ready so the code owners are asked — so that by the time CODEOWNERS are pulled in the PR is genuinely reviewable. Promotion is the signal; this makes it safe to give without a human in the loop.
Promotion is gated on all four of:
#
Gate
Passes when
1
copilot_review
a Copilot review exists whose commit_id is the head SHA
2
no_conflicts
mergeable == true
3
ci_green
every check run on the head SHA finished green
4
threads_resolved
no review thread is still open
"Unknown" is never a pass: a nullmergeable means GitHub has not finished computing it, not that the branch is clean.
The blocker, and what fixed it
Requesting a Copilot review could not be done from a restricted session. POSTing the bot to requested_reviewers returns HTTP 200 with requested_reviewers unchanged and empty — a silent no-op — and GitHub's documented GraphQL requestReviews route is unavailable where only gh api REST works.
There is a REST endpoint that does work:
POST /repos/{owner}/{repo}/pulls/{n}/copilot-code-review
{"review_effort": "max"}
Review depth is selectable. The levels are adaptive, lite, balanced, max, with balanced the default — read out of the API's own 422 by sending an invalid value, since the docs page for the levels 404s. Availability is per pull request, so the requester walks max → balanced → adaptive → lite rather than giving up.
Drafts need asking explicitly: the org ruleset Automatic Copilot code review is set with review_draft_pull_requests: false, which points the opposite way to the convention — followed literally, "open as draft → Copilot review" would wait forever.
Changes
.github/scripts/pr-gates.sh — checks all four gates; human-readable or --json; exit 0/1/2.
.github/scripts/pr-request-copilot-review.sh — requests a Copilot review at the most thorough effort available.
.github/workflows/copilot-review-drafts.yml — requests that review on drafts, which the org ruleset skips. Never fails the build, since CI being green is itself a promotion gate.
.claude/skills/pr-drive/SKILL.md — the agent loop: triage threads, answer them, decide whether to promote.
.claude/hooks/pr-ready-guard.sh + .claude/settings.json — a PreToolUse hook that refuses an agent's promotion command when the gates do not pass.
docs/pr-promotion-loop.md — the design, the API findings and the traps.
.gitignore — narrows a wholesale .claude/ ignore to the per-developer files, so the shared hook and skill are tracked. Worth a look: this changes repo policy, and a hook nobody has is not a guardrail.
Thread handling
The only part left to an agent is reading and writing prose. Every open thread goes into exactly one of three buckets: addressed (fix it, say what changed, resolve), answered (explain why no change is needed, resolve), or needs a human (reply, and leave it open). The third blocks gate 4 and therefore blocks promotion, which is the correct outcome.
Several of Copilot's findings on #284 were real bugs, not nits — so resolving a thread to clear the board is the single failure this loop exists to prevent.
Scope
The CODEOWNERS notification that promotion triggers is a sibling automation and is not built here. CODEOWNERS approval is already required by the repository ruleset; nothing here changes that. This drives a PR forward, it does not gate merges.
Testing
This PR is the demonstration: opened as a draft, Copilot requested at max through the new script, gates run against it, promoted only if all four pass.
Automates the team convention — open as draft, get a Copilot review, work
through every thread, promote to Ready so the code owners are asked — so
that by the time CODEOWNERS are pulled in, the PR is genuinely reviewable.
Promotion is gated on all four of: Copilot has reviewed the current head
commit, the branch does not conflict with the base, CI is green, and no
review thread is still open. `pr-gates.sh` checks all four the same way
every time, and treats "unknown" as a block rather than a pass — a null
`mergeable` means GitHub has not finished computing it, not that the branch
is clean.
The blocker was requesting the Copilot review at all. POSTing the bot to
`requested_reviewers` returns HTTP 200 and changes nothing, and GitHub's
documented GraphQL route is unavailable to restricted sessions. There is a
REST endpoint that works: POST .../pulls/{n}/copilot-code-review with a
`review_effort`. The levels are adaptive, lite, balanced and max — read out
of the API's own 422, since the docs page for them 404s — so reviews are
requested at `max` with a step-down ladder, because availability is per
pull request.
Drafts need asking explicitly: the org ruleset that auto-requests Copilot
is set with `review_draft_pull_requests: false`, which points the opposite
way to the convention. A workflow closes that gap for drafts in this repo,
and never fails the build, since CI being green is itself a promotion gate.
Thread handling stays with the agent, because it is the only part that
needs reading and writing prose. It distinguishes "addressed, resolve it"
from "needs a human, leave it open and say so" — resolving a thread to
clear the board is the one failure this loop exists to prevent.
The .gitignore change narrows a wholesale `.claude/` ignore to the
per-developer files, so the shared hook and skill are actually tracked.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical guard and checker flaws can permit PR promotion despite bypassed gates, incorrect target validation, stale commit checks, or unreadable CI statuses.
All ten findings from Copilot's max-effort review were real. Most were
fail-open: the guard or the checker treating something it could not
evaluate as something that had passed.
The guard (.claude/hooks/pr-ready-guard.sh):
- A heredoc fed to a shell is executable input, not inert text. Bodies were
stripped before scanning, so `bash <<'EOF' ... EOF` ran a promotion with
no gate check at all. Bodies are now kept when they feed bash, sh, eval,
source and friends, and stripped only when they feed an ordinary command.
- `cat <<<"abc"` matched as a heredoc opening on delimiter `abc`, which no
here-string ever supplies, so everything after it was swallowed as body
and a promotion on the next line was invisible. Here-strings are now
neutralised before the heredoc match.
- Missing jq exited 0, permitting a promotion without evaluating anything.
It now denies anything that looks like a promotion. Reading stdin moved
from `cat` to a shell builtin for the same reason: an impoverished PATH
must not be able to silence the guard.
- `gh pr ready` is refused outright instead of half-parsed. `-R`, `--repo`,
`--repo=` and GH_REPO all redirect it and only the command text is
visible, so `gh pr ready 123 -R other/repo` would have cleared the local
PR while gh promoted another repository's. `--undo` is always allowed:
demoting is the right response to a re-opened gate.
- Only the first promotion target was checked, and it was extracted from
the raw command rather than the heredoc-stripped text. Every target is
now checked, from the stripped text, so a passing PR cannot escort an
unchecked one through on the same line.
The checker (.github/scripts/pr-gates.sh):
- A failed commit-status read defaulted to an empty status list, which with
green check runs passed the CI gate on evidence nobody could read.
- The head could move mid-run — the mergeability retries alone span ten
seconds — leaving the Copilot and CI gates describing a commit that was
no longer the head. The head is re-read before any pass is reported.
The requester: the fallback ladder included levels *above* the requested
one, so `--effort lite` would try `max` and spend more budget than asked.
It now only steps down, and rejects an unknown level.
The workflow: Actions runs a `run:` step as `bash -e`, and `set -uo
pipefail` does not clear errexit, so a refused request killed the step
before the status capture, the summary and the `exit 0`. The job that
promises never to fail the build would have failed it, turning a Copilot
outage into a blocked CI gate. It now sets +e explicitly.
Adds pr-ready-guard.test.sh covering all sixteen cases, including the
allow-on-pass path that had no test. It runs the real hook against a stub
gate checker, so it is offline and deterministic, and runs in CI beside the
repository's other "guard the guard" job.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
The promotion guard had 16 offline tests; the gate checker it calls had
none — and the gate checker is the piece that decides whether a pull
request goes in front of code owners. Four fixes from the review of this
branch had no regression test at all.
Adds `.github/scripts/pr-gates.test.sh`: 41 cases driving the real
scripts against a stubbed `gh` that serves canned responses from
fixtures. No network, no credentials.
The stub does two things a plain fixture server cannot:
* it counts reads per endpoint, so a fixture can return a different
head SHA on the *second* read. That is the only way to reproduce a
push landing between the first API call and the verdict, which
without the re-read yields a clean pass for code that was never
reviewed or tested.
* it pages, so a response can span two pages. The CI fixture puts 100
green check runs on page one and the single failure alone on page
two — a checker that stops early, or that cannot unwrap the object
`check-runs` returns, reports that pull request green.
The workflow's `set +e` is tested by extracting the `run:` body from
copilot-review-drafts.yml and executing it under `bash -e`, as Actions
does. Grepping the file for the string would pass equally well with the
line commented out.
Every case was checked by reintroducing the bug it guards and confirming
it goes red; a test that has never failed is not yet evidence. Dropping
the object unwrap turns a red build green in four separate cases, and
letting the effort ladder walk the whole list makes `--effort lite`
request `max`.
Both suites now run in the existing `Promotion guard` CI job.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
Match the API endpoint and method, not arbitrary arguments
.claude/hooks/pr-ready-guard.sh:130
This treats endpoint text in arbitrary arguments as a promotion. For example, gh api repos/dfinity/imcp2/issues/1/comments -f body='repos/dfinity/imcp2/pulls/2/ccr/ready_for_review' only posts documentation, but the hook checks PR #2 and refuses the comment whenever its gates fail. Distinguish the API request's endpoint and method from quoted body or query arguments before deciding that it promotes anything.
Provide a manual resume path when activity subscription is unavailable
.claude/skills/pr-drive/SKILL.md:60
The skill assumes subscribe_pr_activity exists, but local Claude Code sessions may not provide that cloud-session tool. With polling forbidden and no fallback, those sessions cannot resume this loop automatically. Make subscription conditional and provide a manual-resume path; the same assumption appears in docs/pr-promotion-loop.md:305–307.
Request a review when the current draft head still lacks one
.github/workflows/copilot-review-drafts.yml:35
If B is pushed while Copilot reviews A, the synchronize request can return already pending and exit successfully without requesting B. Once A's review finishes, none of these triggers requests another review, leaving the draft's Copilot gate stale. Handle review completion by checking whether the current draft head still lacks a review and requesting one if needed.
Copilot's second review found eight more issues, all High, all real and all
reproduced before fixing. Seven are ways past the guard; counting the first
round, nine in total:
cat <<EOF with $(gh api ...) an unquoted body is expanded, so it runs
<<'END-DOC' delimiter normalised to ENDDOC, so the
terminator never matched and the rest of
the command was swallowed
x=$((1<<2)) arithmetic read as a heredoc on "2"
/bin/bash <<'EOF' the interpreter check wanted a bare name
cat <<'EOF' | bash it looked only before the operator
gh pr ready the pattern matched a single space
gh pr ready 1 --undo; gh api --undo anywhere exempted the whole line
repos/$REPO/pulls/$PR/... no literal target, so no target was found
repos/{owner}/{repo}/... likewise
Every one is the same bug: the guard defaulted to ALLOW whenever it failed to
understand something. Shell is not a regular language, so patching each case
in turn only buys time until the tenth.
The default is now inverted. The question is no longer "does this promote?"
but "can I prove this promotes nothing I have not checked?":
* text that mentions no promotion exits silently, as before;
* anything promotion-shaped defaults to DENY;
* a heredoc body is dropped only when the delimiter is quoted, there is no
pipe, and the command owning it is PROVEN not to execute its input --
cat, tee, dd, git. Naming the dangerous interpreters instead would mean
enumerating bash, sh, python3, perl, node ... and the first one forgotten
is the next bypass, which is how /bin/bash got through;
* every promotion must resolve to a literal owner/repo/number. Counting
promotions against resolvable targets is what makes this hold when an
unresolvable one sits beside a resolvable one.
Also from the review:
* .claude/settings.json drops its `if: Bash(gh *)` filter. It reads the
start of the command string, so the hook was never invoked for
`bash -c 'gh api ...'` -- a command it can judge perfectly well. The
offline tests could not catch this, since they invoke the script directly.
* pr-gates.sh: ci_green passed when the only check present was `skipped`,
which happens when the draft-review workflow reports before CI registers
anything. It now counts checks that actually ran, and
PR_GATES_REQUIRED_CHECKS can pin names that must have reported.
* The two-target test ran against a stub that blocked BOTH pull requests,
so it passed whether the guard checked both or only the first -- the
regression it existed to catch. It now uses a stub that passes #1 and
blocks #2, confirmed by making the guard check only the first and
watching the case go red.
* The skill documented the {owner}/{repo} form, which the guard now denies.
Suites: 36 guard cases (was 16), 45 gate cases (was 41).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
…uest
A third Copilot review, this one against the inverted guard. Three of its six
findings were already fixed in 8620b6a (it ran against the commit before it).
The other three are real and reproduced:
1. `git push && gh api .../ccr/ready_for_review` promoted an unreviewed head.
The hook reads the gates when it fires, before ANY of the command runs, so
the checker saw the old head -- reviewed, green, clean -- and the push then
replaced it. The check was honest and the answer was stale by the time it
was used.
No PreToolUse hook can close that window: it cannot run between two halves
of one command. So it refuses the shape instead. Every segment must itself
be a promotion, which denies `git push && ...`, `cd x && ...` and
`... ; anything`. Several promotions together stay allowed, since promoting
one pull request cannot change another's head.
2. The gate checker's final re-read checked only the head SHA. The BASE can
advance without the head moving, and a merge that was clean when gate 2 ran
may conflict by the time the verdict is used -- so all_pass came back for a
branch that no longer merged. It now re-reads `mergeable` too, and a null
there blocks like any other unknown.
3. A `409 already pending` stranded the Copilot gate. Pushing while Copilot
reviews the previous head gets the request refused as a duplicate; that
review then lands on the OLD commit, so gate 1 reads `stale` and no further
pull_request event is ever coming. The draft workflow now also triggers on
`pull_request_review: [submitted]`, skipping when the review already covers
the current head.
Each was verified by reintroducing it and watching the matching case go red;
1 and 2 both show the fail-open signature, `got ok/exit 0`. The workflow
trigger has only a structural test -- a job `if:` is evaluated by GitHub and
nothing runnable here can exercise it -- and the docs say so rather than
implying the suite covers it.
Suites: 40 guard cases (was 36), 49 gate cases (was 45).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
Round four of review found ten further ways past the promotion guard. Most
were not parsing mistakes: they were places where the inverted default had
never actually been applied.
The largest is step 4, which asked "is a caller present?" and named gh, curl
and wget — a deny-list in the middle of a guard built on allow-lists. It let
/usr/bin/gh, "gh" and a python urlopen straight through, all three of which
the checks below it already catch. That test is now inverted: a command is
mere text only when every segment is provably inert, and segmentation splits
on command substitution and subshells too, since in
gh pr ready $(gh pr ready 2) --undo
the inner command runs first and has to be judged on its own.
The subtlest is a fail-open in the cheapest line of the hook. Under pipefail,
printf | grep -q reports failure when grep exits at its FIRST match and
printf dies of SIGPIPE — so a command that did contain a promotion read as
containing none. It needs a command past the 64 KiB pipe buffer to fire,
which is why two earlier rounds missed it. Those pipelines are here-strings
now.
Also closed: the GraphQL spelling of the mutation, a heredoc operator inside
a quoted commit message, a padded delimiter, a heredoc captured by command
substitution, and one redirected into a process substitution. Each is
reproduced as a regression test against the PASSING sandbox, so a denial can
only come from the guard refusing the shape, and each fix is mutation-tested.
The CI gate could pass on a commit whose build had not started: a check run
that has not registered is invisible, so counting the runs that did appear
proves nothing. PR_GATES_REQUIRED_CHECKS is the only cure, and it was unset
exactly where it mattered — the hook calls the checker with no environment.
The repository's list now lives in .github/scripts/pr-gates.conf beside the
checker and is sourced by it.
Gate 1 now reads the issue timeline, the only place an accepted-but-unstarted
Copilot request is visible. A request measured here sat nineteen minutes with
no check run on any commit before the review arrived, so the gate reports it
as pending with the request time rather than advising a re-request that can
only answer 409. It does not try to judge a queued request dead: a grace
period long enough to be safe is too long to be useful.
CONTRIBUTING no longer claims steps 4-6 are automated. Only the draft review
request is, and only for same-repo branches.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
Round five, all four real.
The required-tools check omitted tr and head. Both are load-bearing: the
standalone-command check is a pipeline through them, and an empty result from
a missing binary reads as "nothing left over" — the allow answer. The guard
now refuses without them, and the missing-tool tests cover all four.
A promotion could still carry a command substitution in an argument:
gh api .../ccr/ready_for_review -X POST -H "X-Preflight: $(git push)"
is one segment of exactly the permitted shape with nothing left over, yet the
substitution runs first and replaces the head the gates were read against.
The segmentation now splits on parentheses and backticks as well, and a
substitution anywhere in a promotion is refused outright. The two overlap on
purpose; removing both re-opens the hole, which is what the test pins.
Gate 3 counted "Request a Copilot review" as CI. It compiles nothing and
tests nothing, yet reports success seconds after a push — early enough to be
the only green check on a commit whose build has not registered. It is now
excluded from CI evidence through its own pattern, deliberately not through
CI_EXCLUDE: gate 1 identifies Copilot's check run with that one, and folding
the requester in would make the requester look like the review.
The draft-review workflow held its concurrency group at workflow level, where
it covers runs the job condition skips. A human review on the current head
started a run that cancelled a requester still in flight, and the skipped
replacement did nothing — so no review was ever requested. Moved to the job.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
One review comment raised two further heredoc cases. Running them settles
which is which.
A commented operator is a real bypass. In
cat /dev/null # <<'EOF'
<promotion>
bash opens no heredoc and runs the second line, while the scanner dropped it
as a body. A word-boundary hash ahead of the operator is now exit 3.
An unterminated body is not a bypass. Bash warns, treats everything to
end-of-file as the body, and the promotion is written to the file rather than
executed — verified by running it. The scanner matches the shell exactly, so
allowing it is correct, and a test now pins that so a later fix does not
break it.
Also removed the last two printf-into-grep pipelines. Both are safe, since
grep -c and grep -oE consume all of their input, so nothing dies of SIGPIPE.
The shape is what cost a fail-open once already, so it leaves the file.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
The allow-list of inert tools had the same disease as the caller roster it
replaced, one level down. It named sed, awk, sort and git as incapable of
running anything. All four can, confirmed by running each with echo in place
of the promotion:
sed -n 'e CMD' <<<x GNU sed's e command executes CMD
awk 'BEGIN{system("CMD")}' plus print | "sh" and getline
sort --compress-program=CMD f sort spawns CMD
git -c alias.p='!CMD' p a ! alias is a shell command
Three were live bypasses. awk was denied only by accident, because the
segmentation happens to split on the parentheses of system(...).
The fix is a shorter list, not a longer one with caveats. What remains has no
execution primitive at all. less and more left too (!, LESSOPEN).
git is kept in a validated shape: the subcommand must follow the word git
immediately, which excludes -c, -C and --exec-path since all three must
precede it. It earns the exception because committing a message that mentions
the endpoint is an everyday command.
Two tests change their expectation from allow to deny: searching a file with
awk or sed is no longer mere text. That is a real cost and the right trade —
grep and rg still work and cannot run a command.
Three rounds in a row have now found this same bug at a different depth. An
allow-list only helps when membership is proved, and being unable to think of
a way to execute something is not a proof.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
The Release workflow (.github/workflows/v-release.yml) triggers on
pull_request with no path filter, and its `plan` job carries no condition, so
it runs on every pull request. It was missing from the required-checks list,
which meant the five CI jobs could go green and allow promotion while `plan`
was still queued or about to fail. Added.
The CONTRIBUTING examples invoked both scripts without --repo. Both fall back
to the `origin` remote when GITHUB_REPOSITORY is unset, and in a fork clone
that is the fork — so the commands would have reported on whatever unrelated
pull request happened to share the number. The examples now name the upstream
repository, with a line saying why.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
When any tool the guard needs is missing from PATH it cannot run its
indicator regex, so it falls back to a shell case-glob on the raw payload
and denies anything promotion-shaped. That glob only ever knew the REST
spelling: the regex had been widened to cover markPullRequestReadyForReview
rounds earlier, the glob had not, and nothing linked the two. A GraphQL
promotion with jq, awk, tr or head absent was therefore allowed outright,
without a single gate being read.
Widen the fallback to *Ready* and *READY*. It is deliberately cruder than
the regex: in the degraded path the only safe failure is a false deny.
The missing-tool regression cases now run both spellings against all four
tools -- eight cases, not the four that only tested the spelling that
already worked. Reverting the glob fails exactly the four new ones.
Also: a segment made only of variable assignments matched no inert command
name and so was unclassifiable, which means deny -- the guard refused an
ordinary "SP=/tmp/x && grep ..." of my own. A bare assignment executes
nothing, so treat it as inert, with a test pinning that an assignment in
front of a real promotion is still denied.
72 guard cases, 60 gate cases, both suites green. Both fixes mutation
tested.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
pr-gates.conf was sourced above the argument loop, so it was read before
--repo had been parsed and its defaults applied to whatever repository the
checker was then pointed at. A pull request in another repository was
blocked unless it produced all six of this repository's job names, however
green its own CI was, and --allow-no-ci could not clear it because a named
required check is judged before the no-checks branch.
Source the conf below the argument loop, once the target repository is
resolved, and guard its defaults with `if [ "$REPO" = "dfinity/imcp2" ]`.
CI_EXCLUDE, CI_IGNORE and REQUIRED_CHECKS move down with it so every knob a
conf can influence resolves after the repository does. An explicit
PR_GATES_* in the environment still wins, the empty string included.
The ordering of required checks against --allow-no-ci is left alone: a
declared check that has not reported is the exact race the list exists to
catch, so it must outrank a flag that means "this repository has no CI".
Scoping the conf is what stops that reaching across to other repositories.
Said so in the help text and at the branch.
The three conf tests ran as o/r and passed only because the conf was
unscoped -- they encoded the bug. Fixture keys now follow the target
repository, the conf cases run as the repository the conf names, and two new
cases cover another repository: green CI is not blocked, and --allow-no-ci
works there. Unguarding the conf fails both; sourcing it early again fails
the missing-job case.
62 gate cases, 72 guard cases, both green.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The hook mistakes heredoc markers inside multiline quoted strings for real openers, hiding executable promotion commands from readiness and standalone-command checks.
GitHub resolves owner and repository names case-insensitively and returns
the canonical spelling for either, but the conf guard added in 2d54f83
compared the slug literally. So --repo DFINITY/imcp2 -- the same repository,
differently typed -- selected no repository defaults at all, dropping all six
required checks. The CI gate then passed on a lone green "Promotion guard"
check with the build and test jobs not yet registered: exactly the
registration race the required-checks list exists to close, reachable by
capitalising a letter. The promotion hook accepts uppercase path components
and passes the parsed slug straight to the checker, so a capitalised
promotion path reached it.
Lower-case the slug once, where the repository is resolved, above everything
that reads it -- not at each comparison, since one comparison written
literally later is all it takes to reopen. Verified against the live API that
DFINITY/imcp2 and dfinity/IMCP2 both resolve to dfinity/imcp2, so this
changes no request the checker makes.
The hook lower-cases each extracted target too, before de-duplicating them,
so two spellings of one pull request are one target rather than the same
pull request gate-checked twice.
Three gate cases cover the spellings DFINITY/imcp2, dfinity/IMCP2 and
Dfinity/Imcp2; one guard case asserts the two-spelling command reaches the
checker once, as dfinity/imcp2. Removing either normalisation fails exactly
those cases.
65 gate cases, 73 guard cases, both green.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
A Max-effort review flagged, without filing it as an issue, that a promotion
can reach the shell through a script or a file descriptor even when the gate
checker blocks every pull request. That is accurate. Verified with a stub
checker that blocks everything: `bash promote.sh`, `. promote.sh`,
`cat promote.sh | bash`, `bash < promote.sh` and `bash <(...)` are all
allowed, because the promotion is not in the command string.
It is not a hole to be patched. A PreToolUse hook gets the command string
and nothing else; closing this would mean resolving and scanning whatever a
command might execute, which is unbounded and racy, and a guard that
half-reads files offers false assurance. The first step is allowed on
purpose besides: writing a file that quotes the endpoint is how this
document gets written, and the guard's own first refusal was a command
writing its own documentation.
So say plainly what the hook is -- a guardrail against promoting by
accident, not a sandbox -- and where the real control lives: the repository
ruleset requiring code-owner approval, and the Promotion guard CI job that
re-runs both suites on every head.
Documentation only; no behaviour change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
The latest review reports no open issues, but its headline flags that a promotion can reach the shell "through a script or file descriptor even when the checker blocks every PR". That is accurate, and worth answering rather than leaving on the board.
I verified it against a stub checker that blocks every pull request, so each ALLOW below is a command the gates never authorised:
command
verdict
direct promotion
DENY
bash -c '<promotion>'
DENY
bash promote.sh
ALLOW
. promote.sh
ALLOW
cat promote.sh | bash
ALLOW
bash < promote.sh
ALLOW
bash <(cat promote.sh)
ALLOW
It is not a hole I am going to patch. A PreToolUse hook is handed the command string and nothing else. Closing this would mean resolving and scanning whatever a command might go on to execute — a script that sources another, a path held in a variable, a file written by an earlier step — which is unbounded, and racy besides, since the file can change between the hook's read and the shell's. A guard that half-reads files would mostly offer false assurance.
The first step of that two-step is allowed deliberately, and has to be: writing a file that quotes the promotion endpoint is how this repository's own documentation gets written. The guard's very first refusal was a command writing its own docs, and a guard that blocks ordinary work is a guard that gets switched off.
So the honest framing, now written into docs/pr-promotion-loop.md in 7e0b9f7: the hook is a guardrail against promoting by accident — a direct promotion, one riding along on another command, one aimed at a pull request whose gates were never read. It is not a sandbox and does not try to be one; reaching the two-step path takes deliberately writing a promotion to a file and then running that file.
What actually governs a merge is unaffected: the repository ruleset requires code-owner approval, and the Promotion guard CI job re-runs both suites on every head. The gate checker decides whether a pull request is ready; the hook only stops this agent stepping around it inattentively.
Flagging it here rather than quietly closing it, since "is a text-scanning hook the right control?" is a judgement for a human, not something I should settle by resolving a thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automates the team convention — open as draft, get a Copilot review, work through every thread, promote to Ready so the code owners are asked — so that by the time CODEOWNERS are pulled in the PR is genuinely reviewable. Promotion is the signal; this makes it safe to give without a human in the loop.
Promotion is gated on all four of:
copilot_reviewcommit_idis the head SHAno_conflictsmergeable == trueci_greenthreads_resolved"Unknown" is never a pass: a
nullmergeablemeans GitHub has not finished computing it, not that the branch is clean.The blocker, and what fixed it
Requesting a Copilot review could not be done from a restricted session. POSTing the bot to
requested_reviewersreturns HTTP 200 withrequested_reviewersunchanged and empty — a silent no-op — and GitHub's documented GraphQLrequestReviewsroute is unavailable where onlygh apiREST works.There is a REST endpoint that does work:
Review depth is selectable. The levels are
adaptive,lite,balanced,max, withbalancedthe default — read out of the API's own 422 by sending an invalid value, since the docs page for the levels 404s. Availability is per pull request, so the requester walksmax → balanced → adaptive → literather than giving up.Drafts need asking explicitly: the org ruleset
Automatic Copilot code reviewis set withreview_draft_pull_requests: false, which points the opposite way to the convention — followed literally, "open as draft → Copilot review" would wait forever.Changes
.github/scripts/pr-gates.sh— checks all four gates; human-readable or--json; exit 0/1/2..github/scripts/pr-request-copilot-review.sh— requests a Copilot review at the most thorough effort available..github/workflows/copilot-review-drafts.yml— requests that review on drafts, which the org ruleset skips. Never fails the build, since CI being green is itself a promotion gate..claude/skills/pr-drive/SKILL.md— the agent loop: triage threads, answer them, decide whether to promote..claude/hooks/pr-ready-guard.sh+.claude/settings.json— aPreToolUsehook that refuses an agent's promotion command when the gates do not pass.docs/pr-promotion-loop.md— the design, the API findings and the traps..gitignore— narrows a wholesale.claude/ignore to the per-developer files, so the shared hook and skill are tracked. Worth a look: this changes repo policy, and a hook nobody has is not a guardrail.Thread handling
The only part left to an agent is reading and writing prose. Every open thread goes into exactly one of three buckets: addressed (fix it, say what changed, resolve), answered (explain why no change is needed, resolve), or needs a human (reply, and leave it open). The third blocks gate 4 and therefore blocks promotion, which is the correct outcome.
Several of Copilot's findings on #284 were real bugs, not nits — so resolving a thread to clear the board is the single failure this loop exists to prevent.
Scope
The CODEOWNERS notification that promotion triggers is a sibling automation and is not built here. CODEOWNERS approval is already required by the repository ruleset; nothing here changes that. This drives a PR forward, it does not gate merges.
Testing
This PR is the demonstration: opened as a draft, Copilot requested at
maxthrough the new script, gates run against it, promoted only if all four pass.pr-gates.shrun against feat(oql): let a Candid query through when the OQL surface does not cover it #284 and against this PR; correctly distinguishespending/stale/missingCopilot states and blocks on eachpr-request-copilot-review.sh— effort ladder confirmed against the live APIcargo build/cargo test— no Rust changed; CI runs them anywayChecklist
docs/pr-promotion-loop.md, plus the PR flow inCONTRIBUTING.md.Generated by Claude Code