Skip to content

Commit 492df4b

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): don't keep the checks of a pipeline with trigger jobs
A trigger job that does not wait lets its parent pipeline finish while the child still runs, and retrying a child job never moves the parent's updated_at, so the kept trigger check went stale. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c52972f commit 492df4b

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎apps/server/src/pullRequest/GitLabPullRequestCli.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,32 @@ layer("GitLabPullRequestCli.layer", (it) => {
10191019
}),
10201020
);
10211021

1022+
it.effect("reads a finished pipeline's trigger jobs every time", () =>
1023+
Effect.gen(function* () {
1024+
// A trigger job that does not wait lets the parent finish while its child still runs.
1025+
const bridge = (status: string) =>
1026+
JSON.stringify([
1027+
{
1028+
id: 3,
1029+
name: "trigger:docs",
1030+
stage: "test",
1031+
status: "success",
1032+
downstream_pipeline: { id: 30, status },
1033+
},
1034+
]);
1035+
const pipeline = { ...headPipeline, id: 500, status: "success" };
1036+
answer({ jobs: pageOf(1, 2), bridges: bridge("running") }, pipeline);
1037+
const running = yield* read(true);
1038+
expect(running.checks.at(-1)?.status).toBe("pending");
1039+
1040+
answer({ jobs: pageOf(1, 2), bridges: bridge("failed") }, pipeline);
1041+
const failed = yield* read(true);
1042+
1043+
expect(jobReads()).toBe(4);
1044+
expect(failed.checks.at(-1)?.status).toBe("failure");
1045+
}),
1046+
);
1047+
10221048
it.effect("reads a running pipeline's jobs every time", () =>
10231049
Effect.gen(function* () {
10241050
answer(

‎apps/server/src/pullRequest/GitLabPullRequestCli.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,9 @@ export const make = Effect.gen(function* () {
930930
* The checks of finished pipelines, by pipeline and the moment it settled, or null where its
931931
* jobs could not stand for it. A finished pipeline's jobs do not change until it runs again,
932932
* and that moves the moment, so every refresh of a merge request whose pipeline is done costs
933-
* no job reads. Only answers GitLab gave are kept: a read that failed is tried again.
933+
* no job reads. Only answers GitLab gave are kept: a read that failed is tried again. A
934+
* pipeline with trigger jobs is never kept: the pipelines they start run on their own, past
935+
* the parent finishing and through retries that never move the parent's moment.
934936
*/
935937
const settledPipelineChecks = new Map<string, ReadonlyArray<PullRequestCheck> | null>();
936938
const rememberSettledPipeline = (key: string, checks: ReadonlyArray<PullRequestCheck> | null) => {
@@ -1013,7 +1015,9 @@ export const make = Effect.gen(function* () {
10131015
[...jobs, ...bridges]
10141016
.toSorted((left, right) => left.id - right.id)
10151017
.map((job) => job.check);
1016-
if (settledKey !== null) rememberSettledPipeline(settledKey, checks);
1018+
if (settledKey !== null && bridges?.length === 0) {
1019+
rememberSettledPipeline(settledKey, checks);
1020+
}
10171021
return checks === null ? detail : { ...detail, checks };
10181022
}),
10191023
Effect.orElseSucceed(() => detail),

0 commit comments

Comments
 (0)