fix(grpc-data): A1 review round 2 F1 + F2 — an ack-revert establishes nothing; every Good edge withdraws; Bad edge forgets unsignalable
F1: RevertNativeAlarmAck projected through WriteAlarmCondition, which re-marked a comms-withdrawn native condition known; with the Good edge's conditional withdrawal skipped (GoodSinceUtc null) it read known-inactive-Good until the replay. AlarmStateUpdate.EstablishesState (false for the revert) rides a new default sink overload WriteAlarmCondition(..., establishesState) through the deferred and SDK sinks to the node manager, and every Good edge now withdraws unconditionally. F2: the Bad edge clears the unsignalable set, so a stale report cannot arm the backstop on the next Good edge. The rig's CollectAlarmTraffic skips withdrawals (every edge now sends one).
This commit is contained in:
@@ -53,6 +53,10 @@ public sealed class DeferredAddressSpaceSink : IOpcUaAddressSpaceSink, ISurgical
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm)
|
||||
=> _inner.WriteAlarmCondition(alarmNodeId, state, sourceTimestampUtc, realm);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm,
|
||||
bool establishesState) => _inner.WriteAlarmCondition(alarmNodeId, state, sourceTimestampUtc, realm, establishesState);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void WriteAlarmQuality(string alarmNodeId, uint statusCode, DateTime sourceTimestampUtc, AddressSpaceRealm realm)
|
||||
=> _inner.WriteAlarmQuality(alarmNodeId, statusCode, sourceTimestampUtc, realm);
|
||||
|
||||
@@ -81,6 +81,20 @@ public interface IOpcUaAddressSpaceSink
|
||||
/// the condition was materialised under).</param>
|
||||
void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm);
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="WriteAlarmCondition(string, AlarmConditionSnapshot, DateTime, AddressSpaceRealm)"/> that says
|
||||
/// whether the projection ESTABLISHES the condition's state (A1 §5.1 T2). <see langword="false"/> for a projection
|
||||
/// no source decided — the #760 ack-revert re-projects the projector's cached prior state — so it never makes a
|
||||
/// withdrawn condition known again (review round 2 F1). The default ignores the flag.
|
||||
/// </summary>
|
||||
/// <param name="alarmNodeId">The condition node id.</param>
|
||||
/// <param name="state">The full condition state.</param>
|
||||
/// <param name="sourceTimestampUtc">The source timestamp in UTC.</param>
|
||||
/// <param name="realm">The condition's realm.</param>
|
||||
/// <param name="establishesState">Whether this projection establishes the condition's state.</param>
|
||||
void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm,
|
||||
bool establishesState) => WriteAlarmCondition(alarmNodeId, state, sourceTimestampUtc, realm);
|
||||
|
||||
/// <summary>Annotate a materialised condition's source-data quality OUT OF BAND from any alarm
|
||||
/// transition (used by the driver-connectivity path: comms lost → <see cref="OpcUaStatus.BadNoCommunication"/>,
|
||||
/// restored → <see cref="OpcUaStatus.Good"/>). Sets ONLY the condition's Quality — never
|
||||
|
||||
@@ -1327,6 +1327,11 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
/// <param name="sourceTimestampUtc">The timestamp of the alarm state change in UTC.</param>
|
||||
/// <param name="realm">The address-space realm (Raw or Uns) the alarm node lives in.</param>
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm)
|
||||
=> WriteAlarmCondition(alarmNodeId, state, sourceTimestampUtc, realm, establishesState: true);
|
||||
|
||||
/// <inheritdoc cref="IOpcUaAddressSpaceSink.WriteAlarmCondition(string, AlarmConditionSnapshot, DateTime, AddressSpaceRealm, bool)"/>
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm,
|
||||
bool establishesState)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrEmpty(alarmNodeId);
|
||||
ArgumentNullException.ThrowIfNull(state);
|
||||
@@ -1428,7 +1433,8 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
// scripted known-ness comes ONLY from MarkConditionsKnown (the engine's inputs-established flip).
|
||||
// The record is raised by ReportConditionEvent when the gate fires, otherwise here as a state-only
|
||||
// record (ConditionClass and the other silent fields).
|
||||
if (_nativeAlarmNodeIds.Contains(key)) _conditionStateKnown.Add(key);
|
||||
// Review round 2 F1: a projection no source decided (the #760 ack-revert) never establishes state either.
|
||||
if (establishesState && _nativeAlarmNodeIds.Contains(key)) _conditionStateKnown.Add(key);
|
||||
if (fire)
|
||||
{
|
||||
ReportConditionEvent(condition, sourceTimestampUtc);
|
||||
|
||||
@@ -91,6 +91,10 @@ public sealed class SdkAddressSpaceSink : IOpcUaAddressSpaceSink, ISurgicalAddre
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm)
|
||||
=> _nodeManager.WriteAlarmCondition(alarmNodeId, state, sourceTimestampUtc, realm);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm,
|
||||
bool establishesState) => _nodeManager.WriteAlarmCondition(alarmNodeId, state, sourceTimestampUtc, realm, establishesState);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void WriteAlarmQuality(string alarmNodeId, uint statusCode, DateTime sourceTimestampUtc, AddressSpaceRealm realm)
|
||||
=> _nodeManager.WriteAlarmQuality(alarmNodeId, statusCode, sourceTimestampUtc, realm);
|
||||
|
||||
@@ -78,11 +78,11 @@ public sealed partial class DriverHostActor
|
||||
|
||||
/// <summary>
|
||||
/// A connectivity edge restarts the F5 window (from quality Good) and the backstop; a Bad edge cancels both.
|
||||
/// Review S2: the Bad edge withdraws "known" from the driver's conditions — the source can no longer vouch for
|
||||
/// their state, and an alarm raised during the outage would otherwise read known-inactive, Good after the
|
||||
/// reconnect until the replay. A Good edge withdraws too (ahead of the Good quality annotation) when no Bad edge
|
||||
/// was seen since the previous Good one, or it comes from a new child incarnation. They become known again only
|
||||
/// on the reconnected source's next signal (or transition).
|
||||
/// Review S2 / round 2 F1: every edge withdraws "known" from the driver's conditions — on the Bad edge the source
|
||||
/// can no longer vouch for their state (an alarm raised during the outage would otherwise read known-inactive,
|
||||
/// Good after the reconnect until the replay), and the Good edge withdraws again, unconditionally. They become
|
||||
/// known again only on the reconnected source's next signal (or transition). The Bad edge also forgets the
|
||||
/// unsignalable set (F2).
|
||||
/// </summary>
|
||||
private void OnConditionSignalConnectivity(string driverInstanceId, bool connected, IActorRef sender, long? connectionEpoch)
|
||||
{
|
||||
@@ -99,17 +99,22 @@ public sealed partial class DriverHostActor
|
||||
}
|
||||
|
||||
var t = Tracker(driverInstanceId);
|
||||
// A Good edge with no Bad edge since the previous Good one (or from a new incarnation) — withdraw here instead.
|
||||
var missedBadEdge = connected && (t.GoodSinceUtc is not null || (t.Owner is not null && !Equals(t.Owner, sender)));
|
||||
t.Owner = sender;
|
||||
t.Epoch++;
|
||||
Timers.Cancel(SignalTimeoutKey(driverInstanceId));
|
||||
Timers.Cancel(BackstopKey(driverInstanceId));
|
||||
t.Pending.Clear();
|
||||
t.PendingSinceUtc = null;
|
||||
if (!connected || missedBadEdge) WithdrawDriverConditionsKnown(driverInstanceId);
|
||||
// Review round 2 F1: withdraw on EVERY edge — the Good one too, unconditionally (ahead of the Good quality
|
||||
// annotation): whatever made a condition known since the Bad edge (an ack-revert projection, a missed Bad
|
||||
// edge, a new incarnation) cannot vouch for the reconnected source's state.
|
||||
WithdrawDriverConditionsKnown(driverInstanceId);
|
||||
if (!connected)
|
||||
{
|
||||
// Review round 2 F2: an unsignalable report belongs to the subscription that made it; the reconnected
|
||||
// subscription reports again if it still cannot signal. Kept, it would arm the backstop on the next Good
|
||||
// edge and turn a later FAILED refresh into known-by-timer instead of F5's unknown.
|
||||
t.Unsignalable.Clear();
|
||||
t.GoodSinceUtc = null;
|
||||
t.ConnectionEpoch = null;
|
||||
return;
|
||||
|
||||
@@ -2680,7 +2680,10 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
"reverting the condition to unacknowledged", _localNode, conditionNodeId, reason);
|
||||
// Native conditions live in the Raw realm at their bare NodeId (the apply pass's single raw condition).
|
||||
_opcUaPublishActor?.Tell(new ZB.MOM.WW.OtOpcUa.Runtime.OpcUa.OpcUaPublishActor.AlarmStateUpdate(
|
||||
conditionNodeId, snapshot, DateTime.UtcNow, AddressSpaceRealm.Raw));
|
||||
conditionNodeId, snapshot, DateTime.UtcNow, AddressSpaceRealm.Raw,
|
||||
// Review round 2 F1: the projector's cached prior state, not a driver transition — it establishes nothing
|
||||
// (a condition withdrawn by a comms loss must stay unknown until its driver signals again).
|
||||
EstablishesState: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -79,8 +79,10 @@ public sealed class OpcUaPublishActor : ReceiveActor, IWithTimers
|
||||
/// <param name="Source">A1 (plan §5.1 G3): the emitting source — the driver instance id for a native projection,
|
||||
/// <see cref="ScriptedSource"/> for the scripted host, null when unattributed. Only used to discard a source's
|
||||
/// deferred <see cref="MarkConditionsKnown"/> when one of its deferred projections is dropped or skipped.</param>
|
||||
/// <param name="EstablishesState">A1 review round 2 F1: false for a projection no source decided (the #760 ack-revert),
|
||||
/// which must never make a withdrawn condition known again.</param>
|
||||
public sealed record AlarmStateUpdate(string AlarmNodeId, AlarmConditionSnapshot State, DateTime TimestampUtc, AddressSpaceRealm Realm,
|
||||
string? Source = null);
|
||||
string? Source = null, bool EstablishesState = true);
|
||||
|
||||
/// <summary>The <see cref="AlarmStateUpdate.Source"/> / <see cref="MarkConditionsKnown.Source"/> of the scripted host.</summary>
|
||||
public const string ScriptedSource = "scripted-alarms";
|
||||
@@ -787,7 +789,7 @@ public sealed class OpcUaPublishActor : ReceiveActor, IWithTimers
|
||||
if (PlanPipelineBusy) DeferAlarm(msg);
|
||||
try
|
||||
{
|
||||
_sink.WriteAlarmCondition(msg.AlarmNodeId, msg.State, msg.TimestampUtc, msg.Realm);
|
||||
_sink.WriteAlarmCondition(msg.AlarmNodeId, msg.State, msg.TimestampUtc, msg.Realm, msg.EstablishesState);
|
||||
Interlocked.Increment(ref _writes);
|
||||
OtOpcUaTelemetry.OpcUaSinkWrite.Add(1, new KeyValuePair<string, object?>("kind", "alarm"));
|
||||
}
|
||||
@@ -1156,7 +1158,7 @@ public sealed class OpcUaPublishActor : ReceiveActor, IWithTimers
|
||||
}
|
||||
|
||||
alarms++;
|
||||
try { _sink.WriteAlarmCondition(alarm.AlarmNodeId, alarm.State, alarm.TimestampUtc, alarm.Realm); }
|
||||
try { _sink.WriteAlarmCondition(alarm.AlarmNodeId, alarm.State, alarm.TimestampUtc, alarm.Realm, alarm.EstablishesState); }
|
||||
catch (Exception ex) { _log.Warning(ex, "OpcUaPublish: replaying a deferred alarm write threw for {Node}", alarm.AlarmNodeId); }
|
||||
}
|
||||
|
||||
|
||||
@@ -230,6 +230,24 @@ public sealed class ConditionStateNodeManagerTests : IDisposable
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Review round 2 F1: a native projection flagged as not establishing (the #760 ack-revert) applies its state
|
||||
/// but never makes a withdrawn condition known again.</summary>
|
||||
[Fact]
|
||||
public async Task F1_A_non_establishing_native_projection_does_not_mark_known()
|
||||
{
|
||||
var (host, nm, sink) = await BootAsync();
|
||||
MaterialiseAll(nm);
|
||||
nm.WriteAlarmCondition(Native, State(true, false), DateTime.UtcNow, AddressSpaceRealm.Raw);
|
||||
nm.MarkConditionsUnknown("drv", [Native], AddressSpaceRealm.Raw).ShouldBe(1); // the Bad edge
|
||||
|
||||
nm.WriteAlarmCondition(Native, State(true, false, message: "reverted"), DateTime.UtcNow, AddressSpaceRealm.Raw, establishesState: false);
|
||||
|
||||
nm.IsConditionStateKnown(Native, AddressSpaceRealm.Raw).ShouldBeFalse();
|
||||
sink.Records.Last().ShouldSatisfyAllConditions(r => r.Message.ShouldBe("reverted"), r => r.StateKnown.ShouldBeFalse());
|
||||
AssertParity(nm, sink);
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task T3_The_marker_moves_only_on_a_new_occurrence()
|
||||
{
|
||||
|
||||
+55
@@ -157,6 +157,61 @@ public sealed class NativeAlarmInitialStateSignalTests : NativeAlarmSignalTestBa
|
||||
.ConditionIds.ShouldBe([A, B], ignoreOrder: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Review round 2 F1 — the exact scenario: comms lost (Bad edge withdraws), an operator acks while the driver is
|
||||
/// Reconnecting, so the ack fails and the host reverts the condition. That revert is the projector's cached state,
|
||||
/// not a driver transition: it must not establish the condition (EstablishesState false). And the reconnect's Good
|
||||
/// edge withdraws again, unconditionally, ahead of the Good quality annotation — so an alarm that re-raised
|
||||
/// upstream during the outage cannot read known-inactive, Good until the replay.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void An_ack_revert_during_an_outage_does_not_establish_and_the_Good_edge_withdraws_again()
|
||||
{
|
||||
var rig = StartRig(DriverTypeNames.Galaxy, ["hi"]);
|
||||
rig.Driver.Raise(A).ShouldBeTrue();
|
||||
rig.Driver.Signal([A]).ShouldBeTrue();
|
||||
rig.Publish.FishForMessage<OpcUaPublishActor.MarkConditionsKnown>(m => m.Known, TimeSpan.FromSeconds(5), cancellationToken: Ct);
|
||||
|
||||
rig.Host.Tell(new ReconnectDriver("c1", DriverId, "test", Guid.NewGuid()), TestActor);
|
||||
rig.Publish.FishForMessage<OpcUaPublishActor.MarkConditionsKnown>(m => !m.Known, TimeSpan.FromSeconds(5), cancellationToken: Ct);
|
||||
|
||||
rig.Host.Tell(new DriverHostActor.RouteNativeAlarmAck(A, null, "operator"), TestActor);
|
||||
var revert = rig.Publish.FishForMessage<OpcUaPublishActor.AlarmStateUpdate>(u => u.AlarmNodeId == A && !u.State.Acknowledged,
|
||||
TimeSpan.FromSeconds(5), cancellationToken: Ct);
|
||||
revert.EstablishesState.ShouldBeFalse("an ack-revert re-projects cached state; it establishes nothing");
|
||||
|
||||
// The reconnect: a withdrawal must precede the Good quality annotation.
|
||||
var withdrawnAgain = false;
|
||||
var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
while (true)
|
||||
{
|
||||
var m = rig.Publish.ReceiveOne(deadline - DateTime.UtcNow, Ct);
|
||||
m.ShouldNotBeNull("the reconnect's Good quality annotation never arrived");
|
||||
if (m is OpcUaPublishActor.MarkConditionsKnown { Known: false } w && w.ConditionIds.Contains(A)) withdrawnAgain = true;
|
||||
if (m is OpcUaPublishActor.MarkConditionsKnown { Known: true }) throw new ShouldAssertException("marked known before the driver signalled");
|
||||
if (m is OpcUaPublishActor.AlarmQualityUpdate { StatusCode: OpcUaStatus.Good }) break;
|
||||
}
|
||||
|
||||
withdrawnAgain.ShouldBeTrue("the Good edge withdraws unconditionally");
|
||||
}
|
||||
|
||||
/// <summary>Review round 2 F2: an unsignalable report belongs to the subscription that made it. After a Bad edge the
|
||||
/// reconnected subscription has not reported, so the backstop must not arm from the stale set — a refresh that then
|
||||
/// fails leaves the conditions unknown (F5), never known-by-timer.</summary>
|
||||
[Fact]
|
||||
public void An_unsignalable_report_does_not_survive_a_Bad_edge()
|
||||
{
|
||||
// The settle outlasts the window before the Bad edge, so the report is still pending (an elapsed backstop clears it).
|
||||
var rig = StartRig(DriverTypeNames.OpcUaClient, ["hi"], o => o.WithOpcUaClientSettle(TimeSpan.FromSeconds(3)));
|
||||
rig.Driver.Signal([A], unsignalable: true).ShouldBeTrue();
|
||||
|
||||
rig.Host.Tell(new ReconnectDriver("c1", DriverId, "test", Guid.NewGuid()), TestActor);
|
||||
rig.Publish.FishForMessage<OpcUaPublishActor.AlarmQualityUpdate>(q => q.StatusCode != OpcUaStatus.Good, TimeSpan.FromSeconds(5), cancellationToken: Ct);
|
||||
// The reconnect's Good edge (the child retries on its reconnect interval).
|
||||
rig.Publish.FishForMessage<OpcUaPublishActor.AlarmQualityUpdate>(q => q.StatusCode == OpcUaStatus.Good, TimeSpan.FromSeconds(30), cancellationToken: Ct);
|
||||
AssertNoMark(rig.Publish, TimeSpan.FromSeconds(4.5)); // a stale set would arm the 3 s backstop from this Good edge
|
||||
}
|
||||
|
||||
/// <summary>Open question answered — re-arm F5 for refs a deploy adds while the driver is connected. Today every such
|
||||
/// deploy changes the driver's config (its authored RawTags are folded into it), so the driver is respawned: the
|
||||
/// stopped incarnation's conditions are withdrawn, and the new incarnation's Good edge puts EVERY ref — the added one
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class NativeAlarmSignalTestBase : RuntimeActorTestBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The publish-actor messages that are alarm-state updates or marks, in arrival order, until
|
||||
/// <summary>The publish-actor messages that are alarm-state updates or KNOWN marks (withdrawals skipped), in arrival order, until
|
||||
/// <paramref name="until"/> matches (inclusive).</summary>
|
||||
/// <param name="publish">The probe.</param>
|
||||
/// <param name="until">Stop condition.</param>
|
||||
@@ -156,6 +156,8 @@ public abstract class NativeAlarmSignalTestBase : RuntimeActorTestBase
|
||||
var m = publish.ReceiveOne(deadline - DateTime.UtcNow);
|
||||
if (m is null) break;
|
||||
if (m is not (OpcUaPublishActor.AlarmStateUpdate or OpcUaPublishActor.MarkConditionsKnown)) continue;
|
||||
// Withdrawals (every connectivity edge sends one, review round 2 F1) are not marks.
|
||||
if (m is OpcUaPublishActor.MarkConditionsKnown { Known: false }) continue;
|
||||
seen.Add(m);
|
||||
if (until(m)) return seen;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user