GitHub.searchIssues fails with 422 when perPage does not evenly divide the 1000-result cap
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- typescript
- 領域
- api
調査の方向性
src/prompt-generators/github/github.ts から始めて、normalizeMaxResults と GITHUB_SEARCH_RESULT_LIMIT に加えて、searchIssues のページネーションループを調べてください。perPage: 70 と 1,000 件を超える結果を返すクエリで問題を再現し、ページウィンドウが上限を超えるリクエストを行う前に、422 をスローせずページネーションが停止することを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Observed behavior
GitHub.searchIssues throws GitHub API error 422: Only the first 1000 search results are available when perPage is set to a value that does not evenly divide 1000 and the underlying query has more than 1000 matching issues.
GitHub's REST search API has a hard cap of 1,000 results per query, and any request where page * per_page > 1000 is rejected with HTTP 422. normalizeMaxResults caps the effective maximum at GITHUB_SEARCH_RESULT_LIMIT (1000), and the pagination loop in searchIssues continues until issues.length >= maxResults. With a non-divisor perPage value, the loop reaches a page where page * perPage overshoots 1000 before issues.length reaches 1000.
Example with perPage: 70 and the default maxResults of 1000 against a query that returns 5000+ issues:
- Pages 1 to 14 return 70 items each, accumulating 980 issues.
- The break conditions at the end of page 14 are all false (
items.length (70) < perPage (70)is false,980 < total_countis true,980 < 1000is true), so the loop continues. - Page 15 is requested with
per_page=70, so15 * 70 = 1050 > 1000. GitHub returns HTTP 422 andsearchIssuesthrows.
This is silent at the type/config level: the docstring on GitHubIssueSearchParams.perPage says "GitHub accepts 1 to 100" with no caveat about result-window alignment.
Expected behavior
searchIssues should not crash with a 422 when used within the documented perPage and maxResults contracts. It should either stop paginating once the next request would overshoot the 1000-result window, or normalize perPage so that it always evenly divides the effective cap.
Minimal reproduction
import { GitHub } from 'loop-the-loop/prompt-generators/github/github';
import { vi } from 'vitest';
vi.stubGlobal(
'fetch',
vi.fn().mockImplementation((url: string) => {
const u = new URL(url);
const page = Number(u.searchParams.get('page'));
const perPage = Number(u.searchParams.get('per_page'));
if (page * perPage > 1000) {
return Promise.resolve({
ok: false,
status: 422,
text: () =>
Promise.resolve(
JSON.stringify({
message: 'Only the first 1000 search results are available',
}),
),
});
}
return Promise.resolve({
ok: true,
status: 200,
text: () =>
Promise.resolve(
JSON.stringify({
total_count: 5000,
items: Array.from({ length: perPage }, (_v, i) => ({
number: (page - 1) * perPage + i + 1,
title: 't',
html_url: 'https://github.test/x',
state: 'open',
})),
}),
),
});
}),
);
const github = new GitHub({ origin: 'https://api.test' });
await github.searchIssues({
repository: 'octocat/Hello-World',
query: 'is:open',
perPage: 70,
});
// throws: GitHub API error 422: Only the first 1000 search results are available
Suggested fix
In the pagination loop in src/prompt-generators/github/github.ts, stop iterating once the next request would push past the result window. For example, extend the post-page break to also handle the cap:
if (
reply.items.length < perPage ||
issues.length >= reply.total_count ||
issues.length >= maxResults ||
(page + 1) * perPage > GITHUB_SEARCH_RESULT_LIMIT
) {
break;
}
Alternatively, normalize perPage so that it always divides maxResults (and therefore GITHUB_SEARCH_RESULT_LIMIT) cleanly when the cap is in effect, and document the rounding behavior on GitHubIssueSearchParams.perPage.
- 主要言語
- TypeScript
- スター
- 2
- フォーク
- 1
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
joewalker/loop-the-loop のほかの issue
-
bug S4
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal informationオープンbug S3
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
joewalker/loop-the-loop#79 ·
joewalker/loop-the-loop の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
marmelab/react-admin#11431 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
db-ux-design-system/core-web#8655 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
stripe/react-stripe-js#728 ·
-
[Upload Grade C dataset] the pop-up changes it's size while uploading the document => Jumping effectオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
epam/statgpt-admin-frontend#305 ·
メンテナーはふだん 1 日以内に返信