Skip to content

fix(github): count each page of a paginated GitHub read - #5070

Merged
dan-petty merged 2 commits into
mainfrom
fix/4737-count-paginated-reads
Nov 12, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/4737-count-paginated-reads

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

devops gh api --paginate handed every read to gh. gh walks all Link pages in one process, so run_gh counted the walk as one request with the status none, and the GitHub request panels undercounted by an amount that nobody could measure.

A REST GET of a path now reads through the GitHub session. The session counts each page with the status of its answer and sends conditional requests. GitHubSession.pages() gives each page whole. The --jq filter runs on each page through jq.py, and each value prints as gh prints it. gh keeps GraphQL, writes, gh placeholders, full URLs, --template, --cache and other gh flags. The metrics row read stays with #3941.

Closes #4737

Change: openspec/changes/archive/2026-11-12-4737-count-each-page-of-a-paginated/

@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/github GitHub Projects v2, Views, Milestones, Labels, and PR automation labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Fail-to-pass and measurements

Fail-to-pass (devops ci fail-to-pass --base origin/main, local run on 2026-11-12, exit 0): 8 changed tests fail on the base and pass on the head. tests/github/test_github_api_pages.py does not collect on the base, because it imports the new module.

  • test_gh_api_paginate_counts_each_page_it_reads: on the base, the github_api fake refuses the gh command, and the output is not JSON. On the head, 4 pages add 4 to devops_cli_github_requests_total with the status 200.
  • test_gh_api_paginate_runs_the_jq_filter_on_each_page, test_gh_api_paginate_exits_1_naming_a_listing_github_does_not_find and test_gh_api_paginate_dry_run_plans_the_session_read fail on the base for the same cause.
  • The 4 pages tests of tests/github/test_github_session.py fail on the base with AttributeError: 'GitHubSession' object has no attribute 'pages'.

Live read through the session (2026-11-12): devops gh api 'repos/dan-petty/devops-cli/issues?state=open&per_page=100' --paginate --jq length printed 7 lines (6 of 100 and one of 4). The same read through gh before the change printed 7 lines in one counted request.

gh output form (gh 2.103.1): devops gh api meta --jq '"str", null, true, 1.5, 0.125, 3, {"b":1,"a":"x"}' printed str, an empty line, true, 1.50, 0.12, 3 and {"a":"x","b":1}. test_each_value_of_a_jq_filter_prints_as_gh_prints_it holds these rules.

Local checks: devops ci --check --only lint,format,typecheck,docs,openspec,deps,constructs,test-tree,startup-imports,swallowed-failures,audit passed. pytest tests/github tests/commands/test_gh_cmd.py tests/telemetry tests/invariants passed (2,529 tests).

git grep -n -- --paginate src after the change

File Lines Reason
src/devops_cli/commands/gh.py 3 The --paginate option, the argv of the reads that gh keeps, and the comment on the gh walk timeout. gh keeps GraphQL (it pages by a cursor in the query, which the session does not send), a write, a gh placeholder (gh fills it from its own base repository), a full URL (it can name another host), --template (a Go template), --cache (the response cache of run_gh) and any other gh flag, such as --slurp.
src/devops_cli/github/client.py 2 GhCliClient.api(paginate=True), whose one caller is the taxonomy read of the metrics row, and the text of parse_paginated_json. #3941 moves that read to the session and removes the second open-issue listing.
src/devops_cli/github/metrics.py 1 The dry-run line of the same metrics read (#3941).
src/devops_cli/github/api_pages.py text The module text of the new read.
src/devops_cli/config/constants.py 1 The table of the gh api argv parser. It sends no request.
src/devops_cli/config/defaults.py 1 The text of the gh walk timeout.
src/devops_cli/github/request_classifier.py 1 Text.

Dependency

jq==1.13.0 (jq.py, BSD-2-Clause, released 2026-10-18, wheels for CPython 3.14 on manylinux 2.28, musllinux 1.2, macOS and Windows). jq.py ships no type information, so typings/jq.pyi types the 3 calls and mypy_path = "typings" finds it. The suppression ceiling of [[tool.mypy.overrides]] stays at 1.

Cost of the built part (the printer of the --jq values, about 40 lines): about 150,000 tokens and 2 hours to build, and about 10,000 tokens a year to keep it equal to gh's output.

Steps for a person

devops gh api --paginate handed every read to gh, which walks all Link
pages in one process, so run_gh counted the walk as one request with
the status none. A REST GET of a path now reads through the GitHub
session, which counts each page with the status of its answer and
sends conditional requests. The --jq filter runs on each page through
jq.py and prints each value as gh prints it. gh keeps GraphQL, writes,
placeholders, full URLs, --template, --cache and other gh flags.

GitHubSession.pages() gives each page whole, and paginate() and pages()
share one walk with the same page cap.
@dan-petty
dan-petty force-pushed the fix/4737-count-paginated-reads branch from d0767a3 to 51447f4 Compare November 12, 2026 13:44
@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 13:57
@dan-petty
dan-petty merged commit 908e24a into main Nov 12, 2026
31 checks passed
@dan-petty
dan-petty deleted the fix/4737-count-paginated-reads branch November 12, 2026 13:57
@dan-petty

Copy link
Copy Markdown
Owner Author

Check results

Head commit: 51447f446110ca054c5d558129b4f6fb1ed3824d

Check Conclusion Link
Tests & Coverage success run
devops-cli success run
zizmor success run
trivy-config success run
CodeQL success run
Plan Check skipped run
Tests on Main skipped run
Test Job Duration skipped run
Dependency Freshness skipped run
DevContainer Image success run
Fail-to-Pass Check success run
Analyze (actions) success run
Service Image Tests (shard 5 of 6) success run
Service Image Tests (shard 1 of 6) success run
Service Image Tests (shard 3 of 6) success run
Service Image Tests (shard 4 of 6) success run
Service Image Tests (shard 2 of 6) success run
Tests & Coverage (shard 1 of 4) success run
Tests & Coverage (shard 3 of 4) success run
Tests & Coverage (shard 4 of 4) success run
Tests & Coverage (shard 2 of 4) success run
Design Tokens success run
Runner Image success run
Analyze (python) success run
Static Analysis success run
MCP Server Image success run
Service Image success run
Semantic PR title success run
Service Image Tests (shard 6 of 6) success run
Changed-Test Independence success run
Docs Site Build success run

Fail-to-pass run: https://github.com/dan-petty/devops-cli/actions/runs/43230235509/job/131223305358

Skipped check: Plan Check
Skipped check: Tests on Main
Skipped check: Test Job Duration
Skipped check: Dependency Freshness

@dan-petty

Copy link
Copy Markdown
Owner Author

Review finding after the merge, and what I did:

  1. Blocking, confirmed: the session path sends no per_page=100 (src/devops_cli/github/api_pages.py). gh adds per_page=100 to a paginated REST read when the endpoint has none (addPerPage in pkg/cmd/api). The session path does not, so GitHub sends pages of 30. I checked it live on 2026-11-12: devops gh api 'repos/dan-petty/devops-cli/labels' --paginate --jq length prints 30, 30, 30, 5 (4 requests) on main at 8a7b113, and 95 (1 request) at 16356d8 on the gh path. A listing of more than 3,000 items now stops at the 100-page cap with GitHubUnreadError. This PR is merged, so I did not change it. I filed fix(github): a paginated devops gh api read sends per_page=100 as gh does #5100 with the evidence and the fix: add per_page=DEFAULT_GH_REST_PER_PAGE with urllib.parse when the query has none, and a command test that asserts the first request URL.

dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.119.0](v0.118.0...v0.119.0)
(2026-11-12)


### Features

* **repos:** the claim sets In Progress
([#5111](#5111))
([06ef1c6](06ef1c6))
* **roadmap:** a fix-plan step repairs a plan PR with open findings
([#5104](#5104))
([ca5b16d](ca5b16d))
* **roadmap:** extend stage review rounds while open findings drop
([#5090](#5090))
([bacf713](bacf713))
* **roadmap:** re-anchor a stale citation that matches one line
([#5040](#5040))
([16356d8](16356d8))


### Bug Fixes

* **ci:** keep failed test IDs in the service image shard summary
([#5106](#5106))
([88589ef](88589ef))
* **github:** count each page of a paginated GitHub read
([#5070](#5070))
([908e24a](908e24a))
* **github:** keep the metrics permissions out of the runner Job token
([#5064](#5064))
([fb549ff](fb549ff))
* **github:** pace mutations through the clock seam
([#5063](#5063))
([2bd87bc](2bd87bc))
* **k8s:** delete the CoreDNS files that k3s never applies
([#5055](#5055))
([463f601](463f601))
* **monitoring:** tidy LLM stack windows, units and lines
([#5052](#5052))
([375d724](375d724))
* **roadmap:** a refused kept plan uses no stage gate return
([#4983](#4983))
([b8adbca](b8adbca))
* **roadmap:** count a command as removed only when MUST NOT governs it
([#4985](#4985))
([2e6f407](2e6f407))
* **roadmap:** cut prose after a cited stage command
([#4982](#4982))
([a172563](a172563))
* **roadmap:** name every module of a group with no named test
([#5089](#5089))
([27a0e79](27a0e79))
* **roadmap:** stage returns every open review finding to the planner
([#5067](#5067))
([21b116e](21b116e))
* **roadmap:** the alternatives check reads the tools in use
([#5062](#5062))
([8903233](8903233))
* **roadmap:** the constants gate reads 6_500 and no new value
([#5080](#5080))
([8a7b113](8a7b113))
* **roadmap:** the constants gate reads only a stated value
([#5042](#5042))
([cf4733e](cf4733e))
* **telemetry:** read repository traffic as the GitHub App
([#4932](#4932))
([7c42823](7c42823))
* **tests:** close the UDP, DNS and git gaps of the network floor
([#5101](#5101))
([047ee48](047ee48))
* **tests:** repair the bwrap contract suite and gate it
([#5110](#5110))
([9a0659d](9a0659d)),
closes [#4715](#4715)


### Performance Improvements

* **ci:** build the Service image once for its test shards
([#5079](#5079))
([dcf5bd5](dcf5bd5))
* **ci:** run only the required checks on the release PR
([#5057](#5057))
([8174071](8174071))
* **ci:** stop the cache export of pull request image builds
([#5113](#5113))
([ba30820](ba30820))
* **roadmap:** consolidate keeps its vectors in the shared tiers
([#5099](#5099))
([2a8bf1a](2a8bf1a))


### Code Refactoring

* **roadmap:** one Status writer for every job
([#5109](#5109))
([24cfedc](24cfedc))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/github GitHub Projects v2, Views, Milestones, Labels, and PR automation type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(github): count each page of a paginated GitHub read

1 participant