Files
lmxopcua/docs/plans/evidence/grpc-data-ext/X0.md
T

191 lines
12 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# X0 evidence: tolerant readers and contract reservation
Phase X0 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`. It has two parts:
1. the provenance of revision 4's settled offline investigations (plan §5.1, §5.5, §5.6, §9.3);
2. what X0 changed, and the gate runs.
## 1. Revision 4 investigations (provenance)
All three investigations were offline, against the pinned `OPCFoundation.NetStandard.Opc.Ua.Server` 2.0.1
(`Directory.Packages.props`). The second Fable pass reviewed them in
`docs/plans/2026-11-23-grpc-data-connections-history-alarms-relay-plan-review.md` (§"B5 — `ICallAsyncNodeManager.CallAsync`:
confirmed", N5, m-T7). That pass could not re-run the harness, because the harness was not yet in the repo. It is committed
here.
### (a) SDK Call dispatch trace (B5, plan §5.6 step 1)
The trace was decompiled with `ilspycmd` from
`~/.nuget/packages/opcfoundation.netstandard.opc.ua.server/2.0.1/lib/net10.0/Opc.Ua.Server.dll`. The excerpts were kept in
the session scratchpad and are not committed (SDK source). Files and members used:
| Step | Decompiled file | Member |
|---|---|---|
| Service entry, async end to end | `StandardServer.cs` | `StandardServer.CallAsync` awaits `ServerInternal.NodeManager.CallAsync` |
| Master hand-off | `Opc.Ua.Server.MasterNodeManager.cs` | `MasterNodeManager.CallAsync` → `NodeManagerServiceDispatcher.CallAsync`; managers wrapped by `ToAsyncNodeManager()` |
| Validation, then per-manager await | `Opc.Ua.Server.NodeManagerServiceDispatcher.cs` | `CallAsync` runs `ValidateCallRequestItemAsync` (`GetManagerHandleAsync`, `FindMethodStateAsync`, `ValidatePermissionsAsync`). It marks bad items `Processed`, then awaits `IAsyncNodeManager.CallAsync` on each registered manager **sequentially**, with `ConfigureAwait(false)` |
| Adapter decision | `Opc.Ua.Server.AsyncNodeManagerAdapter.cs` | `CallAsync`: `if (SyncNodeManager is ICallAsyncNodeManager m) return m.CallAsync(...)`, else the synchronous `Call` (checked at call time, ≈ line 269) |
| Lock scope during validation | `Opc.Ua.Server.CustomNodeManager2.cs` | `FindMethodState` holds `lock (Lock)` only around `ValidateNode` + `FindMethod` |
| Where the lock is taken today | `Opc.Ua.Server.CustomNodeManager2.cs` | `Call` → `CallSynchronousBatch` → `GetMethodCalls`, which skips `Processed` items and locks per owned item. NM adds its own `lock (Lock)` in `ReportAfterMethod` |
| Interface | `Opc.Ua.Server.ICallAsyncNodeManager.cs` | `ValueTask CallAsync(OperationContext, ArrayOf<CallMethodRequest>, IList<CallMethodResult>, IList<ServiceResult>, CancellationToken)` |
Conclusion: `OtOpcUaNodeManager` can implement `ICallAsyncNodeManager`. It claims imported-condition calls (sets `Processed`),
runs `base.Call` for the rest, and then awaits the claimed calls with no NM `Lock` held. Lock-freedom stays a hard A3 gate (L3).
The review added two non-blocking notes, both now in §5.6:
- `base.Call` runs under `BeginNodeManagerOperation()`. Finish it before awaiting.
- Managers are awaited sequentially. A mixed batch delays later-registered managers.
### (b) Condition node and byte count (N5, plan §5.5)
The harness is `harness/Program.cs` and `harness/count.csproj`, copied verbatim. It builds each condition type with the
optional children NM adds before `Create()`: `ConfirmedState`, `Confirm`, `ShelvingState` and `MaxTimeShelved`
(`NM:2461-2475`). It then counts the tree through `GetChildren`.
| Type | Nodes | Objects / variables / methods |
|---|---|---|
| `AlarmConditionType` | 48 | 2 / 38 / 8 |
| `OffNormalAlarmType` | 49 | 2 / 39 / 8 |
| `DiscreteAlarmType` | 48 | 2 / 38 / 8 |
`Quality`, `BranchId` and `Comment` are present.
Retained size is ≈ 157 KiB per condition (160,997 B). It was measured on 2,000 `OffNormal` instances as a
`GC.GetTotalMemory(true)` delta.
- It excludes NM's indexes, the `c1.` identifier strings, the EventId registry and placement sets (m-T7).
- L2 (A3 exit) is the authority for `MaxImportedConditionBytes`.
### (c) Snapshot-copy timing (plan §5.1)
The same harness copies the snapshot fields of each of the 2,000 `OffNormalAlarmState` instances into a record. It takes
3.3–5.8 ms per 2,000 over three warm runs, which is ≈ 1.7–2.9 µs per condition.
- At `MaxConditions` 1,000, one `Lock` hold is ≈ 2–3 ms.
- This was measured outside the server. L1 (A1) measures the real hold under load.
To re-run: `dotnet run -c Release --project docs/plans/evidence/grpc-data-ext/harness/count.csproj`. It is not part of the
solution.
## 2. What X0 changed
- **Operation bits.** `DataOperations` reserves `HistoryRead`, `AlarmSubscribe`, `AlarmAcknowledge`, `AlarmConfirm` and
`AlarmShelve` (32 to 512). `DataOperationSets` is the one authority: `V1`, `Understood` (= `V1` in X0) and `Reserved`.
- **Tolerant readers.** Any bit outside `Understood` is dropped, fail closed (an unknown grant is no grant), at every
node-side reader:
- `DataConnectionValidator.ValidateDeployed` re-validates a deployed artifact. It is called by `DeploymentArtifact`
data-row parsing and `LocalExportCatalog.Compile`.
- It ignores every bit outside `Understood`, not only the reservation. A newer central may define bits this build has
never heard of.
- It still validates the understood subset: a row must be non-empty, and a mapping may not grant an understood
operation its connection lacks.
- These two sites were missed by the plan. Before X0 they rejected the whole snapshot (consumer side) or the whole
origin catalog (origin side).
- `DataConnectionDeploymentRuntime.Apply` drops the bits per connection row.
- `LocalExportCatalog` masks export rules.
- `ProjectedMappingDeploymentRuntime.Stage` masks its frozen mapping copies.
- `DataCapabilities.Operations` masks in its accessor, both at construction and on `with`.
- `DataProtoMapper` masks metadata and capabilities on decode.
- **Dropped-bit diagnostics.**
- Every drop is logged as a Warning naming the row id and the bits.
- It is counted on `otopcua.dataconnection.unknown_operations_dropped`, tagged `kind` = connection | export | mapping.
The helper is `UnknownOperationDrops`.
- A drop is counted once per row per accepted artifact change. Re-applying the same revision does not recount, A → B → A
does, and a restart resets.
- Drops are collected under each component's lock and logged after the lock is released.
- Production reader: `NodeDiagnosticsSnapshot` (AdminUI fleet diagnostics).
- Each `DataConnectionDiagnosticsSnapshot` carries `DroppedUnknownOperations` and `MappingsWithDroppedOperations`.
- The node carries `DroppedExportOperations`.
- **Grow sites unchanged.** Authoring `Validate` still rejects everything outside `V1`. `ProjectedDataAccess` and
`LocalDataServices.Implemented` are unchanged.
- **Feature header.** `x-otopcua-data-features` is parsed on every RPC after authentication.
- The server records requested and effective features. Effective = requested ∩ `SupportedFeatures` = none in X0.
- A binary value, or a value longer than 256 characters in total, gets `InvalidArgument`.
- The consumer derives the header per selected endpoint. It is always empty in X0, so it is never sent.
- **Proto reservations.** These are comments plus `DataConnectionProtoContract` constants:
- Capabilities 16 `HistoryCapabilities history` and 17 `ConditionCapabilities conditions`;
- Metadata 14 `HistoryInfo history`;
- SubscriptionItem 4 `ConditionScope condition_scope`;
- SubscriptionFrame oneof `frame` arm 9 `ConditionStates condition_states`.
The descriptor tests pin name, singular message type and oneof, so `string history = 16` fails.
`DataConnectionProtoContract.Validate()` (frozen numbers plus reservations) now runs at host start in
`AddOtOpcUaDataConnections`, when data connections are enabled. No field was added, so the server advertises nothing new.
### Recorded-v1-client gate: what is real and what is faked
`GrpcDataV1CompatibilityTests` (Host.Tests) works as follows.
- **Inputs.** It parses each recorded v1 request from `GrpcDataV1Goldens.Requests`, the golden hex itself (not
re-encoded), and calls the six RPCs in-process.
- **Real.**
- `DataConnectionGrpcService`: header parsing, authentication seam, readiness and permission gates, budget clamping,
response serving stamp, size checks and the subscription delivery sink;
- `DataProtoMapper` (all encoders and decoders);
- `DataConnectionAuthenticator` with a real API key.
- **Faked.**
- The origin facade behind `IDataConnectionFactory`: a deterministic fake `Origin`, not `LocalDataServices`,
`LocalExportCatalog` or `DataCapabilitiesProvider`;
- the gRPC/HTTP2 transport: a hand-built `ServerCallContext`. Response marshalling is the generated `ToByteArray()`.
- **Assertions.**
- Response bytes equal goldens captured on pre-X0 master `2e4e4063` (commit `3279a7f9d`, before any X0 change). Nothing
varies, so nothing is normalised.
- This holds with no header, and with `history,conditions` (the server supports nothing yet).
- The v1 rejection statuses keep their code, detail and empty trailers, with and without the header: Unimplemented
major, PermissionDenied for each missing grant.
- A binary or oversized header gets `InvalidArgument` with the family's existing detail and no trailers.
- **Not covered: a real-origin variant** (`LocalDataServices` + `LocalExportCatalog` + `DataCapabilitiesProvider`). It needs
the Runtime.Tests origin fixture rebuilt in Host.Tests through public APIs, plus its own golden set captured against
pre-X0 code. That was judged too heavy for X0 and is left as a follow-up.
- **Rule for H2, A2 and A3.**
1. First extend the fake `Origin` (and the real-origin variant, once it exists) so it emits that phase's new-shape data:
history info, conditions, and the new operation bits in metadata and capabilities.
2. Then, **without the header**, the test must still see the same golden bytes.
3. **Never re-record the goldens**. A difference is a v1 wire regression.
## 3. Gate runs
Run on macOS, 2026-11-23, on HEAD `981c60784`: every code and test change, after the review fixes. The only later commit
is this results table.
| Gate | Result |
|---|---|
| `dotnet build ZB.MOM.WW.OtOpcUa.slnx` | succeeded, 0 warnings, 0 errors |
| `run-unit-phase.py X0` | passed, 95 tests |
| P01 / P02 / P03 / P04 / P05 | passed: 53 / 213 / 239 / 542 / 939 |
| P06 / P07 / P08 / P09 | passed: 353 / 455 / 619 / 248 |
| `pytest test_unit_phase_runner.py` | 30 passed |
The full unit suites of the touched projects, filtered `Category!=E2E&Category!=LiveIntegration`, all passed:
| Project | Passed |
|---|---|
| Core.Abstractions | 849 |
| Commons | 485 |
| Configuration | 314 |
| Runtime | 1,835 (3 pre-existing skips) |
| Host | 424 |
| ControlPlane | 476 |
| AdminUI | 2,689 |
Final round (second Fable pass, approve; three small fixes `9b29a5f65`, `5453c20d9`, `87c9f9c0b`), re-run on HEAD
`87c9f9c0b`: X0 passed 99 tests; P02 213, P07 456, P08 620 passed; Runtime 1,837 (3 pre-existing skips) and
Configuration 314 passed. Follow-ups: #918 (real-origin variant of the v1 gate, required before the H2 exit), #919
(render the dropped-operation diagnostics in AdminUI).
History of failed runs:
- The first P02/P07 run (before `75cf5eb8f`) failed.
- P02 pinned `1 << 30` as malformed. The review later reversed that; it is now tolerated.
- P07 reflects over the runtime constructor.
Commands:
```bash
dotnet build ZB.MOM.WW.OtOpcUa.slnx
python3 scripts/validation/grpc-data/run-unit-phase.py X0 # and P01 … P09
python3 -m pytest scripts/validation/grpc-data/test_unit_phase_runner.py
dotnet test <touched project> --filter "Category!=E2E&Category!=LiveIntegration"
```