fix(alarms): a scripted condition's Part 9 method returns the engine's verdict (#937)
Before: the alarm-commands topic is fire-and-forget, so an OPC UA method (and a remote gRPC-data condition method) returned Good even when the engine rejected the command because its last load failed. - ScriptedAlarmCommandReadinessView: the host's latest load outcome; the node manager's handler refuses BadInvalidState before the SDK applies anything while the last load failed (lock-free read). - Bounded ask: inside CallAsync (off Lock) each local request runs base.Call alone; the handler only STARTS AlarmCommandAsker (broadcast for the peer + DriverHostActor -> ScriptedAlarmHostActor.ExecuteAlarmCommand on the local engine, CommandId-deduplicated) and the Call awaits the verdict: refused => BadInvalidState, no answer => BadTimeout OutcomeUnknown. - Remote CallConditionMethod: ExecuteConditionMethodAsync => DriverConfirmedFailure / OutcomeUnknown on the origin. - Host ownership uses the latest plan set (stable across a load in flight and a failed load's half-built set). - Docs: ScriptedAlarms.md (verdicts, residual, duplicate-activation trade-off), DataConnections.md, rules/alarms.md. Live leg scenario F937 + seeder scripted_predicate mutation. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+46
-3
@@ -186,9 +186,15 @@ after a full rebuild, carrying the unchanged `LastTransitionUtc`. Decisions:
|
||||
occurrence (`Activated`, `Unacknowledged`). Restating the pre-failure snapshot instead would hide an alarm that cleared and
|
||||
re-fired inside the window. While blind, an operator command is **rejected** with `ScriptedAlarmCommandRejectedException`
|
||||
(nothing is persisted — applying it to the half-built Fresh entry would overwrite the real row), and queued re-evaluations
|
||||
and shelving checks are dropped. The command topic is fire-and-forget (the OPC UA method / AdminUI call already returned
|
||||
Good), so the rejection's only record is the host's Warning `… NOT applied — …`; the next good load re-asserts the node
|
||||
from the store, undoing whatever the method showed.
|
||||
and shelving checks are dropped. **Since #937 an OPC UA Part 9 method (and a remote gRPC-data condition method) on a
|
||||
scripted condition reports this**: while the last load failed the node manager refuses the call `BadInvalidState` before the
|
||||
SDK applies anything (no event, nothing routed); a call that passed that pre-check and then met a rejection (it was queued
|
||||
behind a load that failed) also returns `BadInvalidState` — see [Operator command verdicts](#operator-command-verdicts-937).
|
||||
The AdminUI `/alerts` buttons still publish fire-and-forget ("Ack sent"), so for them the only record remains the host's
|
||||
Warning `… NOT applied — …`. The next good load re-asserts every node from the store.
|
||||
**Accepted trade-off:** because the next good load after a failed one reads the store (which has no `Active` column), each
|
||||
alarm whose predicate is still true is a new occurrence — **one transient failed deploy costs one duplicate activation
|
||||
(`Activated` + `Unacknowledged`, one `alerts` row) per still-true alarm** on the next good deploy.
|
||||
- **Concurrency.** The capture happens under `_evalGate`, so it includes every evaluation and operator command that completed
|
||||
before the load. An operator command looks its alarm up only once it holds the gate (review S1 — it used to look up first,
|
||||
so a command racing a load could save the load's interim `Fresh` entry over the carried Active condition), so a command
|
||||
@@ -411,6 +417,43 @@ On allow, the handler publishes a `Commons.OpcUa.AlarmCommand` (containing comma
|
||||
- **Scripted conditions** — all eight Part 9 operations (including Enable/Disable) route through `AlarmCommandRouter` onto the `alarm-commands` topic, which `ScriptedAlarmHostActor` dispatches to the engine (`EnableAsync` / `DisableAsync` / `AcknowledgeAsync` / …). On enable, `ActiveState` is re-derived from the next predicate evaluation.
|
||||
- **Native (driver-fed) conditions** — `OnAcknowledge` branches to `NativeAlarmAckRouter` and routes the ack to the owning driver rather than the scripted engine (see §[Native-alarm OPC UA operator operations](#native-alarm-opc-ua-operator-operations) above). `OnEnableDisable`, `OnConfirm` and `OnShelve` return `BadNotSupported` immediately — a native condition supports Acknowledge and AddComment only (no engine-side surface, no upstream path, and the driver projection owns its Confirmed/Shelving; Gitea #587 review).
|
||||
|
||||
### Operator command verdicts (#937)
|
||||
|
||||
A scripted condition's Part 9 method no longer returns Good merely because the command was published. Two layers, neither
|
||||
of which blocks under the node manager's `Lock`:
|
||||
|
||||
1. **Pre-check** — `ScriptedAlarmCommandReadinessView` (Runtime singleton) holds the outcome of the host's latest completed
|
||||
load; the handler reads it (one volatile read) after the role/ACL gate and the Warm-standby check. While the last load
|
||||
failed it returns `BadInvalidState` and nothing is applied, routed or reported. It never refuses before the first load.
|
||||
2. **Bounded ask** — inside the Call service (`OtOpcUaNodeManager.CallAsync`, which the SDK invokes off `Lock`), each local
|
||||
request runs through the SDK's `base.Call` on its own; the handler, under `Lock`, only *starts* the ask
|
||||
(`AlarmCommandAsker`): the hosted service broadcasts the command on `alarm-commands` for the redundant peer (as before)
|
||||
and asks **this node's** `ScriptedAlarmHostActor` (via `DriverHostActor`, `ExecuteAlarmCommand`) for its verdict, with a
|
||||
fresh `CommandId` so the local host applies whichever copy reaches it first, once. The SDK applies its node state and
|
||||
reports the one method event exactly as before; then the Call awaits the verdict with no lock held.
|
||||
|
||||
| Engine verdict | Method status |
|
||||
|---|---|
|
||||
| applied (incl. an idempotent no-op) | `Good` |
|
||||
| refused — last load failed, alarm not loaded on this node, malformed command, no engine on this node | `BadInvalidState` |
|
||||
| no answer within min(5 s, request deadline − 250 ms), or the engine op timed out / failed in the store | `BadTimeout` / `BadInternalError`, diagnostic "OutcomeUnknown" — the command **may still apply**, never reported as refused |
|
||||
|
||||
`BadInvalidState` is Part 4's general "object … uninitialized or in some other invalid state" code; Part 9's method result
|
||||
codes (bad EventId, already acked/confirmed/shelved, disabled, shelving time out of range) do not cover "the state owner
|
||||
cannot act", and the server already uses `BadInvalidState` for a native ack off-Primary. The status is the contract: a plain
|
||||
SDK client sees only the code (the reason text travels in diagnostics, returned only when requested).
|
||||
|
||||
**Redundancy.** The verdict is the LOCAL engine's — the one that projects this node's condition node. The peer still applies
|
||||
its broadcast copy independently (and both engines' saves converge through the replicated LocalDb row). A remote
|
||||
gRPC-data `CallConditionMethod` on a scripted condition carries the same verdict (`ExecuteConditionMethodAsync`): applied ⇒
|
||||
`DriverConfirmedSuccess`, refused after dispatch ⇒ `DriverConfirmedFailure`, no answer ⇒ `OutcomeUnknown`.
|
||||
|
||||
**Residual.** Only the pre-check stops the SDK from applying the node change. A refusal that arrives through the ask (a load
|
||||
in flight when the command queued behind it, which then failed) leaves the node showing the change — and its one event
|
||||
reported — until the next good deploy re-asserts the node from the store; the caller gets `BadInvalidState`.
|
||||
**Not covered:** the AdminUI `/alerts` buttons are still fire-and-forget across the central→node transport (they report
|
||||
"Ack sent", not "applied").
|
||||
|
||||
`OnTimedUnshelve` (the SDK's internal auto-unshelve timer, armed for the real remaining time since Gitea #597) is a **no-op**: the engine owns timed-shelve expiry via `ApplyShelvingCheck` (`system / AutoUnshelve`), and routing an `Unshelve` from the timer pre-empted that on every expiry as an operator-style unshelve from both pair nodes (review R1 M2).
|
||||
|
||||
### Delta-gate de-duplication
|
||||
|
||||
Reference in New Issue
Block a user