Skip to content

fix(github): pr monitor reports copilot as idle or completed when its timeline or reviews read fails #806

Closed

Description

@dan-petty

Problem Statement

devops pr monitor (and FastMCP pr_monitor, which shells out to it at src/devops_cli/ai/mcp/server.py:2151-2178) can report that Copilot is idle or has finished reviewing when it actually failed to read Copilot's state. Checked at the release/v0.2.25 tip:

  • _query_timeline_copilot_state returns (False, "") (not working) when the timeline read exits non-zero (src/devops_cli/github/pr_monitor.py:321-334). An exhausted run_gh retry loop returns returncode=1 with empty stdout and stderr (src/devops_cli/github/rate_limiter.py:1835-1858), and with check=False nothing raises (:1861-1871), so a rate-limited or failed gh call lands in the silent branch.
  • _fetch_raw_reviews returns [] when the reviews read fails (pr_monitor.py:509-522).
  • _detect_copilot_status then reports completed from an earlier Copilot review, or idle if there is none (pr_monitor.py:377-391). Its state vocabulary is idle | working | completed | changes_requested (:80); there is no unread value.
  • is_review_ready treats both states as settled (pr_monitor.py:132-142), and _check_pr_ready_step repeats the same rule (pr_monitor.py:803-806).

The two other reads in the same status snapshot already fail loud: _fetch_pr_details raises GitHubOperationError (pr_monitor.py:499-501) and the threads read raises from _run_graphql_query (src/devops_cli/github/pr_threads.py:83-85). Only the timeline and reviews reads fail silent. The check-run side of the same module already has a fail-closed vocabulary: PRCheckRun.is_failure counts CheckBucket.UNREAD as a failure (pr_monitor.py:69, bucket from src/devops_cli/github/check_verdict.py:34).

A failed timeline read on its own is enough to hide a Copilot re-review that is still running. Take an approved PR whose checks pass: once the settle window has passed (pr_monitor.py:794-810), pr monitor certifies it ready with exit 0 (pr_monitor.py:764-773) while Copilot is still reviewing. AGENTS.md:278 ("Copilot post-ready review sessions have settled") and :283-285 ("Wait for Copilot Review Sessions to Settle") require Copilot to settle first.

A failed reviews read is narrower today: with --require-reviews (the default) the empty list makes _resolve_review_decision return None (pr_monitor.py:600-617) and the monitor exits 2 with the misattributed message "requires review approval before merging: current review decision is 'NONE'" (pr_monitor.py:747-756). With --no-require-reviews (approval_ok is True at :135) the PR can be certified ready with Copilot's latest changes-requested review unseen.

Proposed Solution

Add an unread state to CopilotReviewStatus that any failed Copilot read produces, make readiness treat it as not settled, and surface the reason everywhere pr monitor reports Copilot.

  • CopilotReviewStatus (pr_monitor.py:76-82): state gains the value unread; a new field unread_reason: str = "" carries why, named after CheckVerdictSummary.unread_reason (check_verdict.py:75), the existing fail-closed precedent for check runs. is_active stays False for unread; message reads "Copilot review state could not be read: ". The message is an inline string like the four existing state messages (pr_monitor.py:348-391); no lang/ edit is needed.
  • The reason is the gh stderr trimmed to 256 characters, or Exit code N when stderr is empty, the same rule _fetch_pr_details uses (pr_monitor.py:500). No dependency on the error classes of refactor(github): the github session owns transport, ledger, error classes and link pagination #983 (v0.2.28, which lands after this item): the trimmed stderr is enough here, and refactor(github): the github session owns transport, ledger, error classes and link pagination #983 can later feed unread_reason from its classifier without changing the field.
  • _query_timeline_copilot_state and _fetch_raw_reviews report failure to their caller instead of returning the "nothing happened" value. One shape that keeps the existing callers and test patches working: each returns its current value plus an error string (empty on success), and get_pr_monitoring_status (pr_monitor.py:625-672) passes both errors into _detect_copilot_status. The argv of both reads stays as it is (pr_monitor.py:323-330, :513-518), so refactor(github): the github session owns transport, ledger, error classes and link pagination #983's pagination change rebases onto this item without touching its logic. A successful read with empty output is not a failure: an empty timeline or an empty reviews list still means idle, as the existing _detect_copilot_status tests already assert with MagicMock(returncode=0, stdout="") (tests/test_github_pr_monitor.py:503-504).
  • _detect_copilot_status (pr_monitor.py:337-391): if either read failed, return unread before any other branch, including changes_requested. One rule, no precedence table.
  • is_review_ready (pr_monitor.py:132-142) and _check_pr_ready_step (pr_monitor.py:803-806): unread is not settled. The monitor loop keeps polling while the state is unread, exactly as it does for working and pending checks (pr_monitor.py:833-856), and on timeout _build_monitor_timeout_result (pr_monitor.py:777-791) appends the unread reason to its message. Exit codes stay 0/1/2/3 (pr_monitor.py:156).
  • _build_failure_reasons (pr_monitor.py:551-579) adds Copilot review state could not be read: <reason> so failure_reasons in the --format json|yaml|markdown payload (src/devops_cli/commands/pr.py:575-596, via model_dump) and the table output carry it. The table progress line (pr.py:648-651) already prints any non-idle state, so Copilot: unread appears without a change there.
  • Changelog fragment changelog.d/806.md and task file docs/agent/tasks/task-806-<slug>.md, written in the delivering PR. CHANGELOG.md and docs/ROADMAP.md are not edited.

Scope

One pull request touching src/devops_cli/github/pr_monitor.py, tests/test_github_pr_monitor.py, tests/test_pr_cmd.py, changelog.d/806.md and the task file. Effort Low, as groomed.

Key Questions

Acceptance Criteria

  • Timeline read exits 1 and an earlier Copilot review exists: _detect_copilot_status returns state == "unread" with a non-empty unread_reason, not completed, and a PRMonitorStatus carrying it has is_review_ready False. Test: new test_detect_copilot_status_unread_when_timeline_read_fails in tests/test_github_pr_monitor.py, patching devops_cli.github.pr_monitor.run_gh with MagicMock(returncode=1, stdout="", stderr="HTTP 403: rate limit"), as the _detect_copilot_status tests at :492-559 do.
  • Reviews read exits 1: get_pr_monitoring_status returns copilot_status.state == "unread". Test: new test_get_pr_monitoring_status_unread_when_reviews_read_fails, shaped like test_get_pr_monitoring_status_success (:206-276) with the pulls/168/reviews branch of mock_subprocess returning returncode=1.
  • Timeline read exits 1 and the known Copilot review recommends changes: the state is unread, not changes_requested. Test: new test_detect_copilot_status_unread_wins_over_changes_requested.
  • A successful read with empty output still reports idle, and every existing state is unchanged: the existing tests in tests/test_github_pr_monitor.py (TestGetPRMonitoringStatus, TestMonitorPR, the _detect_copilot_status tests) and tests/test_pr_cmd.py::test_pr_monitor_* pass without edits. Command: uv run pytest tests/test_github_pr_monitor.py tests/test_pr_cmd.py -q.
  • monitor_pr does not certify an approved, green PR ready while Copilot is unread: with get_pr_monitoring_status patched to return an otherwise ready status whose copilot_status is unread, the result is exit 3 and the message contains the unread reason. Test: new test_monitor_pr_does_not_certify_ready_while_copilot_unread, shaped like test_monitor_pr_timeout (:368-392).
  • failure_reasons names the unread reason. Test: new test_build_failure_reasons_includes_copilot_unread, shaped like test_build_failure_reasons_includes_review_approval (:875-890).
  • devops pr monitor --format json output carries copilot_status.state == "unread" and copilot_status.unread_reason. Test: new case in tests/test_pr_cmd.py patching devops_cli.github.pr_monitor.monitor_pr as test_pr_monitor_json_format_is_pure_json (:598-629) does, asserting on the parsed JSON payload.
  • No test hits the network: every new test patches run_gh, get_pr_monitoring_status or monitor_pr. Command: uv run devops ci passes.
  • changelog.d/806.md exists and CHANGELOG.md and docs/ROADMAP.md are untouched. Command: devops pr check-readiness passes.

Out of Scope

Dependencies

Readiness check (2026-10-04)

Checked at the release/v0.2.26 tip (b61e5a0). Every cited symbol and test still exists, and the dependency picture is unchanged: #767 merged in v0.2.26 without touching these lines, and #983 is still open in v0.2.28. Only line numbers moved:

  • src/devops_cli/github/pr_monitor.py: every cited line from :42 on is 4 lower, because feat(cli): extend the ruff rule set to the correctness families #420 shortened PRCheckRun's validator. Current lines:
    • PRCheckRun.is_failure is at :65 and CopilotReviewStatus at :72-78, with the state comment at :76.
    • is_review_ready is at :128-137, with approval_ok at :131. The exit-code comment is at :152.
    • _query_timeline_copilot_state is at :317-330 and _detect_copilot_status at :333-387.
    • _fetch_pr_details raises at :495-497; the reason rule is on :496.
    • _fetch_raw_reviews is at :505-518 and _build_failure_reasons at :547-575.
    • _resolve_review_decision is at :596-613 and get_pr_monitoring_status at :621-668, with the details read on :626.
    • The review-approval exit 2 is at :743-752 and the ready certification at :760-769.
    • _build_monitor_timeout_result is at :773-787.
    • _check_pr_ready_step is at :790-806, with copilot_done at :799-802 and return None on :806.
    • The monitor_pr loop is at :829-854. The import on :17 is unchanged.
  • src/devops_cli/commands/pr.py (3 lines lower):
    • _emit_structured_monitor_result is at :578-598.
    • The progress line is at :651-654.
    • The monitor_pr call is at :661-670.
  • src/devops_cli/ai/mcp/server.py: pr_monitor is at :2245-2271.
  • src/devops_cli/github/rate_limiter.py: the retry loop is _run_gh_retry_loop (:1834-1877), and _raise_for_status is at :1880-1890. An exhausted loop returns the last attempt's process with its stderr, so the Exit code N fallback applies only when gh printed nothing.
  • AGENTS.md: the settle rules are at :279 and :286.
  • The test-file lines cited in the acceptance criteria are unchanged.

The acceptance criteria are unchanged. The item agrees with the rules in force: offline tests, a changelog.d fragment, and one PR that closes #806 only.

Activity

  1. added
    type/bug
    scope/github
    priority/p1-high
    on Oct 1, 2026
  2. added this to the v0.2.27 milestone on Oct 2, 2026
  3. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Placed in v0.2.27, one of its slots held for P1 work that surfaced after it was planned. Value High, effort Low. Before it starts: The last criterion ('the #685 inspector shows unread') cannot be met: #685 is open and there is no GitHub tab in ui/ at the tip. 'Depends on: none' is therefore inaccurate. Drop that criterion or make it conditional on #685.

    Checked against the code at the release/v0.2.25 tip.

  4. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Consolidation (2026-10-03): this item is a sub-issue of #998 (one readiness verdict). Its scope and v0.2.27 placement are unchanged, and it lands before #769 and #983. The rule it applies to the Copilot reads, that an unread fact blocks and names its reason, is the one #769 and #797 apply to check runs, statuses and threads.

  5. dan-petty-bot commented on Oct 5, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1234, merged into release/v0.2.27 as 5651e62.

    Summary

    Resolves #806

    Fail-closed handling of Copilot review state in devops pr monitor: report Copilot review state as unread with unread_reason when timeline or review reads fail, rather than reporting completed or idle.

    5 file(s) changed.

    How it was verified

    Check runs at ac3ac2f:

    • Prune PR DevContainer Images: pending
    • CodeQL: pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • Dependency Freshness: skipping
    • DevContainer Image: skipping
    • Service Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-806-pr-monitor-reports-copilot-as-idle-or-completed-when-its-timeline-or-reviews-read-fails.md:

    • Timeline read exits 1 and an earlier Copilot review exists: _detect_copilot_status returns state == "unread" with non-empty unread_reason, and PRMonitorStatus.is_review_ready is False.
    • Reviews read exits 1: get_pr_monitoring_status returns copilot_status.state == "unread".
    • Timeline read exits 1 and known Copilot review recommends changes: state is unread, taking precedence over changes_requested.
    • A successful read with empty output still reports idle, and every existing state is unchanged.
    • monitor_pr does not certify an approved, green PR ready while Copilot is unread, exiting 3 with the unread reason in the timeout message.
    • failure_reasons names the unread reason.
    • devops pr monitor --format json output carries copilot_status.state == "unread" and copilot_status.unread_reason.
    • All tests run offline and patch external subprocess calls.
    • changelog.d/806.md exists and CHANGELOG.md and docs/ROADMAP.md remain untouched.
    • Pending a person: uv run devops ci passes on this branch.
  6. added a commit that references this issue on Oct 6, 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

    priority/p1-highscope/githubtype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions