fix(vtags): prune _planByVtag on child termination + crash-then-change test (H1b review follow-up)

This commit is contained in:
Joseph Doherty
2026-06-15 10:12:11 -04:00
parent ada01e1af8
commit ebf2f1dd7a
2 changed files with 42 additions and 4 deletions
@@ -39,8 +39,9 @@ public sealed class VirtualTagHostActor : ReceiveActor
private readonly Dictionary<string, IActorRef> _children = new(StringComparer.Ordinal);
// vtagId -> folder-scoped OPC UA NodeId the materialiser placed the variable at.
private readonly Dictionary<string, string> _nodeIdByVtag = new(StringComparer.Ordinal);
// vtagId -> the plan its currently-spawned child was built from, so we can detect an in-place
// change (edited Expression/DependencyRefs) and stop+respawn the child to adopt it.
// vtagId -> the plan its live child was built from, so we can detect an in-place change (edited
// Expression/DependencyRefs) and stop+respawn the child to adopt it. Kept in lock-step with
// _children: rebuilt to the desired set at the end of every apply, and pruned in OnChildTerminated.
private readonly Dictionary<string, EquipmentVirtualTagPlan> _planByVtag = new(StringComparer.Ordinal);
/// <summary>Factory method to create Props for a VirtualTagHostActor.</summary>
@@ -161,8 +162,11 @@ public sealed class VirtualTagHostActor : ReceiveActor
foreach (var id in stale)
{
_children.Remove(id);
// NodeId map is rebuilt on the next ApplyVirtualTags; leaving the mapping is harmless
// (no child will publish for it until respawned). A dead child is respawned on next apply.
// Keep _planByVtag in lock-step with _children so it never holds a plan for a dead child.
// (The next apply also resets it, and the change-detect guard short-circuits on the missing
// _children entry — so this is defensive consistency, not a live-bug fix.) NodeId map is
// rebuilt on the next ApplyVirtualTags; leaving that mapping is harmless. Dead child respawns.
_planByVtag.Remove(id);
_log.Warning("VirtualTagHost: child for vtag {VirtualTagId} terminated; will respawn on next apply", id);
}
}