Skip to content

Commit d765631

Browse files
authored
Prevent stuck runs after duplicate dependency resume messages (#1459)
* ignore duplicate dependency resume messages * add changeset
1 parent 5368bcf commit d765631

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

.changeset/lovely-swans-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Ignore duplicate dependency resume messages in deployed tasks

packages/cli-v3/src/entryPoints/deploy-run-controller.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,15 @@ class ProdWorker {
689689
reconnectionDelayMax: 3000,
690690
},
691691
handlers: {
692-
RESUME_AFTER_DEPENDENCY: async ({ completions }) => {
692+
RESUME_AFTER_DEPENDENCY: async ({ attemptId, completions }) => {
693+
logger.log("Handling RESUME_AFTER_DEPENDENCY", {
694+
attemptId,
695+
completions: completions.map((c) => ({
696+
id: c.id,
697+
ok: c.ok,
698+
})),
699+
});
700+
693701
if (!this.paused) {
694702
logger.error("Failed to resume after dependency: Worker not paused");
695703
return;
@@ -720,12 +728,48 @@ class ProdWorker {
720728
return;
721729
}
722730

731+
const firstCompletion = completions[0];
732+
if (!firstCompletion) {
733+
logger.error("Failed to resume after dependency: No first completion", {
734+
completions,
735+
waitForTaskReplay: this.waitForTaskReplay,
736+
nextResumeAfter: this.nextResumeAfter,
737+
});
738+
return;
739+
}
740+
723741
switch (this.nextResumeAfter) {
724742
case "WAIT_FOR_TASK": {
743+
if (this.waitForTaskReplay) {
744+
if (this.waitForTaskReplay.message.friendlyId !== firstCompletion.id) {
745+
logger.error("Failed to resume after dependency: Task friendlyId mismatch", {
746+
completions,
747+
waitForTaskReplay: this.waitForTaskReplay,
748+
});
749+
return;
750+
}
751+
} else {
752+
// Only log here so we don't break any existing behavior
753+
logger.debug("No waitForTaskReplay", { completions });
754+
}
755+
725756
this.waitForTaskReplay = undefined;
726757
break;
727758
}
728759
case "WAIT_FOR_BATCH": {
760+
if (this.waitForBatchReplay) {
761+
if (!this.waitForBatchReplay.message.runFriendlyIds.includes(firstCompletion.id)) {
762+
logger.error("Failed to resume after dependency: Batch friendlyId mismatch", {
763+
completions,
764+
waitForBatchReplay: this.waitForBatchReplay,
765+
});
766+
return;
767+
}
768+
} else {
769+
// Only log here so we don't break any existing behavior
770+
logger.debug("No waitForBatchReplay", { completions });
771+
}
772+
729773
this.waitForBatchReplay = undefined;
730774
break;
731775
}

0 commit comments

Comments
 (0)