fix(opcuaclient): #926 review r1 - loss after the signal withdraws known; gaps outside a bracket, overlapping starts, failed refreshes

- a sequence gap outside a bracket is a loss (re-refresh, same budget); older/repeated
  sequence numbers are ignored and not recorded
- AlarmInitialStateEventArgs.Withdrawn (additive): the driver withdraws 'known' once per
  signalled episode on its first loss; DriverHostActor sends MarkConditionsKnown(Known:false)
  for those conditions, drops them from the backstop and re-arms F5
- a RefreshStart while a bracket is open is a loss (never erases the open bracket's)
- a failed ConditionRefresh call is retried through the same bounded retry
- retry generation token (a finished retry never clears a newer retry's pending flag)
- spent budget renews after a 5-min cool-down; RefreshRequired sweeps coalesced
Red/green per fix (7 mutations) + live opc-plc gate re-run.
This commit is contained in:
Joseph Doherty
2026-11-28 10:07:08 -05:00
parent 99f2b9d8b7
commit 06da40a909
12 changed files with 534 additions and 75 deletions
@@ -213,6 +213,26 @@ public sealed partial class DriverHostActor
return;
}
if (msg.Args.Withdrawn)
{
// #926: the source lost events after establishing these conditions. Take "known" back (same chain as its
// projections, so it lands after them), keep them out of the backstop (which would re-mark them known by
// timer), and put them back in the F5 window so a source that never re-signals is diagnosed.
t.Unsignalable.ExceptWith(msg.Args.ConditionIds);
var withdrawn = MarkDriverConditionsKnown(msg.DriverInstanceId, msg.Args.ConditionIds, known: false);
if (t.GoodSinceUtc is not null && _alarmRefsByDriver.TryGetValue(msg.DriverInstanceId, out var owned))
{
var ownedPaths = owned.Select(r => r.RawPath).ToHashSet(StringComparer.Ordinal);
var before = t.Pending.Count;
t.Pending.UnionWith(msg.Args.ConditionIds.Where(ownedPaths.Contains));
// An F5 window already running covers them; otherwise start one now.
if (t.Pending.Count != before && t.PendingSinceUtc is null) ArmSignalTimeout(msg.DriverInstanceId, t);
}
_log.Info("DriverHost {Node}: driver {Driver} withdrew {Count} condition(s) ({Routed} routed) — state no longer known (events lost)",
_localNode, msg.DriverInstanceId, msg.Args.ConditionIds.Count, withdrawn);
return;
}
if (msg.Args.Unsignalable)
{
// InitialStateUnsignalable: no real signal will come. Only a driver type with a backstop (OpcUaClient) marks
@@ -327,7 +347,7 @@ public sealed partial class DriverHostActor
}
/// <summary>Route driver condition ids (RawPaths) to their condition nodes and send one mark per realm.</summary>
private int MarkDriverConditionsKnown(string driverInstanceId, IReadOnlyCollection<string> conditionIds)
private int MarkDriverConditionsKnown(string driverInstanceId, IReadOnlyCollection<string> conditionIds, bool known = true)
{
if (_opcUaPublishActor is null || conditionIds.Count == 0) return 0;
var byRealm = new Dictionary<AddressSpaceRealm, List<string>>();
@@ -344,7 +364,7 @@ public sealed partial class DriverHostActor
var count = 0;
foreach (var (realm, ids) in byRealm)
{
_opcUaPublishActor.Tell(new PublishActor.MarkConditionsKnown(driverInstanceId, ids, realm));
_opcUaPublishActor.Tell(new PublishActor.MarkConditionsKnown(driverInstanceId, ids, realm, Known: known));
count += ids.Count;
}