fix(grpc-data): a raised F5 diagnostic follows the pending set down after a late native transition

The A1 phase-run failure of A_native_transition_leaves_the_F5_pending_set was a real defect: when the
600 ms F5 window closed before the transition was processed (a loaded run), the diagnostic kept the
count from when it was raised (2) although the node manager held the condition established (1).
New deterministic test closes the window first; red before, green after.
This commit is contained in:
Joseph Doherty
2026-11-24 14:47:36 -05:00
parent 95d90c1933
commit fbf9f7b898
3 changed files with 43 additions and 1 deletions
@@ -195,6 +195,22 @@ public sealed class ConditionStateHub : IConditionStateSink
new KeyValuePair<string, object?>("driver", driverInstanceId));
}
/// <summary>
/// A raised diagnostic follows its driver's pending set down (a native transition established one of its
/// conditions after the window closed). Only an existing diagnostic is updated, and the counter is not charged
/// again: these conditions were counted when the diagnostic was raised.
/// </summary>
/// <param name="driverInstanceId">The driver instance.</param>
/// <param name="conditions">The conditions still unknown.</param>
/// <returns>Whether a raised diagnostic was updated.</returns>
public bool UpdateUnsignalled(string driverInstanceId, int conditions)
{
ArgumentException.ThrowIfNullOrEmpty(driverInstanceId);
while (_unsignalled.TryGetValue(driverInstanceId, out var current))
if (_unsignalled.TryUpdate(driverInstanceId, current with { Conditions = conditions }, current)) return true;
return false;
}
/// <summary>A later signal (or the driver's removal) clears the diagnostic.</summary>
/// <param name="driverInstanceId">The driver instance.</param>
/// <returns>Whether a diagnostic was cleared.</returns>
@@ -237,8 +237,13 @@ public sealed partial class DriverHostActor
private void NoteConditionsEstablished(string driverInstanceId, ConditionSignalTracker t, IEnumerable<string> rawPaths)
{
if (t.Pending.Count == 0) return;
var before = t.Pending.Count;
t.Pending.ExceptWith(rawPaths);
if (t.Pending.Count == 0) ClearPendingWindow(driverInstanceId, t);
// A2 review (A1 phase-run failure): a diagnostic raised before this transition must not keep claiming the
// condition — the node manager holds it established now.
else if (t.DiagnosticRaised && t.Pending.Count != before)
_conditionSignals.Hub?.UpdateUnsignalled(driverInstanceId, t.Pending.Count);
}
/// <summary>A forwarded native transition established <paramref name="rawPath"/> (see <see cref="NoteConditionsEstablished"/>).</summary>
@@ -259,8 +259,29 @@ public sealed class NativeAlarmInitialStateSignalTests : NativeAlarmSignalTestBa
rig.Driver.Raise(A).ShouldBeTrue();
rig.Publish.FishForMessage<OpcUaPublishActor.AlarmStateUpdate>(u => u.AlarmNodeId == A, TimeSpan.FromSeconds(5), cancellationToken: Ct);
// Either order is legal: the transition can land before the F5 window closes (the diagnostic is raised with 1) or
// after it (raised with 2, then lowered to 1). The diagnostic must end at the node manager's count either way.
AwaitCondition(() => rig.Hub.Unsignalled.TryGetValue(DriverId, out var d) && d.Conditions == 1, TimeSpan.FromSeconds(5), Ct);
}
/// <summary>
/// A2 review (the A1 phase-run failure): the F5 window closes BEFORE the transition arrives — what a loaded run
/// does to the 600 ms window above. The raised diagnostic must follow the pending set down (it used to keep the
/// count from when it was raised, so it claimed a condition the node manager already held established).
/// </summary>
[Fact]
public void A_native_transition_after_the_F5_window_closed_lowers_the_raised_diagnostic()
{
var rig = StartRig(DriverTypeNames.Galaxy, ["hi", "lo"], o => o.WithSignalTimeout(DriverTypeNames.Galaxy, TimeSpan.FromMilliseconds(200)));
AwaitCondition(() => rig.Hub.Unsignalled.ContainsKey(DriverId), TimeSpan.FromSeconds(5), Ct);
rig.Hub.Unsignalled[DriverId].Conditions.ShouldBe(1); // only B is still unknown
rig.Hub.Unsignalled[DriverId].Conditions.ShouldBe(2);
rig.Driver.Raise(A).ShouldBeTrue();
rig.Publish.FishForMessage<OpcUaPublishActor.AlarmStateUpdate>(u => u.AlarmNodeId == A, TimeSpan.FromSeconds(5), cancellationToken: Ct);
AwaitCondition(() => rig.Hub.Unsignalled.TryGetValue(DriverId, out var d) && d.Conditions == 1, TimeSpan.FromSeconds(5), Ct);
rig.Driver.Raise(B).ShouldBeTrue(); // the last pending condition established ⇒ the diagnostic clears
AwaitCondition(() => !rig.Hub.Unsignalled.ContainsKey(DriverId), TimeSpan.FromSeconds(5), Ct);
}
/// <summary>Review nit — a signal from anything but the current child (a stopped incarnation, a stray sender) is