Skip to content

feat(github): slim github_list_pr_reviews that never offloads (#357) - #358

Merged
MementoRC merged 2 commits into
developmentfrom
feat/357-slim-review-listing
Nov 23, 2026
Merged

MementoRC merged 2 commits into
developmentfrom
feat/357-slim-review-listing

Conversation

@MementoRC

@MementoRC MementoRC commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a new read-only lean tool, github_list_pr_reviews. It answers "which bots reviewed, and on which commit" on busy PRs without bodies, diff hunks or offloading.

  • All reviews: REST /pulls/{n}/reviews, every page. At MAX_PAGES it fails instead of returning a partial list.
  • Compact rows: id, author (REST login, [bot] kept), author_type (User/Bot), state, commit_id, submitted_at. A null user or login is reported as ghost.
  • Filters: authors (case-insensitive substrings, blank entries ignored) and commit_id (full SHA or a prefix of at least 7 characters, case-insensitive).
  • include_inline_counts: adds a per-review inline comment count using one paginated /comments pass. When it is off, no extra request is made.
  • Never offloaded: NEVER_OFFLOAD_TOOLS in response_offloader.py contains only this tool, and a test enforces that. _process_result skips offload and token-limiter truncation for it. Error bodies in its failures are capped at 500 chars.
  • Registry: listed in registry_github_threads.py next to github_list_review_threads, with reviewer/bot/copilot/sourcery discovery keywords.

Code lives in new small modules. The files that are already over the 500-line limit (registry_github.py, models.py) were not touched.

Testing

  • Full suite (pixi run -e quality test): 3522 passed, 0 failed, 7 deselected. Tree /home/memento/ClaudeCode/Servers/git/worktrees/feat-issues-impl, base a8e89e2 plus these changes, committed as cb6cf9d.
  • lint, format-check and typecheck (pyright, 0 errors) all pass.
  • The new tests cover paging (230 reviews), [bot] login matching, User vs Bot, null user and null login, full/short/uppercase commit filtering, short-SHA rejection, inline counts across 2 comment pages, the MAX_PAGES failure, a non-list response, error-text capping, and a 150-row result staying inline while another tool of the same size still offloads.

Not yet checked against live ci-framework#476 (all 16 reviews, including Copilot's). That needs the running server reloaded with this branch.

Closes #357

Summary by Sourcery

Add a compact, never-offloaded GitHub PR review listing tool for identifying reviewers and the commits they reviewed.

New Features:

  • Add a compact read-only GitHub PR review listing tool with pagination, author and commit filtering, and optional inline comment counts.

Bug Fixes:

  • Prevent oversized review-list responses from being offloaded or token-truncated, and fail instead of returning incomplete results when pagination exceeds the limit.

Enhancements:

  • Register the review listing tool with reviewer, bot, Copilot, Sourcery, and commit discovery keywords.

Tests:

  • Add coverage for review pagination, compact output, filtering, comment counts, malformed and oversized responses, error handling, tool discovery, and never-offload behavior.

On busy PRs there was no cheap way to see which bots reviewed which
commit: github_get_pr_details shows only the last 5 reviews, and
github_get_pr_reviews (inline comment bodies) gets offloaded to /tmp,
which mcp__git__-only agents cannot read.

New read-only tool github_list_pr_reviews:
- REST /pulls/{n}/reviews, all pages; fails at MAX_PAGES rather than
  returning a partial list.
- One compact row per review: id, author (REST login, [bot] suffix
  kept), author_type (User/Bot), state, commit_id, submitted_at. No
  bodies or hunks. Null user/login -> "ghost".
- Filters: authors (case-insensitive substrings, blanks ignored),
  commit_id (full or >=7-char prefix, case-insensitive).
- include_inline_counts adds per-review inline comment counts via one
  paginated /pulls/{n}/comments pass (no extra call when off).
- Compact JSON {pr,total,returned,reviews}.

Never offloaded: new NEVER_OFFLOAD_TOOLS in response_offloader (only
this tool, guarded by a test); _process_result returns its result
without offload or token-limiter truncation. HTTP error text in its
failures is capped at 500 chars.

Registered in registry_github_threads next to
github_list_review_threads, with reviewer/bot/copilot/sourcery
discovery keywords.

Closes #357
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the review-list tool’s input fields and filtering options as the model consumed by its registry entry.

  • src/mcp_server_git/github/models_threads.py L17-35

API

Expose the compact PR review listing tool through the GitHub API exports and registry, including its discovery keywords and user-facing tool description.

  • src/mcp_server_git/github/api.py L19
  • src/mcp_server_git/lean/registry_github_threads.py L38-47 (+4 small edits)

Implementation

Implement paginated retrieval, compact review rows, author and commit filtering, optional inline-comment counts, and bounded failures for the new listing tool.

  • src/mcp_server_git/github/pr_review_list.py L1-131

Mark the review-list tool as exempt from offloading and bypass both offloading and token truncation when processing its result.

  • src/mcp_server_git/lean/interface.py L30, L263-264
  • src/mcp_server_git/lean/response_offloader.py L22-25, L103-104

Tests

Test the new tool’s compact output, pagination, filters, counts, failures, discovery, and guaranteed inline response behavior.

  • tests/unit/github/test_pr_review_list.py L1-277

Verify reviewer, Copilot, and Sourcery search terms discover the new review-list tool.

  • tests/unit/lean/test_tool_match.py L75-83

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 26d75f4

#357 feat(github): slim review listing (author/state/commit_id/submitted_at) that never offloads · 7 of 8 met · 1 to check by hand

# Requirement Status Notes
1 Add github_list_pr_reviews with authors and commit_id filters. ✅ Met The tool accepts both filters, along with the repository and PR identifiers.
2 Return compact review rows with id, author, author_type, state, commit_id and submitted_at, without bodies or hunks. ✅ Met Rows contain the requested fields and omit review bodies and diff hunks.
3 Paginate all reviews and keep results inline rather than offloading them. ✅ Met Pagination fails instead of truncating beyond MAX_PAGES, and the tool bypasses offloading and token limiting.
4 Filter authors by case-insensitive substrings and reviews by commit SHA. ✅ Met Author substrings are case-insensitive; commit IDs support case-insensitive full or at-least-seven-character prefix matching.
5 Optionally return inline comment counts. ✅ Met include_inline_counts adds per-review counts from paginated review comments.
6 Register the tool in the lean registry next to github_list_review_threads. ✅ Met It is included in the review-thread tool definitions and added to the GitHub registry.
7 Report bot logins consistently, with or without the [bot] suffix, as documented. ✅ Met The tool returns the REST login unchanged, preserving any [bot] suffix; its documentation describes this behavior.
8 On ci-framework#476, return all 16 reviews inline, including the Copilot review and its commit_id. 👀 Check by hand (external system) Run the tool against ci-framework#476 with this branch deployed and confirm all 16 reviews, including Copilot's commit_id, are returned inline.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/mcp_server_git/github/pr_review_list.py" line_range="45" />
<code_context>
+        if len(batch) < _PER_PAGE:
+            return items
+    return fail(
+        f"❌ {what.capitalize()} exceed {MAX_PAGES} pages; refusing to truncate."
+    )
+
</code_context>
<issue_to_address>
**Complete page-limit results fail**

When an endpoint contains exactly `MAX_PAGES * _PER_PAGE` items, `_fetch_pages` reaches `fail` after the final full page without checking whether another page exists, so it reports a complete result as exceeding the limit and callers receive no list.

Check whether another page exists before failing, and return the collected items when the endpoint ends at the page limit.
</issue_to_address>

### Comment 2
<location path="src/mcp_server_git/github/pr_review_list.py" line_range="29-41" />
<code_context>
+) -> list[dict[str, Any]] | ToolFailure:
+    """Every REST page of *endpoint*, or a ready failure."""
+    items: list[dict[str, Any]] = []
+    for page in range(1, MAX_PAGES + 1):
+        response = await client.get(
+            endpoint, params={"per_page": _PER_PAGE, "page": page}
+        )
+        if response.status != 200:
+            error_text = await response.text()
+            if len(error_text) > _MAX_ERROR_CHARS:
+                error_text = error_text[:_MAX_ERROR_CHARS] + "…"
+            return fail(f"❌ Failed to fetch {what}: {response.status} - {error_text}")
+        batch = await response.json()
+        if not isinstance(batch, list):
+            return fail(f"❌ Unexpected response shape from {endpoint}: expected list")
+        items.extend(batch)
+        if len(batch) < _PER_PAGE:
+            return items
</code_context>
<issue_to_address>
**Concurrent deletions skew comment counts**

When a review comment is deleted while `include_inline_counts` is fetching multiple `/comments` pages, the next numbered-page request uses an offset into the changed comment list, so a comment shifted onto an already-read page is skipped; `Counter` then returns an incorrect inline count.

Use a cursor/snapshot-capable listing for the count pass, or detect collection changes and retry it before returning counts.
</issue_to_address>

### Comment 3
<location path="src/mcp_server_git/github/pr_review_list.py" line_range="34" />
<code_context>
+            endpoint, params={"per_page": _PER_PAGE, "page": page}
+        )
+        if response.status != 200:
+            error_text = await response.text()
+            if len(error_text) > _MAX_ERROR_CHARS:
+                error_text = error_text[:_MAX_ERROR_CHARS] + "…"
</code_context>
<issue_to_address>
**Large error bodies consume memory**

When gitHub or a proxy returns a very large non-200 response body, `response.text()` buffers the entire upstream error body before `_MAX_ERROR_CHARS` truncates it, so a proxy or service returning an unusually large error response can consume excessive memory while the tool is handling the failure.

Read only a bounded amount of the error response before constructing the failure message.
</issue_to_address>

### Comment 4
<location path="src/mcp_server_git/github/pr_review_list.py" line_range="30" />
<code_context>
+    """Every REST page of *endpoint*, or a ready failure."""
+    items: list[dict[str, Any]] = []
+    for page in range(1, MAX_PAGES + 1):
+        response = await client.get(
+            endpoint, params={"per_page": _PER_PAGE, "page": page}
+        )
</code_context>
<issue_to_address>
**Slow pages delay the listing**

When gitHub or an intermediary responds slowly across multiple pages, `_fetch_pages` awaits each page sequentially, and the shared client’s `get` uses the session’s default timeout without an overall deadline. A slow GitHub or proxy response can therefore hold a call for minutes per page, with up to 50 pages, so callers wait a long time before receiving a result.

Set a bounded overall deadline for the listing (and return a clear timeout failure) rather than allowing every page to consume the client’s full request timeout.
</issue_to_address>

### Comment 5
<location path="tests/unit/github/test_pr_review_list.py" line_range="106-110" />
<code_context>
+    bot = _review(2, "copilot-pull-request-reviewer[bot]", "Bot")
+    client = FakeClient({_REVIEWS: [_review(1), bot]})
+
+    data = json.loads(await _run(client, authors=["COPILOT"]))
+
+    assert data["total"] == 2
+    assert data["returned"] == 1
+    assert data["reviews"][0]["author"] == "copilot-pull-request-reviewer[bot]"
+    assert data["reviews"][0]["author_type"] == "Bot"
+
</code_context>
<issue_to_address>
**Prefix-only author matching passes**

When an implementation matches authors only with `startswith`, `test_list_pr_reviews_matches_bot_login_when_authors_substring_differs_in_case` uses `"COPILOT"` at the start of the bot login on line 106, so an implementation using `startswith` instead of substring matching still passes its assertions on lines 108–111; callers cannot filter by text appearing later in a login.

Use an author filter that occurs only in the middle of a login and assert that the review is returned.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

)

Addresses sourcery-ai threads on pr_review_list.py (complete page-limit
results failed) and test_pr_review_list.py (author filter test now uses a
mid-login substring so prefix-only matching would fail it).

Co-Authored-By: Claude <noreply@anthropic.com>
@MementoRC
MementoRC merged commit d9e51af into development Nov 23, 2026
41 checks passed
@MementoRC
MementoRC deleted the feat/357-slim-review-listing branch November 23, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(github): slim review listing (author/state/commit_id/submitted_at) that never offloads

1 participant