Repository navigation
feat(wait-for-pr-review): [#2581] add a deterministic wait-for-review poller for AI agents - #2683
Conversation
…eview wait poller Implement the poller in torrust#2581, follow the CLI output contract ADR with a timeout result, handle SIGINT and SIGTERM, and link the shutdown research. Co-authored-by: Copilot <[email protected]>
…on library Add the wait-for-pr-review crate as a non-default workspace member: a gh boundary trait, a pull-request snapshot, event detection against a start baseline, and the wait loop, all unit tested with a scripted gh. Co-authored-by: Copilot <[email protected]>
Follow the CLI output contract: one JSON result on stdout (a timeout is a result), NDJSON diagnostics on stderr, exit codes 0/1/2, TTY refusal, and SIGINT/SIGTERM handling that also stops an in-flight gh call. Co-authored-by: Copilot <[email protected]>
…t the poller Document the poller usage, its result kinds, and the review loop, link it from process-pr-review, add it to the CLI output contract table, and list the skill-owned tool in the package catalog. Co-authored-by: Copilot <[email protected]>
…mentation progress V1 to V5 ran against the real GitHub API. V6 (a real da2ce7 review) and V7 (the Copilot re-review path) wait for this feature's pull request. Co-authored-by: Copilot <[email protected]>
… the evidence A head commit of another pull request is not a durable reference. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved correctness issues allow hung requests to bypass the timeout, valid abbreviated SHAs to trigger false head changes, and newly submitted reviews to be missed.
4 open issues
What changed in this PR
Adds a skill-owned Rust poller for #2581, supporting #2003’s goal of deterministic automation. It waits for pull-request activity through the GitHub CLI without model calls.
Changes:
- Implements reviewer filtering, event detection, configurable polling, JSON output, and signal handling.
- Adds unit and CLI integration tests plus manual verification evidence; V6 and V7 remain pending.
- Registers the crate and documents its use in the review loop and CLI output contract.
| File | Description |
|---|---|
project-words.txt |
Adds the verification fixture’s SHA to the dictionary. |
docs/issues/open/2581-2003-pr-review-wait-poller/manual-verification-evidence.md |
Records manual results and pending scenarios. |
docs/issues/open/2581-2003-pr-review-wait-poller/ISSUE.md |
Updates decisions, implementation scope, and progress. |
docs/adrs/20260519000000_define_global_cli_output_contract.md |
Classifies the poller’s output contract. |
Cargo.toml |
Registers the workspace member. |
Cargo.lock |
Records poller dependencies. |
AGENTS.md |
Lists the skill-owned tool. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/tests/cli.rs |
Tests CLI results, failures, and interruption. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/wait.rs |
Implements baseline setup and polling. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/timestamp.rs |
Parses GitHub UTC timestamps. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/snapshot.rs |
Fetches PR activity and commit dates. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/main.rs |
Defines options, output, and signal handling. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/lib.rs |
Exposes the poller library interface. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/gh.rs |
Implements GitHub CLI transport and pagination. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/event.rs |
Detects and serializes review events. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/src/error.rs |
Defines structured failures and diagnostic kinds. |
.github/skills/dev/pr-reviews/wait-for-pr-review/tool/Cargo.toml |
Declares the unpublished crate and dependencies. |
.github/skills/dev/pr-reviews/wait-for-pr-review/SKILL.md |
Documents invocation, results, and the review loop. |
.github/skills/dev/pr-reviews/process-pr-review/SKILL.md |
Links review processing to the waiting skill. |
.dockerignore |
Admits the crate into the container build context. |
Review effort: Balanced
…stead of a maximum A review keeps the ID it got as a draft, so one submitted after the baseline can have a lower ID than a review already submitted, and a pending review present at the start keeps its ID when it is submitted. Compare against the set of submitted review IDs from the start. Co-authored-by: Copilot <[email protected]>
… canonical full commit SHA The CLI accepts abbreviated and uppercase SHAs, but the baseline stored the input verbatim and compared it with GitHub's full lowercase head SHA, so a valid abbreviation of an unchanged head returned head_changed at once. Use the full lowercase SHA that the commit lookup returns. Co-authored-by: Copilot <[email protected]>
… deadline on every gh call A stalled gh call could outlive --timeout-seconds because the child wait checked signals but had no deadline, and the poll loop took one more snapshot after its last sleep spent the budget. Share an absolute deadline with the gh boundary, kill and reap the child when it passes, start no request after it, and report a timeout when it passes after the baseline was taken. Co-authored-by: Copilot <[email protected]>
…andled event is not reported again Rerunning with the same --since-head-sha after an event that needed no push returned the same event at once, and dropping the flag lost activity between runs. Report the GitHub time of the reported review or comment as a cursor, resume strictly after it with --since, and rewrite the review loop so it re-requests a review only after a push. Co-authored-by: Copilot <[email protected]>
…st Copilot review Record the submitted-review ID set, the canonical SHA, the hard deadline, and the resumable cursor in the spec. Co-authored-by: Copilot <[email protected]>
…R 2683 Co-authored-by: Copilot <[email protected]>
|
ACK 1ce8db7 |
… the ephemeral range base_source_precedence and per_value_overrides hard-coded ports 43152 to 43156. They sit in Linux's ephemeral range, which the kernel also hands to port-zero bindings and outgoing connections, so the tracker child exited with Address already in use whenever another process held the port. The test failed that way in three CI runs. Draw random ports from below the range and probe each by binding it. Co-authored-by: Copilot <[email protected]>
…ce_precedence flake fix Co-authored-by: Copilot <[email protected]>
… killed gh call within a bound On the interrupt and deadline path, run returned without collecting the threads that read the child's pipes. Joining them without limit would wait on a grandchild that keeps a pipe open and defeat the deadline, so give them a short grace period to finish after the kill and then let go. Co-authored-by: Copilot <[email protected]>
…t and bound N by the range The search budget was shared by all N ports and N up to the budget was allowed, so duplicate random candidates could make a request fail while free ports existed. Give every port its own budget, bound N by the size of the range, and inject the bind step so the budget logic is tested without sockets: a test that re-bound a just-released port failed in about one run in five, because another test thread's forked tracker child still held the inherited listener until exec. Co-authored-by: Copilot <[email protected]>
…nd the fixture changes Replace the usage_error record that an earlier capture cut at 120 characters with the full record, and update the port fixture evidence for the restructured helper and the flaky test that was removed. Co-authored-by: Copilot <[email protected]>
…PR 2683 Co-authored-by: Copilot <[email protected]>
…ec progress log and the evidence Co-authored-by: Copilot <[email protected]>
|
ACK cfb3d47 |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
4 resolved since last review
The function promisesNdistinct ports and allowsN == MAX_DRAWS, but the candidate stream is… On theErrpath fromwait_for(e.g.,Interrupted/DeadlineExceeded),run()returns early… When--sinceis used as a resumable cursor, returning an arbitrary matching review/comment (based… Theusage_errorexample JSON line appears truncated (missing the closing quote/brace), which…
Review effort: Lite
… that could not be written write_diagnostic dropped every serialization and I/O error and wrote a record in many small pieces. Build the record first and write it with one call, return the error, and exit non-zero when a record whose whole purpose is to be read, such as the help text, could not be written. Co-authored-by: Copilot <[email protected]>
…k of the timestamp parser explicit digits chained a boolean into then and a nested Option. Return early when a field has a non-digit and parse otherwise; behavior is unchanged. Co-authored-by: Copilot <[email protected]>
…R 2683 Co-authored-by: Copilot <[email protected]>
… fifth review Co-authored-by: Copilot <[email protected]>
|
ACK a70d3a6 |
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at a70d3a662b49755e6d0f35f9dd881292334e4a4f (post-merge). Recomputed from the bytes at the merged head, against the base 883cc834c; the PR merged on 2026-10-28 at 18:32:57Z as 968099d93.
Label: POST_MERGE_FINDINGS — Review requested at 2026-10-28T12:19:58Z; the PR merged before this round ran. The findings below stand at the merged head for a follow-up PR. No ACK follows a merged PR.
Change and tests: inspected all new modules, CLI scenarios, and the root port-fixture changes. Argument arrays avoid shell interpolation; pagination is flattened; API errors, including rate limits, fail rather than retry. Elapsed time uses a monotonic clock. Event selection is ordered by timestamp, kind, and ID, but sequential requests are not an atomic snapshot. The documented same-second cursor exclusion requires the caller to read all feedback. Tests cover the ordinary deadline and resume cases, but not a successful child leaving inherited pipes open, a push between snapshot requests, or an overflowing timeout. No compilation was attempted.
Records: 18 source findings map to 18 detail entries and replies on the correct threads; the capture marks all threads resolved. The first five bot reviews contain 4/2/6/4/2 findings; the sixth, 5687775017, arrived at 18:33:35Z, after merge, with no inline findings. Agree with the submitted-review set, canonical SHA, strict timestamp, platform guard, earliest-event ordering, and fixture corrections. Deadline and stale-checkout repairs still have the cases below. F11/F12 properly retain duplicate rows. Historical execution claims remain evidence statements, not independently rerun results.
Hygiene: recomputed 34 commits and 25 changed files; descriptions and subjects identify issue 2581. The description has one closing reference to that issue. Relative Markdown file targets resolve. Attribution footer lines are present; the inspected commit convention permits optional footer lines, so their presence is not a finding. The shared review skill change adds a link and version update; it does not alter the validator changes in the other PRs.
Findings: F19–F20 Major, F21 Minor, F22–F25 Nit.
Checked, no finding: baseline review-ID set, lowercase full SHA comparison, calendar validation, API error propagation, ordinary timeout versus pre-baseline failure distinction, and the explicit unfinished real-review verification item.
Checks
On the loop's compute hub at the merged head, against the base 883cc834c (receipt server-gates-sojka-493; the PR merged as 968099d93): pre-commit profile gate exit 0 (96 s); linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 16 errors / 4 warnings at the merged head and 16 / 4 at the base re-measured, the same 20 diagnostics by path and category; the audit validator over docs/pr-reviews/pr-2683-review/PR-REVIEW.md with the review comments and commit list captured at gate time: ok, 18 rows, 19 log entries, 0 failures; cargo test at the merged head: wait-for-pr-review 82 passed, 0 failed (exit 0, 8 s; no base run); torrust-tracker 225 passed, 0 failed (exit 0, 92 s; 197 at the base); cargo clippy over wait-for-pr-review torrust-tracker with all targets and features and -D warnings: exit 0, 0 diagnostics. GitHub checks at this head at posting time: "Publish (Release): completed/skipped; Publish (Development): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Package Coverage (torrust-tracker): completed/success; Docker E2E: completed/skipped; Documented Clippy Allows: completed/success; Unit (nightly): completed/success; Unit (stable): completed/success; Layer Boundary Bans: completed/success; Workspace Packaging: completed/success; Shipped Features: completed/success; Test (Docker) (release): completed/success; Discover Package Coverage: completed/success; Generate Coverage Report: completed/success; Docs Lint: completed/success; Build on ubuntu-latest (stable): completed/success; Build on windows-latest (nightly): completed/success; Build on macos-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Build on windows-latest (stable): completed/success; Build on ubuntu-latest (nightly): completed/success". At posting, develop is 968099d93.
|
|
||
| let outcome = self.wait_for(&mut child); | ||
|
|
||
| let grace = outcome.is_err().then_some(RECLAIM_GRACE); |
There was a problem hiding this comment.
[Major][F19] Bound pipe collection after a successful child exit too
This re-raises the review bot's 4400587241 deadline concern on a remaining path. When the direct child exits successfully while a descendant retains stdout or stderr, wait_for returns Ok, so grace is None and collect blocks in recv() without checking either the deadline or interruption. A wrapper that starts a descendant and exits reproduces the control flow; both hung-child tests keep the direct child alive and cannot cover it. Collect both pipes against the absolute deadline on every exit path, and add a successful-parent/inherited-pipe regression case.
| }; | ||
|
|
||
| Ok(Snapshot { | ||
| head_sha: pull.head.sha, |
There was a problem hiding this comment.
[Major][F20] Revalidate the head after fetching feedback
This re-raises the review bot's 4401206737 stale-checkout concern for activity arriving during a poll. take_snapshot reads head A first, then fetches reviews and comments. A push to B and a review of B between those calls produce a review result whose review_commit_id is B but whose head_sha is A and whose head_moved is false for checkout A. The skill checks only those latter fields before processing, so the new guard permits processing on stale code. Re-read head/state after collecting feedback and retry or flag a changed snapshot; add a scripted inter-request push test.
| since_moment: cli.since, | ||
| }; | ||
| let started = Instant::now(); | ||
| let gh = GhCli::new("gh", Arc::clone(&interrupted), started + config.timeout); |
There was a problem hiding this comment.
[Minor][F21] Reject timeout values that overflow the monotonic deadline
The CLI accepts every positive u64, including --timeout-seconds 18446744073709551615, but started + config.timeout cannot represent that deadline and panics on the target platforms. That bypasses the documented JSON diagnostic and 0/1/2 exit contract. Use checked_add and emit a usage error, or bound the accepted duration; test the largest accepted integer without making any API request.
| } | ||
|
|
||
| /// Writes one complete NDJSON record to stderr. The line is built first and written with one call, so | ||
| /// a failure cannot leave half a record behind. |
There was a problem hiding this comment.
[Nit][F22] Do not describe write_all as an atomic record write
Building the record first avoids serialization fragments, but write_all can perform several writes and return an error after a prefix has reached stderr. Thus this comment and the F17 Solution at docs/pr-reviews/pr-2683-review/PR-REVIEW.md:290 overstate the fix. Keep the useful nonzero exit behavior and describe it accurately; the full-device test only exercises failure before any byte is written.
| ## Processing Log | ||
|
|
||
| - 2026-10-28 12:35 UTC - The `wait-for-pr-review` poller returned Copilot's review 5682635980, submitted at 12:34:22 UTC (kind `review`, state `COMMENTED`, exit `0`; its stdout file was last written at 12:35:33 UTC). The review opened four inline threads, F1 to F4; all were unresolved. Each was checked against the current tree and found valid. | ||
| - 2026-10-28 12:45 UTC - The four fixes were committed, one signed commit each: F1 at 12:38, F2 at 12:41, F3 at 12:42 and F4 at 12:45 UTC (commit times from `git log --format=%cI`). The spec was refined for the changed contract at 12:47 UTC. |
There was a problem hiding this comment.
[Nit][F23] Append corrections for log entries that narrate later events
The 12:45 entry includes the spec refinement carried by d832d0ebf at 12:47:12Z. The 13:34 entry also narrates reading and validating the review at 14:01. These event stamps precede actions they claim completed, contrary to the review skill's event-stamping rule. Preserve the original entries and append a correction distinguishing review-submission time from later processing time.
| branch: "2581-pr-review-wait-poller" | ||
| related-pr: null | ||
| last-updated-utc: "2026-10-21 07:48" | ||
| last-updated-utc: "2026-10-28 17:55" |
There was a problem hiding this comment.
[Nit][F24] Use an observed update time in both issue records
The issue and manual-verification-evidence.md both carry last-updated-utc: 2026-10-28 17:55, but their final update is already in a70d3a662 at 17:51:59Z. The timestamp is future-dated relative to the bytes that carry it. Replace it with the actual update time and check the companion evidence stamp in the same follow-up.
| @@ -0,0 +1,456 @@ | |||
| //! Runs the real binary against a fake `gh` script, to pin the command-line contract: | |||
There was a problem hiding this comment.
[Nit][F25] Correct the final description of verification coverage
The PR description lists TTY refusal among these integration scenarios, but this file contains no terminal/PTY scenario; refusal is covered only by the separately recorded manual run. The same description still says four reviews/sixteen findings, whereas five reviews/eighteen findings already existed at the merged head. Record the final coverage and counts accurately in the follow-up; either add a maintained terminal-refusal scenario or distinguish it from automated coverage. This anchor is the test-file contract; the inaccurate statements are in the PR description outside the diff.
…ssues/closed f626f75 docs(skills): [#2581] say to push first and request the Copilot review last (Jose Celano) 3f5857d chore(issues): archive closed issue #2581 spec to docs/issues/closed (Jose Celano) Pull request description: Related to #2581 Archives the spec of issue #2581, which closed as completed when PR #2683 merged, from `docs/issues/open/` to `docs/issues/closed/`, following the `cleanup-completed-issues` skill. The issue is already closed on GitHub, so this pull request does not close anything. ## Changes - Moves `docs/issues/open/2581-2003-pr-review-wait-poller/` (the spec and the manual verification evidence) to `docs/issues/closed/`, and sets `status: done`, the new `spec-path`, `related-pr: 2683` and a real `last-updated-utc` in both files. - Records in the evidence that V6 (the poller returning on a real `da2ce7` review) was not run: no `da2ce7` review existed when the pull request merged and the poller had already returned `pr_merged`. The spec's progress log gets an archival entry, and its criterion about manual verification stays unticked for that reason. - Repairs the two live links that named the old path: the `related-artifacts` of the `wait-for-pr-review` skill and of the PR 2683 audit. The PR 2584 audit entries that name the old path are historical records of the path at the time, so they are left as they are. The parent EPIC #2003 does not list #2581, so it needs no change. - Adds a note to the `wait-for-pr-review` skill: push every commit first and request the Copilot review last, because Copilot reviews the head as of the request (on PR #2683 a review requested at head `d000f8881` covered that commit although two more were pushed five minutes later), and use a 45-minute poller budget when waiting for Copilot. It also restores the line continuations of the two re-request commands, which an earlier edit had collapsed. This small skill improvement rides along as its own commit. ## Validation - Pre-commit passed for both commits, and the pre-push hook passed on push. - `frontmatter-validator` passes on the four changed Markdown files, `git diff --cached --check` is clean, and the PR 2683 audit validator still passes (18 rows, 0 failures). - A search of the repository, including hidden folders, for the old spec path finds only the PR 2584 historical entries. - The branch is based on the current `develop` and merges with it cleanly. ACKs for top commit: josecelano: ACK f626f75 Tree-SHA512: 940d4958b57f2d0b77420b722bec7b81c61f03f0542de506f68825cc2b17dff4a30d84ad3a9c2f68997e830d771f35c42f198ea5a1c1850078ac6987c1a883b4
…ownership to josecelano 5f1f676 docs(pr-reviews): [#2003] record the PR #2749 review round 1 (josecelano-bot) 407a0e6 docs(issues): [#2003] attribute the 2026-11-06 progress log entry to a maintainer handle (josecelano-bot) e82bd07 docs(issues): [#2003] mark the order 12 close-out checklist as a historical plan (josecelano-bot) de3affe docs(issues): [#2003] drop the note about rows 16 to 19 from the unordered list (josecelano-bot) cf50477 docs(issues): [#2003] state the end date of da2ce7's ownership (josecelano-bot) 6874dd7 docs(issues): [#2003] refresh the EPIC state and return ownership to josecelano (josecelano-bot) Pull request description: Spec-only PR for EPIC #2003. - Sets `epic-owner` to josecelano and records that da2ce7 held the EPIC from 2026-09-28 to reorganize it and file the friction register. - Adds Subissues rows 16 to 19: #2581 (DONE, PR #2683) and #2712, #2713, #2714 (TODO), which GitHub lists as sub-issues but the spec did not. - Notes that #2347's close-out PR #2367 merged; the #2347 specification stays the record. - Adds a Decisions entry and a Progress Log line. Nothing else changes. Checks: `linter markdown`, `linter cspell` and the pre-commit gate pass. The issue body mirror is not re-derived here; the maintainer decides when. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ACKs for top commit: josecelano: ACK 5f1f676 Tree-SHA512: a573a28811ede31b66fa8fe1bc17def0a70275962b0443362957ff0c57d5fbfd73c76822020bd92390f97a8d38b2ced5b424de43de57543d0c49a37dbf3e13f5


Closes #2581
Parent EPIC: #2003
Summary
Adds
wait-for-pr-review, a deterministic Rust poller that lets an AI agent wait for pull-request reviewers without spending tokens and without the contributor telling it to wait. It reads the pull request through theghCLI, makes no model calls, holds no token, and returns one JSON object as soon as something happens. The spec, including the maintainer decisions of 2026-10-28, is indocs/issues/open/2581-2003-pr-review-wait-poller/ISSUE.md.Behavior
The poller returns a
kindofreview,comment,head_changed,pr_closed,pr_merged, ortimeout. Only reviews and comments from watched reviewers count (da2ce7andcopilot-pull-request-reviewer[bot]by default, repeatable--reviewerto override). The baseline is the poller start, the commit date of--since-head-sha, or a moment given with--since. Arevieworcommentresult carries acursor, so the review loop can resume strictly after a handled event, andhead_movedwhen the head is not the commit the agent has checked out, so the loop synchronizes before processing feedback.--since-head-shaand--sincecan be combined. The defaults are a 2-minute poll interval and a 15-minute timeout, and the timeout is a hard bound on everyghcall.It follows the CLI output contract ADR: one JSON object on stdout, NDJSON diagnostics on stderr, exit codes
0,1and2, and TTY refusal. A timeout is a result (exit0,kind: timeout) rather than a dedicated exit code.SIGINTandSIGTERMstop the wait and any in-flightghcall, write aninterruptedrecord, and exit1.Changes
wait-for-pr-reviewin.github/skills/dev/pr-reviews/wait-for-pr-review/tool/, a workspace member but not a default member, with a.dockerignoreentry.wait-for-pr-reviewdocumenting usage, result kinds, and the review loop, linked fromprocess-pr-review.AGENTS.md.manual-verification-evidence.mdrecorded, and the audit of Copilot's reviews indocs/pr-reviews/pr-2683-review/PR-REVIEW.md(four Copilot reviews, sixteen findings of which fourteen are distinct and two are duplicates; each distinct finding is fixed in its own commit).fix(tests): [#2581] reserve configuration scenario ports below the ephemeral range: the Testing workflow of this pull request failed inbase_source_precedencewithAddress already in use, a flake that also failed runs 37060706317 (2026-10-02) and 38925732709 (2026-10-16). The scenarios hard-coded ports 43152 to 43156, which sit in Linux's ephemeral range. They now draw random ports from below that range. Reproduction, red and green evidence are in section V8 of the evidence file. The holder of the port in CI was not identified.Validation
cargo test -p wait-for-pr-review: unit tests with a scriptedgh, and integration tests that run the real binary against a fakeghscript (exit codes, TTY refusal, signals, hungghcalls with and without a signal,--sinceand the cursor).docker build --target recipe --file Containerfile .succeeds, so the container build still resolves the workspace.cli-configurationsuite passes (29 passed) and passed 40 more runs; before the fix it failed with only 43152 held.Not yet verified
V6 (the poller returning on a real
da2ce7review) is still open in the evidence file. V7 is settled: the RESTrequested_reviewerscall withreviewers[]=copilot-pull-request-reviewer[bot]requests a Copilot review, and Copilot answered about 40 minutes later; the skill records the command and how to check it. The follow-up issue about the ADR scope and exit-code policy is not opened yet.