diff --git a/docs/Configuration.md b/docs/Configuration.md index 47bf26ab6..4f4647e99 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -438,7 +438,7 @@ per cluster at `/clusters/{id}/audit`. It has no `appsettings` section — it is has a `ConfigDb` — but one schema property is worth recording here because it constrains how callers may write to it: -*Flush behaviour (#980 / review 05 H-2):* `AuditWriterActor` batches events and flushes every 5 s (or at 500). A flush that fails because the database did not answer **keeps** the batch and retries on the next tick; the buffer is bounded at 10 000 events (drop-oldest, with `OverflowDroppedCount` and a Warning). Rows the database rejects outright (e.g. a duplicate `EventId`) are still dropped individually. Events are lost only if the actor stops while the database is still down (logged at Error with the count). +*Flush behaviour (#980 / review 05 H-2):* `AuditWriterActor` batches events and flushes every 5 s (or at 500). A flush that fails because the database did not answer **keeps** the batch and retries on the next tick; the buffer is bounded at 10 000 events (drop-oldest, with `OverflowDroppedCount` and a Warning; since #1030 every drop is also exported as the meter counter `otopcua.audit.dropped{reason=buffer_full}` on the `ZB.MOM.WW.OtOpcUa` meter — alert on any non-zero rate, it means `ConfigAuditLog` is missing rows). Rows the database rejects outright (e.g. a duplicate `EventId`) are still dropped individually. Events are lost only if the actor stops while the database is still down (logged at Error with the count). - **`EventId` gives cross-restart deduplication, and the DB enforces it.** Each row carries the stable per-event `AuditEvent.EventId`, under a *filtered* unique index diff --git a/docs/DataConnections.md b/docs/DataConnections.md index ecf289f31..d11dab740 100644 --- a/docs/DataConnections.md +++ b/docs/DataConnections.md @@ -262,6 +262,15 @@ items or an origin is busy. per-parent child count). Removing a projected anchor, or swapping it for a root leaf, now also tombstones the anchor's own monitored node. Removing an imported condition purges only its own cached verdicts. +- **An unresolvable configured reference backs off (#1053, R-25).** `ConfiguredProjectedInterestOwner`'s shared 1 s sweep + used to re-run discovery for every desired reference with no lease, every second, for as long as the interest lasted. + A failed resolve now waits 1 s, doubling to a 30 s ceiling, before the sweep tries it again (an explicit interest change + still re-queues at once; a held lease is still re-checked every sweep). 60 s of an unreachable origin: 61 discoveries ⇒ 6. +- **Not changed, by decision (#1053, R-25):** the driver callback still publishes every value into the source hub whether + or not a gRPC consumer is subscribed. That cache is what a new subscription's first snapshot and a projected Read are + answered from (a gRPC-demanded source switches to acknowledged acquisition instead), so publishing "only with interest" + would leave a slow-changing tag with no first value. The R-3 trigger it fed is closed by the #994 re-queue above. + Perf harness: `GrpcDataWave3PerfTests` (`Category=Perf`, opt-in `OTOPCUA_GRPCDATA_PERF=1`). ### Mixed versions (X0 rollout) diff --git a/docs/DriverLifecycle.md b/docs/DriverLifecycle.md index bfd1ade7a..a079a834d 100644 --- a/docs/DriverLifecycle.md +++ b/docs/DriverLifecycle.md @@ -197,8 +197,11 @@ Things to know before touching any of this: - **Restart/Reconnect reply = the dispatch (#996, review H-3).** `AdminOperationsActor` handles `RestartDriver` / `ReconnectDriver` as synchronous receives: dispatch to the nodes, reply success, then write the `ConfigEdit` audit row on a pool - thread. An audit-write failure is logged (with op, driver, user, correlation) and never changes the reply — it used to answer - "failed" for a command already on its way (the operator retried ⇒ a second restart) and suspended the admin mailbox for a connect timeout. + thread. An audit-write failure never changes the reply — it used to answer "failed" for a command already on its way (the operator + retried ⇒ a second restart) and suspended the admin mailbox for a connect timeout. Since #1051 a TRANSIENT failure is retried on a + doubling backoff (1 s → 30 s cap, `MaxDriverAuditAttempts` = 6 attempts ≈ 30 s of outage); a write the ConfigDb REJECTS (the + coordinator's poison allowlist) is not retried; past the cap the record is logged at Error and dropped. At-least-once: a write + that committed but reported failure can repeat the row. - ⚠️ **The supervision route is the invisible one, and it was the worst.** There is **no** `SupervisorStrategy` anywhere under `src/Server`, so a child that throws gets Akka's default `Restart`. @@ -596,6 +599,10 @@ Warning / counter increment and a disable then re-enable of the same id never in holds the id in the `ChildHealthLedger` (`Forget` then `Readmit` on the next spawn), so the stopped child's late health publish cannot resurrect its diagnostics entry. +An operator **Restart** deliberately KEEPS the latch (#1053): the nodes stay in the address space, still Bad, and the +respawned incarnation is what must re-publish them. The stopped incarnation's `PostStop` comms-loss announcement re-latches +the current ref set and cancels the audit the old incarnation armed; the new incarnation's `Connected` re-arms it. + ### The connect path feeds the circuit breaker (R2-10 T10 closure) `IDriver.InitializeAsync` is routed through the capability invoker as @@ -627,8 +634,20 @@ before touching it: snapshot could never self-correct — only the discarded pipeline's `OnClosed` stamps the close — so a deploy during an outage would otherwise strand a false OPEN chip forever. This was unreachable while breakers never opened; the Initialize wrap made it reachable. -- `ConsecutiveFailures` stays 0 during a connect outage that FAILS fast — the tracker counts retry - attempts, and Initialize has none. The breaker-OPEN chip is the operator signal. +- **`ConsecutiveFailures` counts every failed attempt (#1052, decided).** It used to be fed only by the retry + strategy's `OnRetry`, so a no-retry capability (Write, AlarmAcknowledge, Initialize) never raised it — a connect outage + that failed fast read 0 on `/hosts` — and a retried call's LAST attempt was never counted. An innermost recorder now + counts each attempt that ends in a handled failure (never a caller cancellation or a `DriverOperationRefusedException`; + the pipeline timeout is counted once by `OnTimeout`), and any success resets it. A Tier A Read that fails 4 attempts + now reads 4, not 3. The non-idempotent write pipeline (cached under `host::non-idempotent`) records its failures and + breaker on the CALLER's host, where its success already reset them — it used to show a phantom `::non-idempotent` row. +- **Acknowledged acquisition has its own capability, `AcquisitionSubscribe` (#1047).** gRPC-data acquisition + (`IAcknowledgedAcquisitionSource.SubscribeAcquisitionAsync`) used to call the source unwrapped (OTOPCUA0001 suppressed), + because the Subscribe pipeline retries and a retry would orphan a physical handle `PendingAcquisition` alone owns. It now runs + through the invoker on `AcquisitionSubscribe`: never retries (the parser forces 0), tier timeout 30 s — deliberately longer than + the actor's 10 s acquisition timeout, which stays the effective bound — breaker 5 (Tier C: none). Polly's timeout awaits the + call and passes a completed result through, so the handle contract is unchanged; an open breaker fails the acquisition fast + without calling the source and the reservation is released like any failure. Keyed on the driver instance. - **The pipeline's own timeout is a failure (#999 / review K-6).** A call that outlasts its capability timeout (a blackholed device that never answers) used to reach the breaker as an `OperationCanceledException`, which both predicates excluded — every call burned the full timeout diff --git a/docs/Redundancy.md b/docs/Redundancy.md index ae15892e3..50f69a94f 100644 --- a/docs/Redundancy.md +++ b/docs/Redundancy.md @@ -504,6 +504,15 @@ two-node pair that choice means *any* crash of the oldest node is a full outage. that Akka's -1 is invisible to SCM recovery). Positive control: `sc stop` on the fixed build → clean `Stopped`, exit 0, no recovery. Under `auto-down` the *survivor* no longer needs this (it is never the one downed); the **downed** node still does. + + **Scripted form of that gate (#1030):** `scripts/install/tests/Test-ScmRestartAfterClusterExit.Windows.ps1`, run + elevated on the box hosting an installed `OtOpcUaHost` (the pair's current Primary for the default + `-Trigger Failover`, which pauses while the operator presses *Trigger failover* on the cluster redundancy page; + `-Trigger Command -TriggerCommand '…'` for an unattended trigger). It checks `sc.exe qfailure` has a restart action, + that the leave ends the process non-zero, logs **7031** and comes back `Running` under a new pid, and — as the + negative control — that `Stop-Service` stays `Stopped` with no 7031; `-KillControl` adds a hard-kill leg that + proves the SCM recovery config on its own. It never reconfigures the service and always leaves it running. Not + for the wonder boxes while remote access is on hold. 3. **Both peers listed in `SeedNodes`** on every node, **each node listing itself first**, so a restarted node can re-join via either peer and a node cold-starting while its peer is dead still forms the cluster. Without the self-first ordering it waits in `InitJoin` forever (auto-down removes the crash @@ -835,8 +844,12 @@ deployment green fleet-wide. Now: thread (`AckPersisted` is piped back; one write per node at a time, a newer ack for the same node waits behind it) and decides count/seal on the actor thread. With the ConfigDb slow or unreachable (no EF retry strategy ⇒ a connect timeout per call) the timeouts now overlap instead of serialising N × timeout of unresponsive mailbox; the deadline kicks its whole unpersisted backlog off at - once and decides as soon as the last write lands. The dispatch guard/seed and the terminal seal/fail/timeout writes are still - synchronous single calls (see the follow-up issue). + once and decides as soon as the last write lands. Since #1051 the dispatch guard + expected-set seed (and the #977 superseded + close) and the terminal Sealed/PartiallyFailed/TimedOut writes run off-thread too (`RunDbWork`): the coordinator enters a `Busy` + behaviour that stashes everything but the write's outcome, so each decision stays sequential while the dispatcher thread is free. + A failed terminal/seed write is rethrown on the actor thread when it reports back — the same restart-and-recover contract as the + old throwing `SaveChanges`. Recovery (`ApplyRecovery`, once per singleton start) runs the same work inline, so a failure there is + still a failed load retried on the backoff. - **Central records it without a status-model change.** `ConfigPublishCoordinator.PersistNodeAck` keeps the node's `NodeDeploymentState.Status = Applied` and writes `FailureReason = "Applied degraded: "` (`ConfigPublishCoordinator.IsDegraded` = Applied **and** a reason). The deployment still **seals** — diff --git a/docs/ServiceHosting.md b/docs/ServiceHosting.md index 9d26bbd6c..510361e8a 100644 --- a/docs/ServiceHosting.md +++ b/docs/ServiceHosting.md @@ -187,6 +187,9 @@ steps inside the window (a `data\` backup) and the host start-up to `/health/rea - `scripts/install/Install-Services.ps1 -Roles admin,driver` — installs `OtOpcUaHost`. - `scripts/install/Install-ScriptWorkerIsolation.ps1` — the ScriptWorker identity, ACLs and firewall rule (above); only for `Scripting:Runner` ≠ `InProcess`. - `scripts/install/Invoke-OtOpcUaInstallSwap.ps1` — upgrade/rollback folder swap with the isolation `-Reapply` + `-Verify` gate built in (lmxopcua#901), scoped so only the swapped-in folder is handled while the service is stopped (lmxopcua#905, above). +- `scripts/install/tests/Test-ScmRestartAfterClusterExit.Windows.ps1` — elevated, on the node's own box: checks that a node + leaving its cluster (manual failover) is restarted by the `sc.exe failure` recovery `Install-Services.ps1` sets, and that a + clean `Stop-Service` is not (#980/#1030; `docs/Redundancy.md` §"Recovery still depends on supervision"). - `scripts/install/Uninstall-Services.ps1` — stops + removes the host service. (The historian backend is the external HistorianGateway — not installed/removed by these scripts.) ## Logging diff --git a/docs/security.md b/docs/security.md index fac7da911..3ba21fc0d 100644 --- a/docs/security.md +++ b/docs/security.md @@ -851,7 +851,9 @@ Behaviours worth knowing before enabling it: the creation gate's own seam (`Permits` → `AuthorizeIfRequired`), which bypasses local grants — so an ungranted (e.g. Anonymous) subscription admitted with the flag off is **never** stood down by a tick or a deploy; only gRPC-data projected / imported-condition items, gated in both modes, can lapse (#972 — between - `8ad03e9c5` and the fix, the pass enforced grants with the flag off). Without the timer a key that expired by the + `8ad03e9c5` and the fix, the pass enforced grants with the flag off). With the flag off a local Raw/UNS item is + answered allow before the pass's memo (#1033: a 10k-item pass ~6.5–7 ms / ~1.4 MB ⇒ ~0.5–1 ms / ~0.2 KB; the same + shortcut in the per-request `Permits` was measured and not taken — a 1,000-node Read did not change). Without the timer a key that expired by the clock kept streaming until a deployment happened to land — **indefinitely** on a fleet that has been deployed once and left running, which is exactly the shape a production fleet settles into. @@ -1151,6 +1153,15 @@ device folder asks once per child. Those seams go through a per-`(session, node, decision cache (`SessionAclDecisionCache`), cleared wholesale whenever the authority generation advances. +**A warm cached decision on a UNS node allocates nothing (#1053, review U-8).** The UNS placement still runs on +every call, ahead of the cache (it reads live topology), but its products are cached: the node manager keeps each UNS +folder's live id chain on the folder instance (re-verified against the live ancestry on every call, rebuilt on any +mismatch), the generation hands out one segment array per folder/equipment path, and the authorizer keys its resolved +cache keys on that array. A reference variable is keyed on its own identifier (its scope is its split, the same key a +Path-kind lookup uses), and the caller's `DataCallerIdentity` is built once per session identity. Measured warm per call: +equipment folder 416 → 0 B, folder-owned virtual tag 592 → 0 B, UNS reference variable 680 → 0 B +(`NodeManagerUnsDecisionAllocationTests`). + ⚠️ **The cache holds the grant walk, not the decision.** Grants, principals and the trie are all fixed for the life of a generation, so memoizing the walk is sound. A key's `ExpiresUtc` passes with the *clock*, not with a deployment — so revocation and expiry are re-checked on every call, outside the diff --git a/scripts/install/tests/Test-ScmRestartAfterClusterExit.Windows.ps1 b/scripts/install/tests/Test-ScmRestartAfterClusterExit.Windows.ps1 new file mode 100644 index 000000000..f45c3f50d --- /dev/null +++ b/scripts/install/tests/Test-ScmRestartAfterClusterExit.Windows.ps1 @@ -0,0 +1,187 @@ +<# +.SYNOPSIS + Windows-executed gate for lmxopcua#980 / #1030: an OtOpcUaHost node whose ActorSystem terminates because it LEFT or was + DOWNED from its cluster (manual failover, endpoint step-down, auto-down) must be RESTARTED by Windows SCM recovery + (sc.exe failure), while an operator `sc stop` must stay stopped. + +.DESCRIPTION + Background (docs/Redundancy.md "Recovery still depends on supervision"): ActorSystemTerminationWatchdog exits the process + with code 1 on an unexpected termination, so SCM sees the service process die WITHOUT reporting SERVICE_STOPPED, logs + System event 7031 ("terminated unexpectedly") and runs the configured recovery action. Before #980 the node ended in a + clean stop (SERVICE_STOPPED, win32 exit 0) and SCM never restarted it. This script is the scripted form of the manual + windev gate of 2026-12-03. + + It runs ON the Windows box that hosts the service under test, elevated, against an INSTALLED OtOpcUaHost + (scripts\install\Install-Services.ps1). It never installs, uninstalls or reconfigures anything; it stops/starts only the + named service and always leaves it Running (finally block). + + Legs (each prints PASS/FAIL lines; exit 0 = all passed, 1 = a check failed, 2 = cannot run here): + 1. Recovery config sc.exe qfailure lists at least one RESTART action (what Install-Services.ps1 sets). + 2. Cluster exit the trigger makes this node leave / be downed. Expected: the service process exits (exit code 1 + when readable), SCM logs 7031 for the service, and the service is Running again under a NEW pid + within the recovery delay + -TimeoutSeconds. + 3. Clean stop (unless -SkipStopControl) Stop-Service: the service reports Stopped, NO new 7031 is logged and it + is NOT restarted within the first recovery delay + 15 s; then the script starts it again. + 4. Kill control (only with -KillControl) Stop-Process -Force: a crash is restarted (7031/7034). This proves the + SCM recovery config, not the watchdog — use it to tell "recovery not configured" from "the + node did not exit non-zero" when leg 2 fails. + + Triggers (-Trigger): + Failover (default) the script pauses and asks the operator to press "Trigger failover" on the AdminUI cluster + redundancy page (/clusters/{id}/redundancy). Manual failover asks the driver PRIMARY to leave, so run this on + the box hosting the current Primary of a two-node pair. Needs an interactive console. + Command runs -TriggerCommand (a PowerShell script block, as text) that makes THIS node leave or be downed, e.g. a + local admin tool; the script does not interpret it. + + Do NOT run this on the wonder boxes (vd03 / vq03 / vq04) while remote access is on hold — it is meant for windev or a QA + pair, run locally by an operator. It restarts the node it targets: a two-node pair fails over once (and again for + -KillControl); a single-node cluster has an outage for each leg. + + Run once per PowerShell host if in doubt; it uses nothing host-specific: + + pwsh -NoProfile -File scripts\install\tests\Test-ScmRestartAfterClusterExit.Windows.ps1 + powershell -NoProfile -ExecutionPolicy Bypass -File scripts\install\tests\Test-ScmRestartAfterClusterExit.Windows.ps1 -KillControl + pwsh -NoProfile -File ...\Test-ScmRestartAfterClusterExit.Windows.ps1 -Trigger Command -TriggerCommand '