The best way to control Claude Code, Codex and more from any computer or phone
fix(gitlab): merge request diffs page 30 files at a time so GitLab 15.7 to 17.10 answer (#21909)
Igor Makowski committed
Oct 21, 2026 at 15:16 UTC
588150e39d375b1316ab8093a3f604dc31edc6ae
3 files changed
+42
-5
packages/source-control-gitlab/src/server/GitLabPullRequestCli.legacy.test.ts
+2
-2
@@ -147,7 +147,7 @@ layer("legacy GitLab diff requests through GitLabCli", (it) => {
147
);
148
it.effect("keeps modern pagination without requesting legacy changes", () =>
149
Effect.gen(function* () {
150
- run.mockReturnValueOnce(output(Array.from({ length: 100 }, () => file)));
150
+ run.mockReturnValueOnce(output(Array.from({ length: 30 }, () => file)));
151
run.mockReturnValueOnce(output([file]));
152
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
153
const first = yield* cli.getMergeRequestDiff(input);
@@ -157,7 +157,7 @@ layer("legacy GitLab diff requests through GitLabCli", (it) => {
157
).toBeNull();
158
expect(run).toHaveBeenCalledTimes(2);
159
expect(run.mock.calls[1]?.[0].args).toContain(
160
- "projects/acme%2Fnested%2Fweb/merge_requests/7/diffs?per_page=100&page=2",
160
+ "projects/acme%2Fnested%2Fweb/merge_requests/7/diffs?per_page=30&page=2",
161
);
162
}),
163
);
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+30
-1
@@ -430,10 +430,39 @@ layer("GitLabPullRequestCli.layer", (it) => {
430
assert.strictEqual(mockedExecute.mock.calls.length, 1);
431
assert.isNotNull(diff.nextCursor);
432
assert.isFalse(diff.truncated);
433
- expect(argsOfCall(0)[1]).toContain("merge_requests/7/diffs?per_page=100&page=1");
433
+ expect(argsOfCall(0)[1]).toContain("merge_requests/7/diffs?per_page=30&page=1");
434
}),
435
);
436
437
+ it.effect(
438
+ "pages a merge request diff 30 files at a time, which GitLab 15.7 to 17.10 accept",
439
+ () =>
440
+ Effect.gen(function* () {
441
+ mockedExecute
442
+ .mockReturnValueOnce(Effect.succeed(output(diffPage(0, 30))))
443
+ .mockReturnValueOnce(Effect.succeed(output(diffPage(30, 30))))
444
+ .mockReturnValueOnce(Effect.succeed(output(diffPage(60, 5))));
445
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
446
+ const target = { cwd: "/w", repository: "acme/web", number: 7 };
447
+
448
+ let patch = "";
449
+ let cursor: string | undefined;
450
+ do {
451
+ const slice = yield* cli.getMergeRequestDiff({ ...target, cursor });
452
+ patch += slice.patch;
453
+ cursor = slice.nextCursor ?? undefined;
454
+ } while (cursor !== undefined);
455
+
456
+ expect(mockedExecute.mock.calls.map(([call]) => call.args[1])).toEqual([
457
+ "projects/acme%2Fweb/merge_requests/7/diffs?per_page=30&page=1",
458
+ "projects/acme%2Fweb/merge_requests/7/diffs?per_page=30&page=2",
459
+ "projects/acme%2Fweb/merge_requests/7/diffs?per_page=30&page=3",
460
+ ]);
461
+ assert.strictEqual(patch.match(/^diff --git /gm)?.length, 65);
462
+ expect(patch).toContain("diff --git a/src/64.ts b/src/64.ts");
463
+ }),
464
+ );
465
+
466
it.effect("refuses a cursor it never handed out rather than reading it into a query", () =>
467
Effect.gen(function* () {
468
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+10
-2
@@ -181,6 +181,14 @@ export type GitLabPullRequestCliError =
181
/** GitLab's own ceiling on `per_page`, so a larger page has to be walked. */
182
const MAX_PAGE_SIZE = 100;
183
const COMMIT_PAGE_SIZE = 100;
184
+/**
185
+ * GitLab 15.7 through 17.10 answer the merge request `/diffs` endpoint with a 500 for any
186
+ * `per_page` above 30 (fixed in 17.11), so those pages stay at a size every version accepts.
187
+ * A commit's own diff endpoint never had that bug and keeps the full page.
188
+ */
189
+const MERGE_REQUEST_DIFF_PAGE_SIZE = 30;
190
+const diffPageSize = (commit: string | undefined) =>
191
+ commit === undefined ? MERGE_REQUEST_DIFF_PAGE_SIZE : MAX_PAGE_SIZE;
192
const CONVERSATION_PAGES = 10;
193
const DIFF_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
194
const DIFF_TIMEOUT_MS = 60_000;
@@ -615,7 +623,7 @@ export const make = Effect.gen(function* () {
623
? `merge_requests/${input.number}/diffs`
624
: `repository/commits/${input.commit}/diff`
625
}?${query([
618
- ["per_page", String(MAX_PAGE_SIZE)],
626
+ ["per_page", String(diffPageSize(input.commit))],
627
["page", String(input.page)],
628
])}`,
629
maxOutputBytes: DIFF_MAX_OUTPUT_BYTES,
@@ -673,7 +681,7 @@ export const make = Effect.gen(function* () {
681
const patch = decoded.success.patch;
682
// Counted before decoding, so a page whose files all failed to decode still moves on
683
// rather than pointing the reader back at the page it just read.
676
- const morePages = !legacy && decoded.success.rawCount >= MAX_PAGE_SIZE;
684
+ const morePages = !legacy && decoded.success.rawCount >= diffPageSize(input.commit);
685
return Effect.succeed({
686
// The slice ends on a newline, so a file GitLab gave a header and no hunks for does
687
// not run into the first line of the next slice.