@@ -117,6 +117,17 @@ Possible options:
117117 return attachRepoVisibilityIFCLabel (ctx , deps , client , owner , repo , r , ifc .LabelRepoUserContent )
118118 }
119119
120+ // Each method honours exactly one pagination style: get_review_comments
121+ // takes a GraphQL cursor (`after`), the other list methods take
122+ // `page`/`perPage`. A parameter the selected method cannot use is an
123+ // error rather than a silent no-op, so an LLM caller that passes
124+ // `after` to get_files (or `page` to get_review_comments) learns that
125+ // it did not advance the page instead of receiving the first page
126+ // again as if it had.
127+ if err := rejectUnsupportedPagination (method , args ); err != nil {
128+ return utils .NewToolResultError (err .Error ()), nil , nil
129+ }
130+
120131 switch method {
121132 case "get" :
122133 result , err := GetPullRequest (ctx , client , deps , owner , repo , pullNumber )
@@ -2502,3 +2513,32 @@ func newGQLIntPtr(i *int32) *githubv4.Int {
25022513 gi := githubv4 .Int (* i )
25032514 return & gi
25042515}
2516+
2517+ // rejectUnsupportedPagination returns an error when the caller supplies a
2518+ // pagination parameter the selected pull_request_read method does not honour.
2519+ // get_review_comments paginates by GraphQL cursor (`after`); the other list
2520+ // methods paginate by `page`/`perPage`; `get`, `get_diff` and `get_status`
2521+ // return a single object and paginate by nothing. Without this check the
2522+ // unsupported parameter is dropped silently and the caller receives the first
2523+ // page again, indistinguishable from a successful advance.
2524+ func rejectUnsupportedPagination (method string , args map [string ]any ) error {
2525+ _ , hasAfter := args ["after" ]
2526+ _ , hasPage := args ["page" ]
2527+ _ , hasPerPage := args ["perPage" ]
2528+
2529+ switch method {
2530+ case "get_review_comments" :
2531+ if hasPage {
2532+ return fmt .Errorf ("method %q paginates by cursor (perPage, after); \" page\" is not supported" , method )
2533+ }
2534+ case "get_files" , "get_commits" , "get_reviews" , "get_comments" , "get_check_runs" :
2535+ if hasAfter {
2536+ return fmt .Errorf ("method %q paginates by page/perPage; \" after\" is not supported" , method )
2537+ }
2538+ case "get" , "get_diff" , "get_status" :
2539+ if hasAfter || hasPage || hasPerPage {
2540+ return fmt .Errorf ("method %q returns a single result and does not accept pagination parameters" , method )
2541+ }
2542+ }
2543+ return nil
2544+ }
0 commit comments