Joseph Doherty 8c28506d96 fix(dataconn): #1026 name every origin reset cause; stop binding checks invalidating live sources; renew cohort leases in batches
Gate #1026 (2048 projected items, rig seed --scale 2048) still failed after #1115. Three defects, found by
first making the origin and the consumer say why:

Diagnostics (origin + consumer)
- SourceInvalidationReason (bounded enum, classified from the publisher's reason constants): counted per
  reason (`otopcua.dataconn.source.invalidations{reason}`, `Invalidate.<Reason>` in SourceIngressDiagnostics),
  recorded on the source and logged at Debug (PartitionedSampleHub.Logger).
- An interest lease records why it stopped; the origin Subscribe stream's Reset text names it ("Source
  invalidated (<reason>).", "Source retired.", "Source interest released.", "Source routing changed.",
  "Source partition reset.", "Source binding replaced.") instead of always "Source change history expired.";
  logged at Information (Released at Debug). The texts are for people/counters only: the consumer classifies
  them into ResetSourceInvalidated / ResetInterestLost (no peer branches on them; the rig probe whitelist is
  updated).
- Consumer: renewal started/succeeded/failed/budget/slot counters, RenewalFail.<point> and
  AttemptEnd.<reason> (bounded, constant keys).

1. Origin: a binding check invalidated live sources. The driver actor's source-binding retry re-walks every
   desired reference (offset 0, every <= 30 s once any one failed); for an already-bound reference it took the
   source's serialization gate, and when the poll thread was publishing that source both sides invalidated it
   (BindingContention / SerializationContention) and reset every origin stream holding it. Live s1026-c: the
   only invalidation reasons were those two (5+5 during the open, recurring every ~30 s). EnsureDriverBinding now
   answers an already-bound, current source without the gate. Live after: 0 BindingContention.

2. Consumer: per-item metadata lease renewal could not keep up. Each projected item renewed its 15 s lease with
   its own capabilities + GetMetadata pair holding a 256 KiB unary reservation; at the default 1 MiB budget four
   ran at once and the rest retried on the next 250 ms tick (~16 items/s). Live s1026-d: 155 703 renewals
   started, 153 019 refused by the unary budget, 2 564 committed; ~1900 of 2048 items stood down
   BadUserAccessDenied; 0 recovered after the origin restart. RemoteNamespaceResolver.RenewExactBatchAsync renews
   many items with one capabilities call and one GetMetadata per origin MaxBatchItems (the single-item renewal is
   now the batch of one: same checks, lease bound and commit); a cohort renews every due item of a tick in
   batches of 128, and the between-attempt renewal (every item after an origin restart) is batched too.

3. Consumer: two demands of one node in one cohort deadlocked the batch: the second joined (#969) the first's
   claim, and the batch waited for the joiner before publishing its verdict. The batch now publishes first.

Live (OrbStack rig, 160 + 1888 items, 4 Hz churn, SOURCE pair restart): s1026-f run 1 open 10.2 s, recovery
1.5 s, 0 resets of any kind; s1026-h run 2 PASS (open 3.1 s, recovery 3.6 s, 0 resets, no history-expired or
source-invalidated log line). Remaining (not fixed here): s1026-h run 1 recovered only 852 of 1888 large-mapping
items after the restart: their renewals fail in the catalog cache's predecessor-chain bound
(RenewalFail.Cache.PredecessorChain 81 163).

Tests: GrpcData1026BindingContentionTests (fails without the fast path), GrpcData1026RenewalBatchWireTests
(one tick renews all due items in one metadata call - fails with per-item renewals; two demands of one node -
fails without the ordering fix), GrpcData1026ResetReasonTests.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-12-05 05:43:03 -05:00
Pin libplctag ab_server to v2.6.16 — real release tag + SHA256 hashes for all three Windows arches. Closes the "pick a current version + pin" deferral left by the #180 PR docs stub. Verified the release lands ab_server.exe inside libplctag_2.6.16_windows_<arch>_tools.zip alongside plctag.dll + list_tags_* helpers by downloading each tools zip + unzip -l'ing to confirm ab_server.exe is present at 331264 bytes. New ci/ab-server.lock.json is the single source of truth — one file the CI YAML reads via ConvertFrom-Json instead of duplicating the hash across the workflow + the docs. Structure: repo (libplctag/libplctag) + tag (v2.6.16) + published date (2026-03-29) + assets keyed by platform (windows-x64 / windows-x86 / windows-arm64) each carrying filename + sha256. docs/v2/test-data-sources.md §2.CI updated — replaces the prior placeholder (ver = '<pinned libplctag release tag>', expected = '<pinned sha256>') with the real v2.6.16 + 9b78a3de... hashes pinned table, and replaces the hardcoded URL with a lockfile-driven pwsh step that picks windows-x64 by default but swaps to x86/arm64 by changing one line for non-x64 CI runners. Hash-mismatch path throws with both the expected + actual values so on the first drift the CI log tells the maintainer exactly what to update in the lockfile. Two verification notes from the release fetch: (1) libplctag v2.6.16 tools zips ship ab_server.exe + plctag.dll together — tests don't need a separate libplctag NuGet download for the integration path, the extracted tools dir covers both the simulator + the driver's native dependency; (2) the three Windows arches all carry ab_server.exe, so ARM64 Windows GitHub runners (when they arrive) can run the integration suite without changes beyond swapping the asset key. No code changes in this PR — purely docs + the new lockfile. Admin tests + Core tests unchanged + passing per the prior commit.
2026-04-20 00:04:35 -04:00

OtOpcUa

OPC UA server (.NET 10, AnyCPU) that exposes a fleet of industrial data sources under one OPC UA address space, with two namespaces: a Raw device tree and a UNS (Area → Line → Equipment) tree that references it. Configuration is authored and deployed from a Blazor AdminUI; nodes run as Akka.NET clusters (redundant pairs) and the same OtOpcUa.Host binary serves the admin and driver roles.

Drivers (in-process): AVEVA System Platform Galaxy (via the sibling mxaccessgw gateway), Modbus TCP / RTU-over-TCP, Siemens S7, Allen-Bradley CIP (ControlLogix / CompactLogix), Allen-Bradley Legacy (SLC 500 / MicroLogix), Beckhoff TwinCAT (ADS), FANUC FOCAS, Heidenhain LSV2 (read-only), OPC UA Client (gateway), MQTT (plain JSON + Sparkplug B), MTConnect Agent, SQL poll (SQL Server / Postgres / Oracle / MySQL / ODBC), plus the Calculation pseudo-driver (script-computed tags).

A cross-platform client stack (.NET 10) — shared library, CLI, and Avalonia desktop app — connects to any OPC UA server.

Architecture

          OPC UA clients (Client CLI / UI, ScadaBridge, 3rd-party)          AdminUI (Blazor)
                                  |                                               |
                                  v                                               v
   +--------------------------------------------------------------------------------------+
   |  OtOpcUa.Host (.NET 10) — role-gated: admin (AdminUI + control plane), driver (OPC UA) |
   |    OPC UA server: Raw ns (https://zb.com/otopcua/raw) + UNS ns (.../otopcua/uns)       |
   |    virtual tags · scripted alarms · historian · redundancy (Akka.NET pair)             |
   +--------------------------------------------------------------------------------------+
      |       |     |    |      |       |      |      |        |      |      |     |
   Galaxy  Modbus  S7  AbCip AbLegacy TwinCAT FOCAS Heidenhain OpcUa  MQTT MTConnect Sql
      |                                                       Client
      v                                         Historian backend: HistorianGateway (default)
   mxaccessgw (sibling repo, gRPC)                                | SQL Server | QuestDB
      |
      v
   MXAccess COM (x86 worker, on the AVEVA box)
  • Two namespaces, one source. Each device value comes from its Raw tag; UNS equipment variables reference Raw tags and mirror the same value/quality/timestamp. Reads, writes, alarms and history work through either NodeId. See docs/Raw.md and docs/Uns.md.
  • Clusters and meshes. Central (admin) and site (driver) clusters talk over gRPC with per-cluster PSKs; each 2-node cluster elects a Primary. See docs/Redundancy.md.
  • gRPC data connections. Nodes and clusters can map each other's Raw/UNS branches for browse, read, write and subscribe. See docs/DataConnections.md.
  • Galaxy is the only driver with an external runtime: it speaks gRPC to a separately installed mxaccessgw (sibling repo ~/Desktop/MxAccessGateway), which owns the MXAccess COM apartment and the x86/STA constraint. Everything in this repo is platform-agnostic .NET 10.

Prerequisites

  • .NET 10 SDK.
  • SQL Server for the central configuration database (ConfigDb). Driver-only nodes can run without it, fed by their cluster's config mesh.
  • Galaxy only: a running mxaccessgw — see docs/v2/Galaxy.ParityRig.md.
  • History (HistoryRead, alarm history, continuous historization): one backend, chosen with ServerHistorian:Backend — Gateway (default; a separately deployed ZB.MOM.WW.HistorianGateway in front of AVEVA Historian), SqlServer, or QuestDb. See docs/Historian.md.

Quick Start

dotnet build ZB.MOM.WW.OtOpcUa.slnx
dotnet test  ZB.MOM.WW.OtOpcUa.slnx --filter "Category!=E2E&Category!=LiveIntegration"

Unit suites are tests/**/*.Tests; *.IntegrationTests need their Docker fixtures, and DB-backed tests need the central SQL Server — see infra/README.md.

Local rig (recommended). The docker-dev/ stack runs a central admin+driver pair, SQL Server, migrations and seed data, behind Traefik:

docker-dev/compose.sh up -d --build

AdminUI at http://localhost:9200 (login disabled on the rig); OPC UA at opc.tcp://localhost:4840 (central-1) and :4841 (central-2). Deploy from /deployments before drivers start. See docker-dev/README.md.

Bare host. dotnet run --project src/Server/ZB.MOM.WW.OtOpcUa.Host with OTOPCUA_ROLES=admin,driver (or Cluster:Roles) and a reachable ConfigDb.

Transport security is set by OpcUa:EnabledSecurityProfiles (None, Basic256Sha256Sign, Basic256Sha256SignAndEncrypt; all three when the key is absent). See docs/security.md.

Install as a Windows Service

scripts/install/Install-Services.ps1 installs the single OtOpcUaHost service; -Roles sets its roles. mxaccessgw and the HistorianGateway are installed separately.

.\scripts\install\Install-Services.ps1 `
    -InstallRoot 'C:\Program Files\OtOpcUa' `
    -ServiceAccount 'DOMAIN\svc-otopcua' `
    -Roles admin,driver

See the script header and docs/ServiceHosting.md for all options, including Traefik and the out-of-process script worker isolation.

Client CLI

CLI="dotnet run --project src/Client/ZB.MOM.WW.OtOpcUa.Client.CLI --"
$CLI connect   -u opc.tcp://localhost:4840
$CLI browse    -u opc.tcp://localhost:4840 -r -d 3
$CLI read      -u opc.tcp://localhost:4840 -n "ns=<raw-ns>;s=Plant/Modbus/dev1/Speed"
$CLI write     -u opc.tcp://localhost:4840 -n "ns=<raw-ns>;s=Plant/Modbus/dev1/Speed" -v 42
$CLI subscribe -u opc.tcp://localhost:4840 -n "ns=<raw-ns>;s=Plant/Modbus/dev1/Speed" -i 500

Raw NodeIds are s=<RawPath>; UNS NodeIds are s=<Area>/<Line>/<Equipment>/<Name>. Browse first to find the namespace indexes. The CLI also covers history reads, alarms and redundancy — see docs/Client.CLI.md, docs/Client.UI.md, and the per-protocol driver CLIs in docs/DriverClis.md.

Documentation

docs/README.md is the full documentation index.

Architecture and data path

Topic Doc
OPC UA server composition, driver dispatch docs/OpcUaServer.md
Address space layout docs/AddressSpace.md
Raw device tree (/raw) docs/Raw.md
Unified namespace (/uns) docs/Uns.md
Read / write dispatch docs/ReadWriteOperations.md
Incremental sync and surgical deploys docs/IncrementalSync.md
Driver lifecycle and infrastructure contracts docs/DriverLifecycle.md
gRPC data connections between nodes and clusters docs/DataConnections.md
Redundancy, clusters and meshes docs/Redundancy.md
Telemetry docs/Telemetry.md

Scripting, alarms and history

Topic Doc
Virtual tags (incl. out-of-process script runner) docs/VirtualTags.md
Script editor (Monaco + Roslyn) docs/ScriptEditor.md
Scripted alarms docs/ScriptedAlarms.md
Native alarms and OPC UA conditions docs/AlarmTracking.md
Alarm historian store-and-forward docs/AlarmHistorian.md
Historian backends (Gateway / SQL Server / QuestDB) docs/Historian.md

Operations

Topic Doc
Configuration (appsettings + env vars) docs/Configuration.md
Service hosting and role gating docs/ServiceHosting.md
Security (transport, LDAP, API keys, ACLs) docs/security.md
ZTag / SAPID uniqueness (reservation ledger retired) docs/Reservations.md
AdminUI docs/v2/admin-ui.md
Test and deployment infrastructure infra/README.md
Dev environment docs/v2/dev-environment.md

Drivers

Topic Doc
Driver index and capability matrix docs/drivers/README.md
Galaxy docs/drivers/Galaxy.md
Modbus · S7 · AbCip · AbLegacy · TwinCAT · FOCAS Modbus · S7 · AbCip · AbLegacy · TwinCAT · FOCAS
Heidenhain · OPC UA Client · MQTT · MTConnect · Sql · Calculation Heidenhain · OpcUaClient · Mqtt · MTConnect · Sql · Calculation
Test Connect probes docs/drivers/TestConnectProbes.md
Driver specs (design reference) docs/v2/driver-specs.md
Galaxy parity rig and performance ParityRig · Performance

Design history

docs/v2/ holds the v2 plan and decision log, and docs/plans/ the dated design and implementation plans. The original v1 single-driver docs are archived under docs/v1/ (historical only; v1 retired 2026-04-30). Open work is tracked in Gitea issues on dohertj2/lmxopcua.

License

Internal use only.

S
Description
No description provided
Readme 118 MiB
Languages
C# 74.4%
JavaScript 19.3%
Python 2.6%
HTML 2.3%
PowerShell 0.7%
Other 0.6%