142 lines
8.2 KiB
Markdown
142 lines
8.2 KiB
Markdown
# 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.** Each drops unknown bits, fail closed:
|
||
- `DataConnectionDeploymentRuntime.Apply` drops them per row and counts them (diagnostics property, Warning log, counter
|
||
`otopcua.dataconnection.unknown_operations_dropped`);
|
||
- `DataCapabilities.Operations` masks in its accessor, both at construction and on `with`;
|
||
- `DataProtoMapper` masks metadata and capabilities on decode;
|
||
- `LocalExportCatalog` masks export rules.
|
||
- **Two node-side sites the plan missed.**
|
||
- `DeploymentArtifact` data-row parsing and `LocalExportCatalog.Compile` re-ran the authoring validator, which rejects
|
||
unknown bits.
|
||
- Either would still have rejected a whole snapshot (consumer side) or the whole origin catalog (origin side) when a newer
|
||
central authored a reserved bit.
|
||
- Both now call `DataConnectionValidator.ValidateDeployed`. This is the same validator, but the reserved bits (32 to 512)
|
||
are ignored rather than rejected. Any other unknown bit is still a malformed row. Nothing can author it, and
|
||
`GrpcDataArtifactReadTests` (P02) pins `1 << 30` failing closed.
|
||
- The runtime, decoders and catalog rules still drop any unknown bit.
|
||
- **Grow sites unchanged.** Authoring `Validate`, `ProjectedDataAccess` and `LocalDataServices.Implemented` are unchanged, and
|
||
authoring still rejects bit 32.
|
||
- **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 and descriptor golden tests:
|
||
- Capabilities 16 (`history`) and 17 (`conditions`);
|
||
- Metadata 14 (`history`);
|
||
- SubscriptionItem 4 (`condition_scope`);
|
||
- SubscriptionFrame arm 9 (`condition_states`).
|
||
|
||
No field was added, so the server advertises nothing new.
|
||
- **Recorded-v1-client gate.** `GrpcDataV1CompatibilityTests` (Host.Tests) replays recorded v1 requests for all six RPCs
|
||
against the real `DataConnectionGrpcService` and a deterministic origin. It compares `ToByteArray()` hex with goldens
|
||
captured on pre-X0 master `2e4e4063` (commit `3279a7f9d`, before any X0 change).
|
||
- No field is time-varying, so nothing is normalised.
|
||
- It runs with no header and with `history,conditions`.
|
||
- H2, A2 and A3 rerun it unchanged.
|
||
|
||
## 3. Gate runs
|
||
|
||
Run on macOS, on worktree HEAD `d89bc8619`, 2026-11-23:
|
||
|
||
| Gate | Result |
|
||
|---|---|
|
||
| `dotnet build ZB.MOM.WW.OtOpcUa.slnx` | succeeded, 0 warnings, 0 errors |
|
||
| `run-unit-phase.py X0` | passed, 80 tests |
|
||
| P01 / P02 / P03 / P04 / P05 | passed: 53 / 212 / 239 / 541 / 938 |
|
||
| P06 / P07 / P08 / P09 | passed: 353 / 454 / 618 / 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 | 484 |
|
||
| Configuration | 314 |
|
||
| Runtime | 1,833 (3 pre-existing skips) |
|
||
| Host | 414 |
|
||
| ControlPlane | 476 |
|
||
|
||
The first P02/P07 run, before `75cf5eb8f`, failed. That fix is described in its commit message.
|
||
|
||
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
|
||
```
|