Skip to content

Commit 9ac3a95

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): only keep a finished pipeline's checks when its job list is whole
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 492df4b commit 9ac3a95

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

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

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

1022+
it.effect("reads a finished pipeline's jobs again after a partial read", () =>
1023+
Effect.gen(function* () {
1024+
const pipeline = { ...headPipeline, id: 250 };
1025+
answer(
1026+
{ jobs: JSON.stringify([job(1), { id: 2, status: "failed" }]), bridges: "[]" },
1027+
pipeline,
1028+
);
1029+
const partial = yield* read(true);
1030+
expect(partial.checks).toEqual([pipelineCheck]);
1031+
1032+
answer({ jobs: pageOf(1, 2), bridges: "[]" }, pipeline);
1033+
const whole = yield* read(true);
1034+
expect(whole.checks).toHaveLength(2);
1035+
}),
1036+
);
1037+
10221038
it.effect("reads a finished pipeline's trigger jobs every time", () =>
10231039
Effect.gen(function* () {
10241040
// A trigger job that does not wait lets the parent finish while its child still runs.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -927,15 +927,15 @@ export const make = Effect.gen(function* () {
927927
);
928928

929929
/**
930-
* The checks of finished pipelines, by pipeline and the moment it settled, or null where its
931-
* jobs could not stand for it. A finished pipeline's jobs do not change until it runs again,
932-
* 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. A
930+
* The checks of finished pipelines, by pipeline and the moment it settled. A finished
931+
* pipeline's jobs do not change until it runs again, and that moves the moment, so every
932+
* refresh of a merge request whose pipeline is done costs no job reads. Only whole job lists
933+
* are kept: a read that failed, came back partial or found no jobs is tried again. A
934934
* pipeline with trigger jobs is never kept: the pipelines they start run on their own, past
935935
* the parent finishing and through retries that never move the parent's moment.
936936
*/
937-
const settledPipelineChecks = new Map<string, ReadonlyArray<PullRequestCheck> | null>();
938-
const rememberSettledPipeline = (key: string, checks: ReadonlyArray<PullRequestCheck> | null) => {
937+
const settledPipelineChecks = new Map<string, ReadonlyArray<PullRequestCheck>>();
938+
const rememberSettledPipeline = (key: string, checks: ReadonlyArray<PullRequestCheck>) => {
939939
settledPipelineChecks.set(key, checks);
940940
if (settledPipelineChecks.size > SETTLED_PIPELINE_CAPACITY) {
941941
// Maps iterate in insertion order, so the first key is the oldest.
@@ -997,7 +997,7 @@ export const make = Effect.gen(function* () {
997997
: `${pipeline.projectId}/${pipeline.id}@${pipeline.settledAt}`;
998998
const settled = settledKey === null ? undefined : settledPipelineChecks.get(settledKey);
999999
if (settled !== undefined) {
1000-
return Effect.succeed(settled === null ? detail : { ...detail, checks: settled });
1000+
return Effect.succeed({ ...detail, checks: settled });
10011001
}
10021002
const list = (kind: "jobs" | "bridges") =>
10031003
pipelineJobsPage({
@@ -1015,7 +1015,7 @@ export const make = Effect.gen(function* () {
10151015
[...jobs, ...bridges]
10161016
.toSorted((left, right) => left.id - right.id)
10171017
.map((job) => job.check);
1018-
if (settledKey !== null && bridges?.length === 0) {
1018+
if (settledKey !== null && checks !== null && bridges?.length === 0) {
10191019
rememberSettledPipeline(settledKey, checks);
10201020
}
10211021
return checks === null ? detail : { ...detail, checks };

0 commit comments

Comments
 (0)