diff --git a/docs/plans/evidence/grpc-data-ext/A1-core.md b/docs/plans/evidence/grpc-data-ext/A1-core.md index af0da2765..fe48ebad9 100644 --- a/docs/plans/evidence/grpc-data-ext/A1-core.md +++ b/docs/plans/evidence/grpc-data-ext/A1-core.md @@ -14,8 +14,11 @@ agent's). Branch `worktree-agent-ad44f71fa7ab46039`, based on master `cbb5b396`. driver actors: signal forward, routing, OpcUaClient backstop, F5 timeout (`DriverHostActor.ConditionSignals.cs`, `ConditionSignalOptions`), tests + reusable rig `NativeAlarmSignalTestBase`/`FakeSignallingAlarmDriver` (`47bf3a1c`, `NativeAlarmInitialStateSignalTests` 6/6). -- **In progress:** scripted `OnInputsEstablished` (engine → `ScriptedAlarmHostActor`). -- **Next:** manifest `A1`; gates; evidence tables. + Scripted `OnInputsEstablished` engine → host (`a2486167`, `ScriptedAlarmEngineInputsEstablishedTests` 4/4, + `ScriptedAlarmHostInputsEstablishedTests` 2/2); manifest key `A1` (`81ebdf4f`). +- **In progress:** gates (see "Gates"). +- **Next (other agents):** the six real drivers (seams below); placements / `condition_key` / `c1.` ids (parallel agent); + A2 wire. L4 calibration is not run here. ## Decisions and deviations (each with a reason) @@ -58,6 +61,73 @@ agent's). Branch `worktree-agent-ad44f71fa7ab46039`, based on master `cbb5b396`. - **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). +- **Scripted flips are one event with a flag** — `ScriptedAlarmEngine.OnInputsEstablished(ScriptedAlarmInputsEventArgs + (AlarmId, Established))`; `Established=false` is the "input reverted to never-pushed" withdrawal. Queued "last in + pending" by subclassing the per-call pending list (`PendingEmissions`) and firing its flips after every emission + (`FirePending`), so no evaluation signature changed. `LoadAsync` clears the engine's established set, so every reload + re-raises the flip for every established alarm — that is how scripted conditions become known again after a rebuild + re-created them unknown. +- **The scripted host holds flips during a load** until `OnAlarmsLoaded` has queued the post-load re-assert of + non-normal conditions; otherwise the flip LoadAsync fires before its pipe-back would mark a freshly re-materialised + (inactive) node known ahead of the re-assert of its persisted active state — a falsely-normal known. Held flips are + 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. + +## Seams for the driver agent (ii, iii, vi, vii, viii, ix) + +- **Interface:** `src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/IAlarmInitialStateSignal.cs` — + `event EventHandler InitialAlarmStateDelivered`; args `(IReadOnlyList + ConditionIds, bool Unsignalable = false)`. Raise it synchronously on the `OnAlarmEvent` thread/path, after the + last event it covers, only while an alarm subscription is live, with `ConditionIds` = the RawPaths it established. + OpcUaClient without ConditionRefresh raises it once with `Unsignalable: true` (backstop applies). +- **Nothing else to wire per driver:** `DriverInstanceActor.AttachAlarmSource/DetachAlarmSource` attach the signal + with the alarm handler for any `IAlarmSource` that also implements `IAlarmInitialStateSignal`; `DriverHostActor` + routes it (`DriverHostActor.ConditionSignals.cs`). +- **Hooks (plan §5.1 table):** Galaxy `GatewayGalaxyAlarmFeed.Dispatch` sentinel (`:168`) → `GalaxyDriver` + re-raises; OpcUaClient `RefreshEndEventType` route (`OpcUaClientDriver.cs:3066`) + `SequentialPublishing = true` on + the alarm subscription (`:2445`); FOCAS `FocasAlarmProjection.PollOnceAsync` after `Tick` per host (`:274`); AbCip + `AbCipAlarmProjection.Tick` end (`:195`); Heidenhain `HeidenhainAlarmProjection.OnWalk` Good status (`:214`); + MTConnect resync emission (`MTConnectDriver.Alarms.cs:117`). +- **Test helper:** `tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmSignalTestBase.cs` — inherit it; + `StartRig(driverType, alarmTags, configure?, driver?)` deploys the tags on one enabled driver (any `IDriver` via the + `driver` param once the class is generalised; today a `FakeSignallingAlarmDriver`), returns `Rig(Host, Publish probe, + Driver, Hub)`; `CollectAlarmTraffic` (ordered `AlarmStateUpdate`/`MarkConditionsKnown`), `AssertNoMark`, + `RawPathOf(tag)`. `FakeSignallingAlarmDriver` obeys G5 (`Raise`/`Signal` are no-ops while unsubscribed), + `ReplaySnapshot` = Galaxy-shaped snapshot + sentinel, `SubscribeDelay` holds the DriverInstanceActor mailbox (F2), + `OnSubscribed` = post-subscribe replay. To drive a REAL driver through the rig, widen `StartRig`'s `driver` parameter + from `FakeSignallingAlarmDriver` to `IDriver` and drop the `Subscribed` wait. +- **Config:** `DataConnections:ConditionKnownSignalTimeout:` (s or TimeSpan; default 120 s), + `DataConnections:ConditionKnownSettle:OpcUaClient` (default 60 s) — `ConditionSignalOptions`; tests use + `WithSignalTimeout` / `WithOpcUaClientSettle`. + +## Tests (A1 manifest key) + +| Test | What it pins | +|---|---| +| O `ConditionStateNodeManagerTests` (12) | parity (a) cold start, (b) Warm standby → promotion, (c) rebuild carry-over (known at once, same marker, never-known stays unknown, no removal record for a returning condition, removal for a dropped one), (d) SDK-applied native ack through the real `Acknowledge.OnCall` wrapper, (e) ConditionClass-only (state-only record, no event), (f) ack-revert (+ F4 marker bump), (g) quality-only — each asserted as "delta stream folded == fresh node snapshot"; T1 (state-only known record after the cut, negative + positive control, repeat no-op); `MarkConditionsUnknown`; T3 marker edges; scripted marker kept across a rebuild re-assert; **structural MaxConditions**: 25 conditions, max 10 ⇒ holds `[10,10,5]`, Lock not held at the hook, a delta between holds lands inside slice 2 / after slice 1's watermark | +| R `ConditionStateHubTests` (5) | global versions, per-reader overflow reset, `snapshot_complete` = apply complete ∧ Primary, F5 diagnostic, **falsely-empty** (real NM + hub: not complete until `CompleteAddressSpaceApply`; no known-inactive record for a standing alarm before its projection) | +| R `OpcUaPublishActorConditionKnownTests` (5) | live order; F2 during a held plan (mark replayed after the alarm); **G3** overflow (mark discarded, next signal marks) and out-of-scope skip (only that source's mark discarded); withdrawal → `MarkConditionsUnknown` | +| R `NativeAlarmInitialStateSignalTests` (6) | real DriverInstanceActor + DriverHostActor + fake driver: known only on the signal, after the projection; **(iv) Galaxy-shaped, DriverInstanceActor delayed** 800 ms ⇒ mark still last; **(v) F5** (no mark, diagnostic, late signal clears); OpcUaClient backstop; no backstop for other types; **(xi) G5** | +| S `ScriptedAlarmEngineInputsEstablishedTests` (4) | **(i)** late input ⇒ no flip before the first real evaluation, flip after its `Activated`; seeded at load; **reverting to never-pushed ⇒ unknown again**, re-established on a value; reload re-raises | +| R `ScriptedAlarmHostInputsEstablishedTests` (2) | **(iv) scripted**: mark after the Active projection; a reload holds the mark until after the re-assert | + +**Mutation (red/green) checks**, each restored after the red run: + +| Mutation | Red | +|---|---| +| NM: no record in `ReportConditionEvent`, no state-only record in `WriteAlarmCondition` | 7 of 12 `ConditionStateNodeManagerTests` (b, d, e, f, g, T3, MaxConditions) | +| Publish actor: `SourceLost` always false (no G3 discard) | both G3 tests | +| DriverInstanceActor: signal forwarded straight from the driver thread to the parent (bypassing the mailbox) | F2-delayed and G5 order tests | +| Engine: flips fired BEFORE the pending emissions | (i) and seeded-at-load tests | +| Scripted host: flips never held during a load | reload-holds-the-mark test | + +## Gates + +(filled below) + ## Open questions (none yet)