From af06183412d785e824556bb8205f5e3cbe130689 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 01:04:04 -0500 Subject: [PATCH] fix(grpc-data): projected Processed values keep their aggregate's type Found by the H3 live gate (H02): a Double Average of a UInt16 node was decoded against the node's catalog kind and came back null + BadTypeMismatch per interval (the result status stayed Good, which is why the wire test missed it). Raw/AtTime values are still checked against the catalog kind; Processed values accept any scalar kind. The wire test now asserts the interval's value. Gate: re-browse the projected leaves after every deploy (a deploy retires cold projected nodes; the same opaque ids come back). --- scripts/validation/grpc-data/history_gate.py | 37 +++++++++++++++---- .../DataConnections/ProjectedHistoryAccess.cs | 18 +++++++-- .../GrpcDataProjectedHistoryWireTests.cs | 5 +++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/scripts/validation/grpc-data/history_gate.py b/scripts/validation/grpc-data/history_gate.py index c4514f852..bc9857530 100644 --- a/scripts/validation/grpc-data/history_gate.py +++ b/scripts/validation/grpc-data/history_gate.py @@ -98,6 +98,29 @@ class HistoryGate: self.runner.save("H-projected-nodes.json", {f"{k[0]}/{k[1]}": v for k, v in found.items()}) return consumer + def rebrowse(self, timeout=90): + """A deploy retires cold projected nodes; browse from the anchor again (the SAME opaque ids come back).""" + end = time.monotonic() + timeout + while True: + try: + previous = dict(self.projected) + self.resolve_projected() + self.runner.check(not previous or previous == self.projected, "projected NodeIds are stable across a deploy") + return + except scenarios.ScenarioError: + if time.monotonic() >= end: + raise + time.sleep(3) + + def change(self, **mutation): + """A production mutation + deploy, then re-materialise the projected leaves by browse.""" + self.runner.mutate(**mutation) + self.rebrowse() + + def restore(self): + self.runner.baseline() + self.rebrowse() + def held(self, consumer, extra, name, during, *, marker_timeout=60): """Runs a hand-paged CLI read in the background; `during()` runs once the read reports its held point.""" marker = self.runner.folder / (name + "-" + uuid.uuid4().hex[:6] + ".held") @@ -270,7 +293,7 @@ class HistoryGate: consumer = self.runner.primary("consumer") before, _, _ = self.poll_status(consumer, self.projected[("raw", "counter")], "Good", "before", timeout=30) self.runner.check(before == "Good", "history served before the change") - self.runner.mutate(export_id="export-raw", export_allowed_operations=EXPORT_WITHOUT_HISTORY) + self.change(export_id="export-raw", export_allowed_operations=EXPORT_WITHOUT_HISTORY) observed, attempts, result = self.poll_status(consumer, self.projected[("raw", "counter")], "BadHistoryOperationUnsupported", "not-advertised", timeout=180) self.runner.check(observed == "BadHistoryOperationUnsupported", "an origin that does not advertise history ⇒ unsupported") @@ -287,22 +310,22 @@ class HistoryGate: unhistorized, _, unh = self.poll_status(consumer, self.projected[("raw", "scalar")], "BadHistoryOperationUnsupported", "unhistorized", timeout=30) self.runner.check(unhistorized == "BadHistoryOperationUnsupported", "unhistorized ⇒ BadHistoryOperationUnsupported") - self.runner.mutate(acl_permissions={"node_acl_id": "source-peer", "permission_flags": NODE_PERMISSIONS_ADMIN & ~NODE_PERMISSIONS_HISTORY_READ}) + self.change(acl_permissions={"node_acl_id": "source-peer", "permission_flags": NODE_PERMISSIONS_ADMIN & ~NODE_PERMISSIONS_HISTORY_READ}) denied, attempts, den = self.poll_status(consumer, self.projected[("raw", "counter")], "BadHistoryOperationUnsupported", "origin-denied", timeout=180) normalise = lambda text: re.sub(r"ns=\d+;s=\S+", "", "\n".join(l for l in (text.stdout + text.stderr).splitlines() if "Bad" in l)) self.runner.check(denied == "BadHistoryOperationUnsupported", "origin ACL denial ⇒ BadHistoryOperationUnsupported") self.runner.check(normalise(unh) == normalise(den), "denied and unhistorized are indistinguishable") report["indistinguishable"] = {"unhistorized": normalise(unh), "denied": normalise(den), "attempts": attempts} - self.runner.baseline() + self.restore() # (b) the LOCAL mapping-scope grant: without it, BadUserAccessDenied (a local decision); the other mapping keeps its grant. - self.runner.mutate(acl_permissions={"node_acl_id": "cli-history-map-raw", "permission_flags": NODE_PERMISSIONS_BROWSE}) + self.change(acl_permissions={"node_acl_id": "cli-history-map-raw", "permission_flags": NODE_PERMISSIONS_BROWSE}) local, attempts, _ = self.poll_status(consumer, self.projected[("raw", "counter")], "BadUserAccessDenied", "local-denied", timeout=90) self.runner.check(local == "BadUserAccessDenied", "no local HistoryRead grant on the mapping scope ⇒ BadUserAccessDenied") other, _, _ = self.poll_status(consumer, self.projected[("uns", "counter")], "Good", "local-other-mapping", timeout=30) self.runner.check(other == "Good", "the UNS mapping's own grant still serves") report["local_deny"] = {"raw": local, "uns": other, "attempts": attempts} - self.runner.baseline() + self.restore() consumer = self.runner.primary("consumer") # (c) a consumer session close releases the origin continuation. self.runner.check(self.origin_state() == 0, "no origin continuation open before") @@ -323,7 +346,7 @@ class HistoryGate: report["session_close"] = {"held": counts.get("held"), "after": after, "lines": self.status_lines(abandoned.stdout)} # (d) origin rebuild mid-page: a resumed page after the origin's history epoch moved is BadContinuationPointInvalid. def rebuild(): - self.runner.mutate(rename_tag={"tag_id": "source-array1", "name": "array1-renamed"}) + self.change(rename_tag={"tag_id": "source-array1", "name": "array1-renamed"}) rebuilt = self.held(consumer, ["-n", self.projected[("raw", "counter")], *self.window_args(), "--page-size", "3", "--pause-after-page", "1", "--fresh-after-failure"], "rebuild", rebuild) lines = self.status_lines(rebuilt.stdout) @@ -354,7 +377,7 @@ class HistoryGate: finally: try: self.runner.deadline = time.monotonic() + 600 - self.runner.baseline() + self.restore() restored = True except Exception as failure: error = (error + "; " if error else "") + "restoration " + type(failure).__name__ + ": " + str(failure) diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs index fd4665757..6ac215124 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs @@ -271,7 +271,7 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl target, callerKey, key.Details, nodes[i].Resume is RemoteCursor prior ? prior.AggregateId : nodes[i].AggregateId); } - outcomes[i] = new ProjectedHistoryOutcome(answer.StatusCode, Convert(answer.Samples, target.OriginMetadata), next); + outcomes[i] = new ProjectedHistoryOutcome(answer.StatusCode, Convert(answer.Samples, target.OriginMetadata, key.Details is DataHistoryProcessedDetails), next); } } finally @@ -326,8 +326,12 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl private static string CallerKey(RoleCarryingUserIdentity caller) => string.Join('\0', caller.Principal ?? "", caller.ApiKeyId ?? "", caller.CredentialVersion ?? ""); - /// Values verbatim (status, absent timestamps); a value kind that disagrees with the catalog is BadTypeMismatch. - private static OriginHistorySample[] Convert(IReadOnlyList samples, DataMetadata metadata) + /// + /// Values verbatim (status, absent timestamps). Raw and AtTime values are the node's own values: a kind that disagrees + /// with the catalog is BadTypeMismatch (plan §3.3), never coerced. A Processed value has its AGGREGATE's type (a + /// Double Average or an Int32 Count of a UInt16 node), so only its shape is checked: any scalar kind is accepted. + /// + private static OriginHistorySample[] Convert(IReadOnlyList samples, DataMetadata metadata, bool processed) { var converted = new OriginHistorySample[samples.Count]; for (var i = 0; i < samples.Count; i++) @@ -335,7 +339,13 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl var sample = samples[i]; object? value; var status = sample.StatusCode; - try { value = ProjectedDataAccess.DecodeValue(sample.Value, metadata); } + try + { + var expected = processed && sample.Value.Kind is not (DataValueKind.Null or DataValueKind.Array) + ? metadata with { ValueKind = sample.Value.Kind, ValueRank = -1, Dimensions = [], ArrayElementKind = null } + : metadata; + value = ProjectedDataAccess.DecodeValue(sample.Value, expected); + } catch (Exception ex) when (ex is ArgumentException or InvalidCastException or InvalidOperationException) { value = null; diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs index b97c47ce6..a6771aa60 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs @@ -171,6 +171,11 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests // A served aggregate passes through. var average = await ProcessedHistory(client, anchor, ObjectIds.AggregateFunction_Average); StatusCode.IsGood(average.StatusCode).ShouldBeTrue(average.StatusCode.ToString()); + // Found by the H3 live gate (H02): an aggregate's value has ITS OWN type (a Double Average of an Int32 node), + // never the node's — it must not be refused BadTypeMismatch against the catalog's value kind. + var interval = Values(average).ShouldHaveSingleItem(); + StatusCode.IsGood(interval.StatusCode).ShouldBeTrue(interval.StatusCode.ToString()); + SdkValueBoundary.ToClr(interval.WrappedValue).ShouldBeOfType().ShouldBe(3.0); }, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin)); }