diff --git a/docs/plans/evidence/grpc-data-ext/H3.md b/docs/plans/evidence/grpc-data-ext/H3.md new file mode 100644 index 000000000..64b03f0ae --- /dev/null +++ b/docs/plans/evidence/grpc-data-ext/H3.md @@ -0,0 +1,122 @@ +# H3 evidence — consumer OPC UA projection of remote history + +Phase H3 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`, 2026-11-24. + +## What changed + +- **Projected access level.** `ProjectedVariableDefinition.Historizing` (set by the applier and the exact-item renewal from + `ProjectedHistoryAccess.Advertises(proof)` = mapping∧export grant `HistoryRead` **and** the origin's negotiated + `HistoryInfo.Historizing`). Only then is the node `Historizing` with `CurrentRead | HistoryRead`; it follows renewals in place + (`ApplyProjectedHistorizing`, under `Lock`, a change-mask notify). `HistoryWrite` is never set. +- **`OpcUaServer/IProjectedHistoryAccess.cs`**: SDK-free contract — `ReadAsync(caller, DataHistoryDetails, nodes, deadline, ct)`, + `ProjectedHistoryNode(NodeId, AggregateId, Resume)`, `ProjectedHistoryOutcome(status, OriginHistorySample[], next)` and the + opaque `ProjectedHistoryContinuation` (idempotent `Release`, `TryClaimForResume`). +- **Override split** (`OpcUaServer/ProjectedHistoryRead.cs`, a NM partial). Raw/Processed/AtTime overrides authorize as before, + then `ServeHistoryReadSplit`: with no projected handle the H1 adapter is called exactly as before; otherwise local handles go to + the H1 port and projected handles (mapped/raw, mapped/uns namespaces) to `ProjectedHistoryAccess`, every outcome written to its + handle's own `results[i]`/`errors[i]`. The remote half runs under the same process-wide batch limiter, block-bridged once per + batch; the SDK has released `Lock` before it dispatches the overrides and nothing here takes it. Modified reads ⇒ + `BadHistoryOperationUnsupported`; an aggregate the consumer cannot name ⇒ `BadAggregateNotSupported`, unsent. +- **`HistoryCursorKind.Remote`** + `HistoryContinuationState.Remote`: the cursor lives in the SDK session store, bound to the + node (realm, identifier, namespace tag) and the consumer's history epoch. A take marks the SDK point `Taken`; **any other + dispose** of the point (session close, oldest-eviction, `releaseContinuationPoints` → `ReleaseHistory`, a faulted request) + calls `Remote.Release()` (decompiled SDK 2.0.1 `SessionContinuationPoints`: `Clear`, `AddHistoryContinuationPoint` eviction, + `ReleaseHistory`, `ReleaseSavedHistory` all dispose the stored value). A cursor of another node/kind/epoch is refused + `BadContinuationPointInvalid` and released. +- **`Runtime/DataConnections/ProjectedHistoryAccess.cs`**: per node a `DataOperations.HistoryRead` demand through + `ProjectedDataAccess.TryAcquire` (allowlist extended; requires `definition.Historizing`; policy `AuthorizeMapped(HistoryRead)` ⇒ + mapping bit + local `NodePermissions.HistoryRead` on the mapping scope, ACLs on or off), described by + `TryDescribeHistoryDemand` (mapping id/revision, connection, origin metadata, serving, generation). Groups = + (connection, details, resumed endpoint|fresh) so a resumed item never shares a call with items that may move. The + `RemoteCursor` binds caller key (principal, key, credential version), mapping id+revision, connection id + lease `RouteIdentity`, + projection generation, origin view, serving (node, incarnation, serving generation, role), the ORIGINAL details and aggregate; + `CursorMatches` re-checks all of it on resume, and the route identity before the call; any change ⇒ `BadContinuationPointInvalid` + and the origin token released. Per-request assembly budget = min `MaxHistoryAssemblyBytesPerRequest` of the batch's mappings, + charged in request order across groups; a node that does not fit and every later node ⇒ `BadTooManyOperations` (its origin + cursor released). Deadline = min(remaining `HistoryReadDeadline`, `HistoryTimeoutMilliseconds` — the connection applies the + latter) ⇒ `BadTimeout`; a cancel is never an origin fault. Releases coalesce per connection (25 ms) into one + `ReleaseHistoryAsync`. Values: Raw/AtTime checked against the catalog kind (`BadTypeMismatch`); Processed values keep their + aggregate's own scalar kind. +- **`DataPlaneAuthorizer`**: mapped HistoryRead opened deliberately via an explicit allowlist (Browse/Read/Write*/TransferSubscriptions/ + HistoryRead); every other mapped operation stays closed. **DI/host**: `ProjectedHistoryAccess` registered beside + `ProjectedDataAccess`; `OtOpcUaServerHostedService` wires `NodeManager.ProjectedHistoryAccess`. +- **H2 pin replaced**: `HistoryRead_on_a_projected_node_stays_a_clean_refusal_until_H3` (Runtime) became + `Granted_projected_HistoryRead_is_served_verbatim…` (granted ⇒ served) and `Without_the_local_HistoryRead_grant…` (⇒ + `BadUserAccessDenied`, unsent), both tagged H2 + H3. +- **Client.** `IOpcUaClientService.HistoryReadPageAsync` (one page verbatim) and CLI `historyread --page-size / --pause-after-page / + --resume-when-file / --held-marker-file / --fresh-after-failure / --abandon-after-page / --release-after-page / --hold-seconds / + --at-time`. **Defect found by the gate (H02, pre-existing):** Client.Shared processed reads sent the SDK's default + `AggregateConfiguration` (all false/0), which this server refuses `BadAggregateConfigurationRejected` (#677) — CLI/UI + `--aggregate` never worked against OtOpcUa; now `UseServerCapabilitiesDefaults = true` (OI regression test, red without). +- **Defect found by the gate (H02, H3):** projected Processed values were decoded against the node's catalog kind (a Double + Average of a UInt16 node ⇒ null + `BadTypeMismatch` per interval under a Good result). Fixed; the wire test now asserts the value. + +## Tests + +| Suite | What | +|---|---| +| O `ProjectedHistoryReadTests` (7) | access bit only when historizing, never HistoryWrite; allow/deny with ACLs **off and on** (no local grant, no mapping bit, no identity ⇒ `BadUserAccessDenied`, unsent); mixed local+projected batch keeps slots (one remote call); Remote cursor resumes once (same object), single use, wrong node ⇒ invalid + released, `releaseContinuationPoints` and session close (store `Clear`) release; bad remote answer keeps no cursor; consumer-unknown aggregate and modified read unsent; absent bounds | +| R `GrpcDataConfiguredDiscoveryWireTests` H3 (12) | real consumer SDK session + real projection stack + real origin (`LocalDataServices` over a real NM history port and `PeerHistoryContinuationStore`): page-through verbatim to completion (origin store 0); no local grant ⇒ `BadUserAccessDenied` unsent; session close ⇒ origin continuations 0 and exactly one release call; `releaseContinuationPoints`; resume after lease expiry (route rotated) and after an origin epoch bump ⇒ invalid, fresh read Good; uncapped Raw returns the origin CP; `BadAggregateNotSupported` both ways + a served Average's value; Historizing/AccessLevel follow the grant; assembly budget shared across the batch (25 kB ⇒ 2 of 3, 15 kB ⇒ 1, 1.2 kB ⇒ 0, refused in request order, never partial) | +| R `GrpcDataProjectedHistoryCursorTests` (12) | resume rule: mapping revision change, another mapping/connection, projection rebuild, failover (node), origin restart (incarnation), serving generation, role, origin view, another caller, rotated credential ⇒ refused; epoch-only change resumes | +| OI `GrpcDataProjectedHistoryWireTests` (6) | real consumer session → real origin NM history port: mixed batch slots + page-through (ACL off/on), single use, session close ⇒ origin cursor store 0 (one release), no grant ⇒ denied unsent (ACL off/on); Client.Shared aggregate + page API | +| CLI `HistoryReadPagedCommandTests` (6) | paging, pause/resume + fresh, abandon/release + held marker, AtTime, option validation | + +## Gates + +| Gate | Result | +|---|---| +| `dotnet build ZB.MOM.WW.OtOpcUa.slnx` | 0 warnings, 0 errors | +| `run-unit-phase.py H3` (new key: OpcUaServer.Tests + Runtime.Tests) | passed (at `af0618341`) | +| `run-unit-phase.py H2` | passed (at `af0618341`) | +| `run-unit-phase.py H1, X0, P01–P09` | all passed (at `07eeea2bd`; later commits touch Client/CLI/rig and one Runtime decode path covered by H3/H2 reruns) | +| Full unit suites (`Category!=E2E&Category!=LiveIntegration`) | OpcUaServer 1415 (+1 skip), Runtime 1882 (+3 skips), Host 479, Client.CLI 224, Client.Shared 361, Client.UI 131 — all green | +| OpcUaServer.IntegrationTests `Feature=GrpcData` + history classes | 87 passed, 2 skips (AVEVA live) | +| Rig harness unit tests (`scripts/validation/grpc-data/tests`) | 296 passed | + +The runner accepts unit projects only, so OI is run separately (as H1 did). + +## Live gate — H01–H06 on both origin backends + +Standalone rig (`scripts/validation/grpc-data`, OrbStack, macOS), fresh run per backend at `af0618341`, normal build-hash checks +(no `--pinned-build`), recipe in the rig README §"H3 projected-history gate": + +```bash +python3 scripts/validation/grpc-data/rig.py up --run-id h3f- --history --history-backend --timeout 900 +python3 scripts/validation/grpc-data/rig.py seed --run-id h3f- +sleep 75 +python3 scripts/validation/grpc-data/rig.py deploy --run-id h3f- --timeout 300 +python3 scripts/validation/grpc-data/history_gate.py --run-id h3f- +python3 scripts/validation/grpc-data/rig.py down --run-id h3f- +``` + +Every read goes through the Client CLI `historyread` on CONSUMER's OPC UA endpoint, on projected NodeIds resolved by a CLI +`browse` from the shared root (leaves under the `remote-source` anchors; the same opaque `p1.` ids come back after every +deploy — re-browsed, never constructed), and is compared with the same read on the SOURCE primary. Every scenario restored the +baseline. + +| ID | SqlServer (`h3f-sqlserver`, 06:05–06:15 UTC) | QuestDB (`h3f-questdb`, 06:14–06:21 UTC) | +|---|---|---| +| H01 Raw paging, Raw + UNS | PASS (38): page size 3 ⇒ 11 pages, 31 rows per realm, last page no CP, row-for-row = origin; single read = origin | PASS (38): 10 pages, 29 rows per realm, = origin (µs timestamps) | +| H02 Processed, aggregate refused for the node type | PASS (28): Average on String `text` ⇒ `BadAggregateNotSupported` (origin answers the same); Average on `counter` 4 intervals = origin | PASS (28): same; 3 intervals = origin | +| H03 AtTime, integer node | PASS (26): 3 times, values 7/11/15 = origin, `UInt16` on both | PASS (26): 8/12/16 = origin, `UInt16` | +| H04 continuation across origin failover | PASS (38): page 1 held; `source-1` stopped ⇒ `source-2` primary; resumed page `BadContinuationPointInvalid`; fresh read Good on the new primary | PASS (38): identical | +| H05 v1 origin ⇒ unsupported (**substituted**) | PASS (46): Good ⇒ `BadHistoryOperationUnsupported` once the export drops HistoryRead; the UNS export still Good | PASS (46): identical | +| H06 denied vs unhistorized; session close; rebuild mid-page | PASS (154): unhistorized `scalar` and origin-ACL-denied `counter` ⇒ identical `HistoryRead of failed: BadHistoryOperationUnsupported (0x80720000).`; no local mapping grant ⇒ `BadUserAccessDenied` (UNS mapping still Good); origin open continuations 1 while the CLI held page 1, 0 after its session closed; resume after an origin rename (epoch bump) `BadContinuationPointInvalid`, fresh Good | PASS (154): identical | + +Teardown: `rig.py down` after each run; label-filtered `docker container ls -a / volume / network / image ls` ⇒ 0/0/0/0 for both +runs (the QuestDB container and volume carry the run labels). Results files: `evidence/H3-history--results.json` in each +(removed) run folder; copies taken before `down`. + +Earlier passes on `h3-sql` (pre-fix builds, same rig, `down` 0/0/0/0) found the two H02 defects above and that a deploy retires +cold projected nodes (`BadNodeIdUnknown` until re-browsed — the gate now re-browses after every deploy; a client reading a +projected node it has not browsed since a deploy sees the same; pre-existing v1 projection behaviour). + +## Not verified / substitutions + +- **H05**: the rig builds no pinned v1 image, so "v1 origin" is substituted by an origin that does not advertise history for the + principal (export without bit 32). The v1 wire shape itself is covered by the H2 recorded-v1-client gates. +- **H01 tie clusters**: not representable live on either backend — SqlServer `hist.Sample` PK `(TagId, SourceTimeUtc)`, QuestDB + `DEDUP UPSERT KEYS(ts, tag)` keep one sample per timestamp. Tie paging is proven by the H1 port fuzz (10k seeds). +- **ReadyReplica consistency** on projected history and the Gateway backend (H4) were not run. +- **ACL-off on the live rig**: the rig runs `Security:Acl:Enabled=true`; ACL-off is covered by O and OI tests. +- Diagnostics/metrics for projected history are H4.