Skip to content

Commit bba19f7

Browse files
fix(server): filtered workflow lists return a run once when it becomes skipped (#45264)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent 939693c commit bba19f7

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎apps/server/src/workflows/WorkflowEngine.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,10 @@ const make = Effect.fn("WorkflowEngine.make")(function* (
13301330
...(yield* store.runsWhere({ ...where, skippedTopLevel: false })),
13311331
...(yield* store.runsWhere({ ...where, skippedTopLevel: true })),
13321332
];
1333-
return rows.toSorted((a, b) => b.started_at.localeCompare(a.started_at)).map(toRun);
1333+
// The two reads are separate, so a run that turned skipped between them can be in both.
1334+
return [...new Map(rows.map((row) => [row.run_id, row])).values()]
1335+
.toSorted((a, b) => b.started_at.localeCompare(a.started_at))
1336+
.map(toRun);
13341337
}),
13351338
about: Effect.fn("Workflows.about")(function* (item) {
13361339
// Keyed as the subject was kept, so an item named without its address is found too.

‎apps/server/src/workflows/Workflows.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,44 @@ it.effect("a list by tag keeps the runs that did something apart from skipped on
29702970
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
29712971
);
29722972

2973+
it.effect("a list by tag shows a run once when it turns skipped between the two reads", () =>
2974+
Effect.gen(function* () {
2975+
const skipAfterRead = yield* Ref.make<string | undefined>(undefined);
2976+
const store = Layer.effect(
2977+
WorkflowStore.WorkflowStore,
2978+
Effect.gen(function* () {
2979+
const real = yield* WorkflowStore.make;
2980+
return WorkflowStore.WorkflowStore.of({
2981+
...real,
2982+
runsWhere: (where) =>
2983+
Effect.tap(real.runsWhere(where), () =>
2984+
where.skippedTopLevel === false
2985+
? Effect.flatMap(Ref.getAndSet(skipAfterRead, undefined), (runId) =>
2986+
runId === undefined
2987+
? Effect.void
2988+
: real.runEnded(runId, "skipped", "not applicable", null),
2989+
)
2990+
: Effect.void,
2991+
),
2992+
});
2993+
}),
2994+
);
2995+
const { boot } = yield* harness(store);
2996+
yield* boot(
2997+
Effect.gen(function* () {
2998+
const workflows = yield* Workflows.Workflows;
2999+
const run = yield* workflows.start("sorter", { tags: ["triage"] }, { idempotencyKey: "r" });
3000+
yield* workflows.waitFor(run.runId, status("waiting"));
3001+
yield* Ref.set(skipAfterRead, run.runId);
3002+
assert.deepStrictEqual(
3003+
(yield* workflows.list({ tag: "triage" })).map((listed) => [listed.runId, listed.status]),
3004+
[[run.runId, "skipped"]],
3005+
);
3006+
}),
3007+
);
3008+
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
3009+
);
3010+
29733011
it("tags refuses a list with a gap in it", () => {
29743012
// The same list `tags([, "pr"])` makes: a first entry that was never set.
29753013
const gapped = new Array<string>(2);

0 commit comments

Comments
 (0)