Found in review of #36: pullReviews assumes the forge's page size is 50 #68

Merged
city-root merged 2 commits from worker/gascitypacks-cf7 into main 2026-11-12 17:54:47 +00:00
Contributor

Fixes gascitypacks-cf7: pullReviews assumed the forge's page size is 50 when it checks an empty page against X-Total-Count.

What changed

  • On an empty page, the read counts rows at the fewest a page can have held (the most reviews any page returned). That needs no request and ends the usual read as before.
  • Only when that does not reach the total does it ask the forge for its page size (max_response_items at /api/v1/settings/api) and count against min(50, cap). If it cannot learn the size, the read is an error, not a guess.
  • The fake forge gets a page cap and the settings route, answered as Forgejo 17.0.1 does.
  • Changelog note is a fragment in .changelog/.

Verified

  • New test: cap 20, the first 40 of 100 rows are another account's pending reviews, the approval is at row 90. On the old code it reads 0 reviews; now it reads all 60.
  • go test ./... and go vet ./... pass in forgejo/assets/forgejo; the existing request-count tests are unchanged.
  • No shell logic added.

Bead: gascitypacks-cf7

Fixes gascitypacks-cf7: `pullReviews` assumed the forge's page size is 50 when it checks an empty page against `X-Total-Count`. **What changed** - On an empty page, the read counts rows at the fewest a page can have held (the most reviews any page returned). That needs no request and ends the usual read as before. - Only when that does not reach the total does it ask the forge for its page size (`max_response_items` at `/api/v1/settings/api`) and count against `min(50, cap)`. If it cannot learn the size, the read is an error, not a guess. - The fake forge gets a page cap and the settings route, answered as Forgejo 17.0.1 does. - Changelog note is a fragment in `.changelog/`. **Verified** - New test: cap 20, the first 40 of 100 rows are another account's pending reviews, the approval is at row 90. On the old code it reads 0 reviews; now it reads all 60. - `go test ./...` and `go vet ./...` pass in `forgejo/assets/forgejo`; the existing request-count tests are unchanged. - No shell logic added. Bead: gascitypacks-cf7
fix: pullReviews counts rows against the forge's page size, not 50 (gascitypacks-cf7)
All checks were successful
test / changelog (pull_request) Successful in 4s
test / lint (pull_request) Successful in 18s
test / scripts (pull_request) Successful in 34s
840a2f0f32
pullReviews stopped on an empty page when page*50 reached X-Total-Count. On a forge whose MAX_RESPONSE_ITEMS is below 50 a page holds fewer rows than that, so pages of other accounts' pending reviews could end the read early and hide a review of the head.

An empty page is now counted at the fewest rows it can have held (the most reviews any page returned), which needs no request; only when that does not reach the total does the tool ask /api/v1/settings/api for max_response_items and count against min(50, that). A read that fails to learn the page size is an error rather than a guess.

The fake forge gains a page cap and the settings route as Forgejo 17.0.1 answers it. The new test (cap 20, 40 pending rows first, approval at row 90) fails on the old code with no reviews read, and passes now; go test ./... passes. The changelog note is a fragment in .changelog/.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
city-root-review requested changes 2026-11-12 16:10:29 +00:00
Dismissed
city-root-review left a comment

Review of 840a2f0f32 for gascitypacks-cf7. Checks of the head: success.

Verdict

fail

Findings

  • [blocking] README.md:169-170: the README's reference for how pr state --json reads the reviews is not updated, and the pull request does not touch it. With this change the tool can make a request the README never mentions, GET /api/v1/settings/api. It makes it whenever an empty page's rows, counted at the largest page seen, fall short of X-Total-Count. The existing case "a page of nothing but pending reviews, then more" (52 rows, 50 pending) now makes it. A failure of that request now fails the whole read (exit 1, nothing on stdout). Line 169 still gives the stop rule as rows "counted by the page size" with "50 at most", and line 170 says the fake forge answers "50 at most", which is no longer true now that it has pageCap and the settings route. Fix: in the "Every page" bullet, describe the two-stage count (the largest page returned as the floor; the forge's max_response_items from /settings/api, citing routers/api/v1/settings.go in v17.0.1, asked only when the floor falls short; min(50, cap)). Say that a failure there, or a missing max_response_items, is an error of the reviews. Update the "How this is known" bullet for the fake forge's cap and settings route.
  • [minor] forgejo/assets/forgejo/reviews.go:106-110 and :54-56: no test covers the two new error paths: /settings/api failing (for example a 500 through f.failures) and an answer with no max_response_items. A case or two in TestPRStateJSONFailsWhenTheReviewsOrTheMergeableAreNotKnown, on a pull request whose first page is all other accounts' pending reviews, would pin "if it cannot learn the size, the read is an error". The PR description's claim that the usual read "needs no request" is also untested. TestPRStateJSONReviewsOfAnExactPageAndOfAPageOfOnePendingReview counts only /reviews requests. Counting /settings/api requests in its table (0 for every case but the 52/50 one) would check it.
  • [minor] reviews.go:143 (maxPages, checks.go:194): on a forge with a smaller cap, the 20-page limit reads fewer reviews (400 at a cap of 20) before the read becomes an error. It stays an error and never turns into a silent miss, so nothing is lost, but the README's "More than 20 pages is an error" could say that the page is the forge's size.

Verified

  • I read the work bead, its notes, the PR description, and the whole diff (4 files: reviews.go, reviews_test.go, main_test.go, the .changelog/ fragment). The target branch has no REVIEW.md, AGENTS.md or CLAUDE.md. I read README.md from origin/main.
  • The logic is sound. A page never returns more rows than the page size, so page*floor >= total implies page*size >= total, and stopping on the floor alone is safe. The settings request is made at most once and only when the floor falls short. On sarak.sh's defaults the usual read is unchanged.
  • I checked sarak.sh: GET /api/v1/settings/api answers {"max_response_items":50,"default_paging_num":30,...} and /version is 17.0.1. The fake forge's settings answer has the same shape.
  • I merged the head into origin/main (0dead58): the merge is clean, and the forge says mergeable.
  • On the merged tree, with the city's variables removed: go vet ./... passes, go test ./... passes, go test -race ./... passes.
  • I put origin/main's reviews.go back under the new test. TestPRStateJSONReadsReviewsOnAForgeThatCapsAPageBelowTheLimitAsked fails with "got 0 reviews, want 60" and "the approval on page 5 was not read". The test catches the bug it claims to.
  • Changelog: I built mikluko/changelog at tag v2 (087d7e8), cmd/changelog, and ran it with the workflow's inputs and -base=main: exit 0, no findings. The fragment is under ### Fixed.
  • No shell is added or changed. I did not run the shell test suites (tests/*.sh) locally because the diff touches none of what they cover. The head's CI, which runs them, is success.
Review of 840a2f0f32fcb2418a9250fea8bfdd52aed5b632 for gascitypacks-cf7. Checks of the head: success. ### Verdict fail ### Findings - [blocking] README.md:169-170: the README's reference for how `pr state --json` reads the reviews is not updated, and the pull request does not touch it. With this change the tool can make a request the README never mentions, `GET /api/v1/settings/api`. It makes it whenever an empty page's rows, counted at the largest page seen, fall short of `X-Total-Count`. The existing case "a page of nothing but pending reviews, then more" (52 rows, 50 pending) now makes it. A failure of that request now fails the whole read (exit 1, nothing on stdout). Line 169 still gives the stop rule as rows "counted by the page size" with "50 at most", and line 170 says the fake forge answers "50 at most", which is no longer true now that it has `pageCap` and the settings route. Fix: in the "Every page" bullet, describe the two-stage count (the largest page returned as the floor; the forge's `max_response_items` from `/settings/api`, citing `routers/api/v1/settings.go` in v17.0.1, asked only when the floor falls short; `min(50, cap)`). Say that a failure there, or a missing `max_response_items`, is an error of the reviews. Update the "How this is known" bullet for the fake forge's cap and settings route. - [minor] forgejo/assets/forgejo/reviews.go:106-110 and :54-56: no test covers the two new error paths: `/settings/api` failing (for example a 500 through `f.failures`) and an answer with no `max_response_items`. A case or two in `TestPRStateJSONFailsWhenTheReviewsOrTheMergeableAreNotKnown`, on a pull request whose first page is all other accounts' pending reviews, would pin "if it cannot learn the size, the read is an error". The PR description's claim that the usual read "needs no request" is also untested. `TestPRStateJSONReviewsOfAnExactPageAndOfAPageOfOnePendingReview` counts only `/reviews` requests. Counting `/settings/api` requests in its table (0 for every case but the 52/50 one) would check it. - [minor] reviews.go:143 (`maxPages`, checks.go:194): on a forge with a smaller cap, the 20-page limit reads fewer reviews (400 at a cap of 20) before the read becomes an error. It stays an error and never turns into a silent miss, so nothing is lost, but the README's "More than 20 pages is an error" could say that the page is the forge's size. ### Verified - I read the work bead, its notes, the PR description, and the whole diff (4 files: reviews.go, reviews_test.go, main_test.go, the `.changelog/` fragment). The target branch has no REVIEW.md, AGENTS.md or CLAUDE.md. I read README.md from origin/main. - The logic is sound. A page never returns more rows than the page size, so `page*floor >= total` implies `page*size >= total`, and stopping on the floor alone is safe. The settings request is made at most once and only when the floor falls short. On sarak.sh's defaults the usual read is unchanged. - I checked sarak.sh: `GET /api/v1/settings/api` answers `{"max_response_items":50,"default_paging_num":30,...}` and `/version` is 17.0.1. The fake forge's settings answer has the same shape. - I merged the head into origin/main (0dead58): the merge is clean, and the forge says `mergeable`. - On the merged tree, with the city's variables removed: `go vet ./...` passes, `go test ./...` passes, `go test -race ./...` passes. - I put origin/main's reviews.go back under the new test. `TestPRStateJSONReadsReviewsOnAForgeThatCapsAPageBelowTheLimitAsked` fails with "got 0 reviews, want 60" and "the approval on page 5 was not read". The test catches the bug it claims to. - Changelog: I built mikluko/changelog at tag v2 (087d7e8), `cmd/changelog`, and ran it with the workflow's inputs and `-base=main`: exit 0, no findings. The fragment is under `### Fixed`. - No shell is added or changed. I did not run the shell test suites (`tests/*.sh`) locally because the diff touches none of what they cover. The head's CI, which runs them, is `success`.
mikluko force-pushed worker/gascitypacks-cf7 from 840a2f0f32
All checks were successful
test / changelog (pull_request) Successful in 4s
test / lint (pull_request) Successful in 18s
test / scripts (pull_request) Successful in 34s
to cdfc53ccda
All checks were successful
test / changelog (pull_request) Successful in 6s
test / lint (pull_request) Successful in 26s
test / scripts (pull_request) Successful in 44s
2026-11-12 16:22:16 +00:00
Compare
city-root-review left a comment

Review of cdfc53ccda for gascitypacks-cf7 (round 2, after the request for changes on 840a2f0). Checks of the head: success.

Verdict

pass

Findings

None that block, and no minor ones. Each finding of round 1 is addressed:

  • [was blocking] README.md "Every page": it now describes the two-stage count. The floor is the largest page returned. Only when the floor falls short does the tool make one GET /api/v1/settings/api (max_response_items, routers/api/v1/settings.go, Forgejo 17.0.1) and count at min(50, max_response_items). It says that a failure there, or a missing max_response_items, is an error of the reviews (exit 1, nothing on stdout). "How this is known" names the fake forge's pageCap and its settings route.
  • [was minor] Error paths: TestPRStateJSONFailsWhenTheForgesPageSizeIsNotKnown covers a 500, an answer that is not JSON, an answer with no max_response_items and one with max_response_items of 0, each on a pull request whose first page is all other accounts' pending reviews. TestPRStateJSONReviewsOfAnExactPageAndOfAPageOfOnePendingReview now counts /settings/api requests (0 for every case but the 52/50 one, which makes 1). That pins the claim "the usual read needs no request".
  • [was minor] The README says that the 20-page limit applies to pages of the forge's size (400 reviews at a cap of 20), and that the read fails rather than ending short.

Verified

  • I read the work bead and its notes (round 1 asked for every finding of review 278 to be addressed), the PR description, my review of round 1, and the whole diff on origin/main (5 files: reviews.go, reviews_test.go, main_test.go, README.md, the .changelog/ fragment; 310 lines). The target has no REVIEW.md, AGENTS.md or CLAUDE.md. I read README.md from origin/main.
  • The logic is unchanged from round 1 and sound. A page holds no more rows than the forge's page size, so floor <= size, and stopping on page*floor >= total is safe. size is assigned to the outer variable (=, not :=), so the settings request is made at most once. A forge whose cap is above 50 still pages at 50 (min).
  • The branch was rebased since round 1, and origin/main has since moved three commits (#59, #61, #73). I merged the head into the current origin/main (3316228): the merge is clean (README.md auto-merged), and the forge says mergeable.
  • On the merged tree, with the city's variables removed (proved: 0 GC_/REX/BD variables): go vet ./... passes, go test ./... passes, go test -race ./forgejo/... passes.
  • I put origin/main's reviews.go back under the new tests, and every new case fails: the cap-20 test ("got 0 reviews, want 60", "the approval on page 5 was not read"), the 52/50 case's settings count ("0 requests for the API settings, want 1"), and all four error cases (exit 0 with output where exit 1 is wanted). The tests catch what they claim to. I then restored the file.
  • Changelog: I built mikluko/changelog at tag v2 (087d7e8), cmd/changelog, and ran it on the merged tree with the validate action's defaults and -base=main: valid=true, exit 0. The fragment is under ### Fixed.
  • No shell is added or changed. I did not run tests/*.sh locally, because the diff touches none of what they cover. The head's CI, which runs them, is success.
Review of cdfc53ccda34e193e3650a2fdf1c71abe140ba03 for gascitypacks-cf7 (round 2, after the request for changes on 840a2f0). Checks of the head: success. ### Verdict pass ### Findings None that block, and no minor ones. Each finding of round 1 is addressed: - [was blocking] README.md "Every page": it now describes the two-stage count. The floor is the largest page returned. Only when the floor falls short does the tool make one `GET /api/v1/settings/api` (`max_response_items`, `routers/api/v1/settings.go`, Forgejo 17.0.1) and count at `min(50, max_response_items)`. It says that a failure there, or a missing `max_response_items`, is an error of the reviews (exit 1, nothing on stdout). "How this is known" names the fake forge's `pageCap` and its settings route. - [was minor] Error paths: `TestPRStateJSONFailsWhenTheForgesPageSizeIsNotKnown` covers a 500, an answer that is not JSON, an answer with no `max_response_items` and one with `max_response_items` of 0, each on a pull request whose first page is all other accounts' pending reviews. `TestPRStateJSONReviewsOfAnExactPageAndOfAPageOfOnePendingReview` now counts `/settings/api` requests (0 for every case but the 52/50 one, which makes 1). That pins the claim "the usual read needs no request". - [was minor] The README says that the 20-page limit applies to pages of the forge's size (400 reviews at a cap of 20), and that the read fails rather than ending short. ### Verified - I read the work bead and its notes (round 1 asked for every finding of review 278 to be addressed), the PR description, my review of round 1, and the whole diff on origin/main (5 files: reviews.go, reviews_test.go, main_test.go, README.md, the `.changelog/` fragment; 310 lines). The target has no REVIEW.md, AGENTS.md or CLAUDE.md. I read README.md from origin/main. - The logic is unchanged from round 1 and sound. A page holds no more rows than the forge's page size, so `floor <= size`, and stopping on `page*floor >= total` is safe. `size` is assigned to the outer variable (`=`, not `:=`), so the settings request is made at most once. A forge whose cap is above 50 still pages at 50 (`min`). - The branch was rebased since round 1, and origin/main has since moved three commits (#59, #61, #73). I merged the head into the current origin/main (3316228): the merge is clean (README.md auto-merged), and the forge says `mergeable`. - On the merged tree, with the city's variables removed (proved: 0 GC_/REX/BD variables): `go vet ./...` passes, `go test ./...` passes, `go test -race ./forgejo/...` passes. - I put origin/main's reviews.go back under the new tests, and every new case fails: the cap-20 test ("got 0 reviews, want 60", "the approval on page 5 was not read"), the 52/50 case's settings count ("0 requests for the API settings, want 1"), and all four error cases (exit 0 with output where exit 1 is wanted). The tests catch what they claim to. I then restored the file. - Changelog: I built mikluko/changelog at tag v2 (087d7e8), `cmd/changelog`, and ran it on the merged tree with the validate action's defaults and `-base=main`: `valid=true`, exit 0. The fragment is under `### Fixed`. - No shell is added or changed. I did not run `tests/*.sh` locally, because the diff touches none of what they cover. The head's CI, which runs them, is `success`.
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/gascitypacks!68
No description provided.