Files
lmxopcua/docs/plans/evidence/grpc-data-ext/A2.md
T

114 lines
9.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# A2a (condition streaming) — progress log and evidence
Stage A2a of phase A2 in `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md` (revision 7): condition items on
Subscribe, root-scoped `condition_scope`, origin streaming from the A1 `ConditionStateHub`, the `AlarmSubscribe` bit end to end,
the `AddDataConnectionConditions` migration. Condition METHODS are stage A2b (a later agent, same worktree `a2-wire`).
## Progress log (resume from here)
- **Done:** `Understood` += AlarmSubscribe (`a74a1aee`); config slice — migration/validator/AdminUI/F-P-U tests (`ac945563`,
`ee1556ac`, `6272c7cf`, helper agent); contract + codecs (`73142e52`); origin streaming + host negotiation + consumer decode
(`5b03c8a2`); Runtime R tests `GrpcDataConditionStreamTests` 12/12 ×5 (`14ab6be3`).
- **In progress:** Commons codec/reservation tests; Host wire tests (header-less never arm 9) + v1 gates.
- **Next:** manifest key A2; gates; live smoke; docs.
## What changed
- **Contract (§4.2 numbers as planned).** `CapabilitiesResponse.conditions = 17` (`ConditionCapabilities{root_scope_items=1,
methods=2, max_conditions=3}` — §4.2 left these unnumbered), `SubscriptionItem.condition_scope = 4` (`ConditionScope`),
`SubscriptionFrame` arm 9 `condition_states` (`ConditionStates`, `ConditionState`, `ConditionInfo`, `ActivationMarker`,
exactly §4.2). Domain types in `Core.Abstractions/DataConnections/DataConditionContracts.cs`; codecs
`Commons/DataConnections/DataConditionProtoMapper.cs`. `GrpcDataConditionCodecTests` replaces the X0 tripwire for 17/4/9.
- **Negotiation.** `SupportedFeatures = History | Conditions`. Effective `conditions` = header ∩ origin-servable
(`caps.Conditions` present). Without it: field 17 and bit 64 are stripped from capabilities, bit 64 from metadata, and
every `condition_scope` is cleared from incoming stream commands BEFORE decode (a v1 server ignores field 4, so the item
is the v1 value item it would have been) — the session can therefore never produce arm 9 for a header-less stream; the
`GrpcDeliverySink` refuses a condition frame on such a stream as defence in depth.
- **Origin streaming.** `LocalDataServices.Conditions.cs` (servability, capabilities, `AuthorizeConditionItem`),
`ConditionItemStream.cs` (per-item producer, the A1 replay contract), `DataSubscriptionSession.Conditions.cs` (items,
activation after the ack is delivered, the bounded condition queue, priority selection), `OpcUaServer/OriginConditionSource.cs`
(`IOriginConditionSource` over `SnapshotConditions`, resolved like the H2 history port), `LocalExportCatalog.ListConditionScope`
/ `ConditionLimitFor` / `MaxConditionsFor`.
- Authorization (§5.5 service principal): servable, catalog ready, **Primary** (else `Unavailable`), caller usable,
root resolves, an AlarmSubscribe export of the root's realm contains it (else `Denied`); per placement the export rule
AND the origin ACL `CreateMonitoredItems` on the placement's scope. Re-listed only when the catalog object changes.
- Snapshot: listing first; `> limit` ⇒ begin frame with `total` and nothing else, no `SnapshotConditions` call; otherwise
slices of ≤ limit (NM clamps 5,000), begin frame (`total`, no records), ≤ 128-record / ≤ 256 KiB chunks,
`snapshot_complete` iff `IsSnapshotCompleteFor(slices)`.
- Deltas: per-partition cursors from `StartCursor`, skip a delta at/below its condition's slice watermark, removal only
for a condition sent before, `info` on first appearance.
- Catalog change: leaving conditions get a synthesised removal record (version = hub watermark), joining ones a small
snapshot sent as delta records.
- **`AlarmSubscribe` end to end.** `DataOperationSets.Understood`, validator known set, `Implemented(target)` (only while
servable), capabilities/metadata decode (bit 64 without field 17 is no grant; metadata never carries 64), migration
`AddDataConnectionConditions`, AdminUI checkbox + limits (helper agent: `ac945563`, `ee1556ac`, `6272c7cf`).
- **Consumer decode.** `GrpcDataConnection.ClientFeatures = History | Conditions` (the probe asks for both); `conditions`
is requested per endpoint iff it advertised field 17; arm 9 is decoded only on such a stream and only for a held handle.
No consumer registry (A3).
- **Metrics.** `otopcua.dataconn.conditions.items` (up/down), `…resyncs`, `…capacity_rejections`.
## Schema (helper agent)
`20261124170120_AddDataConnectionConditions`: `DataExport.MaxConditions` (1000), `DataExport.AllowGalaxyServiceAck` (false),
`RemoteNamespaceMapping.MaxConditions` (1000), `ConditionStaleTimeoutMilliseconds` (30000), `ConditionMethodTimeoutMilliseconds`
(5000), `ConditionSnapshotTimeoutMilliseconds` (30000); NOT NULL with SQL defaults, check constraints `> 0`. Up/down/up on
SQL Server `10.100.0.35,14330` (scratch DB, dropped), defaults verified in `sys.default_constraints`. Limits ride the artifact's
entity JSON (pre-A2 artifact parses with defaults) and are not in `DataConnectionScopeRevision`. Validator: MaxConditions
1..5000 (export and mapping), timeouts 1..3,600,000 ms, `DataExportGalaxyAckInvalid` (AllowGalaxyServiceAck only with
AlarmAcknowledge, so it stays false until A2b), and `DataConnectionValidator.ConditionCapacityWarnings` (Σ mapping
MaxConditions × 49 > 122,500 per consumer node; shown on the AdminUI mappings panel, not yet logged on deploy).
## Decisions
1. **No `Control NotReady` kind.** §5.1 says "until then the stream sends a Control NotReady"; `DataStreamControlKind` has
no such member and a new kind would be a new v1-decoder shape. Readiness is expressed by withholding `snapshot_complete`;
the item retakes the snapshot (≥ 1 s apart) once the hub reports apply-complete + Primary.
2. **Priority = control/ack at the head, then conditions, then the v1 queue in FIFO order.** A v1 control queued behind a
value keeps its v1 position (snapshot begin/end ordering depends on it); conditions overtake queued values and never a
control/ack that is next.
3. **Overflow.** Production is pull-based (≤ the 16-frame condition queue), so the session queue never overflows; the
hub is the buffer. A hub reader reset ⇒ the item re-snapshots (counted as a resync). A reset while the item's previous
snapshot is still undelivered ⇒ stream `Reset` ("Condition stream overflow; retry later.").
4. **Over capacity parks the item** (begin frame with `total` only) until the catalog object changes (a deploy).
5. **AlarmSubscribe without Subscribe opens a stream** when the call negotiated `conditions`; header-less keeps the v1
`PERMISSION_DENIED`.
6. **Origin ACL per placement = `CreateMonitoredItems`** (what v1 Subscribe checks; ReadOnly includes it).
7. **`ConditionStateRecord` gained `ConditionType` (`nsu=…;i=…`), `ConditionName`, `ConditionClass`** (ns=0 class id) for
`ConditionInfo` / `condition_class`; `BuildConditionRecord` fills them.
8. **Migration carries every A2 column**, including `AllowGalaxyServiceAck` and `ConditionMethodTimeoutMilliseconds`, so
A2b needs no schema change.
## Deviations
- The plan's `MaxConditions` per hold is the **export's** `MaxConditions` at the origin (the request carries no mapping
limit); the mapping's own `MaxConditions` is the consumer's admission (A3).
- The capacity warning helper is not wired into the deploy path (`AdminOperationsActor.StartDeployment`) — question Q2.
- AdminUI live verification on the rig's admin port is not done (see "Live smoke").
## Seams for A2b
- **Bits:** `DataOperationSets.Understood`/`Reserved` (`DataContracts.cs`), `DataConnectionValidator.KnownOperations`, and
`LocalDataServices.Implemented(target)` (gate on `ConditionsServable`) — add 128/256 together; `GrpcDataOperationToleranceTests`
pins the sets. `DataOperationAuthoring.AuthorableOperations` (AdminUI) for the checkboxes.
- **Columns already present:** `DataExport.AllowGalaxyServiceAck` (+ validator rule `DataExportGalaxyAckInvalid`, not in the
catalog `ExportRule` and not in the AdminUI yet), `RemoteNamespaceMapping.ConditionMethodTimeoutMilliseconds`.
- **Capabilities:** `DataConditionCapabilities.Methods` (0 today, `LocalDataServices.ConditionCapabilitiesFor`) and
`DataConditionInfo.SupportedMethods` (0 today, `ConditionItemStream.Map`).
- **Origin port:** `IOriginConditionSource` / `DeferredOriginConditionSource` / `SdkAddressSpaceSink` — put
`TryExecuteConditionMethod` beside `SnapshotConditions`, same deferred resolution.
- **Placement resolution:** `LocalExportCatalog.TryResolveConditionPlacement` (A1) + `AllowsConditionPlacement(principal,
placement, operation)`; the ACL pattern is `LocalDataServices.AuthorizeConditionItem`'s placement filter.
- **Activation marker:** the wire carries NM's `ConditionIncarnation` GUID verbatim in `ActivationMarker.incarnation` (A1 open
question: serving incarnation vs NM lifetime GUID — decide in A2b).
- **RPC:** proto has no `CallConditionMethod`; `GrpcDataConditionCodecTests` and `GrpcDataHistoryCodecTests` pin 7 methods.
Add it to `DataConnectionEndpoints.Methods` (H2 lesson) and refuse it without `conditions` (`ConditionsNegotiated`).
- **Recorded-v1 gates:** both fake and real origins now serve conditions (`conditions: true` default in
`V1CompatibilityHarness` / `RealOrigin`); extend them for the method shapes the same way.
## Questions (tracked, not asked)
- Q1: Should §5.1 drop "Control NotReady" (decision 1) or should a later phase add the kind?
- Q2: Wire `ConditionCapacityWarnings` into the deploy path (non-blocking log) — A2b or A3?
- Q3: The probe/consumer advertise `conditions` on every capabilities probe now; an origin that advertises conditions gets
the `conditions` header on every RPC of that consumer (no behaviour change until a condition item is opened).