diff --git a/docs/plans/evidence/grpc-data-ext/A2.md b/docs/plans/evidence/grpc-data-ext/A2.md index 108f804ef..c813fe7b9 100644 --- a/docs/plans/evidence/grpc-data-ext/A2.md +++ b/docs/plans/evidence/grpc-data-ext/A2.md @@ -4,7 +4,97 @@ - `1e78c64b` contract + RPC + origin (NM `TryExecuteConditionMethod`, Runtime facade, registry, audit, Galaxy rule, bits). - `f6c9c9d7` consumer client call, validator/AdminUI bits + Galaxy checkbox, capacity warnings at the deploy gate. -- Next: tests (NM, Runtime, Commons, Host v1 gates, F/P/U), mutation checks, gates, live smoke, AdminUI drive. +- Tests: NM, Runtime facade + client, codecs, F/P/U, both recorded-v1 gates, manifest — committed; mutation checks done. +- Next: phase gates (A1/H2/X0 running), solution-wide suites, live smoke (`conditions_smoke.py` remote ack), AdminUI drive. + +## A2b — what changed + +- **Contract (§4.2 numbers as planned).** `rpc CallConditionMethod(ConditionMethodRequest) returns (ConditionMethodResponse)`, + appended 8th; request fields 1–8, response 1–4 exactly §4.2. `method` is a single bit of `DataConditionMethods` + (1 Acknowledge, 2 AddComment, 4 Confirm — §4.2 left the values open; the same values are the `methods` / + `supported_methods` masks). `state` reuses `DataWriteState` (1 RejectedBeforeDispatch, 2 applied/scripted + `DriverConfirmedSuccess`, 4 native `AcceptedUnconfirmed`, 5 `OutcomeUnknown`). Codecs in `DataConditionProtoMapper`. + `DataConnectionEndpoints.Methods` lists it; the codec pins moved 7 → 8. +- **Negotiation.** The host refuses `CallConditionMethod` FAILED_PRECONDITION unless the call negotiated `conditions` AND the + origin is condition-capable (`ConditionsNegotiated`) — a header-less / history-only / v1 caller never reaches the origin. + Bits 128/256 travel only with field 17 (`DataOperationSets.ConditionGrants` = 64|128|256: stripped from capabilities + and metadata on a non-negotiated call; the decoder drops them without field 17). +- **Bits.** `Understood` += AlarmAcknowledge|AlarmConfirm, `Reserved` = AlarmShelve only, validator `KnownOperations`, + `Implemented(target)` (`ConditionMethodsServable`), AdminUI `AuthorableOperations`. `DataCapabilitiesProvider` and + `CanPublishCapabilities` strip the method bits off-Primary (like Write). `DataConditionCapabilities.Methods` = the + methods the caller's exports grant (0 off-Primary / unservable); `ConditionInfo.supported_methods` per condition = + kind support (native: Ack|AddComment) ∩ the principal's export grants on its placements, minus Ack/AddComment for a + Galaxy native condition without the opt-in (`LocalExportCatalog.MethodsFor`). +- **Origin facade** (`LocalDataServices.ConditionMethods.cs`, `LocalDataConnection : IDataConditionMethodService`). Order, + each refusal `RejectedBeforeDispatch` with no state change: servable → catalog ready (+ target role) → **Primary** + (`BadInvalidState`) → expected serving incarnation → budget → caller usable → placement resolves + (`TryResolveConditionPlacement`) AND an export grants the method's bit on it (else `BadNodeIdUnknown`, existence not + disclosed) → origin ACL `AlarmAcknowledge`/`AlarmConfirm` on the **placement's** subject (a UNS placement ⇒ its equipment; + `BadUserAccessDenied`) → native Confirm (`BadNotSupported`) → **Galaxy opt-in** (`BadUserAccessDenied`) → registry → + node manager. +- **Node manager** (`OtOpcUaNodeManager.ConditionMethods.cs`). `TryExecuteConditionMethod` takes `Lock` and checks: exists, + Warm Standby, `NativeAlarmAckPrimaryGate` (both kinds), method supported, **activation marker** + (`ConditionIncarnation` + per-condition sequence; mismatch ⇒ `BadEventIdUnknown`); then invokes the condition's + **wrapped** method `OnCall` (the `WireMethodTransitionReporting` / `ReportAfterMethod` wrapper → SDK handler → + `HandleNativeAlarmAck` / `HandleAlarmCommand`) with the condition's current EventId and an internal + `RemoteConditionMethodContext` (a `ServerSystemContext` carrying a role-less `RoleCarryingUserIdentity` for the service + principal + its `ApiKeyId`). `AlarmCaller` skips `EvaluateAlarmCommandGate` only for that context type AND only for the + very condition it was built for; Warm Standby, Primary gate, native preflight (#760/#765) and the routers run unchanged. + So the SDK path and the remote path share one body: one event, the native Confirmed/Retain re-assert, `NativeAlarmAck` + (OperatorUser = principal, `ApiKeyId` = service key — the Galaxy ack identity lookup of §6), an unchanged `AlarmCommand` + (User = principal, Comment = the Part 9 comment), `ClientUserId` = principal. Never waits under `Lock`. +- **Operation registry.** A per-serving-incarnation `WriteOperationRegistry` (4096 entries, 8 MiB, retention 5 min) keyed + (principal, operation id) with a SHA-256 of (placement, method, expected marker, comment) — never the audit text. A + duplicate joins (awaits/returns the stored outcome, audited `Joined`); the same id with another call ⇒ `BadInvalidArgument`. +- **Consumer client** (`GrpcDataConnection.ConditionMethods.cs`, `IDataConditionMethodService`). Deadline = + min(remaining budget, `ConditionMethodTimeout` — the mapping's `ConditionMethodTimeoutMilliseconds`, default 5 s). Only + a Primary endpoint that advertised the method and serves `expected_serving_incarnation` is eligible. After the request + is handed to the transport, any failure ⇒ `OutcomeUnknown` (`BadCommunicationError`) and **no other endpoint is tried**; + a FAILED_PRECONDITION/UNIMPLEMENTED/INVALID_ARGUMENT/PERMISSION_DENIED answer ⇒ `RejectedBeforeDispatch`. +- **Audit (§6).** `IDataConnectionAuditLog` (default `LoggerDataConnectionAuditLog`, category + `ZB.MOM.WW.OtOpcUa.DataConnections.Audit`): principal, key id, placement address, operation id, method, outcome, + joined, sanitised `on_behalf_of` (Cc/Cf/Zl/Zp/unassigned and unpaired surrogates removed, capped at 128 chars without + splitting a pair). The text reaches nothing else: `OriginConditionMethodCall` has no field for it. +- **Galaxy (§6, Q2).** `LocalConditionPlacement.DriverType` (from the backing driver at compile) + `IsGalaxy`; + `ExportRule.GalaxyServiceAck` = `AllowGalaxyServiceAck && AlarmAcknowledge`; AdminUI export editor checkbox "Allow + remote acknowledge of Galaxy alarms" (disabled unless AlarmAcknowledge is ticked) with the secret-path hint. +- **Capacity warning at the deploy gate (Q2 of A2a).** `DataConnectionValidator.DeployWarnings` (= `ConditionCapacityWarnings`) + is logged non-blocking by `AdminOperationsActor.StartDeployment`, the established deploy-gate warning channel (the + validator's error list has none). The AdminUI mappings panel keeps showing it. +- **Metric.** `otopcua.dataconn.condition_methods{method,outcome}`. + +## A2b — decisions + +1. **One body, two callers.** The remote path calls the SAME wrapped SDK `OnCall` a local client's call runs, rather than + re-implementing apply + report: §5.6's "factored out of `HandleNativeAlarmAck` + `ReportAfterMethod` so neither goes + around the other" is met by making the session gate the only thing that differs (`AlarmCaller`). +2. **The activation-marker incarnation is NM's `ConditionIncarnation`** (the A1 open question): it is what the stream + carries and what changes on any NM restart; the serving incarnation is checked separately + (`expected_serving_incarnation`). +3. **Ungranted ≡ unknown placement** (`BadNodeIdUnknown`): a caller without the export grant learns nothing; with the grant, + an ACL or Galaxy refusal is `BadUserAccessDenied` (§6 names it). +4. **Remote methods are Primary-only for both kinds**: the Runtime checks the serving role and NM applies + `NativeAlarmAckPrimaryGate` to scripted conditions too (local scripted calls are unchanged). +5. **No state applied on a refusal**: NM refusals return before `OnCall`; SDK refusals (bad EventId etc.) fail before the + SDK applies; the facade maps every non-applied verdict to `RejectedBeforeDispatch`. + +## A2b — deviations (for the reviewer) + +- **"Control NotReady" (A2a decision 1, restated).** §5.1 says the stream sends a `Control NotReady` until the origin is + ready; **the implementation sends no such control** — `DataStreamControlKind` has no `NotReady` member and adding one is a + new v1-decoder shape. Readiness is expressed by withholding `snapshot_complete`; the item retakes the snapshot (≥ 1 s apart) + once apply-complete + Primary. Plan text and implementation disagree; the reviewer should either accept this and amend + §5.1 or schedule the kind in a later phase (Q1). +- **`ConditionMethodTimeoutMilliseconds` is enforced by the consumer client** (`GrpcDataConnection.ConditionMethodTimeout`, + default 5 s, per-call deadline); binding the per-mapping value to the import is A3 (no consumer registry yet). The origin + enforces the request's `remaining_budget_ticks` (≤ 0 ⇒ `BadTimeout`, clamped to `UnaryTimeout`). +- **"Driver failure revert seen in the stream"** is proven at the node manager (the #760 revert is DriverHostActor's + `WriteAlarmCondition` re-projection: origin event + an unacked record with the bumped marker in the condition sink, + which is the hub's input); a full DriverHostActor + failing driver run is not part of A2b (not live-gated). +- **Bits 128/256 = AlarmAcknowledge/AlarmConfirm.** AlarmShelve (512) stays reserved (the brief's "Shelve" wording vs the + plan's table — the plan's names were used). +- **Standby refusal is two layers** (the TryExecute pre-check and the handler's own): mutating either alone is masked by the + other; mutating both turns the standby test red. # A2a (condition streaming) — progress log and evidence