Skip to content
Draft
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions packages/sdk/src/server/lib/task-runs/finish-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ export const finishRun = async ({
});
});

// Start notifying the originating Slack thread as soon as the terminal state
// is durable. Run it alongside the parent-task callback so neither remote
// notification delays the other.
const slackFailureNotification =
status === RunStatus.Failed && task.slackThreadTs
? sendSlackFailureNotification(run, channelProviderError).catch((err) => {
console.error(
`[finishRun] Failed to send Slack failure notification for run ${id}: ${
err instanceof Error ? err.message : String(err)
}`,
);
})
: Promise.resolve();

// Deterministic spawned-task feedback: when this run was launched by
// another task's run with notify-on-settle requested, deliver the outcome
// into that launching run's session (waking it if idle) so the parent
Expand All @@ -253,6 +267,7 @@ export const finishRun = async ({
status,
run.task.title,
);
await slackFailureNotification;

// Anonymous analytics (no-op unless enabled): terminal task outcome with
// non-identifying routing facts only.
Expand Down Expand Up @@ -321,20 +336,6 @@ export const finishRun = async ({
await cleanupGithubPrReviewArtifacts(run, status);
}

// Slack failure notification: post a thread reply when the run failed and
// was triggered from Slack (the task carries a Slack thread binding).
if (status === RunStatus.Failed && task.slackThreadTs) {
try {
await sendSlackFailureNotification(run, channelProviderError);
} catch (err) {
console.error(
`[finishRun] Failed to send Slack failure notification for run ${id}: ${
err instanceof Error ? err.message : String(err)
}`,
);
}
}

// Teams failure notification: post a thread reply when the run failed and
// was triggered from Teams (payload carries Teams communication metadata).
if (
Expand Down
Loading