From 099f3c7341e5d8e4bd2e7fc7b6dbbb437a81d276 Mon Sep 17 00:00:00 2001 From: Evgeny Zislis Date: Mon, 2 Mar 2026 01:33:15 +0200 Subject: [PATCH] fix(cron): merge failureAlert mode/accountId and preserve failureDestination on updates - Fix mergeCronFailureAlert to merge mode and accountId fields - Fix mergeCronDelivery to preserve failureDestination on updates - Fix isSameDeliveryTarget to use 'announce' as default instead of 'none' to properly detect duplicates when delivery.mode is undefined --- src/cron/delivery.ts | 2 +- src/cron/service/jobs.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cron/delivery.ts b/src/cron/delivery.ts index e059f7566ca..3d74c68fe5b 100644 --- a/src/cron/delivery.ts +++ b/src/cron/delivery.ts @@ -174,7 +174,7 @@ function isSameDeliveryTarget( delivery: CronDelivery, failurePlan: CronFailureDeliveryPlan, ): boolean { - const primaryMode = delivery.mode ?? "none"; + const primaryMode = delivery.mode ?? "announce"; if (primaryMode === "none") { return false; } diff --git a/src/cron/service/jobs.ts b/src/cron/service/jobs.ts index ed5f57d78af..8c65791888a 100644 --- a/src/cron/service/jobs.ts +++ b/src/cron/service/jobs.ts @@ -668,6 +668,7 @@ function mergeCronDelivery( to: existing?.to, accountId: existing?.accountId, bestEffort: existing?.bestEffort, + failureDestination: existing?.failureDestination, }; if (typeof patch.mode === "string") { @@ -685,6 +686,20 @@ function mergeCronDelivery( if (typeof patch.bestEffort === "boolean") { next.bestEffort = patch.bestEffort; } + if ("failureDestination" in patch) { + if (patch.failureDestination === undefined) { + next.failureDestination = undefined; + } else { + const existingFd = next.failureDestination; + const patchFd = patch.failureDestination; + next.failureDestination = { + channel: patchFd?.channel ?? existingFd?.channel, + to: patchFd?.to ?? existingFd?.to, + accountId: patchFd?.accountId ?? existingFd?.accountId, + mode: patchFd?.mode ?? existingFd?.mode, + }; + } + } return next; } @@ -719,6 +734,14 @@ function mergeCronFailureAlert( : -1; next.cooldownMs = cooldownMs >= 0 ? Math.floor(cooldownMs) : undefined; } + if ("mode" in patch) { + const mode = typeof patch.mode === "string" ? patch.mode.trim() : ""; + next.mode = mode === "announce" || mode === "webhook" ? mode : undefined; + } + if ("accountId" in patch) { + const accountId = typeof patch.accountId === "string" ? patch.accountId.trim() : ""; + next.accountId = accountId ? accountId : undefined; + } return next; }