fix(virtualtags): a disabled VirtualTag keeps its node and reads BadOutOfService (lmxopcua#787, owner decision)
v2-ci / unit-tests (push) Has been cancelled

Revises 963b0d66, which dropped a disabled VirtualTag from the runtime plan so a
bound client got BadNodeIdUnknown. Now the plan carries Enabled (part of value
equality): AddressSpaceComposer.Compose and DeploymentArtifact.BuildEquipmentVirtualTagPlans
keep the row with Enabled=false (byte-parity), the applier materialises the node as
normal, and VirtualTagHostActor spawns no VirtualTagActor for it but publishes
BadOutOfService (new OpcUaStatus constant) with a null value stamped at deploy, on
every apply. Enabled flips are node-irrelevant to the change classifier; enabled->disabled
stops the child, disabled->enabled resumes evaluation. Validator exemption and name
uniqueness unchanged. Scripted alarms keep their not-materialised convention.
Tests updated; new wire test DisabledVirtualTagWireTests. docs/VirtualTags.md updated.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-10 04:48:56 -05:00
parent 8582ce91bc
commit f201f16fd4
10 changed files with 238 additions and 30 deletions
@@ -123,20 +123,23 @@ public static class AddressSpaceChangeClassifier
}
// A VirtualTag's materialised OPC UA node (MaterialiseEquipmentVirtualTags) is derived ONLY from
// {EquipmentId, FolderPath, Name, DataType}. Expression/DependencyRefs/Historize are engine/write-side
// {EquipmentId, FolderPath, Name, DataType}. Expression/DependencyRefs/Historize/Enabled are engine/write-side
// only and are adopted by VirtualTagHostActor's INDEPENDENT respawn (DriverHostActor → ApplyVirtualTags),
// so a delta changing ONLY those three leaves a byte-identical node and needs no address-space rebuild.
// so a delta changing ONLY those four leaves a byte-identical node and needs no address-space rebuild.
// Whitelist-of-may-differ via `with` + the record's custom Equals: any OTHER field difference (current
// or future) makes the override unequal → falls back to a full rebuild (safe default).
/// <summary>Whether a changed equipment virtual tag differs only in fields that do not affect its materialised node.</summary>
/// <param name="d">The virtual-tag delta to classify.</param>
/// <returns><see langword="true"/> when only Expression / DependencyRefs / Historize differ; otherwise <see langword="false"/>.</returns>
/// <returns><see langword="true"/> when only Expression / DependencyRefs / Historize / Enabled differ; otherwise <see langword="false"/>.</returns>
internal static bool VtagDeltaIsNodeIrrelevant(AddressSpacePlan.EquipmentVirtualTagDelta d) =>
(d.Previous with
{
Expression = d.Current.Expression,
DependencyRefs = d.Current.DependencyRefs,
Historize = d.Current.Historize,
// Enabled (lmxopcua#787) is node-irrelevant too: the node exists either way; the VirtualTag host
// publishes BadOutOfService on disable / resumes evaluation on enable from its own apply.
Enabled = d.Current.Enabled,
}).Equals(d.Current);
// v3 surgical raw-tag eligibility: a NON-alarm raw tag whose only differences are the in-place-updatable
@@ -378,6 +378,10 @@ public sealed record EquipmentTagAlarmInfo(string AlarmType, int Severity, bool?
/// which keeps existing positional+named ctor call sites compiling and preserves byte-parity.</param>
/// <param name="ChangeTriggered">Evaluate on a dependency change (entity default <c>true</c>).</param>
/// <param name="TimerIntervalMs">Periodic re-evaluation cadence in ms, or null for none (lmxopcua#783).</param>
/// <param name="Enabled">False for a disabled VirtualTag (lmxopcua#787): the node is still materialised (both
/// subtrees, so a bound client reads a status instead of <c>BadNodeIdUnknown</c>) but no <c>VirtualTagActor</c>
/// is spawned — <c>VirtualTagHostActor</c> publishes <c>BadOutOfService</c> with a null value instead. Entity
/// default <c>true</c>; the composer and the artifact decode carry it identically.</param>
public sealed record EquipmentVirtualTagPlan(
string VirtualTagId,
string EquipmentId,
@@ -388,7 +392,8 @@ public sealed record EquipmentVirtualTagPlan(
IReadOnlyList<string> DependencyRefs,
bool Historize = false,
bool ChangeTriggered = true,
int? TimerIntervalMs = null)
int? TimerIntervalMs = null,
bool Enabled = true)
{
/// <inheritdoc />
// Structural equality: the auto-generated record equality would compare DependencyRefs (an
@@ -406,6 +411,7 @@ public sealed record EquipmentVirtualTagPlan(
Historize == other.Historize &&
ChangeTriggered == other.ChangeTriggered &&
TimerIntervalMs == other.TimerIntervalMs &&
Enabled == other.Enabled &&
DependencyRefs.SequenceEqual(other.DependencyRefs, StringComparer.Ordinal);
/// <inheritdoc />
@@ -414,7 +420,7 @@ public sealed record EquipmentVirtualTagPlan(
var hash = new HashCode();
hash.Add(VirtualTagId); hash.Add(EquipmentId); hash.Add(FolderPath);
hash.Add(Name); hash.Add(DataType); hash.Add(Expression);
hash.Add(Historize); hash.Add(ChangeTriggered); hash.Add(TimerIntervalMs);
hash.Add(Historize); hash.Add(ChangeTriggered); hash.Add(TimerIntervalMs); hash.Add(Enabled);
foreach (var r in DependencyRefs) hash.Add(r, StringComparer.Ordinal);
return hash.ToHashCode();
}
@@ -615,10 +621,11 @@ public static class AddressSpaceComposer
// DependencyRefs = the distinct ctx.GetTag("…") literals the VirtualTagActor subscribes to.
// VirtualTag has no FolderPath today → "".
var scriptsById = resolvedScripts.ToDictionary(s => s.ScriptId, StringComparer.Ordinal);
// A disabled VirtualTag (lmxopcua#787) is not part of the runtime plan: no node, no evaluation —
// the same as a disabled scripted alarm (which is not materialised). Mirrored by the artifact decode.
// A disabled VirtualTag (lmxopcua#787, owner decision) STAYS in the plan with Enabled=false: its node
// is materialised as normal but it is never evaluated — the VirtualTag host publishes BadOutOfService.
// Scripted alarms keep their own convention (a disabled one is not materialised). Mirrored by the
// artifact decode.
var equipmentVirtualTags = vtags
.Where(v => v.Enabled)
.OrderBy(v => v.EquipmentId, StringComparer.Ordinal)
.ThenBy(v => v.Name, StringComparer.Ordinal)
.Select(v =>
@@ -636,7 +643,8 @@ public static class AddressSpaceComposer
DependencyRefs: EquipmentScriptPaths.ExtractDependencyRefs(expanded),
Historize: v.Historize,
ChangeTriggered: v.ChangeTriggered,
TimerIntervalMs: v.TimerIntervalMs);
TimerIntervalMs: v.TimerIntervalMs,
Enabled: v.Enabled);
})
.ToList();