Skip to content

fix(github): a paginated gh api read fails closed on a page that is not the expected json, instead of returning a short listing #1034

Closed

Description

@dan-petty

Problem

_fetch_all_pages (src/devops_cli/github/rate_limiter.py:1590-1624, at 79e1e93), which run_gh uses for every gh api --paginate call through _run_gh_paginated, fails open:

  • A page that exits 0 with empty stdout ends the loop (:1613-1615), the same as a literal [].
  • When extract_json_payload returns None, or a JSON object on a later page, _append_paginated_data returns False and the loop breaks (:1617-1621).
  • Either way _fetch_all_pages returns is_exhausted=True (:1624), so _run_gh_paginated reports exit 0 with the items read so far.

A bad first page therefore reads as an empty listing, and a bad later page as a short one, and no caller can tell. Such pages happen: a proxy's HTML error page, a truncated body, a {"message": ...} error object. extract_json_payload (:388) also scans non-JSON output for the first [ or {, so a body with a preamble can be partly accepted.

Reproduced during #740's review with the real run_gh and a stubbed run_subprocess: page 1 returning <html>upstream</html> gave [] with exit 0, and page 2 returning it gave only page 1's 100 items. #740 works around it by reading and validating each page itself (GitHubRoadmapStore._read_listing). These callers still rely on the shared reader:

  • commands/pr.py:1295 and :1456 (PR readiness), github/check_verdict.py:263 (check runs), github/pr_monitor.py:326, :410, :516;
  • github/issues.py:138 and :393, github/projects.py:783, github/client.py:456, commands/gh.py:1289 (devops gh api --paginate).

A short check-run or review-thread listing can make a readiness check pass on data it never saw.

Acceptance criteria

  • A page that exits 0 but is empty, is not JSON, or is not the expected shape (a JSON list, or the check-runs object run_gh already accepts) is a failed read: run_gh returns a non-zero result whose stderr names the endpoint and the page. A literal [] page still ends a listing normally.
  • extract_json_payload is not used to salvage a paginated page: a page with a preamble before its JSON is a failed read.
  • Tests through the real run_gh with run_subprocess stubbed: an HTML page, an empty page, a truncated body and an error object, each on page 1 and on a later page, give a failed read naming the page; a normal listing that ends with [] or a short page still succeeds. Offline, each well under 1 s.
  • A PR-readiness test: a check-run listing whose second page is malformed makes devops pr check-readiness report the read failure instead of evaluating the first page's checks.
  • changelog.d/1034.md records the fix under ### Fixed. CHANGELOG.md is not edited.
  • uv run devops ci passes.

Key questions

Depends on: none.
Order: before #983 (v0.2.28), which carries the rule forward. #740 can drop its own page validation after this lands.
Related: #740, #983, #767.

Update 2026-10-08: amended criteria (assessed against release/v0.2.29, 910b823)

Why the criteria above are not enough on their own. _query_timeline_copilot_state (src/devops_cli/github/pr_monitor.py:326-345) pages with --paginate and --jq together. run_gh applies --jq to every page, so a page comes back as filtered lines, empty output or a single object, never a JSON list. Under this item's rule every one of those is a failed read. Copilot state then becomes "unread", which goes into the merge-failure reasons (pr_monitor.py:553-554), so devops pr wait and devops pr monitor would never report a PR as ready.

  • Checked offline. On 910b823, two matching timeline events already come back as [], the silent loss this item is about.
  • An implementation of the criteria above alone gives "empty response", "unexpected response shape" and "malformed JSON" for 0, 1 and 2 matching events.

Two more gaps let a short listing through:

  • the page cap (while page <= max_pages, rate_limiter.py:1612, :1639) ends as if the listing were complete;
  • the reader assumes 100 items per page (_extract_page_per_page, :1514), but _build_paginated_url (:1524) never sends per_page, so reviews (pr_monitor.py:495) and the timeline stop after GitHub's default of 30.

#983 is open in the backlog, not in v0.2.28, so this item is the only scheduled fix.

Added acceptance criteria:

  • A paged read (run_gh with --paginate) that also carries -q/--jq, -t/--template, -i/--include or --silent is refused before any request. It exits non-zero, and stderr names the flag. The flags are detected with request_classifier's existing gh api argparse parser, not a new string check.
  • _query_timeline_copilot_state stops using --jq.
    • It reads issues/{n}/timeline?per_page=100 as a JSON listing and filters the Copilot and reviewed events in Python, taking the author from actor.login or user.login.
    • The jq-shaped NDJSON fixtures in tests/test_github_pr_monitor.py (around :248 and :305, and the human-review case around :851) become raw timeline JSON.
    • Test: a two-page timeline whose matching event is on page 2 gives the right Copilot state.
  • A listing that is still full when it reaches DEFAULT_GH_MAX_PAGINATED_PAGES is a failed read that names the cap, as feat(github): current release admission, cap, descoping and stall rules (devops roadmap reprioritize) #740's _read_listing does. It is no longer returned as complete.
  • Every page URL carries per_page, defaulting to DEFAULT_GH_REST_PER_PAGE when the caller gave none, so the short-page rule matches the server's page size.
  • devops gh api graphql --paginate is a query, so it takes the paged path. It is refused with a message that names GraphQL; today it returns page 1's object.

Notes for the implementer:

  • extract_json_payload has nine more callers in github/projects.py (:378 through :1453). Keep the function, and stop using it only to salvage paginated pages.
  • Each devops pr wait poll now reads every timeline page, not just page 1. That is two pages for a release PR with about 110 events.

Activity

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

    @dan-petty
    OwnerAuthor

    The acceptance criteria were amended on 2026-10-08 (see "Update 2026-10-08" at the end of the body). Implementing only the original criteria breaks devops pr wait and devops pr monitor, because the Copilot timeline read pages with --jq, which every page would now fail on, so no PR is ever reported ready. Branch fix/1034-paginated-gh-api-fails-closed follows the original criteria only. Please pick up the added criteria before opening the PR.

  4. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1406, merged into release/v0.2.29 as ae9e3b1.

    Summary

    Resolves #1034.

    Updates _fetch_all_pages in src/devops_cli/github/rate_limiter.py to fail closed when reading paginated GitHub API responses:

    • A page that exits 0 but is empty, not JSON, contains a preamble, or has an unexpected response shape returns a non-zero exit status (returncode=1) naming the endpoint and page in stderr.
    • A paged read (run_gh with --paginate) carrying -q/--jq, -t/--template, -i/--include, or --silent is rejected before making any request, exiting non-zero and naming the flag in stderr.
    • devops gh api graphql --paginate is classified as a query and takes the paged path, exiting non-zero with a message stating that GraphQL queries do not support --paginate.
    • Every page URL carries per_page, defaulting to DEFAULT_GH_REST_PER_PAGE (100) when omitted, and listings that are still full upon reaching DEFAULT_GH_MAX_PAGINATED_PAGES fail closed naming the cap.
    • Updates _query_timeline_copilot_state in src/devops_cli/github/pr_monitor.py to remove --jq and parse raw timeline JSON, extracting author from actor.login or user.login.

    8 file(s) changed.

    How it was verified

    Check runs at 064da1f:

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

    Acceptance Criteria of docs/agent/tasks/task-1034-paginated-gh-api-read-fails-closed.md:

    • A page that exits 0 but is empty, is not JSON, or is not the expected shape is a failed read: run_gh returns a non-zero result whose stderr names the endpoint and the page. A literal [] page still ends a listing normally.
    • extract_json_payload is not used to salvage a paginated page: a page with a preamble before its JSON is a failed read.
    • Tests through the real run_gh with run_subprocess stubbed: an HTML page, an empty page, a truncated body and an error object, each on page 1 and on a later page, give a failed read naming the page; a normal listing that ends with [] or a short page still succeeds. Offline, each well under 1 s.
    • A PR-readiness test: a check-run listing whose second page is malformed makes devops pr check-readiness report the read failure instead of evaluating the first page's checks.
    • A paged read (run_gh with --paginate) carrying -q/--jq, -t/--template, -i/--include or --silent is refused before any request, exiting non-zero and naming the flag in stderr.
    • _query_timeline_copilot_state stops using --jq, queries issues/{n}/timeline?per_page=100, and filters events in Python using actor.login or user.login.
    • Timeline NDJSON fixtures in tests/test_github_pr_monitor.py updated to raw JSON array fixtures.
    • Test: a two-page timeline whose matching event is on page 2 gives the right Copilot state.
    • A listing that is still full when reaching DEFAULT_GH_MAX_PAGINATED_PAGES fails closed naming the cap.
    • Every page URL carries per_page, defaulting to DEFAULT_GH_REST_PER_PAGE (100) when omitted.
    • devops gh api graphql --paginate is classified as a query taking the paged path, and is refused with a message naming GraphQL.
    • changelog.d/1034.md records the fix under ### Fixed. CHANGELOG.md is not edited.
    • uv run devops ci passes.
  5. added a commit that references this issue on Oct 8, 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