Description: Succeeded email sent without a failure
 When the test rule required multiple cycles to fail before the state
 transition, as soft-failure followed by recovery resulted in "Succeeded" email
 without a previous failure notification.
Author: Fabio Augusto De Muzio Tobich <ftobich@debian.org>
Bug-Debian: https://bugs.debian.org/1145157
Origin: upstream, commit:046d1b5
Bug: https://bitbucket.org/tildeslash/monit/issues/1154/succeeded-email-sent-without-a-failure
Forwarded: not-needed
Applied-Upstream: commit:046d1b5
Last-Update: 2026-08-26
Index: monit/src/event.c
===================================================================
--- monit.orig/src/event.c
+++ monit/src/event.c
@@ -147,8 +147,12 @@ static bool _checkState(Event_T E, State
         /* Translate the posted state to a 0/1 (succeeded/failed) class */
         State_Type currentState = (S == State_Succeeded || S == State_ChangedNot) ? State_Succeeded : State_Failed;
 
-        /* Only failed/changed state condition can change the initial state */
-        if (currentState == State_Succeeded && E->state == State_Init && ! (E->source->error & E->id))
+        /* Only failed/changed state condition can change the initial state. While the event is still in the State_Init
+         * phase (the error didn't accumulate enough cycles to pass the "for X cycles" watermark), a success just clears
+         * the pending soft error and must not be reported as a state change. No failure was reported yet, so there is
+         * nothing to recover from.
+         */
+        if (currentState == State_Succeeded && E->state == State_Init)
                 return false;
 
         /* Internal instance and action events are reported on every occurrence */

