fix(grpc-data): maxAge=0 projected reads served from an awaited origin read; origin refusals are access denials; Write/CreateMonitoredItems renew lapsed leases (#938, #939, #940)

#938: OtOpcUaNodeManager implements IReadAsyncNodeManager. A projected Value read whose maxAge the
cache cannot satisfy (0 always: Part 4 "read the source"; ScadaBridge's DCL and the Client CLI send
0) is served from IProjectedDataAccess.ReadNowAsync in the same request — same unary admission,
authenticated freshness-checked read and cache publication as ScheduleRead, pumped through the
unary budget, at most 5 s / request deadline − 250 ms, no Lock, no blocked thread. A lapsed lease
is renewed first and read in the same request. Previously every maxAge=0 read answered
BadWaitingForInitialData forever.

#939: RemoteNamespaceResolver.RenewExactOutcomeAsync reports Renewed/Refused/Failed. Refused only
for the origin's verdict (PERMISSION_DENIED call, Denied item, Metadata not granted, operation not
granted / not writable) ⇒ BadUserAccessDenied, held 5 s per node+operation unsent; transport and
other failures stay retryable. HistoryRead follows it.

#940: RenewLapsed accepts Write (gated on the local write role) and Subscribe. WriteAsync awaits the
renewal (≤ 4 s, ≤ half the timeout hint) then dispatches, BadResourceUnavailable unsent otherwise.
CreateMonitoredItems awaits renewals once per request (ICreateMonitoredItemsAsyncNodeManager) and
classifies each projected item PER ITEM outside Lock (lapse ⇒ BadResourceUnavailable, refusal ⇒
BadUserAccessDenied) — a refusal thrown from the item manager used to fault the whole request.

Red/green: 15 wire tests in GrpcDataProjectedOriginAccessWireTests (12 red on the pre-fix source,
controls green both ways); 4 existing tests updated where the first read is now Good. Evidence:
docs/plans/evidence/grpc-data-ext/938-939-940-948.md.
This commit is contained in:
Joseph Doherty
2026-12-01 19:55:49 -05:00
parent 4fcabdf24a
commit 62d9504868
15 changed files with 1151 additions and 131 deletions
@@ -0,0 +1,75 @@
# #938 / #939 / #940 / #948 — projected Read age, origin refusals, lapsed Write/Subscribe, consumed candidates
2026-12-01. Follow-ups of #920 and #922 (`920.md`, `fu922.md`). Consumer side of gRPC data connections.
## #938 — `maxAge = 0` never returned Good
**Root cause.** The projected Value Read (`OtOpcUaNodeManager.Read` pre-loop) served the cache only when `maxAge > 0`, and every
other case scheduled a fire-and-forget origin read and answered `BadWaitingForInitialData` (the sync SDK callback could not wait).
With `maxAge = 0` the cache is never eligible, so every read was `BadWaitingForInitialData`, forever.
**Who sends 0.** The Client CLI default (`read --max-age 0`) and **ScadaBridge's DCL**:
`RealOpcUaClient.ReadValuesAsync` (`src/ZB.MOM.WW.ScadaBridge.DataConnectionLayer/Adapters/RealOpcUaClient.cs:1546`) calls
`session.ReadAsync(null, 0, …)` for every Value read (`ReadValueAsync` delegates to it). Its other `ReadAsync` calls (lines 1687,
1992) read DataType/ValueRank/AccessLevel, not Value.
**Fix.** `OtOpcUaNodeManager` implements `IReadAsyncNodeManager` (forwarded by the SDK's `AsyncNodeManagerAdapter`): before the
unchanged sync `Read`, it serves every projected Value read the cache cannot satisfy from an awaited origin read
(`IProjectedDataAccess.ReadNowAsync` — the same admission, authenticated/freshness-checked read and cache publication as
`ScheduleRead`). A lapsed lease is renewed first (#922 classification) and read in the same request. Bounded by 5 s
(`ProjectedOriginReadWait`) and the request deadline − 250 ms; reads are pumped through the unary budget (the default 1 MiB budget
admits one read at a time). Unanswered / unservable ⇒ `BadWaitingForInitialData` as before; the caller's demand is re-checked at
serve time. The renewal no longer schedules a separate warming read.
## #939 — an origin refusal read as retryable
**Root cause.** `RemoteNamespaceResolver.RenewExactAsync` returned `bool`, so an origin that stopped granting the operation looked
exactly like an unreachable one (`BadResourceUnavailable`, 250 ms back-off, retried forever).
**Fix.** `RenewExactOutcomeAsync` → `ProjectedRenewalResult {Renewed, Refused, Failed}`. `Refused` only for the origin's own verdict:
the call answered `PERMISSION_DENIED` (as the cause of the connection's "no ready endpoint" failure), the item answered `Denied`, the
principal no longer holds Metadata, or the metadata no longer grants the operation (a write: or is not writable). It is answered
`BadUserAccessDenied` (Read, HistoryRead, Write, CreateMonitoredItems) and held 5 s (`LapseRefusalHold`) per node and operation,
unsent. `Unauthenticated`, unreachable, unready, capacity and timeouts stay `Failed` (retryable).
## #940 — Write / CreateMonitoredItems on a lapsed node
**Root cause.** Neither classified a refused acquire; both answered `BadUserAccessDenied`. CreateMonitoredItems threw it from the item
manager, which runs under the SDK's `Lock` and faults the WHOLE request.
**Fix.** `RenewLapsed` accepts Write (also gated on the local write role) and Subscribe. `OtOpcUaSdkServer.WriteAsync` awaits the
renewal (≤ 4 s, ≤ half the timeout hint) and dispatches; `BadResourceUnavailable` (unsent) when it cannot renew. CreateMonitoredItems:
`ICreateMonitoredItemsAsyncNodeManager` awaits the renewals once per request (≤ 4 s), then the sync override classifies each projected
Value item outside `Lock` (probe acquire; lapse ⇒ `BadResourceUnavailable`, refusal ⇒ `BadUserAccessDenied`) PER ITEM.
## #948 — orphan proof candidate for a consumed acquisition
**Decision: not intended.** A candidate exists to prove one SDK notification; a re-delivered acquisition the item already delivered
produces none (same value/status/timestamps ⇒ the SDK filter drops it), so the candidate and its shared budget charge lingered.
`ProjectedMonitoredItem` now remembers the last consumed acquisition (key only, no value). A complete snapshot of it, with nothing
queued since (no candidate, no queued loss, no rebind / client mode change / unmatched notification), renews health evidence and adds
no candidate. Any queue reset clears the memory, so a wrong skip can only cost an unproven notification + baseline request.
## Red / green (Runtime harness, real consumer SDK session + projection stack)
| Test (`Trait Issue`) | pre-fix | fix |
|---|---|---|
| 938 `A_max_age_zero_read_is_served_from_the_origin_in_the_same_request_every_time` | **FAIL** | pass |
| 938 `A_max_age_zero_batch_larger_than_the_unary_budget_is_pumped_and_fully_served` | **FAIL** | pass |
| 938 `A_max_age_zero_read_of_a_lapsed_node_renews_and_is_served_in_one_request` | **FAIL** | pass |
| 938 `A_max_age_zero_read_without_the_read_grant_is_denied_and_never_reaches_the_origin` (control) | pass | pass |
| 939 `An_origin_refusing_the_renewal…` × {ItemDenied, OperationNotGranted, PermissionDeniedCall} | **FAIL** ×3 | pass |
| 939 `An_unreachable_origin_for_a_lapsed_node_stays_retryable_not_denied` | **FAIL** (final read) | pass |
| 939 `An_origin_that_stops_granting_history_answers_a_lapsed_history_read_access_denied_unsent` | added after (pre-fix: `BadResourceUnavailable` by #922 design) | pass |
| 940 `A_write_to_a_lapsed_node_renews_on_demand_and_is_dispatched` | **FAIL** | pass |
| 940 `A_write_to_a_lapsed_node_whose_origin_is_unreachable_is_retryable_and_unsent` | **FAIL** | pass |
| 940 `A_write_to_a_lapsed_node_without_the_write_grant…` (control) | pass | pass |
| 940 `Creating_a_monitored_item_on_a_lapsed_node_renews_on_demand_instead_of_denying` | **FAIL** | pass |
| 940 `Creating_a_monitored_item_on_a_lapsed_node_whose_origin_is_unreachable_is_retryable` | **FAIL** | pass |
| 940 `Creating_a_monitored_item…without_the_subscribe_grant…` (control) | **FAIL** (request fault, not per item) | pass |
| 948 `A_redelivered_already_consumed_acquisition_leaves_no_orphan_candidate` | **FAIL** (1 orphan) | pass |
Updated (behaviour changed by #938, first read now Good): `Sdk_mapped_read_preserves…`, `Cold_sdk_read_publishes…`,
`New_primary_renews_same_monitored_item_after_a_prior_mapped_read(warmByRead)`, the #922 value-read test's second idle gap.
Not live-gated (no rig run in this change).