fix(scripted-alarms): #935 review round 1 — commands look up under the gate, a restatement writes nothing, a failed load ends the generation
S1: ApplyAsync looked its alarm up before taking _evalGate, so a command racing a LoadAsync applied to the load's interim Fresh entry (an ack no-op that then saved Fresh over the carried Active condition — the #935 re-Activate on the next push) or wrote an old-generation state over the new one. The lookup is now under the gate: a command queued behind a load applies to the generation that load produced. A command that changes nothing (value-equal result) writes nothing. S2: a load re-saved every alarm's post-predicate state, so a node that missed an operator command upserted its stale carried state over the LocalDb last-writer-wins row on every deploy. A held seed (carried or persisted) left value-equal is not written. The push path's ReferenceEquals check (always false: ApplyPredicate returns a clone) is now value equality too, so a no-op re-evaluation no longer writes/replicates. S3: a failed load ends the generation. The engine is blind until the next good load, so (decision, same rule as removed/disabled alarms) that load reads the store — a still-true alarm is a new occurrence — instead of restating the pre-failure snapshot. While blind, operator commands throw ScriptedAlarmCommandRejectedException (the host logs it distinctly; the command topic is fire-and-forget, so that Warning is the record) and queued re-evaluations / shelving checks are dropped. N5: a timed shelve that expired before a load is unshelved through the shelving check (AutoUnshelve audit + Unshelved emission), not silently by ApplyPredicate. Tests (each red on revert, verified): ack racing a held load (S1), idempotent command (S1), restatement vs real change saves (S2), no-op push saves (S2), command rejected after failed load (S3), re-evaluation after failed load (S3), failed load -> new occurrence + store fault mid-seed -> one Activated (S3/S4), runner Unavailable at reload freezes carried state (S4), expired timed shelve at load (N5). N4: the Bad-input reload test now waits on a Good-bucket QualityChanged.
This commit is contained in:
@@ -812,6 +812,15 @@ public sealed class ScriptedAlarmHostActor : ReceiveActor
|
||||
_log.Warning("ScriptedAlarmHost: engine op {Op} for alarm {AlarmId} timed out after {Timeout} — the condition-state store is stalled",
|
||||
cmd.Operation, cmd.AlarmId, _commandTimeout);
|
||||
}
|
||||
catch (ScriptedAlarmCommandRejectedException ex)
|
||||
{
|
||||
// #935 review S3: the last LoadAsync failed, so the engine holds no trusted state and refuses the
|
||||
// command rather than persist one derived from a Fresh seed. The command is a fire-and-forget topic
|
||||
// broadcast (the OPC UA method / AdminUI already returned), so this Warning is the operator-visible
|
||||
// record; the next successful deploy re-asserts the condition node from the store.
|
||||
_log.Warning("ScriptedAlarmHost: {Op} for alarm {AlarmId} NOT applied — {Reason}",
|
||||
cmd.Operation, cmd.AlarmId, ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// A failing engine op must not crash the actor — mirror OnLoadFailed's log-and-stay-inert style.
|
||||
|
||||
Reference in New Issue
Block a user