Skip to content

Commit f53d2ca

Browse files
committed
fix(run-engine): don't emit runStatusChanged when promotion was skipped
When the idempotency guard fires (concurrent worker already promoted the run, updateMany returns count=0), the transaction returned early — but the eventBus.emit('runStatusChanged') call was outside the transaction and fired unconditionally. Have the transaction return a boolean and guard the emit on it.
1 parent 1794758 commit f53d2ca

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

internal-packages/run-engine/src/engine/systems/pendingVersionSystem.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class PendingVersionSystem {
125125
});
126126

127127
for (const run of pendingRuns) {
128-
await this.$.prisma.$transaction(async (tx) => {
128+
const promoted = await this.$.prisma.$transaction(async (tx) => {
129129
// Idempotency guard: only flips PENDING_VERSION → PENDING. If another
130130
// worker already promoted this run between our findMany and the
131131
// update, count is 0 and we skip the enqueue.
@@ -135,7 +135,7 @@ export class PendingVersionSystem {
135135
});
136136

137137
if (updateResult.count === 0) {
138-
return;
138+
return false;
139139
}
140140

141141
const updatedRun = await tx.taskRun.findFirstOrThrow({ where: { id: run.id } });
@@ -150,8 +150,12 @@ export class PendingVersionSystem {
150150
// if it sits queued waiting on a concurrency slot.
151151
includeTtl: true,
152152
});
153+
154+
return true;
153155
});
154156

157+
if (!promoted) continue;
158+
155159
this.$.eventBus.emit("runStatusChanged", {
156160
time: new Date(),
157161
run: {

0 commit comments

Comments
 (0)