Skip to content

refactor(github): pr readiness is one verdict module that the pr commands, the monitor and mcp consume #998

Closed
2 of 2 issues completed

Description

@dan-petty

Context & Rationale

The readiness rules live inside a Typer module. commands/pr.py:1177-1806 is 33 helpers and 525 lines; typer.Exit is raised 14 times inside commands and 23 times inside 14 helpers. Checked at 9c879ae.

  • Fetching and classifying check runs is written three times (pr.py:1258-1405, github/pr_monitor.py:394-495, github/check_verdict.py:220-355); _extract_page_runs exists three times, _fetch_pr_details twice, the mergeable evaluation twice, the unresolved-thread evaluation twice. refactor(github): read a pull request's checks once, fail-closed, for wait, monitor and readiness #769 unifies the check read; this item unifies the verdict around it.
  • The Item rule from feat(github): pr readiness requires an issue-linked, completed task file #704, "one PR closes exactly one issue and changes its Task file", exists only as private helpers (_closes_one_issue and _changes_its_task_file) called from _grounding_blockers.
  • pr monitor re-fetches details, checks and threads with its own helpers and its own PRMonitorStatus.is_ready_for_merge; pr ready uses a third path through check_verdict.fetch_pr_check_verdicts.
  • The MCP tool pr_check_readiness (ai/mcp/server.py:2204) reuses the rules by spawning uv run devops pr check-readiness.
  • Tests import or patch 19 pr.py private helpers and patch commands.pr.run_gh 21 times.

Deletion test: delete the pr.py block and the rules reappear in pr_monitor and the MCP tool. One module concentrates them.

Scope & Deliverables

Strategic Alignment

Scope added 2026-10-02: checked at 38517a8. _extract_page_runs is in commands/pr.py:1277 and github/pr_monitor.py:394, and github/check_verdict.py:220 holds the third copy as _extract_page_check_runs. _fetch_pr_details is at pr.py:228 and pr_monitor.py:495. The Item rules are at pr.py:1594-1700, and _evaluate_pr_blockers at :1703. The MCP tool pr_check_readiness (ai/mcp/server.py:2208-2222) runs uv run devops pr check-readiness. Tests name devops_cli.commands.pr.run_gh 53 times in 3 files, 19 of them as one-line patch(...) calls. Check-run exit codes already live on CheckVerdictSummary.exit_code: 0 pass, 8 pending, 1 failing or unread (check_verdict.py:101-115).

Acceptance criteria

Key questions

Finding from the v0.2.25 release PR (2026-10-03): pr wait gives up before pending checks finish

Problem (added). On #1089 (the v0.2.25 release PR), devops pr wait exited as soon as it saw unresolved review threads while required checks were still running. A person then had to re-run the wait after resolving the threads, and a check failure that arrived later was reported only on that second run. Unresolved threads are a blocker a person can still clear while CI runs; they are not a reason to stop waiting for checks.

Acceptance criteria (added).

  • The verdict separates pending (checks still running or queued) from blocked. While any required check is pending, pr wait keeps waiting, whatever other blockers it sees.
  • When the checks settle, pr wait reports every blocker at once: failed or unread checks, unresolved threads, Copilot state and any other predicate, each with its reason.
  • A scripted test: a head with two pending required checks and one unresolved thread; the checks complete (one fails) after the thread is first seen. pr wait returns once, after the checks settle, and names both the failed check and the thread.

Placement. No change. This item's children (#806, #797, #769) supply the reads; the waiting rule lives in this one verdict.

Update 2026-10-08: refinement

#769 and #806 landed; this waits on #797. Checks have one reader (github/check_verdict.py:220), and rg 'def _extract_page' would also hit rate_limiter.py:1581; use rg -n 'def _extract_page_(check_)?runs' src. Still duplicated: _fetch_pr_details, the mergeable rules and thread reads (commands/pr.py:239, :1209; github/pr_monitor.py:488, :525). pr wait still exits while checks pend (pr_monitor.py:681-723). #1324 moves readiness into github/; the Item rules go to roadmap/. Whichever lands second rebases.

Proposed design

Problem statement

The pull request readiness rules are currently scattered across multiple modules and duplicated in several places, making them hard to maintain and test. The goal is to centralize these rules into a single module that can be consumed by various commands, monitors, MCP tools, and future components like Closure and the Service.

Acceptance criteria

  • Criterion 1: One module returns a readiness verdict from a repository, a pull request number and a runner with run_gh's signature
    Verification: The new module accepts repository, PR number and a runner with run_gh's signature, returning blockers, advisories, grounding facts and an exit code
  • Criterion 2: pr check-readiness, pr ready, pr monitor and the MCP pr_check_readiness tool use the centralized verdict module
    Verification: All commands and tools call the new verdict module instead of their own implementations
  • Criterion 3: The verdict takes its checks from refactor(github): read a pull request's checks once, fail-closed, for wait, monitor and readiness #769's fail-closed reader and reads none itself
    Verification: Verify that the check-run readers are consolidated in one place and the new verdict module uses them
  • Criterion 4: The Item rules are public predicates over the grounding facts, each with a table test
    Verification: Item rules (_closes_one_issue, _changes_its_task_file, _leaves_release_files_to_the_cut) are moved to roadmap/ and tested with table tests
  • Criterion 5: Tests compute verdicts from canned payloads through a scripted runner
    Verification: No readiness test patches devops_cli.commands.pr.run_gh; all tests use the new fake runner pattern
  • Criterion 6: The exit codes of pr check-readiness, pr ready and pr monitor do not change
    Verification: Run existing tests to ensure exit code behavior is preserved for all commands

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added
    type/refactor
    scope/github
    priority/p2-medium
    on Oct 2, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Consolidation (2026-10-03): this item is the parent of the readiness reads. One rule applies to every input: an unread fact blocks and names its reason (unread_reason). Sub-issues and order:

    Linked, not sub-issues:

  3. added this to the v0.2.37 milestone on Oct 17, 2026
  4. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  5. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Amendment (2026-10-18): a test-shaped handler in the check verdict module

    _fetch_commit_statuses_from_rest (src/devops_cli/github/check_verdict.py:360-388 at release/v0.2.37 66ff3d6) wraps its runner call in except StopIteration, IndexError: return [], None, "".

    • Why it exists: the production runner, run_gh, never raises either. Both come from a test's mocked reply list running out, so the handler exists only to cope with mocks. AGENTS.md lists product code that detects tests as a signal to stop and fix the cause.
    • It fails open: when it fires, the commit-status read returns no statuses and no unread reason, so the verdict reads "no statuses" rather than "statuses unread". Today that can only happen under a mock, but it would hide a read failure if a runner ever raised it.
    • Proposed, with this item's verdict module: delete the handler. Script the status call explicitly in every test that reaches it: the tests that relied on running out of replies then fail, and each gets its status reply or its github_api fake. A read that fails reports its unread reason, as the check-runs read does once refactor(github): the github session owns transport, ledger, error classes and link pagination #983 PR 4 merges.

    Found while #983 PR 4 moved _fetch_check_runs_from_rest (in the same module) onto the GitHub session.

  6. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Amendment (2026-10-18): the monitor ends on one transient unread poll

    devops pr monitor 1678 exited 1 after its third poll with "PR check verification failed closed: GitHub check-runs API error: GitHub gave no readable answer to GET /repos/dan-petty/devops-cli/commits/.../check-runs (page 1): ConnectTimeout". The first two polls had read the check runs fine. Three probes of the same read right afterwards each returned all 15 runs in under 2 s, and a fresh monitor reported 15/15 passed. One transient connect timeout ended the watch and reported a CI failure that did not exist.

    Cause, at release/v0.2.37 cca1ed9:

    Failing closed is right for a one-shot readiness verdict (devops pr check-readiness). A polling monitor should treat an unread poll as "not known yet". It keeps polling and fails closed only when the reads stay unread: for a set number of consecutive polls (a constant in config/defaults.py), or until its own timeout, whichever comes first. Its output names the read failures it saw either way.

    Tests first, offline: a monitor over a fake whose check-runs read fails once and then reports every check passed finishes successfully, and its output mentions the one unread poll. A read that stays unread for the bound fails closed with exit 1, naming the last reason.

  7. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Amendment (2026-10-18), from #1345 PR 1's review

    The review decision lets a COMMENTED reply replace a person's verdict. _extract_latest_reviews_by_user (src/devops_cli/github/pr_monitor.py:558-572 at 7607f0f) keeps each person's latest review of any state.

    • A probe shows [APPROVED, COMMENTED] by the same login gives REVIEW_REQUIRED, and [CHANGES_REQUESTED, COMMENTED] gives REVIEW_REQUIRED with no changes requested.
    • On feat(release): v0.2.28 #1283, 44 of 57 reviews are a person's empty COMMENTED thread replies.
    • It cannot be reached today: no release PR has had an approving review, and main requires 0 approvals. It becomes reachable once someone other than the approver opens release PRs, for example the planned GitHub App identity.
    • Fix in this item's verdict module: only APPROVED, CHANGES_REQUESTED and DISMISSED change a person's state, and DISMISSED clears it. The decisive states are a constant in config/constants.py. Do not switch to GraphQL reviewDecision, which is null when the base requires no approvals.

    No budget rule in the monitor. #1345's plan says this item "moves the monitor's review gate, with the budget rule, into the one verdict module". #1345 PR 1 adds no budget rule to the monitor. Its review confirmed _build_changes_status (#216) already reports Copilot's changes-recommended state as completed once no thread is unresolved, and an unresolved thread blocks by itself. Drop the budget rule from this item's plan. Optionally, have the verdict module name the unresolved threads in its "Copilot review requested changes" message, which is the only difference the rule would have made.

  8. modified the milestones: v0.2.37, v0.2.38 on Oct 19, 2026
  9. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 0ae4ea4 (see proposed design in issue body).

  10. modified the milestones: v0.2.38, on Oct 20, 2026
  11. changed the title [-]refactor(github): pr readiness is one verdict module that the pr commands, the monitor, mcp and closure consume[/-] [+]refactor(github): pr readiness is one verdict module that the pr commands, the monitor and mcp consume[/+] on Oct 23, 2026
  12. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    This item is larger than one pull request on today's code (origin/main 4226904), so it is split into two sub-issues:

    1. refactor(github): pr check-readiness reads one merge-readiness verdict from github/, and the item rules are public predicates in roadmap/ #2442: one merge-readiness verdict module in github/ that devops pr check-readiness renders, and the item rules as public predicates in roadmap/. No behavior changes.
    2. refactor(github): pr ready and pr monitor read the merge-readiness verdict, and pr monitor waits until the checks settle and names every blocker #2443: devops pr ready and devops pr monitor (and pr wait) read that verdict, and the monitor waits until the checks settle and then names every blocker. This part changes the monitor's behavior.

    Evidence of the size:

    What changed since this item was written:

    Decisions on the key questions (best practice):

    • The verdict lives in github/. The item rules are pure predicates in roadmap/.
    • The verdict decides what blocks and what is advisory, and carries pending checks as their own fact. Each command maps the verdict to its own exit codes, which do not change. Advisories never change an exit code.
  13. added
    status/ready
    value/medium
    effort/high
    on Oct 28, 2026
  14. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Both parts of this item are merged:

    The MCP tool needed no change: since #997 it is generated from the command and runs in process.

  15. removed
    status/ready
    on Oct 30, 2026
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

    effort/highpriority/p2-mediumscope/githubtype/refactorvalue/medium

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions