From 2d7f67de724d53e5906b4ae1b6a628041c208311 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 11:03:09 -0500 Subject: [PATCH] =?UTF-8?q?docs(grpc-data):=20A1=20review=20round=201=20?= =?UTF-8?q?=E2=80=94=20findings,=20resolutions,=20mutations=20and=20gates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/plans/evidence/grpc-data-ext/A1-core.md | 65 ++++++++++++++++++-- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/docs/plans/evidence/grpc-data-ext/A1-core.md b/docs/plans/evidence/grpc-data-ext/A1-core.md index e3457ae5e..0c6c6654f 100644 --- a/docs/plans/evidence/grpc-data-ext/A1-core.md +++ b/docs/plans/evidence/grpc-data-ext/A1-core.md @@ -57,7 +57,8 @@ agent's). Branch `worktree-agent-ad44f71fa7ab46039`, based on master `cbb5b396`. - **F5 window** starts at each `ConnectivityChanged(Connected)` edge and covers every alarm ref the driver owns at that instant (`_alarmRefsByDriver`); a Bad edge cancels the F5 and backstop timers. Conditions added by a later deploy while connected are not covered by F5 until the next Good edge (they still become known on the next signal). - Diagnostic cleared when a signal empties the pending set, or the driver is removed. + Diagnostic cleared when a signal empties the pending set, or the driver is removed. **Review round 1** changed this: + the Bad edge withdraws known, a native transition leaves Pending, and the reindex re-arms F5 for added refs (see below). - **Backstop** applies only to driver type `OpcUaClient` (`ConditionKnownSettle:OpcUaClient`, default 60 s); an `Unsignalable` report from any other type is logged and ignored (the conditions stay unknown). @@ -73,8 +74,10 @@ agent's). Branch `worktree-agent-ad44f71fa7ab46039`, based on master `cbb5b396`. dropped by a newer `ApplyScriptedAlarms` (that load re-raises them). Residual: a flip from a superseded load that is raised after the newer apply arrives is held and flushed with the newer load (rare; at worst it re-marks an alarm the newer load also established). -- **A flip is raised on "established" whenever no input is never-pushed**, even when an input is pushed-but-Bad (the - engine then holds its prior state; the consumer sees Quality Bad). That is the plan's predicate. +- ~~A flip is raised on "established" whenever no input is never-pushed, even when an input is pushed-but-Bad.~~ + **Superseded by review S1:** "established" is raised only after the first predicate evaluation that COMPLETES since + the load or a revert (inputs ready, evidence valid, predicate returned a bool); a Bad input, a runner that is not up or + a timed-out/refused/throwing predicate establishes nothing. Reverting an input to never-pushed still withdraws it. ## Seams for the driver agent (ii, iii, vi, vii, viii, ix) @@ -146,8 +149,60 @@ now also receives the new `MarkConditionsKnown` that follows the first projectio - **Serving incarnation for the activation marker** is a GUID per node-manager lifetime. A2 may want the serving incarnation that the data-connection `Serving` already carries. That would be a one-line `ConditionIncarnation` setter. -- **The F5 window ignores conditions added by a deploy while the driver is connected** until the next Good edge. They - still become known on the next signal. Should a deploy re-arm F5 for the added refs? +- ~~The F5 window ignores conditions added by a deploy while the driver is connected~~ — **answered (re-arm F5)**, see + Review round 1. - **`MaxConditions` per hold is a parameter** (default 1,000). A2 should pass the mapping's configured `MaxConditions`. - **The hub never pushes; readers poll `Watermark`/`Read`.** A2 decides on a wake signal. It must not run under the node manager's `Lock`. + +## Review round 1 (2026-11-24, branch `a1-review-fixes`) + +Each finding was fixed in a focused commit with a test, and each test was mutation-checked: the fix was reverted (or +neutralised), the named test went red, and the fix was restored. + +| Finding | Resolution | Red on revert (mutation) / green | +|---|---|---| +| **B1** `WriteAlarmCondition` set known for every projection (restored-unacked scripted re-assert, an early ack) | Known is set there only for native keys (`_nativeAlarmNodeIds`). Scripted known-ness comes only from `MarkConditionsKnown` (`e9d82a6a`) | Revert ⇒ red: `ConditionStateNodeManagerTests.B1_A_scripted_projection_never_marks_known_a_native_one_does` and `ScriptedAlarmHostInputsEstablishedTests.A_restored_unacked_alarm_is_not_known_through_its_reassert_or_an_early_ack`. The second test uses a real host and engine with a persisted unacked state, a restart re-assert, an operator ack before the inputs, then a late input; the host's traffic is applied to a real NM and hub | +| **S1** "established" was raised before readiness, the evidence check and the predicate | `NoteInputsReverted` (withdraw only) at refill; `NoteEvaluationCompleted` after a completed predicate (serial path and runner path) (`6ba5185f`) | Old behaviour restored ⇒ 3 red: `A_Bad_input_never_establishes_and_the_first_good_evaluation_does`, `A_predicate_timeout_or_an_unavailable_runner_never_establishes(timeout: true/false)` | +| **S2** native known was never withdrawn on comms loss; stale signal across a bounce | The Bad edge withdraws (`MarkConditionsKnown(Known:false)` per realm, ahead of the quality annotation). A Good edge also withdraws when no Bad edge was seen since the last Good, or when it comes from a new incarnation. `StopChild` withdraws. Only a **retired** child's late Bad edge withdraws (unless the current child is connected); a stray sender changes nothing. `DriverInstanceActor` bumps a connection epoch on each Connected entry and stamps it on the signal (read at raise time) and on `ConnectivityChanged(Connected)`. A signal from an earlier connection is dropped by the child and by the host. G3 never discards a deferred withdrawal (`f08ca7d9`, `795ad6cc`) | Each mutation ⇒ red: withdrawal removed ⇒ `Comms_loss_withdraws_known_and_a_signal_from_before_the_bounce_is_dropped`; host epoch check removed ⇒ same test; G3 `mark.Known &&` removed ⇒ `A_deferred_withdrawal_is_replayed_even_for_a_source_that_lost_a_projection` | +| S2 — F5 bookkeeping consistent with NM | A forwarded native transition removes its ref from `Pending` (NM marks a native projection known) | Removed ⇒ red: `A_native_transition_leaves_the_F5_pending_set_like_the_node_manager` | +| S2 — Primary demote/re-promote | **Checked, not real:** `DriverInstanceActor` has no role gating, and `ForwardNativeAlarm`'s condition write is ungated (Warm only suppresses events). A demote neither stops the feed nor freezes nodes, and the comms edges still apply | — | +| **S3a** no start cursor | `SnapshotConditions` reads the watermark under `Lock` before enumerating, and every slice carries it as `StartCursor` (`16166c21`) | `StartCursor := slice watermark` ⇒ red: `S3a_A_condition_materialised_after_the_enumeration_is_covered_by_deltas_after_the_start_cursor` (uses the new `OnConditionSnapshotKeysEnumerated` seam) | +| **S3b** readiness not atomic with the cut | Each hold captures the apply generation (bumped at rebuild start) and the complete flag. `ConditionSnapshotSlice.IsCompleteSnapshot` and `ConditionStateHub.IsSnapshotCompleteFor(slices)` reject a straddled snapshot. An empty scope still takes one hold | Generation := 0 ⇒ red: `S3b_A_rebuild_straddling_a_multi_slice_snapshot_makes_it_incomplete` | +| **S3c** unbounded per-hold max | Clamped to `MaxConditionsPerHoldLimit` = 5,000 (≈ 9–15 ms per hold at the measured cost) | Clamp removed ⇒ red: `S3c_MaxConditions_per_hold_is_clamped` (5,001 conditions ⇒ holds `[5000, 1]`) | +| **S4** completion ran on a throwing or degraded apply | New default sink member `CompleteAddressSpaceApply(bool succeeded)`, forwarded by the deferred and SDK sinks. The publish actor passes `!outcome.Degraded`. On failure the NM keeps readiness false and the pending-removal set, so no removals are emitted; the next successful apply completes the rebuild | NM guard removed ⇒ red: `S4_A_failed_rebuild_apply_emits_no_removals_and_keeps_readiness_withheld`. Publish actor `succeeded: true` ⇒ red: `A_throwing_apply_completes_the_address_space_apply_as_failed` | +| **Open question: re-arm F5** | `RearmConditionSignalsAfterReindex`: for a connected driver, the refs a deploy added join `Pending` and the F5 timer restarts at the reindex; removed refs leave `Pending`. **Finding:** today every deploy that adds alarm refs also changes the driver's config, because `DriverDeviceConfigMerger` folds the authored RawTags (TagConfig included) into it. So `DriverSpawnPlanner` respawns the driver, and the new incarnation's Good edge re-arms F5 for every ref. The reindex path is defensive, for a future in-place deploy | `A_deploy_that_adds_alarm_refs_while_connected_covers_them_with_F5` (green; it pins the respawn behaviour: withdrawal, then the diagnostic covers both refs). Removing the reindex re-arm cannot go red through a deploy today (see above) | +| Nit: late message from a stopped child | `IsCurrentChild` gate on signals and edges, so no tracker is recreated after `ForgetConditionSignals` | Gate neutralised ⇒ red: `A_signal_from_a_sender_that_is_not_the_current_child_is_dropped` | +| Nit: `DateTime.UtcNow` | `ConditionClockUtc` = the injected `TimeProvider` | — | +| Nit: `DistinctPlacements` silent | Optional `logger` on `LocalExportCatalog.Compile` (the coordinator passes its own). A Warning lists the colliding addresses, in the local log only (`2fdf9d87`) | `Colliding_placements_are_dropped_and_logged_at_Warning` | +| Nit: `UnshelveTime` | `ConditionStateRecord.UnshelveTimeUtc`, the absolute expiry tracked from `WriteAlarmCondition`'s `UnshelveAtUtc` | `A_timed_shelve_record_carries_its_UnshelveTime` | +| Nit: `Read(max = int.MaxValue)` | `ConditionStateHub.DefaultReadMax` = 1,024; `max ≥ 1` | — | +| Nit: superseded-scripted-load deferred-mark window (`OpcUaPublishActor.cs` ~802) | **Note only, no code change.** A mark from a superseded load that is raised after the newer apply arrives is held and flushed with the newer load. At worst it re-marks an alarm the newer load also established. With S1 that alarm's predicate has completed, so the re-mark is not falsely normal | — | +| Plan text: `condition_key` formula | Plan §5.2 now states `HMAC(K, UTF8(upper(cluster)) ‖ 0x00 ‖ realm(1 Raw / 2 Uns) ‖ UTF8(ConditionId))`, with K = HKDF-SHA256 (empty salt, info `otopcua/condition-key/v1`, 32 bytes) (`3b242f58`) | `ConditionKeysTests` golden vectors, computed independently (Python `hmac`/`hashlib`) | +| Rig secret | `DataConnections__ConditionKeySecret` dev literal (43 bytes), identical on `source-1`/`source-2` in `scripts/validation/grpc-data/compose.yml` (`6c94a2ec`) | — | + +**Merge note for the driver agent's branch:** after this branch, a native driver's tests can also see +`MarkConditionsKnown { Known: false }` (withdrawals) on the publish probe after a Bad edge, a Good edge with no Bad edge +before it, or a respawn. `NativeAlarmSignalTestBase.AssertNoMark` now ignores withdrawals. A test that fishes for "the +mark" should match `m => m.Known`. The rig gained `Redeploy(rig, tags)` and `ChildOf(rig)`. `AlarmInitialStatePublished` +and `ConnectivityChanged` gained an optional `ConnectionEpoch`. + +**Observed once:** under the M5 mutation (StopChild withdrawal removed), the unrelated +`OpcUaPublishActorConditionKnownTests.Live_a_mark_applies_after_the_alarm_state_sent_before_it` failed once. It passed +3/3 on re-runs, so it was load timing during the mutation run, not that mutation. That mutation is masked: a stopped +child's own PostStop Bad edge withdraws too, so no test goes red. The StopChild withdrawal is belt-and-braces. + +### Review round 1 gates + +Run one at a time after the last code commit (`795ad6cc`): + +| Gate | Result | +|---|---| +| `dotnet build ZB.MOM.WW.OtOpcUa.slnx` | 0 errors / 0 warnings | +| `run-unit-phase.py A1` | passed (6 test runs). The first A1 run found one regression: `DriverHostActorNativeAlarmTests.Driver_disconnect_and_reconnect_annotate_native_condition_quality` Tells `ConnectivityChanged` from the test actor, and it received a withdrawal before the quality update. Fixed in production by `795ad6cc`: only a retired child's Bad edge withdraws, and a stray sender changes nothing | +| `run-unit-phase.py X0`, `H2` | passed | +| `Runtime.Tests` (`Category!=E2E&Category!=LiveIntegration`) | 1950 passed, 3 skipped, 1 failed. The failure is `GrpcDataConfiguredDiscoveryWireTests.Failed_sdk_item_construction_releases_candidate_and_fanout_ownership`, the known flaky class (#920). Re-run alone: 110/110 passed | +| `OpcUaServer.Tests` (same filter) | 1438 passed, 1 skipped, 0 failed | +| `Core.ScriptedAlarms.Tests` | 125 passed | +| `Commons.Tests` | 505 passed | +