diff --git a/docs/plans/evidence/grpc-data-ext/A3.md b/docs/plans/evidence/grpc-data-ext/A3.md index 1a474b258..dc2b5f353 100644 --- a/docs/plans/evidence/grpc-data-ext/A3.md +++ b/docs/plans/evidence/grpc-data-ext/A3.md @@ -435,3 +435,121 @@ Consumer: `stream 1 for connection consumer-source opened (2 mapping(s), serving `SubscribePrimaryAsync`); barrier `map-raw=Complete, map-uns=Complete; 1 record(s)`. Bogus EventId ⇒ `BadEventIdUnknown`; ack through the consumer `Acknowledge successful` (608 ms); origin subscriber and consumer subscriber each saw exactly one Active/Acknowledged. Teardown: no run-labelled containers or networks left. + +--- + +# A3 — Review round 1 (A3b adversarial review, `a3b-review-round1.md`, written against `3c941458`) + +2026-11-25, branch `a3-consumer`, on top of the A3a fix round (`01a4e8db`). Not merged, not pushed. Commits: `72dece7f` (fixes + +tests), `perf(grpc-data): … BytesPerCondition` (L2 re-derivation), this docs commit. + +"Red on revert": the single fix was removed by a scripted mutation (`mut.py`, one mutation per build), the named test run and seen +red, the file restored (`git status` clean after the 19 mutations). + +| Finding | Resolution | Test(s) | Red on revert | +|---|---|---|---| +| **S1** a throw after `base.Call` faults the batch | `CallAsync` runs each claimed item through `CallImportedGuardedAsync` (never faults, a synchronous throw included) and collects per-item results; a fault before the port is called ⇒ that item's `BadInternalError`, unsent (logged); `DispatchImportedAsync` answers every post-dispatch failure itself | `A_fault_before_dispatch_is_a_per_item_BadInternalError…` (gate throws: imported-first batch ⇒ `[BadInternalError, Good]`, local ack routed once, nothing sent; a pre-validation failure (`MethodId` null) answered per item beside a dispatched call; a port THROWING after dispatch ⇒ `BadCommunicationError`, one dispatch) | yes (both catch-alls removed ⇒ ServiceFault) | +| **S2** mapping timeout capped at 5 s; BadTimeout inferred | the mapping's `ConditionMethodTimeoutMilliseconds` is honoured (up to the validator's 3,600,000 ms): it rides `RemainingBudget`, and `GrpcDataConnection.ConditionMethodTimeout` defaults to that validator ceiling (`MaxConditionMethodTimeout`) instead of 5 s. The client maps gRPC `DeadlineExceeded` ⇒ `OutcomeUnknown` + `BadTimeout`; `MapOutcome` takes the transport's status (BadTimeout stays BadTimeout, anything else unknown ⇒ BadCommunicationError) — no clock comparison | Runtime `Without_a_connection_ceiling_the_deadline_is_the_requests_budget_not_a_hidden_5s` (8 s budget ⇒ grpc-timeout > 6 s); `A_deadline_passing_after_send_is_OutcomeUnknown_with_BadTimeout_known_not_inferred`; OI timeout test: port answers `OutcomeUnknown/BadTimeout` at once ⇒ `BadTimeout` | yes / yes / yes | +| **S3** unsent / definite failures labelled unknown | cancel while waiting for a slot ⇒ `BadRequestCancelledByClient` unsent; an invalid request is `RejectedBeforeDispatch` `BadInvalidArgument` in `ProjectedConditionAccess.CallAsync` (before the lease) and in the client (never thrown); `DriverConfirmedFailure` ⇒ the origin's status (+ diagnostic) | Runtime `An_invalid_request_is_refused_unsent_before_the_lease` (not even leased); client `An_invalid_request_is_RejectedBeforeDispatch_never_thrown`; OI timeout test (`DriverConfirmedFailure`/`BadConditionAlreadyEnabled` passes through) | yes / yes / yes. Slot-wait cancellation: **not tested** — the SDK 2.0.1 server gives no client-driven way to cancel an in-flight Call (no Cancel wiring into `OperationContext.CancellationToken` found); by inspection only | +| **S4** no fairness; dispatch with a few ms left | per-connection sub-limit `DefaultImportedMethodConcurrencyPerConnection = 4` inside the node-wide 8 (connection slot first, then node slot, both released in `finally`); a dispatch with < `ImportedMethodMinimumDispatchBudget` (250 ms) left is `BadTimeout` UNSENT (checked before the waits and again after them). Per-principal fairness not added (a principal is bounded by the per-connection limit; documented) | `One_stalled_connection_cannot_starve_another_and_its_excess_calls_are_BadTooManyOperations_unsent` (8 stalled calls on conn-a: 4 dispatched, 4 `BadTooManyOperations` unsent, a conn-b call Good < 1.5 s — slot exhaustion included); `A_request_deadline_below_the_dispatch_floor_is_BadTimeout_unsent` (TimeoutHint 450 ms ⇒ unsent; 2,000 ms ⇒ dispatched with budget ≤ 1,750 ms) | yes / yes | +| **S5 L3** stall below the port only | the L3 test is now a Theory: `realPath: true` puts a REAL `ProjectedConditionAccess` (runner, serving incarnation, lease) and a REAL `GrpcDataConnection` (capabilities, eligibility, deadline, HTTP/2 gRPC framing) between the node manager and an in-process origin whose `CallConditionMethod` handler stalls 5 s (`RealConditionMethodPath`); only the condition stream is a quiet stand-in carrying Primary provenance. The per-caller gate stays the fake (pinned by the Runtime gate tests) | L3 numbers below | yes (M1 on the real path: port awaited under `Lock` ⇒ both cases red) | +| **S5 L2** not worst case | harness now: two placements per condition (two mappings, both folders wired), all 32 EventId slots filled (asserted), three event items (Server object + both folders, publishing off, queue 1000), runner Live + Buffer record copies; max of three runs, rounded up: `BytesPerCondition` 205,665 → **230,000**, `MaxImportedConditionBytes` default = 230,000 × 2,500 = **575,000,000 B (≈ 548 MiB)** | L2 numbers below | n/a (measurement) | +| **S6** test gaps | RefreshRequired after an un-re-bindable resync asserted over the wire (Server-object item receives `RefreshRequiredEventType`); native Confirm with a listing that HAS Confirm (still refused) and scripted lacking it (refused) / having it (dispatched); real gate: first authorized placement of several, realm mismatch, unknown mapping, ungranted folder; Warm standby refusal; different principals never join; imported-first mixed batch; batch with a pre-validation failure; throwing port; slot exhaustion; the `cancelled` flag is written/read with `Volatile` | `A_resync_that_cannot_re_bind_sends_RefreshRequired…`; `Native_Confirm_is_refused_even_when_listed…`; Runtime `The_gate_routes_through_the_first_authorized_placement_and_refuses_a_realm_mismatch`; `A_warm_standby_refuses_an_imported_method_unsent`; `Identical_calls_from_different_principals_do_not_join`; S1/S4 tests above | native guard yes; supported-methods guard yes; gate (stop at first refusal) yes; standby yes; principal dropped from the join key yes. **ACL-on gate variant: not added** — `AuthorizeMethod` has no `Security:Acl:Enabled` input at all (`DataOperationPolicy.AuthorizeLocal` regardless of the flag, by design §5.6); the mixed/fault batches run with enforcement on. **Mid-call cancel: not tested** (see S3) | +| **N1** `bounded` not cancelled on TimeoutException | `bounded.Cancel()` in the `TimeoutException` catch | timeout test (`cancelled` observed) | **no** — the CancelAfter timer usually still fires first; the race the fix closes is not forceable | +| **N2** re-bind on any marker move | F6 re-binding only when the INCARNATION changed at an unchanged time; a same-incarnation sequence bump mints + RefreshRequired | `A_resync_that_cannot_re_bind…` | yes | +| **N3** null-marker transition | a marker appearing or disappearing is a marker change: mint + RefreshRequired | `A_marker_appearing_on_an_unchanged_state_mints_an_ackable_EventId` | yes | +| **N4** joiner inherits the first caller's cancel/deadline | kept (documented in code): a joiner asked for the same thing at the same moment and never dispatches twice; the key includes the principal | — | n/a | +| **N5** existence answers before the gate | kept; the comment corrected — `BadNodeIdUnknown`/`BadNotSupported` are what SDK pre-validation reveals anyway | — | n/a | +| **N6** "OutcomeUnknown" text only with diagnostics | kept: the status is always Bad (never read as done); the text reaches a client requesting diagnostics and the Warning log | — | n/a | +| **N7** grace past TimeoutHint; elapsed subtracted twice | one end instant = min(start + mapping timeout, request deadline − grace); waits and the port budget derive from it, so the answer lands inside the client's TimeoutHint | floor test positive control (budget ≤ hint − grace) | not separately reverted | +| **N8** unsynchronised reads | `ImportedCondition.Placements` volatile publication; `SupportedMethods` an atomic 64-bit word | — | n/a (memory model) | +| **N9** method gate does not require visibility | documented: Ack on placement B suffices without seeing it via A; the EventId (128-bit, minted per consumer, only delivered to items that see the condition) is the practical visibility requirement | — | n/a | + +## L3 — real dispatch path (review S5) + +The A3b measurement repeated with the stall behind a real `ProjectedConditionAccess` + `GrpcDataConnection` (in-process origin +handler stalling 5 s), and with the original port-level stall, 10 rounds each: + +| Run | Path | Stall | Read max | Browse max | Data Publish max | `Lock` acquire max | +|---|---|---|---|---|---|---| +| 1 | port | 5002 ms | 0.4 ms | 0.3 ms | 100.0 ms | 0.01 ms | +| 1 | **real** | 5044 ms | 0.5 ms | 0.3 ms | 101.6 ms | 0.01 ms | +| 2 | port | 5003 ms | 1.5 ms | 2.2 ms | 102.1 ms | 0.01 ms | +| 2 | **real** | 5051 ms | 2.3 ms | 0.3 ms | 100.8 ms | 0.01 ms | +| 3 | port | 5002 ms | 0.7 ms | 0.3 ms | 94.6 ms | 0.00 ms | +| 3 | **real** | 5040 ms | 0.4 ms | 0.3 ms | 102.6 ms | 0.00 ms | +| 4 | port | 5002 ms | 0.5 ms | 0.3 ms | 96.7 ms | 0.01 ms | +| 4 | **real** | 5042 ms | 0.4 ms | 0.3 ms | 109.1 ms | 0.01 ms | + +(Measured inside the 4 combined OI gate runs, i.e. under the whole suite's parallel load.) All < 200 ms; the ~100 ms publish +figure is the minimum publishing interval, as before. The real-path stall is ~40 ms longer (capabilities probe + channel set-up +of the first call). **L3: PASS on the real dispatch path.** + +## L2 — worst case (review S5) — **FAILS the 200 MiB gate** + +Two placements per condition, every EventId slot (32) filled, three event items holding up to 1,000 events each (publishing off), +Live + Buffer record copies; forced compacting GCs; three runs: + +| Run | Managed heap growth | Working-set growth | heap B/condition | after materialise (heap) | +|---|---|---|---|---| +| 1 | +92.3 MiB (GC noise: below the after-materialise figure) | +125.7 MiB | 96,770 | 217,948 | +| 2 | **+217.8 MiB** | **+210.0 MiB** | 228,353 | 217,979 | +| 3 | **+217.7 MiB** | **+206.1 MiB** | 228,299 | 217,931 | + +At this worst case BOTH the managed heap (≈ 218 MiB) and the working set (206–210 MiB in 2 of 3 runs) exceed the 200 MiB gate; +the A3b single-placement figure (heap 197.4 MiB, WS ≈ 107 MiB) passed it only because it was not worst case. Recorded, not +adjusted: the harness keeps asserting ≤ 200 MiB and fails when opted in. The byte cap is now derived from the worst case +(230,000 B × 2,500 ≈ 548 MiB), so admission accounting is honest; whether the §9.3 L2 gate (200 MiB for 1,000 conditions) is +re-scoped to the single-placement case or the per-condition cost is reduced (≈ 210 KB is the SDK condition node + children — +X0's node-only figure was 161 KB — plus the second wiring) is an owner decision. + +## Task: the OI condition-refresh failures (`ConditionRefreshDeferralWireTests` / `FolderConditionRefreshWireTests`) + +**Conclusion: reproduces only with the A3 test classes in the run; NOT reproduced on master; root cause NOT established. +Not marked flaky.** No A3 production path is reached in the failing rigs (no imported condition exists in them; +`ReplayImportedConditions` returns at `Count == 0`; every other A3 hunk on the delivery/refresh path is a namespace-index test or a +`Find` returning null). + +Evidence (combined filter `Feature=GrpcData|…ConditionMethodEvent|…NativeAlarmEventIdentityFieldDelivery|…FolderConditionRefresh| +…ConditionRefreshDeferral`, `--blame-hang-timeout 120s`, one run at a time): + +| Build | Runs | Failed runs | Failures | +|---|---|---|---| +| master `83c7e586` (109 tests) | 4 | **0** | — | +| master `83c7e586`, only the two deferral classes, 14 busy-loop CPU burners | 2 | 0 | — | +| A3a r1 `01a4e8db` (130 tests) | 4 | 2 | gate test `A_refresh_waits_for_a_deferred_delivery…` (`window.Count` 4, expected 2); folder `Deferred_events_older…(enforced: False, …, modify: True)` (RefreshEnd not seen in 10 s, line 93) | +| `01a4e8db` + diagnostics (window dump on failure) | 6 | 0 | — (the failure did not recur, so no window dump was captured) | +| this round `72dece7f`+ (139 tests) | 4 | 3 | folder `Deferred_events_older…(enforced: True…)` ×2 (RefreshEnd not seen, line 93); folder `A_condition_removed_during_a_plain_refresh_is_not_replayed(serverObject: False)` (RefreshEnd not seen, line 527 — **no stall, no deferral involved**) | +| same + thread-pool latency sampler (50 ms probe) | 4 | 1 | folder `Deferred_events_older…` ×2; pool dispatch latency max **11 ms** in the failing run (≤ 21 ms in all), ≤ 21 pool threads | +| same + `DOTNET_ThreadPool_ForceMinWorkerThreads=64` | 1 | 1 | `ConditionRefreshDeferralWireTests.Deferred_events_older…(enforced: True…)`; pool max 15 ms | + +Ruled out: +- **A3 production code in those rigs** — not reached (above); the shared helpers (`ApplyConditionState`, `CreateConditionNode`) are + pure extractions. +- **Thread-pool starvation** (the SDK's ConditionRefresh worker blocks a pool thread in `WaitOne` per server, which made it the + first suspect) — dispatch latency stayed ≤ 21 ms in failing runs and forcing 64 minimum workers did not prevent a failure. +- **Plain CPU load** — 14 burners on master's two classes: 0 failures. + +What it is: mostly **a RefreshEnd that never reaches a folder (direct) event item** within 10 s — once in the plain +(non-deferring) refresh path with no stall at all — plus, once, two extra deferred events inside a Server-object refresh window. +It needs other tests running in the same process at the same time (it scales with the size of the parallel suite: 0/4 at 109 +tests, 2/4 at 130, 3/4 at 139). Process-wide shared state is the remaining lead — e.g. `ProjectedEventDelivery`'s static +`FilterGroup` registry keyed by filter text, which every rig's server shares — but no mechanism was demonstrated. Pre-existing +code (#854/#855), exposed by suite composition rather than introduced by A3 behaviour as far as the evidence goes; to be filed. + +## Gates (review round 1 A3b) + +| Gate | Result | +|---|---| +| `dotnet build ZB.MOM.WW.OtOpcUa.slnx --no-incremental` | 0 warnings, 0 errors | +| `run-unit-phase.py A3` | passed (`20261125T010625…`) | +| `run-unit-phase.py A2` | passed (`20261125T010724…`) | +| `run-unit-phase.py A1` | passed (`20261125T010836…`) | +| `run-unit-phase.py X0` | passed (`20261125T011156…`) | +| Host.Tests `.DataConnections.` (both v1 gates) | 207 passed | +| Runtime.Tests full (`Category!=E2E&Category!=LiveIntegration`) | 2054 passed, 3 skipped | +| OpcUaServer.Tests full (same filter) | 1456 passed, 1 skipped | +| OI combined (139) | **not 3 clean**: 1 of 4 clean; every failure is in `FolderConditionRefreshWireTests` / `ConditionRefreshDeferralWireTests` (see the investigation above); every A3/GrpcData test passed in every run | +| OI `ImportedConditionMethodWireTests` (16) | 16/16 (and in each combined run) | +| L2 worst case (opt-in) | **FAIL** 2 of 3 runs (above) | +| `git diff master -- '*Goldens.cs'` | empty |