Skip to content

Commit 8d9e444

Browse files
committed
fix: prevent race between cancelPlan and async job completion handlers
1 parent aca4bfa commit 8d9e444

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/lib/orchestrator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,11 @@ If your work needs human review before it can proceed: mc_report(status: "needs_
11671167
return;
11681168
}
11691169

1170+
// Unsubscribe from monitor events BEFORE killing jobs to prevent
1171+
// completion/failure handlers from racing with plan cleanup.
1172+
this.unsubscribeFromMonitorEvents();
1173+
this.activePlanId = null;
1174+
11701175
const runningJobs = (await getRunningJobs()).filter((job) => job.planId === plan.id);
11711176
for (const job of runningJobs) {
11721177
try {
@@ -1187,7 +1192,6 @@ If your work needs human review before it can proceed: mc_report(status: "needs_
11871192

11881193
await deleteIntegrationBranch(plan.id);
11891194
await clearPlan();
1190-
this.unsubscribeFromMonitorEvents();
11911195
}
11921196

11931197
async skipJob(jobName: string, reason?: string): Promise<void> {

0 commit comments

Comments
 (0)