The best way to control Claude Code, Codex and more from any computer or phone
fix(gitlab): a fork's same-named branch no longer hides the branch's own merge request (#29791)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 03:28 UTC
abac6837e95e45f97117be7e73b4879b24497cb5
4 files changed
+118
-37
packages/source-control-gitlab/src/server/GitLabCli.test.ts
+41
@@ -166,6 +166,47 @@ layer("GitLabCli.layer", (it) => {
166
}),
167
);
168
169
+ it.effect(
170
+ "retries oversized MR lists with smaller pages without losing same-named branches",
171
+ () =>
172
+ Effect.gen(function* () {
173
+ const entries = Array.from({ length: 4 }, (_, index) => ({
174
+ iid: index + 1,
175
+ title: "MR " + index,
176
+ // The first alone escapes past the default 1 MB cap; together they pass the list cap.
177
+ description: index === 0 ? '"'.repeat(600_000) : "x".repeat(3_000_000),
178
+ web_url: "https://gitlab.com/acme/web/-/merge_requests/" + (index + 1),
179
+ target_branch: "main",
180
+ source_branch: "feature",
181
+ source_project_id: index === 3 ? 100 : 101,
182
+ target_project_id: 100,
183
+ }));
184
+ mockedRun.mockImplementation((input) => {
185
+ const size = Number(input.args[input.args.indexOf("--per-page") + 1]);
186
+ const pageIndex = input.args.indexOf("--page");
187
+ const page = pageIndex < 0 ? 1 : Number(input.args[pageIndex + 1]);
188
+ const raw = JSON.stringify(entries.slice((page - 1) * size, page * size));
189
+ const cap = input.maxOutputBytes ?? 1_000_000;
190
+ return Effect.succeed({
191
+ ...processOutput(raw.slice(0, cap)),
192
+ stdoutTruncated: raw.length > cap,
193
+ });
194
+ });
195
+ const glab = yield* GitLabCli.GitLabCli;
196
+ const result = yield* glab.listMergeRequests({
197
+ cwd: "/repo",
198
+ headSelector: "feature",
199
+ state: "open",
200
+ limit: 4,
201
+ });
202
+ assert.deepStrictEqual(
203
+ result.map((mr) => mr.number),
204
+ [1, 2, 3, 4],
205
+ );
206
+ assert.strictEqual(result[3]?.isCrossRepository, false);
207
+ }),
208
+ );
209
+
210
it.effect("creates same-project MRs without a repository lookup", () =>
211
Effect.gen(function* () {
212
mockedRun.mockReturnValueOnce(Effect.succeed(processOutput("{}")));
packages/source-control-gitlab/src/server/GitLabCli.ts
+57
-37
@@ -1,5 +1,6 @@
1
import * as Context from "effect/Context";
2
import * as Effect from "effect/Effect";
3
+import * as Exit from "effect/Exit";
4
import * as Layer from "effect/Layer";
5
import * as Match from "effect/Match";
6
import * as Option from "effect/Option";
@@ -22,6 +23,11 @@ import {
23
import type * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
24
25
const DEFAULT_TIMEOUT_MS = 30_000;
26
+// GitLab allows ~1M-character descriptions; glab's JSON escaping (`\u003c`) can grow one sixfold.
27
+const MERGE_REQUEST_LIST_MAX_BYTES = 8_000_000;
28
+const decodeJsonArray = Schema.decodeUnknownExit(
29
+ Schema.fromJsonString(Schema.Array(Schema.Unknown)),
30
+);
31
32
const gitLabCliExecutionErrorContext = {
33
operation: Schema.Literal("execute"),
@@ -481,43 +487,57 @@ export const make = Effect.gen(function* () {
487
488
return GitLabCli.of({
489
execute,
484
- listMergeRequests: Effect.fn("GitLabCli.listMergeRequests")(function (input) {
485
- return execute({
486
- cwd: input.cwd,
487
- args: [
488
- "mr",
489
- "list",
490
- "--source-branch",
491
- sourceRefName(input),
492
- ...stateArgs(input.state),
493
- "--per-page",
494
- String(input.limit ?? 20),
495
- "--output",
496
- "json",
497
- ],
498
- }).pipe(
499
- Effect.map((result) => result.stdout.trim()),
500
- Effect.flatMap((raw) =>
501
- raw.length === 0
502
- ? Effect.succeed([])
503
- : Effect.sync(() => decodeGitLabMergeRequestListJson(raw)).pipe(
504
- Effect.flatMap((decoded) => {
505
- if (!Result.isSuccess(decoded)) {
506
- return Effect.fail(
507
- new GitLabMergeRequestListDecodeError({
508
- operation: "listMergeRequests",
509
- command: "glab",
510
- cwd: input.cwd,
511
- cause: decoded.failure,
512
- }),
513
- );
514
- }
515
-
516
- return Effect.succeed(decoded.success.map(toSummaryWithOptionalUpdatedAt));
517
- }),
518
- ),
519
- ),
520
- );
490
+ listMergeRequests: Effect.fn("GitLabCli.listMergeRequests")(function* (input) {
491
+ const limit = input.limit ?? 20;
492
+ let pageSize = limit;
493
+ let page = 1;
494
+ const items: GitLabMergeRequestSummary[] = [];
495
+ while (items.length < limit) {
496
+ const result = yield* execute({
497
+ cwd: input.cwd,
498
+ args: [
499
+ "mr",
500
+ "list",
501
+ "--source-branch",
502
+ sourceRefName(input),
503
+ ...stateArgs(input.state),
504
+ "--per-page",
505
+ String(pageSize),
506
+ ...(page > 1 ? ["--page", String(page)] : []),
507
+ "--output",
508
+ "json",
509
+ ],
510
+ maxOutputBytes: MERGE_REQUEST_LIST_MAX_BYTES,
511
+ });
512
+ if (result.stdoutTruncated && pageSize > 1) {
513
+ pageSize = Math.max(1, Math.floor(pageSize / 2));
514
+ page = 1;
515
+ items.length = 0;
516
+ continue;
517
+ }
518
+ const raw = result.stdout.trim();
519
+ if (raw.length === 0) break;
520
+ const decoded = decodeGitLabMergeRequestListJson(raw);
521
+ if (result.stdoutTruncated || !Result.isSuccess(decoded)) {
522
+ return yield* new GitLabMergeRequestListDecodeError({
523
+ operation: "listMergeRequests",
524
+ command: "glab",
525
+ cwd: input.cwd,
526
+ cause: Result.isFailure(decoded) ? decoded.failure : "MR list output was truncated",
527
+ });
528
+ }
529
+ items.push(...decoded.success.map(toSummaryWithOptionalUpdatedAt));
530
+ // Count raw entries: the decoder drops invalid ones, which would end paging early.
531
+ const entries = decodeJsonArray(raw);
532
+ if (
533
+ page * pageSize >= limit ||
534
+ (Exit.isSuccess(entries) && entries.value.length < pageSize)
535
+ ) {
536
+ break;
537
+ }
538
+ page += 1;
539
+ }
540
+ return items.slice(0, limit);
541
}),
542
getMergeRequest: Effect.fn("GitLabCli.getMergeRequest")(function (input) {
543
return executeMergeRequest({
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts
+15
@@ -199,6 +199,21 @@ selfhosted
199
);
200
});
201
202
+it.effect(
203
+ "looks up a branch's merge requests a full page at a time, past forks' same-named branches",
204
+ () =>
205
+ Effect.gen(function* () {
206
+ const provider = yield* makeProvider({});
207
+ assert.deepStrictEqual(
208
+ provider.headBranchProbe?.({
209
+ headSelectors: ["octocat:feature", "feature"],
210
+ state: "open",
211
+ }),
212
+ { headSelectors: ["feature"], limit: 100 },
213
+ );
214
+ }),
215
+);
216
+
217
it.effect.each(["merge_requests", "issues"])(
218
"resolves %s subjects on the linked host without using the checkout",
219
(kind) =>
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts
+5
@@ -210,6 +210,11 @@ export const make = Effect.gen(function* () {
210
211
return SourceControlProvider.SourceControlProvider.of({
212
kind: SourceControlProviderKind.make("gitlab"),
213
+ // GitLab lists fork merge requests by source branch with no owner filter, so read a full page.
214
+ headBranchProbe: ({ headSelectors }) => ({
215
+ headSelectors: headSelectors.filter((selector) => !selector.includes(":")),
216
+ limit: 100,
217
+ }),
218
readChangeRequestTemplate: Effect.fn("GitLabSourceControlProvider.readChangeRequestTemplate")(
219
function ({ cwd, treeish }) {
220
return GitLabChangeRequestTemplate.detect(cwd, treeish, git.execute);