docs(grpc-data): A3b evidence — implementation, A3a live defects, tests + red-on-revert, L2/L3 numbers, live a3b-cond-3 PASS, deviations, gates

This commit is contained in:
Joseph Doherty
2026-11-24 18:14:57 -05:00
parent 82ecc1164c
commit 3c941458f5
+212 -1
View File
@@ -1,4 +1,4 @@
# A3 evidence — PART 1 (A3a): consumer condition registry, visibility and event delivery
# A3 evidence — consumer condition registry, visibility, event delivery (A3a) and remote methods (A3b)
Phase A3 (first half) of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`, 2026-11-24, branch
`a3-consumer` (from master `83c7e586`). A3b (§5.6 remote methods: `ICallAsyncNodeManager`, claim / `base.Call` / await,
@@ -161,3 +161,214 @@ own the live leg); the unit + OI wire tests above use a real SDK server and real
- RefreshRequired to an item whose UNMARKED list the rewriter dropped (deviation 4); explicit Primary endpoint for
condition items (deviation 9); the mapping-change runner hand-over (an old runner's in-flight batch can still reach the
sink until its cancellation is observed — bounded by one frame).
---
# A3 — PART 2 (A3b): methods on imported conditions, no `Lock` waits; A3 exit (L2, L3, live)
2026-11-24, branch `a3-consumer`, on top of A3a (`b5ab6e7c`). Not merged, not pushed.
## Progress log
1. `c1be5725` NM: `ICallAsyncNodeManager` (`OpcUaServer/ImportedConditionMethods.cs`), EventId registry gate, N6 re-binding.
2. `28098a8d` Runtime/Host: `ProjectedConditionAccess : IProjectedConditionMethods` (`ProjectedConditionAccess.Methods.cs`), the
runner's stream serving identity, `DataConnectionDeploymentLease : IDataConditionMethodService`, host wiring.
3. `de51886d` OI wire tests; `2d0147f9` Runtime tests + `A3` manifest; `fecb178e` L2 harness + byte cap.
4. `4e6535ee` live smoke (`conditions_a3_smoke.py`, seeder conditions profile makes the CONSUMER condition-bearing).
5. Live `a3b-cond-1` / `-2` FAILED and found two A3a integration defects, fixed in `404a664c` (logger) and `82ecc116` (root view);
live `a3b-cond-3` PASS.
## What is implemented (A3b, plan §5.6)
- **Interception (step 1).** Verified against the pinned SDK 2.0.1 (ilspy): `CustomNodeManager2` has a public virtual
`CallAsync(OperationContext, ArrayOf<CallMethodRequest>, IList<CallMethodResult>, IList<ServiceResult>, CancellationToken)` but
does NOT declare `ICallAsyncNodeManager`, so `AsyncNodeManagerAdapter.CallAsync` ran the synchronous `Call`. NM now declares
`ICallAsyncNodeManager` and overrides `CallAsync`: (a) claims every unprocessed request whose ObjectId is in the
`mapped/conditions` namespace — a namespace-index test, **no lock at all** — and marks it `Processed`; (b) calls
`base.Call(...)` unchanged (it skips the claimed ones; local behaviour incl. `ReportAfterMethod` under `Lock` is unchanged),
completed before any remote await; (c) runs the claimed calls concurrently and awaits them. No `Lock` is held at any point;
the SDK pre-validation `FindMethodState` takes `Lock` only for its lookup (plan's residual).
- **Local checks (step 2), no I/O, no NM `Lock`:** condition resolved from the ObjectId (`TryParse`, lock-free registry
`Find`) else `BadNodeIdUnknown`; method from the MethodId — the type declarations (`AcknowledgeableConditionType_Acknowledge`
/ `_Confirm`, `ConditionType_AddComment`) or this condition's instance child (`c1.…/Acknowledge` etc.); anything else
(shelve, enable/disable) `BadNotSupported`; no port ⇒ `BadNotSupported`; **per-caller mapping gate**
`IProjectedConditionMethods.AuthorizeMethod(local caller, placements, method)` ⇒ `BadUserAccessDenied` unsent; native
Confirm ⇒ `BadNotSupported`; the origin's `supported_methods` (kept from the listing) lacks the method ⇒ `BadNotSupported`;
Warm Standby ⇒ the standby refusal; argument shape (`BadArgumentsMissing` / `BadTooManyArguments` / `BadTypeMismatch`);
**EventId**: must be one this consumer minted for that condition AND bound to the CURRENT marker, else `BadEventIdUnknown`
unsent. The EventId registry (`RecentEvents`, 32 per condition) and `Activation` are now read/written under a per-condition
`MethodGate` (the plan's "small registry with its own lock"); `TryResolveImportedEvent` also uses it instead of `Lock`.
- **The gate** (`ProjectedConditionAccess.AuthorizeMethod`, real `DataOperationPolicy`): for a placement in primary order whose
mapping is current, condition-bearing, of the placement's realm and itself grants the method's bit (AlarmAcknowledge for
Acknowledge/AddComment, AlarmConfirm for Confirm): `AuthorizeLocal(caller, AlarmAcknowledge|AlarmConfirm, folder scope)`,
which re-checks the caller's key (#563); regardless of `Security:Acl:Enabled` (as the A3a visibility gate). Returns the
placement to dispatch through and that mapping's `ConditionMethodTimeoutMilliseconds`.
- **Dispatch (steps 4–5).** Bounded by a per-node semaphore (8; waiting counts against the budget, exhausted ⇒
`BadTooManyOperations` unsent). Budget = min(request `OperationDeadline`, the mapping's method timeout). A fresh operation id
(`a3-<guid>`) per dispatch; **an identical call already in flight** (same caller, condition, EventId, method, comment) **joins**
it — one dispatch, the same answer. The port call is bounded by budget + 250 ms (`WaitAsync` + `CancelAfter`). The Runtime
addresses the origin with the placement, `expected_activation` = the latest applied marker, `expected_serving_incarnation` =
the serving identity of the CURRENT condition stream (`IDataSubscriptionProvenance`), `on_behalf_of` = the local principal,
through the deployed lease (`DataConnectionDeploymentLease` now implements `IDataConditionMethodService`: the row's
AlarmAcknowledge/AlarmConfirm bit else `UnauthorizedAccessException` ⇒ `BadUserAccessDenied`, unsent). No open condition stream
(connection down / never opened) ⇒ `BadNoCommunication`, nothing leased or sent.
- **No local apply.** Imported conditions keep their A3a `BadNotSupported` SDK handlers; nothing in the claimed path touches
node state. The node changes only when the origin's record arrives on the condition stream.
- **Outcome mapping (documented choice).** `DriverConfirmedSuccess` (scripted) / `AcceptedUnconfirmed` (native) ⇒ `Good` (the
client may see Good before the confirming event); `RejectedBeforeDispatch` ⇒ the origin's status (+ its diagnostic);
**`OutcomeUnknown` ⇒ `BadTimeout` when the budget elapsed, otherwise `BadCommunicationError`**, always with
"OutcomeUnknown: …" in the diagnostic and a Warning log. Chosen over an Uncertain code: Part 4 gives a Call result no
"maybe applied" Uncertain meaning, and an Uncertain-family status reads as success to most clients; a Bad status plus the
confirming (or absent) condition event is the honest answer. Never retried.
- **N6 re-binding** (`RebindImportedEventIds`). After a record that changed no state: a moved marker re-binds retained EventIds
only when the record's `time` equals the time they were bound under (F6); otherwise a fresh EventId bound to the new marker is
stamped on the node (what a ConditionRefresh now returns) and `RequireRefresh(connection)` is queued after the apply
(outside `Lock`). A condition whose first record reported no event gets one bound EventId.
## A3a defects found by the live gate (fixed)
1. **`ProjectedConditionAccess` logged to `NullLogger` in production** (DI passed no logger): the first live failure
(`a3b-cond-1`, nothing imported) left no trace. Now the host logger; plus Information logs for stream open (serving), a
refused item (Warning, status + diagnostic) and each snapshot barrier (statuses, record count, timeout).
2. **The UNS root item was refused `Denied`** (`a3b-cond-2`: `map-uns item refused by the origin (Denied)`, `map-raw` Complete,
0 records). The item view was built from the anchor address with subject = the address identifier (an opaque EquipmentId);
the origin requires its own subject (`area/line/plc`). Now metadata is asked exactly as `RemoteNamespaceResolver` asks it
(subject = `RemoteRootEntityId`) and the item carries the origin's canonical view from the metadata answer. Pinned by
`The_condition_item_carries_the_origins_canonical_root_view_learned_from_metadata` (red with the item view reverted).
The A3a unit tests could not see either: their fake origin accepted any view.
## Tests (A3b)
| Project | Class | What |
|---|---|---|
| OI | `ImportedConditionMethodWireTests` (7, Phase=A3) | real SDK server + client sessions; the port fakes the origin: **once + join** (duplicate in-flight call joins, one dispatch, both Good; still unacked until the origin record; record ⇒ acked; a later call = new dispatch, fresh op id); **child Call** via the instance method id, denied caller `BadUserAccessDenied` unsent, re-gated per local caller, Acknowledge grant ≠ Confirm; **unknown / superseded EventId** `BadEventIdUnknown`, native Confirm + OneShotShelve `BadNotSupported`, all unsent, positive control carries the current marker; **N6** same-time resync re-binds, other-time resync ⇒ old EventId unknown + fresh ackable EventId; **L3 lock-freedom**; **mixed batch** (local native Ack through `base.Call` = Good + routed once + one local ack event, imported Ack dispatched, imported unchanged); **timeout** (300 ms mapping timeout ⇒ `BadTimeout` < 3 s, port cancelled, one dispatch), OutcomeUnknown ⇒ `BadCommunicationError`, refusal statuses passed through (`BadInvalidState`, `BadNoCommunication`), nothing applied |
| Runtime | `GrpcDataProjectedConditionMethodTests` (5, Phase=A3, manifest `A3`) | gate with a real `DataOperationPolicy` (AlarmAcknowledge ⇒ Ack/AddComment not Confirm; Subscribe-only ⇒ denied; mapping lacking the bit ⇒ denied; mapping timeout 4321 ms carried; unknown mapping/caller/null denied); no open stream ⇒ `BadNoCommunication`, never leased, nothing sent; call carries the stream's serving incarnation, placement, marker, op id, budget, on-behalf-of; OutcomeUnknown passed through; connection down after a stream end ⇒ `BadNoCommunication`, nothing sent; lease refusal ⇒ `BadUserAccessDenied` unsent; canonical root view |
| OI | `ImportedConditionMemoryMeasurementTests` (opt-in `OTOPCUA_A3_L2=1`, Category=Perf) | L2 harness |
OI suites run outside the unit-phase runner (it accepts unit projects only), as for A3a.
**Red-on-revert (each mutation built, run, restored; `git status` clean after):**
| Mutation | Test | Result |
|---|---|---|
| M1: port call waited synchronously under `lock (Lock)` | L3 lock-freedom | **red** (the first Read/Browse waited out the 5 s stall: `ack.IsCompleted` already true) |
| M2: in-flight join disabled | once + join | **red** (joined count never 1) |
| M3: `AuthorizeMethod` verdict ignored | child Call gate | **red** (denied caller got Good) |
| M4: EventId marker check ignored | unknown/superseded EventId | **red** (superseded EventId accepted) |
| M5: mapping timeout ignored (30 s budget) | timeout | **red** (elapsed > 3 s) |
| M6: N6 re-bind disabled | re-binding | **red** (same-time resync EventId refused) |
| M7: `base.Call` skipped when anything is claimed | mixed batch | **red** (local Ack not Good) |
| R1: no-stream check removed (Runtime) | connection down | **red** |
| R2: mapping-bit check removed (Runtime) | gate | **red** |
| R3: item view reverted to the address-only view | canonical root view | **red** |
| native-Confirm check removed (not run) | — | expected **masked**: `supported_methods` of a native condition (Native = 3) lacks Confirm, a second layer refusing the same call `BadNotSupported` unsent |
## L3 — lock-freedom (§9.3, hard gate) — PASS
Measured by the OI wire test (in-process, real SDK server; the origin's method handler is stalled 5 s at the consumer's
`IProjectedConditionMethods` port — the consumer-side boundary, below which everything is the remote origin). 10 rounds of
concurrent Read (raw variable), Browse (Plant folder) and a data Publish (value write → client notification, publishing interval
20 ms) while the call is in flight, plus `Monitor.TryEnter(Lock)` from the test thread; `AckedState` asserted false after every
round; the origin record applied after release flips it (positive control). Three runs:
| Run | Stall | Read max | Browse max | Data Publish max | `Lock` acquire max | Baseline (no stall) read / browse / publish |
|---|---|---|---|---|---|---|
| 1 | 5003 ms | 1.8 ms | 1.2 ms | 99.7 ms | 0.01 ms | 1.3 / 5.0 / 105.8 ms |
| 2 | 5003 ms | 1.9 ms | 6.3 ms | 98.6 ms | 0.01 ms | 1.3 / 4.6 / 107.7 ms |
| 3 | 5002 ms | 2.6 ms | 1.1 ms | 99.7 ms | 0.01 ms | 1.2 / 5.4 / 105.9 ms |
All < 200 ms. The ~100 ms publish figure is the server's minimum publishing interval (identical without a stall), not a delay.
Deviation: the plan lists L3 as a docker-dev measurement; the live rig has no hook to stall the origin's handler, so the gate is
this deterministic in-process measurement (its mutation M1 proves it detects a `Lock` wait).
## L2 — consumer memory, 1,000 imported conditions in one mapping (§9.3) — PASS
In-process harness (`ImportedConditionMemoryMeasurementTests`, opt-in): a running SDK server, 1,000 conditions materialised through
the real `IProjectedConditionSink` (nodes + instance-scoped children, ids, registry + folder/notifier indexes, one more transition
each so every N6 EventId slot is used, the verdict cache exercised once per condition) plus the update records the runtime keeps per
key. Forced compacting GCs before/after. Three runs:
| Run | Working-set growth | Managed heap growth | per condition (heap) | materialise / transition |
|---|---|---|---|---|
| 1 | +107.1 MiB | +197.4 MiB | 207,036 B | 605 / 80 ms |
| 2 | +106.2 MiB | +197.4 MiB | 207,029 B | 704 / 91 ms |
| 3 | +112.2 MiB | +197.4 MiB | 207,029 B | 747 / 77 ms |
| 4 (after-materialise split) | +106.8 MiB | +196.1 MiB | 205,665 B (204,612 after materialise alone) | 602 / 83 ms |
Working-set growth ≤ 200 MiB: **PASS** (the heap grows more than the working set because the process had already committed GC
regions at baseline). Per the plan, `MaxImportedConditionBytes` is now set from the measurement: `BytesPerCondition` 160,997 →
**205,665** (the managed-heap figure, the larger of the two) and the default `DataConnections:MaxImportedConditionBytes` =
205,665 × 2,500 = **514,162,500 B (≈ 490 MiB)** (was 400 MiB). `MaxConditions` (1,000 per mapping) needs no lowering.
Nearly all of it is the SDK condition node + children (X0's node-only figure was 160,997); the A3b EventId registry adds ~1 KB.
## Live — run `a3b-cond-3` (build `82ecc116`, clean tree) — PASS
```bash
python3 scripts/validation/grpc-data/rig.py up --run-id a3b-cond-3 --conditions --timeout 1200
python3 scripts/validation/grpc-data/rig.py seed --run-id a3b-cond-3
# ~90 s for CONTROL's ClusterNode contact refresh
python3 scripts/validation/grpc-data/rig.py deploy --run-id a3b-cond-3 --timeout 300
python3 scripts/validation/grpc-data/conditions_a3_smoke.py --run-id a3b-cond-3
python3 scripts/validation/grpc-data/rig.py down --run-id a3b-cond-3
```
The conditions profile now also makes the CONSUMER condition-bearing (connection + both mappings carry 64|128|256; ConfigDb
showed 479 on both). `conditions_a3_smoke.py` raises ScalarHigh, runs CLI `alarms --refresh` on the SOURCE Primary (origin's own
subscriber) and the CONSUMER Primary, acks through the consumer with CLI `ack`, then clears.
| Item | Observed | Result |
|---|---|---|
| Consumer import | `stream 1 … opened (2 mapping(s), serving source-1:4053)`; barrier `map-raw=Complete, map-uns=Complete; 1 record(s)`; consumer CLI shows ScalarHigh Active/Unacknowledged with ConditionNodeId `ns=6;s=c1.…` (mapped/conditions) and a consumer EventId | PASS |
| Bogus EventId via the consumer | `Acknowledge failed: BadEventIdUnknown [0x809A0000]`; origin shows no ack | PASS |
| Ack via the consumer (CLI `ack`) | `Acknowledge successful` in 580 ms | PASS |
| Origin audit (source-1) | `Data-connection condition method Acknowledge by fixture-consumer (key …) on Uns:…:source-scalar-high op a3-1eabf280…: DriverConfirmedSuccess 0x00000000; on behalf of fixture-cli` — the service principal, the consumer's fresh op id, the local caller as on-behalf-of | PASS |
| Origin's own subscriber | ScalarHigh: Active/Unacknowledged, **exactly one Active/Acknowledged** | PASS |
| Consumer subscriber | Active/Unacknowledged, **exactly one Active/Acknowledged** (the origin's record re-imported) | PASS |
| Teardown | no run-labelled containers / networks left | — |
Failed attempts (history): `a3b-cond-1` — nothing imported, no log (A3a defect 1); `a3b-cond-2` — map-uns Denied (A3a defect 2).
Each fix changed the image inputs, so each run was torn down and a fresh run id brought up.
## Deviations / decisions (A3b)
1. **EventIds retained: 32** (A3a's `RecentEventIds`), not the plan's "last N (default 8)"; validity is "minted for this condition
under the current marker", as §5.6 step 3 specifies.
2. **Consumer-side join of identical in-flight calls** (the brief's "duplicate call joins"): each dispatch has a fresh operation id
(the origin's own registry joins duplicates of an id); two identical local calls in flight share one dispatch. A repeat after
completion is a new dispatch (no retry, no stale join).
3. **Dispatch placement** = the first placement (primary order) the CALLER passes the method gate on, not unconditionally the
primary placement: a caller authorized only via a second mapping is addressed through that mapping's placement.
4. **`expected_serving_incarnation`** = the serving identity of the condition stream the records arrived on (no stream ⇒
`BadNoCommunication`, unsent). A stream that does not expose provenance cannot be called through (production streams do).
5. **OutcomeUnknown ⇒ Bad** (`BadTimeout` / `BadCommunicationError`), see "Outcome mapping".
6. **The node manager enforces the mapping timeout itself** (budget + 250 ms grace around the port), so a port that never answers
cannot hold a request past it; the Runtime passes the budget to `GrpcDataConnection`, whose own ceiling still applies.
7. **L3 measured in-process** (see L3). **L2 measured in-process** (allowed by the brief).
8. Defaults changed at the A3 exit: `BytesPerCondition` 205,665, `MaxImportedConditionBytes` ≈ 490 MiB (L2).
9. Two A3a files were edited beyond A3b's seams because the live gate required it: the ProjectedConditionAccess DI logger and the
condition item root view (defects above); plus the per-condition `MethodGate` and N6 re-binding hook in `ApplyImported` /
`ReportImported` / `TryResolveImportedEvent`.
## Open / follow-ups
- RefreshRequired after an un-re-bindable resync goes to every item that may see the connection's conditions (A3a's
`RequireRefresh`), not only the affected mapping's notifiers.
- The A3a deviation 9 (explicit Primary endpoint for condition items) is still open; the live run happened to stream from the
Primary (source-1).
## Gates (A3b, at `82ecc116`)
| Gate | Result |
|---|---|
| `dotnet build ZB.MOM.WW.OtOpcUa.slnx --no-incremental` | 0 warnings, 0 errors |
| `run-unit-phase.py A3` (Runtime + OpcUaServer + Host) | passed (`20261124T225624…`) |
| `run-unit-phase.py A2` | passed (`20261124T225724…`) |
| `run-unit-phase.py A1` | passed (`20261124T225845…`) |
| `run-unit-phase.py X0` | passed (`20261124T230234…`) |
| Host.Tests `.DataConnections.` (both v1 gates) | 207 passed |
| Runtime.Tests full (`Category!=E2E&Category!=LiveIntegration`) | 2035 passed, 3 skipped (no #920 rerun needed) |
| OpcUaServer.Tests full (same filter) | 1455 passed, 1 skipped |
| OI `Feature=GrpcData` + ConditionMethodEvent / NativeAlarmEventIdentityFieldDelivery / FolderConditionRefresh / ConditionRefreshDeferral | 123 passed, 1 skipped (the opt-in L2 harness) |
| OI `ImportedConditionMethodWireTests` ×3 | 7/7 each |
| `git diff master -- '*Goldens.cs'` | empty |
| Live `a3b-cond-3` | PASS (above) |