Files
lmxopcua/docs/plans/evidence/grpc-data-ext/A4.md
T
Joseph Doherty b2fab8b075 test(grpc-data): #928 — overflow test asserted one of two legal outcomes; deterministic Reset test + either-outcome contract test; DataConnections.md A4 reconcile (#930 retries, condition metrics, AdminUI fields)
The origin item sees a hub eviction only at its next hub read: Reset if the last snapshot chunk is
still undelivered, otherwise a silent fresh snapshot on the same stream (both per A2, both loss-free
since the A3 consumer swaps a buffered re-snapshot in as a full replacement). Since A2 review S5 the
3,000-record snapshot is 59 chunks and the silent path wins when run alone (fails 3/3 alone at the A2
merge too; passes in its class). No product change. Also fixes the stale ack/confirm/shelve comment on
ConditionMethodTimeoutMilliseconds.
2026-11-25 00:08:06 -05:00

18 KiB
Raw Blame History

A4 evidence — code part (diagnostics, #930, #931, L1, L5)

Phase A4 of docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md, 2026-11-24/25, branch a4-code (from master 91438049). Not merged, not pushed. The docs part (DataConnections.md, AlarmTracking.md, ScriptedAlarms.md, security.md) is a separate worktree; the A01–A08 fleet scenarios are not part of this code pass.

#930 — a permanently refused mapping no longer storms (N2), ConditionCapacity recovers (N3)

ProjectedConditionAccess.Runner.cs:

  • In-stream retry. A mapping that is Unavailable (item refused, root metadata failed, snapshot timed out) or ConditionCapacity is retried ON THE OPEN STREAM: its root is re-resolved if it never resolved, any still-open item is removed, and its item is re-added (AddSubscriptionItems, a fresh command id; acks are matched on (mapping, command id)). The stream is no longer ended for it, so the healthy mappings are never re-snapshotted and methods are not answered BadNoCommunication in a reconnect gap.
  • Backoff per mapping. Definitive refusals (Denied, NotFound, Unsupported, item or root) and ConditionCapacity: ProjectedConditionOptions.LongRetryDelay (new, default 5 min) × 2ⁿ, ≤ 4×. Transient: the snapshot timeout × 2ⁿ, ≤ 8× (the old B2 schedule). A retry whose snapshot has not completed by its deadline goes back to Unavailable (claim released); a late completion of that item is still taken. A completed snapshot resets the retry count.
  • RefreshRequired only on a changed incomplete set. Each barrier records the set of mappings not known; an incomplete barrier whose set equals the previous barrier's (e.g. a stream that ended for another reason with the same mapping still refused) sends no RefreshRequired. A mapping that completes in-stream leaves the recorded set, so a later relapse is told again.
  • T2 holds: a retried mapping is Pending (unknown) while its retry runs, so nothing it might list is removed or marked known-inactive meanwhile; a capacity mapping's retry likewise blocks removals until it is known again.

Decision: a ConditionCapacity mapping is "known-empty" while parked but "unknown" during its retry window. Conservative (removals by other mappings in that window are held as BadNoCommunication instead of removed) — never the T2-unsafe direction.

#931 — nits N4–N8

Nit Fix
N4 A stream that ended before its barrier (every root failing, no Primary) backs off ReconnectDelay × 2^(n−1) up to the new MaxReconnectDelay (60 s); reset when a barrier passes. The repeated end logs at Debug after the first.
N5 The ledger charges max(Materialised, Σ known claims + max(Unlisted, Σ unknown claims)): held-but-unlisted keys (an Unavailable mapping's stale keys) are charged beside a known mapping's new claim (the under-count), but overlap an unknown mapping's claim (it may be re-listing those very keys — no false capacity rejection of a retry). The swap commits its count via Commit (never refused). SetMaterialised now reports when the node is over a cap (logged; materialising is never refused — bounded by Σ MaxConditions).
N6 _runners is a ConcurrentDictionary (mutated under _gate only); CallAsync and the diagnostics poll read a runner's Serving without _gate. No test (a lock-ordering change with no observable seam; reviewed by reading).
N7 A capacity reset whose reconcile removed conditions sends no second RefreshRequired — the removal already carried one to every item that held them (the sink's §5.2 "removal + RefreshRequired"); it still asks when nothing was removed.
N8 A parked (_stopping) runner is dropped once its removal finished (it hands over an empty set); new test observation IsParked.

Red/green (each reverted alone, the named test re-run, then restored)

Fix Revert Test Red
N2 in-stream end the stream when a retry is due B2_S7_a_refused_item… (rewritten: Add arrives, no new stream, map-b not re-applied) and N3_a_ConditionCapacity_mapping_is_re_added_in_stream… both red
N2 unchanged set alreadyTold = false N2_an_unchanged_incomplete_set_on_a_new_stream… red
N2 definitive Definitive ignores the refusal status N2_a_definitive_refusal_waits_the_long_backoff… red
N4 fixed ReconnectDelay N4_streams_that_never_reach_a_barrier_back_off_exponentially (< 12 metadata calls in 2 s; ~40 without) red
N5 known + unknown (old under-count) N5_held_stale_keys_are_charged_beside_a_known_mappings_new_claim… red
N7 if (outcome.Refresh) RequireRefresh() B1_an_in_stream_re_snapshot_over_capacity… (now asserts one RefreshRequired per reset: the removal's) red
N8 continuation never removes the parked entry N8_a_stopped_runner_is_not_kept_parked… red

Also new: N3_a_retry_still_over_capacity_stays_ConditionCapacity… (backoff doubles, map-b's key never removed).

Test-only fix found on the way: the condition-access tests waited for BarriersCompleted and then asserted RefreshRequired, but the barrier count moves before the barrier's refresh (the A4 manifest's first run caught it in N2_an_unchanged…); they now wait for the refresh itself, with the third stream's refresh as the positive control for the second stream's absence.

Diagnostics and metrics (plan §6)

  • Runtime/DataConnections/DataConnectionConditionDiagnostics.cs (new DI singleton, no dependencies — the H4 shape): shared by the origin condition items (ConditionItemStream, via LocalDataServices.ConditionDiagnostics), the consumer runtime (ProjectedConditionAccess.Diagnostics) and the readers (DataConnectionDeploymentRuntime.ConditionDiagnostics, DriverHostActor). The condition hub's unsignalled count is attached at DI time (no lazy-composition gap like H4 review 2).
  • Metrics (OtOpcUa meter, every one with side = origin | consumer, no ids): otopcua.dataconn.conditions.items{side} (consumer side new: one per acked mapping item), …conditions.resyncs{side}, …conditions.capacity_rejections{side}, …condition_methods{method,outcome,side} (consumer side new: every forwarded call), and the new otopcua.dataconn.conditions.refresh_required{side=consumer}. The A2 instruments were reused (only side added).
  • Contracts (Commons, additive optional members; older senders ⇒ null = "unavailable"): DataConnectionDiagnosticsSnapshot.Conditions (ConsumerConditionDiagnostics: stream state idle|connecting|snapshotting|live, last snapshot, materialised, state_known=false count, RefreshRequired, resyncs, capacity rejections, per mapping status / observed / MaxConditions / refusal, node budget vs host cap, method outcome classes), NodeDiagnosticsSnapshot.OriginConditions (OriginConditionDiagnostics: open items, the item nearest its limit, last snapshot, resyncs, capacity rejections, unsignalled, methods served). Arrays in production (H4 Akka JSON note); no bool flag was added.
  • AdminUI ClusterDataConnections.razor (already in <PageErrorBoundary>) + DataConnectionDiagnostics helpers: an "Imported conditions" line per connection (notice style when a mapping is Unavailable/ConditionCapacity or any count ≥ 80 % of its limit) and a served-conditions segment in the origin panel.

Decisions: the consumer RefreshRequired count is requests made by the runtime (explicit + each removal batch), not per client item; method outcome classes: DriverConfirmedSuccess = succeeded, RejectedBeforeDispatch = rejected, DriverConfirmedFailure = failed, the rest (AcceptedUnconfirmed, OutcomeUnknown) = unknown. A method the node manager refuses before forwarding (no local grant) is not counted on the consumer side.

Tests: Runtime GrpcDataConditionDiagnosticsTests (3), GrpcDataConditionDiagnosticsSerializationTests (2: cluster-serializer round trip; an older payload decodes Conditions/OriginConditions null), GrpcDataProjectedConditionAccessTests.A4_consumer_diagnostics…; AdminUI GrpcDataConditionDiagnosticsDisplayTests (4). Manifest key A4 in unit-phases.json.

AdminUI live — run a4c-cond-1 (prerendered HTML from control-1's admin, login disabled)

/clusters/CONSUMER/data-connections after the smoke:

  • consumer-1: "Imported conditions: stream live · last snapshot 2026-11-25 04:44:51Z · conditions 1 (state unknown 0) · node budget 1/2500 · RefreshRequired 0 · resyncs 0 · capacity rejections 0 · methods succeeded 1 · … · mappings map-raw Complete 0/1000; map-uns Complete 1/1000".
  • consumer-2 (no event subscriber): "stream idle · … · mappings map-raw Pending 0/1000; map-uns Pending 0/1000".
  • origin panel for consumer-1/2: "condition items open 0 · last snapshot none since start · … · state unknown (unsignalled) 0".

/clusters/SOURCE/data-connections origin panel: source-1 "condition items open 2 · largest listing 1/1000 · last snapshot 2026-11-25 04:44:51Z · resyncs 0 · capacity rejections 0 · state unknown (unsignalled) 0 · methods served succeeded 1"; source-2 (Secondary) zeros. /metrics: consumer-1 conditions_items{side="consumer"} 2, condition_methods_total{method="Acknowledge", outcome="DriverConfirmedSuccess",side="consumer"} 1; source-1 conditions_items{side="origin"} 2, the same method series with side="origin" 1 — page and metrics agree. Not driven in a browser (Chrome tools not used); prerender runs the same render.

L1 — origin SnapshotConditions Lock hold (§9.3) — PASS (A1 had not measured it)

A1-core.md/A1-L4.md record only L4 (X0 measured a field copy outside the server). Measured now with the opt-in harness OpcUaServer.Tests/ConditionSnapshotLockHoldMeasurementTests (OTOPCUA_L1=1): a running SDK server, 1,000 native conditions + 500 variables, two publisher threads (WriteValue, WriteAlarmCondition, both under Lock), 500 snapshots after 20 warm-up. The hold is an upper bound (keys-enumerated hook → post-hold hook; 1,000 = one hold at DefaultMaxConditionsPerHold). macOS (developer Mac), Debug build:

Run hold p50 / p99 / max (ms) WriteValue p99 / max (ms) WriteAlarmCondition p99 / max (ms)
1 1.61 / 4.65 / 5.89 1.93 / 6.39 1.94 / 6.42
2 1.44 / 4.32 / 5.00 1.71 / 6.34 1.71 / 6.38
3 1.45 / 4.53 / 5.90 1.65 / 6.81 1.66 / 6.76

p99 ≤ 10 ms and no publish delayed > 50 ms: pass. In-process, not on docker-dev (deviation: the brief allowed in-process).

L5 — condition counts vs defaults

  • docker-dev export (run a4c-cond-1, from the new diagnostics): map-raw 0/1000, map-uns 1/1000 (0.1 %); consumer node 1/2500 conditions (host caps 122,500 nodes / 400 MiB ⇒ 2,500); origin largest listing 1/1000. All ≤ 80 %: pass, defaults unchanged.
  • Production export: BLOCKED. No production ConfigDb is reachable read-only from configuration in the repo (production ConfigDbs are on the wonder boxes, which this brief forbids touching), and the data-connections feature is not deployed in production (v1 merged, undeployed), so no production export exists to count yet. To be filed.

Gates (at a4-code HEAD)

Gate Result
dotnet build ZB.MOM.WW.OtOpcUa.slnx --no-incremental 0 warnings, 0 errors
run-unit-phase.py A4 (new) passed (20261125T040920…)
run-unit-phase.py A3 / A1 / H4 / X0 passed
run-unit-phase.py A2 first run failed Overflow_before_the_snapshot_is_drained_resets_the_stream (below); re-run passed (20261125T042208…)
Host.Tests .DataConnections. 207 passed
Runtime.Tests full (Category!=E2E&Category!=LiveIntegration) 2066 passed, 3 skipped, 2 failed: GrpcDataConfiguredDiscoveryWireTests (#920) and Overflow_before_… (below)
OpcUaServer.Tests full 1458 passed, 2 skipped (the L1 harness is one)
AdminUI.Tests full 2707 passed
OI combined (139) 138 passed, 1 skipped
Live conditions_a3_smoke.py, run a4c-cond-1 passed: true (imported ScalarHigh ns=6;s=c1.…, 32-char EventId; bogus EventId ⇒ BadEventIdUnknown; ack via consumer 635 ms; exactly one Active/Acknowledged on origin and consumer); rig.py down ⇒ 0 run containers / networks
git diff master -- '*Goldens.cs' empty
Configuration.Tests not touched

Classification (b): test defect, no product change. The origin item notices a hub eviction only when it next reads the hub, which it does not do while it is producing snapshot chunks. At that read it takes one of two paths (ConditionItemStream.ReadDeltas):

  • the previous snapshot's last chunk is still undelivered (_deliveredSnapshot < Snapshots) ⇒ Overflowed ⇒ the session sends a stream Reset ("Condition stream overflow; retry later.");
  • otherwise ⇒ ResetSnapshot: a fresh snapshot (new begin) on the same stream, counted as a resync.

Both are what A2 specified (A2.md "Overflow" item 3: "a hub reader reset ⇒ the item re-snapshots … a reset while the item's previous snapshot is still undelivered ⇒ stream Reset"). Which one an eviction during a long delivery gets depends on whether the pump reads the hub before the session commits the last chunk (DirectReader.MoveNextAsync commits before returning the frame, so a consumer that has caught up commits it first). Neither loses a change. The Reset path makes the consumer reconnect and take a complete snapshot. The silent path's new snapshot is taken from the source, so it includes every evicted change. The A3 consumer (ProjectedConditionAccess.Runner.cs, the IsSnapshot && Total branch and the SnapshotComplete swap) buffers any snapshot begin into a new ConditionSet, keeps applying live deltas to both, and at snapshot_complete swaps it in as a full replacement: old ∪ new keys are re-merged and a key only the old set listed is removed. So a silent re-snapshot is safe, and the Overflowed rule protects the snapshot memory lease and back-pressure (no snapshot is taken behind an undelivered one). It is not a correctness signal the consumer depends on.

Evidence (instrumented copy of the test, alone, a4-code): 3,000 records came in chunks of 51 records, not the 24 × ~125 the test comment assumed: since A2 review S5 (20bf9372) the chunk budget is min(256 KiB, MaxPendingBytes = 200,000 in the fixture, MaxMessageBytes), and a record with info estimates ≈ 3.9 KB. Frames #1–#59 were snapshot 1 (complete on #59). #60 was a new begin (total=3000), then snapshot 2 was complete at #120, with Snapshots=2, Resets=1, Overflowed=false and no Reset control. So the test waited for a Reset that the legal silent path never sends. The original contract test, with its outcome instrumented, took the silent path 10/10 alone.

Why it "started" failing: it did not. Neither ConditionItemStream.cs, DataSubscriptionSession.Conditions.cs nor the test changed between the A2 merge (83c7e586) and master 91438049 (A3 touched only consumer files). At 83c7e586 (detached worktree, built clean) the test fails 3/3 alone but its class (22 tests) passes. It has been order- and JIT-warmth-dependent since S5 made the snapshot 59 chunks. A2 gated it only inside the class or suite. A3 and A4 add tests and change the scheduling of suite runs, so full-suite failures became more frequent.

Fix (tests only, GrpcDataConditionStreamTests.cs):

  1. Overflow_before_the_snapshot_is_drained_resets_the_stream is now deterministic. 300 records (begin + 6 chunks) fit the 16-frame condition queue. The consumer reads nothing after the ack. The test waits until the snapshot is taken and charged (ChargedBytes > 0, so the start cursor precedes the raises), raises 6 times (capacity 2 ⇒ eviction above the cursor), ticks until Overflowed, and then asserts the Reset ("overflow") and Snapshots == 1.
  2. New An_eviction_during_a_long_snapshot_delivery_resets_or_resnapshots_without_losing_a_change keeps the 3,000-record race and asserts the contract for either outcome. On Reset ⇒ Overflowed, and a reconnected stream's complete snapshot (3,000) holds the source's final state for the raised condition. On re-snapshot ⇒ begin total=3000, only snapshot chunks until snapshot_complete, 3,000 records with the final state, Resets == 1, Snapshots == 2, Overflowed == false, and the stream not ended. Any other outcome fails.

Red/green (mutations of ConditionItemStream.ReadDeltas, each restored):

Mutation Deterministic Overflow test Contract test
none green 10/10 alone green 10/10 alone (silent path 10/10)
M1: Overflowed rule disabled (false && …) red (Condition not reached — no Reset) green (silent path, which is legal)
M2: eviction swallowed (_cursors[p] = read.Floor; continue), Overflowed kept green (Overflowed still set) green (took the Reset path)
M3: eviction swallowed and no Overflowed (a lost change) red red ("Neither a Reset nor a fresh snapshot.")

Gates after the #928 fix + docs reconcile (tests + docs, and one XML doc comment in RemoteNamespaceMapping.cs; no behaviour change, so OpcUaServer.Tests full and the live smoke were not re-run):

Gate Result
dotnet build ZB.MOM.WW.OtOpcUa.slnx --no-incremental 0 warnings, 0 errors
The two #928 tests alone, 10× 10/10 green
run-unit-phase.py A2 / A3 / A4 passed (20261125T050036…, 20261125T050157…, 20261125T050252…)
Runtime.Tests full (Category!=E2E&Category!=LiveIntegration) 2068 passed, 3 skipped, 1 failed: GrpcDataConfiguredDiscoveryWireTests.Two_sdk_cadences_… (#920), which passed when re-run alone
Host.Tests .DataConnections. 207 passed

Left over

  • File: production L5 count (blocked, above). #928 resolved above (test defect, tests fixed).
  • Not done here: A01–A08, reviewer approval, the ScadaBridge consumer-impact record, docs (other worktree).