docs(grpc-data): A3 round 2 — pooled EventFieldList root cause, L2 re-measured (PASS), gates, live a3r2-cond-1 PASS

This commit is contained in:
Joseph Doherty
2026-11-24 22:11:28 -05:00
parent b884db5fb1
commit 5bece2a5a5
+133
View File
@@ -561,3 +561,136 @@ ScalarHigh at the consumer (`ns=6;s=c1.…`, 32-char EventId); bogus EventId ⇒
consumer `Acknowledge successful` (596 ms, through the new per-connection slot + dispatch floor + mapping-timeout path); origin
subscriber and consumer subscriber each saw exactly one Active/Acknowledged; `passed: true`. Teardown: no run-labelled containers
or networks left.
# A3 — Round 2 (merge blocker: the OI condition-refresh failures; L2 worst-case memory)
2026-11-25, branch `a3-consumer`. Not merged, not pushed. Commits: `6be0b8dc` (fix + red/green test), `b884db5f` (L2), this docs
commit.
## Root cause of the OI condition-refresh failures — an A3 defect, now fixed
**SDK 2.0.1 pools `EventFieldList` process-wide, and `ProjectedEventFieldList` (A3a, §5.4) went back into that pool.**
`EventFieldListActivator : PooledEncodeableType<EventFieldList>` (bounded, process-global, 1,024); `MonitoredItem.GetEventFields`
rents every event's list from it; `SentMessageQueue.ReuseNotificationPayloads` calls `Reuse()` on every list of an acknowledged /
evicted message, and the base `ReuseCore` resets the instance and returns it — **whatever its runtime type** — to the stock pool.
A released `ProjectedEventFieldList` was therefore rented by ANY server's next `GetEventFields` — an unrelated session's
`RefreshStart`/`RefreshEnd` or local condition event — still carrying the imported condition's `ProjectedEventMarker`, and
`ProjectedNotificationRewriter` judged that unrelated event by the stale marker: when its gate denied (a revoked caller, a removed
condition), the event was **dropped**. The data path already knew this trap (`ProjectedSdkNotification` overrides `ReuseCore` and
"stays out of the shared stock pool"; `OrdinaryTagMarker` validates itself against its notification); the A3a event subclass did
not follow it.
This is a production defect, not a test artifact: in one server process, any session's events (refresh markers, local alarms,
acks) could be dropped by another session's imported-condition gate, and every recycled list pinned a marker closure (condition +
identity) for as long as it sat in the pool.
How it was found (one test run at a time, `--blame-hang-timeout 120s`):
| Step | Set | Runs | Failed runs |
|---|---|---|---|
| A3 build, full combined filter (139) | — | 1 | 1 |
| A3 build, master's 109 only (`FullyQualifiedName!~ImportedCondition`) | **A3 production code alone** | 4 | **0** ⇒ the A3 tests trigger it |
| without `ImportedConditionMethodWireTests` (123) | event wire tests in | 4 | 2 |
| deferral + folder classes + event wire tests only (52) | — | 4 | **4** |
| … + half A (6 tests) | — | 3 | 2 |
| … + `Exactly_one…`, `A3_SEC_with_ACLs_off…`, `A_condition_child_Read…` | — | 3 | 3 |
| … + `A_condition_child_Read…` only (no event subscription) | — | 3 | 0 |
| … + `Exactly_one…` only (no revocation) | — | 3 | 0 |
| … + `A3_SEC_with_ACLs_off…` only (**revokes** a marked event's caller) | — | 3 | 2 |
Then a temporary publish-path trace (server: the SDK's message before and after the rewriter; client: RefreshStart/End received;
reverted, never committed) on a failing run showed it directly:
```
PUBraw app=urn:OtOpcUa.Refresh855.… sub=3999762809 seq=2 h=19 START EventFieldList
PUBraw app=urn:OtOpcUa.Refresh855.… sub=3999762809 seq=2 h=19 END ProjectedEventFieldList ← a non-imported rig's RefreshEnd
PUB app=urn:OtOpcUa.Refresh855.… sub=3999762809 seq=2 h=19 START EventFieldList ← END dropped by the rewriter
RCV sub=3999762809 h=19 START
PUBraw app=urn:OtOpcUa.Refresh854Gate.… sub=990727810 seq=3 h=30 END ProjectedEventFieldList (never published)
```
That explains every symptom: "RefreshEnd never arrives" (the recycled list was the RefreshEnd), "RefreshStart missing but
RefreshEnd present" (the recycled list was the RefreshStart), "no stall/deferral at all" (plain refresh, same pool), extra events
inside a window (a recycled list whose stale marker PERMITTED), the scaling with suite size and the need for other tests in the
process (more marked lists in the pool), and master never reproducing (no marked lists). The earlier leads (thread-pool
starvation, CPU load, the static `FilterGroup` registry) were not it.
**Fix** (`ProjectedEventDelivery.cs`): `ProjectedEventFieldList` overrides `ReuseCore` — clears its marker, `ResetForReuse()`,
never returns to the stock pool (the GC takes it), exactly like `ProjectedSdkNotification`. `Marker` is nullable; the rewriter
treats a released (marker-less) list as denied (fail closed; it is never published again anyway). No `Lock` involvement.
**Red/green** (`ImportedConditionClassifierTests.A_released_marked_event_list_never_returns_to_the_SDK_pool_so_no_other_session_rents_its_marker`,
OpcUaServer.Tests, deterministic): `Reuse()` a marked list as `SentMessageQueue` does, drain `DefaultMaximumRetained + 64` lists
from `EventFieldListActivator.Instance`, assert none is a `ProjectedEventFieldList`, the marker is gone, and a released list
through the rewriter is dropped. Red on revert, both ways: override body → `base.ReuseCore()` ⇒ `marked.Marker should be null`;
`Marker = null; base.ReuseCore()` ⇒ `rented should not contain an element satisfying the condition`.
After the fix: the 52-test reproducer 0/3 (was 4/4); the combined OI filter — see gates.
## L2 worst-case memory — PASS (the round-1 "FAIL" was a measurement artifact)
1. **EventId window → 8** (`ProjectedConditionRegistry.RecentEventIds`), the plan's §5.6 step 3 "within its last N (default 8)".
A3a's 32 had no recorded need (deviation 1 only stated it); validity is "minted under the current marker", which only the
newest few EventIds can meet. No test depended on 32 (only the L2 harness reads the constant).
2. **`GC.GetTotalMemory` is not the retained heap on .NET 10 regions.** In the same process state it reported **+92 or +218 MiB**
run to run (bimodal; it is the source of round 1's "+217.8 MiB" and run 1's "GC noise"). In those very runs
`GC.GetGCMemoryInfo().HeapSizeBytes` was 135.5 MB both times, and a heap dump of a "+218" run (`dotnet-dump`, taken while
paused after the measurement) held **136 MB of objects in total** (`eeheap -gc`: allocated 136,318,696 B, committed
236,208,128 B): the extra ~125 MiB was committed-but-free region space, and the working set measured the instant after the
forced GCs counted it too (+214 MiB; +133 MiB two seconds later in the same run). The harness now takes
`HeapSizeBytes − FragmentedBytes` after a full blocking GC, samples the working set until the GC has decommitted (two samples
500 ms apart within 1 MiB, ≤ 10 s), still logs the `GetTotalMemory` delta for comparison, and asserts **both** heap and working
set ≤ 200 MiB (stricter than before, not looser).
3. **What dominates** (end-of-run dump, 32-slot build): of 136 MB live, our own types are 6.4 MB — 3.1 MB of it the 32-slot
EventId window (32,000 `LinkedListNode` + 33,000 `DataActivationMarker`, now ÷4), the rest registry entries, placements,
1,000 `ImportedCondition`, 3,000 marked lists/markers (queues capped at 1,000 per item), the harness's Live + Buffer records
(~0.6 MB). ~86 MB is SDK `Opc.Ua.*` node state (property/variable/method states, `ReferenceDictionary`, 158 `Lock`s and 400
`object`s per condition), not ours to cut without touching the SDK node model.
Worst case (2 placements per condition, all 8 EventId slots filled, 3 event items with publishing off, Live + Buffer records):
| Run | Managed heap growth | Working-set growth (settled) | heap B/condition | WS B/condition | `GetTotalMemory` delta (not used) |
|---|---|---|---|---|---|
| 1 | +106.5 MiB | +151.3 MiB | 111,715 | 158,629 | +211.6 MiB |
| 2 | +106.5 MiB | +149.2 MiB | 111,682 | 156,434 | +211.5 MiB |
| 3 | +106.5 MiB | +149.4 MiB | 111,654 | 156,663 | +211.5 MiB |
**L2: PASS** (both ≤ 200 MiB in every run). `BytesPerCondition` = the larger of the two per-condition figures, max of three runs,
rounded up: 158,629 → **160,000** (was 230,000); `MaxImportedConditionBytes` default = 160,000 × 2,500 = **400,000,000 B
(≈ 381 MiB)** (was ≈ 548 MiB). The X0 node-only figure (160,997) and A3b's 197.4 MiB were taken with `GetTotalMemory` too and are
likely inflated the same way (not re-measured here).
## Gates (round 2, at `b884db5f`)
| Gate | Result |
|---|---|
| `dotnet build ZB.MOM.WW.OtOpcUa.slnx --no-incremental` | 0 warnings, 0 errors |
| `run-unit-phase.py A3` | passed (`20261125T024649…`) |
| `run-unit-phase.py A2` | passed (`20261125T024744…`) |
| `run-unit-phase.py A1` | passed (`20261125T024855…`) |
| `run-unit-phase.py X0` | passed (`20261125T025234…`) |
| Host.Tests `.DataConnections.` (both v1 gates) | 207 passed |
| Runtime.Tests full (`Category!=E2E&Category!=LiveIntegration`) | 2054 passed, 3 skipped (see note) |
| OpcUaServer.Tests full (same filter) | 1457 passed, 1 skipped |
| OI combined (139) | **3 consecutive clean runs**: 138 passed, 1 skipped (the opt-in L2 harness) each |
| L2 worst case (opt-in) | PASS 3/3 (above) |
| `git diff master -- '*Goldens.cs'` | empty |
Note (Runtime): the first full run, made while the live rig's images were building (heavy CPU), failed one test,
`GrpcDataConditionStreamTests.Overflow_before_the_snapshot_is_drained_resets_the_stream` (A2, unchanged by A3 — it races 6 raises
against the condition item's read position to force a hub eviction). Not touched by round 2 (no Runtime behaviour changed; only the
`BytesPerCondition` constant). The class passed 5/5 alone and the full suite passed on the re-run without load. Not root-caused
here and not called a flake: to be filed as a load-sensitivity follow-up.
## Live — run `a3r2-cond-1` (build `b884db5f`, clean tree) — PASS
Same procedure as `a3b-cond-3` (`rig.py up --conditions`, seed, 90 s, deploy, `conditions_a3_smoke.py`, `rig.py down`). Imported
ScalarHigh at the consumer (`ns=6;s=c1.…`, 32-char EventId); bogus EventId ⇒ `BadEventIdUnknown [809A0000]`; ack through the
consumer `Acknowledge successful` (1,990 ms); origin subscriber and consumer subscriber each saw exactly one
Active/Acknowledged; `passed: true`. Teardown: no run-labelled containers or networks left.
## Left over
- File: the `GrpcDataConditionStreamTests.Overflow_before_the_snapshot_is_drained_resets_the_stream` load sensitivity (above).
- The plan's L2 / X0 figures (≈ 157–161 KiB per condition node, §5.5 table) came from `GC.GetTotalMemory` and are likely
inflated by the same region accounting; the plan's §5.5 table was not edited (evidence only).