Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent stuck runs after duplicate dependency resume messages #1459

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-swans-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Ignore duplicate dependency resume messages in deployed tasks
46 changes: 45 additions & 1 deletion packages/cli-v3/src/entryPoints/deploy-run-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,15 @@ class ProdWorker {
reconnectionDelayMax: 3000,
},
handlers: {
RESUME_AFTER_DEPENDENCY: async ({ completions }) => {
RESUME_AFTER_DEPENDENCY: async ({ attemptId, completions }) => {
logger.log("Handling RESUME_AFTER_DEPENDENCY", {
attemptId,
completions: completions.map((c) => ({
id: c.id,
ok: c.ok,
})),
});

if (!this.paused) {
logger.error("Failed to resume after dependency: Worker not paused");
return;
Expand Down Expand Up @@ -616,12 +624,48 @@ class ProdWorker {
return;
}

const firstCompletion = completions[0];
if (!firstCompletion) {
logger.error("Failed to resume after dependency: No first completion", {
completions,
waitForTaskReplay: this.waitForTaskReplay,
nextResumeAfter: this.nextResumeAfter,
});
return;
}

switch (this.nextResumeAfter) {
case "WAIT_FOR_TASK": {
if (this.waitForTaskReplay) {
if (this.waitForTaskReplay.message.friendlyId !== firstCompletion.id) {
logger.error("Failed to resume after dependency: Task friendlyId mismatch", {
completions,
waitForTaskReplay: this.waitForTaskReplay,
});
return;
}
} else {
// Only log here so we don't break any existing behavior
logger.debug("No waitForTaskReplay", { completions });
}

this.waitForTaskReplay = undefined;
break;
}
case "WAIT_FOR_BATCH": {
if (this.waitForBatchReplay) {
if (!this.waitForBatchReplay.message.runFriendlyIds.includes(firstCompletion.id)) {
logger.error("Failed to resume after dependency: Batch friendlyId mismatch", {
completions,
waitForBatchReplay: this.waitForBatchReplay,
});
return;
}
} else {
// Only log here so we don't break any existing behavior
logger.debug("No waitForBatchReplay", { completions });
}

this.waitForBatchReplay = undefined;
break;
}
Expand Down