agent posted review comments to the wrong PR number after pagination off-by-one
Fixes review agents commenting on the wrong PR due to pagination indexing bugs. Use when agent comments land on a different PR than intended. Not for comments on the right PR but wrong lines.
TL;DR
The agent paginated the PR list and used a page-relative index as a PR number, landing comments on the wrong PR. Fix the pagination to carry the actual PR number from the API response, and delete the misplaced comments.
Error
Agent log: posting review to PR #42 - actual target was PR #47 (page 2, index 2 treated as PR number).Steps
- Confirm the misplacement: find the agent's comments on the wrong PR. Expected: comments referencing code from a different PR.
- Delete or hide the misplaced comments and notify the wrong PR's author. Expected: the wrong PR is clean again.
- Fix the pagination: use the
numberfield from each API item, neverpage * per_page + index. Expected: the agent targets the true PR number. - Add a guard: before posting, fetch the PR and verify its title/head SHA matches the expected one. Expected: a mismatch aborts instead of misposting.
When to use
- Agent review comments appear on a PR the agent was not reviewing.
- The agent paginates PR listings.
When not to use
- Comments are on the right PR but the wrong lines - that is a diff-position bug, not pagination.
- A human posted to the wrong PR; this fix is for the agent's code.
Tool compatibility
- Any agent using the GitHub/GitLab PR list APIs.
- REST or GraphQL.
Variant phrasings
Off-by-one in GraphQL cursor pagination
Same root cause: cursors are opaque - always read the item's number field.
Wrong PR due to search API ordering
Search results reorder; re-fetch the PR by number before acting.
Why it happens
Paginated list APIs return items with their true identifiers, but page-relative math (page*size+i) computes a different number. Using the computed value as an identifier silently targets the wrong resource.
Edge cases
- Deleting someone else's PR comments needs write access; coordinate with repo admins if the agent lacks it.
- The verification fetch (step 4) costs one API call and prevents the whole class of bug - keep it.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_OvhxixwnxuRd5p8MV9l57g