Auto: twincat-2.3 — symbol-version invalidation listener

Closes #312
This commit is contained in:
Joseph Doherty
2026-04-25 22:16:05 -04:00
parent 569001364f
commit 4098d72bbb
6 changed files with 518 additions and 14 deletions

View File

@@ -172,17 +172,21 @@ the second pass issues zero new `CreateVariableHandleAsync` calls. It runs
under the standard `[TwinCATFact]` gate (XAR reachable; no `TWINCAT_PERF`
opt-in needed because 50 symbols is cheap).
**Staleness caveat**: handles can go stale after a TwinCAT online change
(POU edit + activate). Until PR 2.3 ships the proactive Symbol-Version
invalidation listener, the safety net is twofold: (1) the
`DeviceSymbolVersionInvalid` evict-and-retry path catches cases where the
descriptor moves but the symbol survives, and (2) operators can call
`ITwinCATClient.FlushOptionalCachesAsync` manually after a known online
change to wipe the cache without forcing a full reconnect. The bulk
Sum-read / Sum-write path remains on symbolic paths in PR 2.2 (the bulk
path's per-call symbol resolution is already amortised across N tags;
the perf delta vs. handle-batched bulk is marginal — tracked as a
follow-up for the Phase-2 perf sweep).
**Self-invalidation (PR 2.3)**: handle cache is now self-invalidating on
TwinCAT online changes. `AdsTwinCATClient` registers an
`AdsSymbolVersionChanged` event listener (Beckhoff's high-level wrapper
around the SymbolVersion ADS notification, IndexGroup `0xF008`) on connect;
when the PLC's symbol-version counter increments — full re-init after a
download / activate-config — the listener fires and wipes the handle cache
proactively. Three-layered defence in depth: (1) proactive listener
preempts the next read entirely on full re-inits, (2) the
`DeviceSymbolVersionInvalid` evict-and-retry path from PR 2.2 catches the
narrower "symbol survives but its descriptor moved" race, and (3)
operators can still call `ITwinCATClient.FlushOptionalCachesAsync` manually
for the truly-paranoid case. The bulk Sum-read / Sum-write path remains
on symbolic paths in PR 2.2 (the bulk path's per-call symbol resolution
is already amortised across N tags; the perf delta vs. handle-batched
bulk is marginal — tracked as a follow-up for the Phase-2 perf sweep).
## Follow-up candidates