fix(alarms): #951 #952 #953 — late refusal reverts, never-started command is NotApplied, superseded load failure ignored

#951: the hosted-service Ask lives LateVerdictWindow (30 s) past the caller's bound
(ExecuteAlarmCommand deadline unchanged); the OutcomeUnknown it returns carries the
still-running ask as AlarmCommandOutcome.LateOutcome (process-local). The node manager
watches it (or the asker task itself when its backstop expired, following unknown
chains) and reverts the node on a late NotApplied, under the existing per-condition
mutation-counter guard. Both CallAsync and remote ExecuteConditionMethodAsync paths.

#952: ScriptedAlarmEngine throws ScriptedAlarmCommandNotStartedException (an OCE) when a
command is cancelled before it acquires _evalGate; a cancellation inside SaveAsync stays
a plain OCE (unknown). The host maps not-started to NotApplied and remembers it, except on
the direct ask once its asker's deadline passed (asker already answered unknown and
broadcast): then unknown + not remembered, so the broadcast copy decides (as review r2 M2).

#953: a faulted load pipes back AlarmsLoadFailed(cause, generation); a failure from a
generation a newer apply superseded publishes no readiness (it would refuse every command
while the newer load is in flight).

Red/green: each fix reverted individually turns its tests red (Core 1, Runtime 3,
Host 1, OpcUaServer.IntegrationTests 4).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-12-01 19:42:24 -05:00
parent 6b60845931
commit 068124d1ae
14 changed files with 596 additions and 33 deletions
@@ -0,0 +1,23 @@
namespace ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms;
/// <summary>
/// #952: an operator command (acknowledge, confirm, shelve, enable/disable, comment) whose cancellation token fired
/// while it was still waiting for the engine's evaluation gate — typically queued behind a long
/// <see cref="ScriptedAlarmEngine.LoadAsync"/>. The command never ran: nothing was looked up, applied or persisted, so
/// it is definitely NOT applied (unlike a cancellation inside the store save, which may have committed and stays a
/// plain <see cref="OperationCanceledException"/>).
/// </summary>
/// <remarks>Derives from <see cref="OperationCanceledException"/> so a caller that only knows "cancelled" is unchanged.</remarks>
public sealed class ScriptedAlarmCommandNotStartedException : OperationCanceledException
{
/// <summary>Creates the exception for <paramref name="alarmId"/>.</summary>
/// <param name="alarmId">The alarm the command was for.</param>
/// <param name="inner">The cancellation observed while waiting for the gate.</param>
public ScriptedAlarmCommandNotStartedException(string alarmId, OperationCanceledException inner)
: base($"Command for alarm {alarmId} was cancelled before the scripted-alarm engine started it; nothing was applied.",
inner, inner.CancellationToken)
=> AlarmId = alarmId;
/// <summary>The alarm the command was for.</summary>
public string AlarmId { get; }
}