Scripted alarms: every deploy re-activates a still-active alarm (Acked reset to Unacknowledged, new LastTransitionUtc, duplicate alerts row) #935

Closed
opened 2026-11-25 03:09:46 -05:00 by dohertj2 · 1 comment
Owner

Found while root-causing the A4 live gate (grpc-data condition forwarding, F2; branch a4-code).

ScriptedAlarmEngine.LoadAsync runs on EVERY deploy (ApplyScriptedAlarms), clears _alarms, and seeds each alarm from IAlarmStateStore.LoadAsync. The production store (LocalDbAlarmConditionStateStore) does not persist Active — it is restored as Inactive by design (docs/ScriptedAlarms.md §State persistence). With the predicate still true, Part9StateMachine.ApplyPredicate(seed Inactive, true) is an Inactive→Active transition: Activated emission, Acked = Unacknowledged, Confirmed = Unconfirmed, LastTransitionUtc = now.

Consequences on every deploy, for every still-active scripted alarm:

  • an operator-acknowledged active alarm comes back Unacknowledged (the docs claim the opposite: "operators never re-ack"); the origin node then reports a real un-ack event and the activation marker bumps (consumers mint new EventIds);
  • an Activated emission reaches the alerts topic → duplicate historian/AVEVA alarm row per deploy (the #487 re-assert was made node-only precisely to avoid this);
  • the condition Time moves to the deploy instant (live: a4dbg-1 origin records v16/v17 for source-scalar-high at the deploy with the same state and marker, t = load time; re-asserted 1 non-normal condition node(s) then writes LastTransitionUtc).

Startup_recovery_preserves_ack_but_rederives_active_from_predicate does not cover it: it seeds an InMemory store WITH Active and the predicate goes false.

Suggested fix: a same-process reload is a restatement, not a new occurrence — seed a surviving alarm id from the engine's previous in-memory condition (previous ?? persisted ?? Fresh) before _alarms.Clear(), so a still-true predicate yields None (the #487 re-assert still restores the node after a rebuild). Process restart keeps today's behaviour (Active not persisted).

The A4 consumer-side fixes (held conditions across a deploy) make consumers mirror this restatement silently while state and marker are unchanged; the acked case is still wrong at the origin itself.

Found while root-causing the A4 live gate (grpc-data condition forwarding, F2; branch `a4-code`). `ScriptedAlarmEngine.LoadAsync` runs on EVERY deploy (`ApplyScriptedAlarms`), clears `_alarms`, and seeds each alarm from `IAlarmStateStore.LoadAsync`. The production store (`LocalDbAlarmConditionStateStore`) does not persist `Active` — it is restored as `Inactive` by design (`docs/ScriptedAlarms.md` §State persistence). With the predicate still true, `Part9StateMachine.ApplyPredicate(seed Inactive, true)` is an **Inactive→Active transition**: `Activated` emission, `Acked = Unacknowledged`, `Confirmed = Unconfirmed`, `LastTransitionUtc = now`. Consequences on every deploy, for every still-active scripted alarm: - an operator-**acknowledged** active alarm comes back **Unacknowledged** (the docs claim the opposite: "operators never re-ack"); the origin node then reports a real un-ack event and the activation marker bumps (consumers mint new EventIds); - an `Activated` emission reaches the `alerts` topic → duplicate historian/AVEVA alarm row per deploy (the #487 re-assert was made node-only precisely to avoid this); - the condition `Time` moves to the deploy instant (live: `a4dbg-1` origin records v16/v17 for `source-scalar-high` at the deploy with the same state and marker, `t` = load time; `re-asserted 1 non-normal condition node(s)` then writes `LastTransitionUtc`). `Startup_recovery_preserves_ack_but_rederives_active_from_predicate` does not cover it: it seeds an InMemory store WITH `Active` and the predicate goes false. Suggested fix: a same-process reload is a restatement, not a new occurrence — seed a surviving alarm id from the engine's previous in-memory condition (`previous ?? persisted ?? Fresh`) before `_alarms.Clear()`, so a still-true predicate yields `None` (the #487 re-assert still restores the node after a rebuild). Process restart keeps today's behaviour (Active not persisted). The A4 consumer-side fixes (held conditions across a deploy) make consumers mirror this restatement silently while state and marker are unchanged; the acked case is still wrong at the origin itself.
dohertj2 added the type:bugpriority:p2 labels 2026-11-25 03:09:47 -05:00
Author
Owner

Fixed on master (merge of fu-935). A same-process reload (deploy) now seeds each surviving scripted alarm from the previous generation's in-memory condition (previous ?? persisted ?? Fresh) — a still-true predicate is a restatement: no Activated, Acked kept, LastTransitionUtc and the activation marker unchanged, no alerts row. Review round 1: operator commands look up under _evalGate (a command racing a load applies to the new generation), unchanged results are not saved (also stops a per-push replicated write), a failed load ends the generation (commands rejected with a Warning until the next good load, which reads the store like a restart), expired timed shelve at reload is unshelved with audit. Live: ack → deploy → still Acknowledged, same EventId, no event on origin or consumer; A01–A08 8/8. Evidence: docs/plans/evidence/followups/935.md.

Fixed on master (merge of `fu-935`). A same-process reload (deploy) now seeds each surviving scripted alarm from the previous generation's in-memory condition (`previous ?? persisted ?? Fresh`) — a still-true predicate is a restatement: no Activated, Acked kept, LastTransitionUtc and the activation marker unchanged, no `alerts` row. Review round 1: operator commands look up under `_evalGate` (a command racing a load applies to the new generation), unchanged results are not saved (also stops a per-push replicated write), a failed load ends the generation (commands rejected with a Warning until the next good load, which reads the store like a restart), expired timed shelve at reload is unshelved with audit. Live: ack → deploy → still Acknowledged, same EventId, no event on origin or consumer; A01–A08 8/8. Evidence: docs/plans/evidence/followups/935.md.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#935