The best way to control Claude Code, Codex and more from any computer or phone
fix(gitlab): a failed child pipeline no longer shows as a passing check (#24688)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 31, 2026 at 04:01 UTC
4146e511989c35e25b29c1779fc0753c9781ab03
5 files changed
+228
-2
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+116
@@ -963,6 +963,122 @@ layer("GitLabPullRequestCli.layer", (it) => {
963
}),
964
);
965
966
+ it.effect("shows a failed child pipeline that left the head pipeline green", () =>
967
+ Effect.gen(function* () {
968
+ mockedExecute
969
+ .mockReturnValueOnce(
970
+ Effect.succeed(
971
+ output(
972
+ mergeRequestJson({
973
+ // A fork's pipeline runs in the source project, so its id is not the target's.
974
+ head_pipeline: {
975
+ id: 31,
976
+ project_id: 12,
977
+ status: "success",
978
+ web_url: "https://gitlab.com/bilal/web/-/pipelines/31",
979
+ },
980
+ }),
981
+ ),
982
+ ),
983
+ )
984
+ .mockReturnValueOnce(
985
+ Effect.succeed(
986
+ output(
987
+ JSON.stringify([
988
+ {
989
+ name: "deploy",
990
+ status: "success",
991
+ downstream_pipeline: {
992
+ status: "failed",
993
+ web_url: "https://gitlab.com/bilal/web/-/pipelines/32",
994
+ },
995
+ },
996
+ { name: "docs", status: "created", downstream_pipeline: null },
997
+ ]),
998
+ ),
999
+ ),
1000
+ );
1001
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1002
+
1003
+ const detail = yield* cli.getMergeRequestDetail({
1004
+ cwd: "/w",
1005
+ repository: "acme/web",
1006
+ number: 7,
1007
+ });
1008
+
1009
+ expect(detail.checks.map((check) => [check.name, check.status, check.url])).toEqual([
1010
+ ["Pipeline", "success", "https://gitlab.com/bilal/web/-/pipelines/31"],
1011
+ ["deploy", "failure", "https://gitlab.com/bilal/web/-/pipelines/32"],
1012
+ ]);
1013
+ expect(argsOfCall(1)[1]).toBe("projects/12/pipelines/31/bridges?per_page=100");
1014
+ }),
1015
+ );
1016
+
1017
+ it.effect("keeps the one pipeline check when the trigger jobs cannot be read whole", () =>
1018
+ Effect.gen(function* () {
1019
+ const detailOutput = output(
1020
+ mergeRequestJson({ head_pipeline: { id: 31, project_id: 12, status: "success" } }),
1021
+ );
1022
+ const failedChild = { name: "deploy", downstream_pipeline: { status: "failed" } };
1023
+ mockedExecute
1024
+ .mockReturnValueOnce(Effect.succeed(detailOutput))
1025
+ .mockReturnValueOnce(
1026
+ Effect.fail(
1027
+ new GitLabCli.GitLabCliCommandError({
1028
+ operation: "execute",
1029
+ command: "glab",
1030
+ cwd: "/w",
1031
+ cause: new Error("403 Forbidden"),
1032
+ }),
1033
+ ),
1034
+ )
1035
+ .mockReturnValueOnce(Effect.succeed(detailOutput))
1036
+ // A full page may have left out the trigger job whose pipeline failed.
1037
+ .mockReturnValueOnce(
1038
+ Effect.succeed(output(JSON.stringify(Array.from({ length: 100 }, () => failedChild)))),
1039
+ );
1040
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1041
+
1042
+ for (const scenario of ["read fails", "page is full"]) {
1043
+ const detail = yield* cli.getMergeRequestDetail({
1044
+ cwd: "/w",
1045
+ repository: "acme/web",
1046
+ number: 7,
1047
+ });
1048
+ expect(
1049
+ detail.checks.map((check) => [check.name, check.status]),
1050
+ scenario,
1051
+ ).toEqual([["Pipeline", "success"]]);
1052
+ }
1053
+ }),
1054
+ );
1055
+
1056
+ it.effect("reads merge permissions without reading the trigger jobs", () =>
1057
+ Effect.gen(function* () {
1058
+ mockedExecute.mockReturnValueOnce(
1059
+ Effect.succeed(
1060
+ output(
1061
+ mergeRequestJson({
1062
+ head_pipeline: { id: 31, project_id: 12, status: "success" },
1063
+ user: { can_merge: false },
1064
+ }),
1065
+ ),
1066
+ ),
1067
+ );
1068
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1069
+
1070
+ const detail = yield* cli.getMergeRequestDetail({
1071
+ cwd: "/w",
1072
+ repository: "acme/web",
1073
+ number: 7,
1074
+ downstreamChecks: false,
1075
+ });
1076
+
1077
+ expect(detail.viewerCanMerge).toBe(false);
1078
+ expect(mockedExecute).toHaveBeenCalledTimes(1);
1079
+ }),
1080
+ );
1081
+
1082
it.effect("reads who has access to the project and who is already on the merge request", () =>
1083
Effect.gen(function* () {
1084
mockedExecute
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+40
-1
@@ -8,6 +8,7 @@ import { resolvePullRequestAuthorFilter, VcsProcessExitError } from "@t3tools/co
8
import type {
9
PullRequestAction,
10
PullRequestActor,
11
+ PullRequestCheck,
12
PullRequestComment,
13
PullRequestCommit,
14
PullRequestInvolvement,
@@ -45,6 +46,7 @@ import {
46
decodeProjectLabelsJson,
47
decodeProjectUsersJson,
48
decodeRepositoryBlobsJson,
49
+ decodeTriggerJobChecksJson,
50
decodeViewerJson,
51
gitLabAwardName,
52
MERGE_REQUEST_FILE_STATS_GRAPHQL_QUERY,
@@ -245,6 +247,8 @@ export class GitLabPullRequestCli extends Context.Service<
247
readonly host?: string | undefined;
248
readonly repository: string;
249
readonly number: number;
250
+ /** `false` skips the trigger job read; the permission check before every write does. */
251
+ readonly downstreamChecks?: boolean;
252
}) => Effect.Effect<GitLabMergeRequestDetail, GitLabPullRequestCliError>;
253
254
/** Line counts for the given merge requests; one with no answer is left out. */
@@ -996,6 +1000,29 @@ export const make = Effect.gen(function* () {
1000
}),
1001
);
1002
1003
+ // Best-effort: a trigger job read that fails, or a full page that may have left out the one
1004
+ // whose pipeline failed, adds no rows and leaves the detail as it was.
1005
+ const triggerJobChecks = (input: {
1006
+ readonly cwd: string;
1007
+ readonly pipeline: { readonly id: number; readonly projectId: number };
1008
+ }): Effect.Effect<ReadonlyArray<PullRequestCheck>> =>
1009
+ api({
1010
+ cwd: input.cwd,
1011
+ // `bridges` rather than `trigger_jobs`: GitLab 19.2 deprecates it but still serves it, and
1012
+ // older self-managed installs know no other name.
1013
+ path: `projects/${input.pipeline.projectId}/pipelines/${input.pipeline.id}/bridges?${query([
1014
+ ["per_page", String(MAX_PAGE_SIZE)],
1015
+ ])}`,
1016
+ }).pipe(
1017
+ Effect.map((result) => {
1018
+ const decoded = decodeTriggerJobChecksJson(result.stdout.trim());
1019
+ return Result.isSuccess(decoded) && decoded.success.rawCount < MAX_PAGE_SIZE
1020
+ ? decoded.success.checks
1021
+ : [];
1022
+ }),
1023
+ Effect.orElseSucceed((): ReadonlyArray<PullRequestCheck> => []),
1024
+ );
1025
+
1026
const projectUsers = (input: {
1027
readonly cwd: string;
1028
readonly host?: string | undefined;
@@ -1297,7 +1324,19 @@ export const make = Effect.gen(function* () {
1324
return listPage({ ...input, page, collected: [], cursorAdvance: 0 });
1325
}),
1326
1300
- getMergeRequestDetail: mergeRequestDetail,
1327
+ getMergeRequestDetail: Effect.fn("GitLabPullRequestCli.getMergeRequestDetail")(
1328
+ function* (input) {
1329
+ const detail = yield* mergeRequestDetail(input);
1330
+ if (input.downstreamChecks === false || detail.headPipeline === undefined) return detail;
1331
+ const downstream = yield* triggerJobChecks({
1332
+ cwd: input.cwd,
1333
+ pipeline: detail.headPipeline,
1334
+ });
1335
+ return downstream.length === 0
1336
+ ? detail
1337
+ : { ...detail, checks: [...detail.checks, ...downstream] };
1338
+ },
1339
+ ),
1340
1341
listMergeRequestStats,
1342
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+1
-1
@@ -317,7 +317,7 @@ export const make = Effect.gen(function* () {
317
// through on, and access granted or withdrawn within the minute must count.
318
getViewerPermissions: (input) =>
319
cli
320
- .getMergeRequestDetail(input)
320
+ .getMergeRequestDetail({ ...input, downstreamChecks: false })
321
.pipe(Effect.mapError(fail("getViewerPermissions")), Effect.map(gitLabViewerPermissions)),
322
323
forgetChangeRequestReads: (scope) =>
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts
+21
@@ -12,6 +12,7 @@ import {
12
decodeMergeRequestStatsJson,
13
decodeNotesJson,
14
decodeOwnAwardIdJson,
15
+ decodeTriggerJobChecksJson,
16
} from "./gitLabMergeRequestJson.ts";
17
18
function listJson(entries: ReadonlyArray<Record<string, unknown>>): string {
@@ -454,6 +455,26 @@ describe("decodeMergeRequestDiffsJson", () => {
455
});
456
});
457
458
+describe("decodeTriggerJobChecksJson", () => {
459
+ it("reads a downstream failure GitLab was told to allow as neutral, not failure", () => {
460
+ const result = expectSuccess(
461
+ decodeTriggerJobChecksJson(
462
+ JSON.stringify([
463
+ { name: "e2e", allow_failure: true, downstream_pipeline: { status: "failed" } },
464
+ { name: "deploy", allow_failure: false, downstream_pipeline: { status: "running" } },
465
+ { name: 7 },
466
+ ]),
467
+ ),
468
+ );
469
+
470
+ expect(result.checks.map((check) => [check.name, check.status])).toEqual([
471
+ ["e2e", "neutral"],
472
+ ["deploy", "pending"],
473
+ ]);
474
+ expect(result.rawCount).toBe(3);
475
+ });
476
+});
477
+
478
describe("merge request viewer fields", () => {
479
it("leaves merging permitted where GitLab answered without the field", () => {
480
expect(expectSuccess(decodeMergeRequestDetailJson(detailJson({}))).viewerCanMerge).toBe(true);
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+50
@@ -32,11 +32,19 @@ const RawUserSchema = Schema.Struct({
32
});
33
34
const RawPipelineSchema = Schema.Struct({
35
+ id: Schema.optional(Schema.NullOr(Schema.Int)),
36
+ project_id: Schema.optional(Schema.NullOr(Schema.Int)),
37
status: Schema.optional(Schema.NullOr(Schema.String)),
38
web_url: Schema.optional(Schema.NullOr(Schema.String)),
39
source: Schema.optional(Schema.NullOr(Schema.String)),
40
});
41
42
+const RawTriggerJobSchema = Schema.Struct({
43
+ name: Schema.String,
44
+ allow_failure: Schema.optional(Schema.NullOr(Schema.Boolean)),
45
+ downstream_pipeline: Schema.optional(Schema.NullOr(RawPipelineSchema)),
46
+});
47
+
48
const RawMergeRequestSchema = Schema.Struct({
49
iid: Schema.Int,
50
title: Schema.String,
@@ -198,6 +206,8 @@ export interface GitLabMergeRequestDetail extends GitLabMergeRequestListItem {
206
/** Absent means not counted, not up to date. */
207
readonly divergedCommits?: number;
208
readonly headSha?: string;
209
+ /** On a fork the pipeline often belongs to the source project, not the target. */
210
+ readonly headPipeline?: { readonly id: number; readonly projectId: number };
211
}
212
213
function toActor(raw: Schema.Schema.Type<typeof RawUserSchema> | null | undefined) {
@@ -331,12 +341,16 @@ function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLab
341
: {}),
342
...(raw.diverged_commits_count == null ? {} : { divergedCommits: raw.diverged_commits_count }),
343
...(headSha === null ? {} : { headSha }),
344
+ ...(raw.head_pipeline?.id == null || raw.head_pipeline.project_id == null
345
+ ? {}
346
+ : { headPipeline: { id: raw.head_pipeline.id, projectId: raw.head_pipeline.project_id } }),
347
};
348
}
349
350
const decodeUnknownList = decodeJsonResult(Schema.Array(Schema.Unknown));
351
const decodeMergeRequestEntry = Schema.decodeUnknownExit(RawMergeRequestSchema);
352
const decodeMergeRequest = decodeJsonResult(RawMergeRequestSchema);
353
+const decodeTriggerJobEntry = Schema.decodeUnknownExit(RawTriggerJobSchema);
354
const decodeNoteEntry = Schema.decodeUnknownExit(RawNoteSchema);
355
const decodeUserEntry = Schema.decodeUnknownExit(RawUserSchema);
356
const decodeCommitEntry = Schema.decodeUnknownExit(RawCommitSchema);
@@ -396,6 +410,42 @@ export function decodeMergeRequestDetailJson(
410
: Result.fail(decoded.failure);
411
}
412
413
+export interface GitLabTriggerJobChecks {
414
+ readonly checks: ReadonlyArray<PullRequestCheck>;
415
+ readonly rawCount: number;
416
+}
417
+
418
+/**
419
+ * Without `strategy: depend` a trigger job succeeds as soon as it starts its downstream
420
+ * pipeline, so the head pipeline stays green when that pipeline fails. Each row carries the
421
+ * downstream pipeline's own status instead of the trigger job's.
422
+ */
423
+export function decodeTriggerJobChecksJson(
424
+ raw: string,
425
+): Result.Result<GitLabTriggerJobChecks, DecodeFailure> {
426
+ const decoded = decodeUnknownList(raw);
427
+ if (!Result.isSuccess(decoded)) {
428
+ return Result.fail(decoded.failure);
429
+ }
430
+ const checks: PullRequestCheck[] = [];
431
+ for (const entry of decoded.success) {
432
+ const job = decodeTriggerJobEntry(entry);
433
+ if (Exit.isFailure(job)) continue;
434
+ const name = trimmed(job.value.name);
435
+ const downstream = job.value.downstream_pipeline;
436
+ if (name === null || !downstream) continue;
437
+ const status = toPipelineStatus(downstream.status);
438
+ checks.push({
439
+ name,
440
+ // The same reading as `manual`: GitLab was told this failure does not fail the pipeline.
441
+ status: status === "failure" && job.value.allow_failure === true ? "neutral" : status,
442
+ description: "Downstream pipeline",
443
+ url: trimmed(downstream.web_url),
444
+ });
445
+ }
446
+ return Result.succeed({ checks, rawCount: decoded.success.length });
447
+}
448
+
449
export function decodeViewerJson(raw: string): Result.Result<string | null, DecodeFailure> {
450
const decoded = decodeViewer(raw);
451
return Result.isSuccess(decoded)