fix(grpc-data): A3a review r1 — condition-bearing projected folders are event notifiers from materialisation (folder-only demand), null-safe revalidation log; NM tests: B3 revalidation + demand release, S1 rebuild, deviation 3/6/8, S2 verdict TTL, A3-SEC delivery gate isolated (DroppedOnPublish 0)

This commit is contained in:
Joseph Doherty
2026-11-24 18:46:11 -05:00
parent 69aeeb770b
commit 14343bf086
6 changed files with 242 additions and 4 deletions
@@ -73,6 +73,10 @@ public interface IProjectedConditionAccess
/// folder event item (and its demand) before any imported condition is wired there.</summary>
bool CanSubscribeFolder(RoleCarryingUserIdentity? caller, string mappingId, string folderLocalSubject);
/// <summary>Deviation 3 (review r1): whether a deployed mapping is condition-bearing — its projected folders are event
/// notifiers from materialisation (the SDK refuses an event item on a node without <c>SubscribeToEvents</c>).</summary>
bool IsConditionBearingMapping(string mappingId);
/// <summary>A generation that moves whenever anything the gate reads may have changed (verdict caches key on it).</summary>
long AuthorityGeneration { get; }
@@ -8707,7 +8707,8 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
if (eventsStoodDown > 0 || eventsRestored > 0)
{
_authorizer!.LogFiltered(
// An imported-notifier item is revalidated through the imported gate even where no authorizer is wired (A3 r1 B3).
_authorizer?.LogFiltered(
"RevalidateEventSubscriptions", principal: null, eventsStoodDown, _eventItems.Count);
}
}
@@ -73,6 +73,8 @@ internal sealed class ProjectedConditionRegistry
/// projected node per apply chunk); resolved against the live projected maps at use.</summary>
internal readonly Dictionary<(string Mapping, string Subject), NodeId> FolderIds = new();
internal readonly Dictionary<NodeId, (string Mapping, string Subject)> FolderKeys = new();
/// <summary>Deviation 3: projected folders of condition-bearing mappings, event notifiers from materialisation.</summary>
internal readonly HashSet<NodeId> PromotedFolders = new();
/// <summary>Review r1 S2: a positive verdict is re-proved at least this often (credential expiry is honoured exactly).</summary>
internal static readonly TimeSpan PositiveVerdictTtl = TimeSpan.FromSeconds(5);
private readonly object _verdictGate = new();
@@ -574,7 +576,8 @@ public sealed partial class OtOpcUaNodeManager : IProjectedConditionSink
{
_importedConditions.WiredByFolder.Remove(folder.NodeId);
RemoveRootNotifier(folder);
folder.EventNotifier = (byte)(folder.EventNotifier & ~EventNotifiers.SubscribeToEvents);
if (!_importedConditions.PromotedFolders.Contains(folder.NodeId))
folder.EventNotifier = (byte)(folder.EventNotifier & ~EventNotifiers.SubscribeToEvents);
folder.ClearChangeMasks(SystemContext, includeChildren: false);
}
}
@@ -585,6 +588,12 @@ public sealed partial class OtOpcUaNodeManager : IProjectedConditionSink
if (_importedConditions.FolderKeys.Remove(folder.NodeId, out var previous)) _importedConditions.FolderIds.Remove(previous);
_importedConditions.FolderIds[(mappingId, localSubject)] = folder.NodeId;
_importedConditions.FolderKeys[folder.NodeId] = (mappingId, localSubject);
if (ProjectedConditionAccess is { } access && access.IsConditionBearingMapping(mappingId))
{
// Deviation 3 (review r1): a folder-only client can subscribe (and so open condition demand) before anything is wired.
_importedConditions.PromotedFolders.Add(folder.NodeId);
folder.EventNotifier = (byte)(folder.EventNotifier | EventNotifiers.SubscribeToEvents);
}
if (_importedConditions.Count == 0 || !_importedConditions.ByFolderKey.TryGetValue((mappingId, localSubject), out var set)) return;
foreach (var id in set.ToList())
if (_importedConditions.Find(id) is { } c) WireImportedFolder(c, folder);
@@ -594,6 +603,7 @@ public sealed partial class OtOpcUaNodeManager : IProjectedConditionSink
private void OnProjectedFolderRemoving(NodeId folderId)
{
if (_importedConditions.FolderKeys.Remove(folderId, out var key)) _importedConditions.FolderIds.Remove(key);
_importedConditions.PromotedFolders.Remove(folderId);
if (!_importedConditions.WiredByFolder.TryGetValue(folderId, out var entry)) return;
foreach (var id in entry.Conditions.ToList())
if (_importedConditions.Find(id) is { } c) UnwireImportedFolder(c, entry.Folder);
@@ -606,6 +616,7 @@ public sealed partial class OtOpcUaNodeManager : IProjectedConditionSink
foreach (var folderId in _importedConditions.WiredByFolder.Keys.ToList()) OnProjectedFolderRemoving(folderId);
_importedConditions.FolderIds.Clear();
_importedConditions.FolderKeys.Clear();
_importedConditions.PromotedFolders.Clear();
}
/// <summary>
@@ -158,6 +158,11 @@ public sealed partial class ProjectedConditionAccess : IProjectedConditionAccess
return Gate(identity, _mappings.Current, mappingId, null, folderLocalSubject);
}
/// <inheritdoc />
public bool IsConditionBearingMapping(string mappingId) =>
_mappings.Current.Any(x => string.Equals(x.Mapping.RemoteNamespaceMappingId, mappingId, StringComparison.OrdinalIgnoreCase)
&& x.Authority.IsActive && IsConditionBearing(x.Mapping));
/// <summary>The mapping gate for one (mapping, folder) placement; <paramref name="realm"/> null = the mapping's own.</summary>
private bool Gate(DataCallerIdentity identity, IReadOnlyList<ProjectedMappingPlacement> current, string mappingId, DataRealm? realm,
string folderLocalSubject)