Skip to content

Comments

Reduce context usage for get_pull_request_review_comments using pull_request_read#2062

Merged
tommaso-moro merged 2 commits intomainfrom
tommy/reduce-context-pr-review-comments
Feb 23, 2026
Merged

Reduce context usage for get_pull_request_review_comments using pull_request_read#2062
tommaso-moro merged 2 commits intomainfrom
tommy/reduce-context-pr-review-comments

Conversation

@tommaso-moro
Copy link
Contributor

Closes:

Summary

This PR reduces the context window usage when fetching pull request review comments using the pull_request_read tool (get_review_comments).

It does so by using the minimal types pattern (which is already used elsewhere in the codebase for the same reason) to reduce the payload that is sent back to the model when the tool is used. Specifically, GraphQL node IDs are removed, nested author objects are flattened to plain strings, and the Comments.Nodes nesting is flattened to a direct comments array, eliminating unnecessary JSON noise per review thread.

Tests & Metrics

When tested with this PR:
Before: 6815 tokens
After: 5823 tokens
Context reduction: 14.56%

Fields preserved

Thread: is_resolved, is_outdated, is_collapsed, comments, total_count
Comment: body, path, line, author (flattened from Author.Login), created_at, updated_at, html_url (from URL)
Pagination: has_next_page, has_previous_page, start_cursor, end_cursor, total_count

Fields dropped

Thread ID (GraphQL node ID, not used for pagination or any subsequent tool call), Comment ID (GraphQL node ID, not useful for reasoning — html_url is the meaningful identifier)

Why

The raw GraphQL response returned by the GitHub API includes GraphQL node IDs on both threads and comments, deeply nested author objects (Author.Login), and a nested Comments.Nodes array structure that add up across threads and waste context window on every call. These fields are not used by models for reasoning or follow-up tool calls — pagination relies on cursors, and the html_url serves as the useful comment identifier.

What changed

  • Added MinimalPageInfo, MinimalReviewComment, MinimalReviewThread, and MinimalReviewThreadsResponse types to minimal_types.go
  • Added convertToMinimalReviewThreadsResponse, convertToMinimalReviewThread, and convertToMinimalReviewComment converter functions
  • Updated GetPullRequestReviewComments to return via MarshalledTextResult instead of manual json.Marshal of raw GraphQL structs
  • Updated tests to assert against typed MinimalReviewThreadsResponse fields instead of map[string]any

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Note: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

@tommaso-moro tommaso-moro requested a review from a team as a code owner February 23, 2026 12:05
Copilot AI review requested due to automatic review settings February 23, 2026 12:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Reduces token/context usage for pull_request_read’s get_review_comments path by returning a minimized, flattened representation of PR review threads/comments instead of the raw GraphQL-shaped payload.

Changes:

  • Introduces minimal output types + converters for PR review threads/comments (flattened authors, flattened comment nodes, dropped GraphQL IDs).
  • Updates GetPullRequestReviewComments to return the new minimal response via MarshalledTextResult.
  • Updates pullrequests_test.go assertions to validate the typed minimal response shape.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/github/pullrequests.go Switches review-comments response to marshalled minimal response type.
pkg/github/minimal_types.go Adds minimal structs and converters for review threads/comments + pagination.
pkg/github/pullrequests_test.go Updates tests to unmarshal and assert on MinimalReviewThreadsResponse.

omgitsads
omgitsads previously approved these changes Feb 23, 2026
@tommaso-moro tommaso-moro merged commit ee3ab7b into main Feb 23, 2026
16 checks passed
@tommaso-moro tommaso-moro deleted the tommy/reduce-context-pr-review-comments branch February 23, 2026 14:32
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.

2 participants