#16262·mautic

Deleting a decision from a campaign causes an infinite email-resend loop via redirect_event_id (InactiveExecutioner::handleRedirectedEvent)

Author: edoardoCameCreated Jun 14, 2026Updated Sep 25, 2026
LabelsT2bugcampaignsstalemautic-7

Mautic Series

7.1.x series

Mautic installed version

7.1.2

Way of installing

I installed with composer using https://github.com/mautic/recommended-project

PHP version

8.3.6

What browsers are you seeing the problem on?

Chrome

What happened?

[Bug] Deleting a decision from a campaign causes an infinite email-resend loop via redirect_event_id (InactiveExecutioner::handleRedirectedEvent)

Severity

Critical – a single deleted decision can make a published campaign re-send the same email to contacts indefinitely (every cron run), with no automatic stop. In our case it sent the same email 11,500 times to 100 contacts in ~4 hours before being stopped manually.

Environment

  • Mautic: 7.1.2 (verified the same buggy code is still present in 7.2.0-rc)
  • PHP: 8.3.6 (CLI memory_limit 512M)
  • DB: MariaDB 10.11
  • OS: Ubuntu 24.04
  • Cron: mautic:campaigns:trigger every 2 minutes
  • Install: composer (mautic/recommended-project)

Summary

When a decision event is deleted from a campaign, Mautic soft-deletes it (deleted timestamp) and sets a redirect_event_id pointing to another (still-live) event, so that "orphaned" contacts are redirected. However, InactiveExecutioner::handleRedirectedEvent() re-executes that redirect target without marking the execution in campaign_lead_event_log and without paginating past the first batch, while incrementing the campaign rotation each time. As a result, every cron run re-processes the same batch of contacts, bumps their rotation, and re-sends the redirect-target email — forever.

Steps to reproduce

  1. Build a campaign with a form.submit decision that has a positive ("yes") immediate email action (e.g. "Thank you") and a negative ("no") path.
  2. Delete that decision (and/or its branch) in the campaign builder. Mautic sets redirect_event_id on the deleted decision, pointing to a surviving email action.
  3. Publish the campaign against a sizeable segment.
  4. Let contacts flow through until they reach the stage of the deleted decision (the inactive path becomes due).
  5. Observe: the redirect-target email is sent once per cron run to the same batch of contacts, with campaign_leads.rotation increasing by 1 each run.

Expected behavior

A contact should receive the redirect-target action once, and the event should be recorded as executed so it is not repeated.

Actual behavior

The redirect-target email is re-sent on every cron run to the same ~batch-limit contacts; rotation climbs without bound; the email is never recorded as "executed" so the loop never terminates on its own.

Root cause (code)

app/bundles/CampaignBundle/Executioner/InactiveExecutioner.php

The decisions loop redirects deleted decisions:

php
// executeEvents()
foreach ($this->decisions as $key => $decisionEvent) {
    $originalDecisionEvent = $decisionEvent;
    $decisionEvent = $this->redirectionHelper->handleEventRedirection($decisionEvent, $this->decisions, $key);
    if ($decisionEvent->getId() !== $originalDecisionEvent->getId()) {
        $this->handleRedirectedEvent($decisionEvent, $originalDecisionEvent);
        continue;
    }
    ...

The redirect handler – note it increments rotation, does not call recordLogsAsExecutedForEvent, and has no pagination loop:

php
private function handleRedirectedEvent(Event $redirectEvent, Event $originalDecisionEvent): void
{
    $contacts = $this->inactiveContactFinder->getContacts(
        $this->campaign->getId(), $originalDecisionEvent, $this->limiter, true);
    if (!$contacts->count()) {
        return;
    }
    $this->progressBar->advance($contacts->count());
    $this->counter->advanceEvaluated($contacts->count());
    $contactIds = $contacts->getKeys();

    $this->leadRepository->incrementCampaignRotationForContacts(   // rotation++
        $contactIds, $redirectEvent->getCampaign()->getId()
    );
    $eventCollection = new ArrayCollection([$redirectEvent]);
    $this->executioner->executeEventsForContacts($eventCollection, $contacts, $this->counter);
    // <-- no recordLogsAsExecutedForEvent(), no `while ($contacts->count())` loop
}

Compare with the normal inactive path in the same file, which does record execution:

php
// Record decision for these contacts
$this->executioner->recordLogsAsExecutedForEvent($decisionEvent, $contacts, true);

Event::shouldBeRedirected() (app/bundles/CampaignBundle/Entity/Event.php) is what arms this:

php
public function shouldBeRedirected(): bool
{
    return $this->isDeleted() && null !== $this->redirectEvent;
}

The redirect_event_id is assigned on deletion by CampaignModel::handleDeletedEventsWithRedirect() and the redirect_event_id column was introduced in migration Version20250512114846 (2025-05-12).

Confirmed unchanged in 7.2.0-rc: handleRedirectedEvent is identical (still no recordLogsAsExecutedForEvent, no pagination, still increments rotation).

Evidence (from our production incident)

Deleted decision points its redirect at the email action that looped:

campaign_events (campaign_id=22):
 id=215  type=form.submit  deleted=2026-06-12 15:02:03  redirect_event_id=213   <-- deleted DECISION
 id=213  type=email.send   name="Thank you" (email_id=30)                       <-- redirect target

Same contact re-processed once per cron run, rotation climbing:

campaign_lead_event_log (lead_id=619, event_id=213):
 rotation=2   2026-06-14 15:22:36
 rotation=3   2026-06-14 15:24:12
 rotation=4   2026-06-14 15:26:28
 ... one row per ~2-minute cron run ...
 rotation=116 2026-06-14 19:10:xx
campaign_leads: lead_id=619 rotation=116 manually_removed=0 date_last_exited=NULL

Aggregate impact:

email_stats (email_id=30): 11,500 sends to 100 distinct contacts  (115 each)
window: 2026-06-14 15:22 -> 19:10 (loop stopped only when the campaign was unpublished)

Audit log confirms the decision was deleted before publishing (so this is not "editing a live campaign"):

2026-06-12 15:02:22  update  events removed: 214 Blocco 3, 215 Registrazione (decision), 216, 217
2026-06-12 15:09:03  update  isPublished 0 -> 1   (published AFTER the deletion)
2026-06-14 19:10:58  update  isPublished 1 -> 0   (manual stop; matches last send 19:10)

Secondary symptom – the runaway volume also exhausted PHP memory in the cron worker (collateral, not the root cause):

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted
  in app/bundles/EmailBundle/Event/EmailSendEvent.php on line 342
  (mautic:campaigns:trigger)

Why only ~100 contacts and not the whole segment

handleRedirectedEvent processes a single getContacts(...) batch (bounded by the contact limiter, default ~100) and never advances minContactId, so the same first batch is re-processed each run while the rest of the segment is never reached.

Suggested fix

In handleRedirectedEvent:

  1. Call recordLogsAsExecutedForEvent($redirectEvent, $contacts, ...) (or otherwise persist execution) so contacts are not re-selected next run.
  2. Wrap in a pagination while ($contacts->count()) loop like the normal inactive path, advancing the limiter.
  3. Re-evaluate whether incrementCampaignRotationForContacts should be called here at all for a deleted-decision redirect (it converts a one-time redirect into a per-run rotation bump).

Workaround for operators

  • Do not publish a campaign that contains a soft-deleted decision with a redirect_event_id. Detection query:
sql
SELECT e.campaign_id, c.name, c.is_published, COUNT(*) AS deleted_decisions_with_redirect
FROM campaign_events e JOIN campaigns c ON c.id = e.campaign_id
WHERE e.event_type = 'decision' AND e.deleted IS NOT NULL AND e.redirect_event_id IS NOT NULL
GROUP BY e.campaign_id;
  • Cloning the campaign clears the redirect (Event::__clone() sets redirectEvent = null), which disarms the loop.

How can we reproduce this issue?

Add a decision to a decision tree and then delete it

Relevant log output

bash

Code of Conduct

  • I confirm that I have read and agree to follow this project's Code of Conduct



Care about this issue? Want to get it resolved sooner? If you are a member of Mautic, you can add some funds to the Bounties Project so that the person who completes this task can claim those funds once it is merged by a member of the core team! Read the docs here.