Repository navigation
AutoID client: read a device's status without browsing - #4854
Merged
marcschier merged 3 commits intoOct 21, 2026
Merged
Conversation
ReadDeviceAsync browses the children of the device on every call, so polling the status of many readers costs a Browse and a Read per reader and cycle; AutoIdReadOptions.StatusOnly only narrows the Read. Add AutoIdClient.RefreshDeviceAsync(snapshot), which reads DeviceStatus and, when published, LastScanData, LastScanTimestamp and DeviceLocation again through the NodeIds the snapshot carries: one Read, no Browse, no client-side state. A stale snapshot surfaces the status of the Read: a bad DeviceStatus throws, a bad LastScanData is returned in LastScanStatus; the caller then reads the device again. Document the network cost of both calls in the XML docs, docs/AutoID.md and the client NugetREADME, and add strict-mock tests (no Browse issued) and end-to-end tests against the hosted AutoID server.
marcschier
approved these changes
Oct 20, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A new integration assertion assumes initial state on a shared reader, making it dependent on test execution order.
1 open issue
What changed in this PR
Adds snapshot-based AutoID polling, avoiding repeated discovery browses.
Changes:
- Adds
RefreshDeviceAsyncto refresh runtime values with one Read and no Browse. - Documents polling costs and stale-snapshot behavior.
- Adds strict-mock and hosted-server tests.
| File | Description |
|---|---|
| tests/Opc.Ua.AutoID.Tests/AutoIdRefreshDeviceTests.cs | Tests request shape, validation, errors and cancellation. |
| tests/Opc.Ua.AutoID.Tests/AutoIdReaderEndToEndTests.cs | Tests live refresh and stale NodeIds. |
| src/Opc.Ua.AutoID.Client/NugetREADME.md | Describes browse-free refresh. |
| src/Opc.Ua.AutoID.Client/AutoIdReadOptions.cs | Links read options to refresh. |
| src/Opc.Ua.AutoID.Client/AutoIdDeviceSnapshot.cs | Documents snapshot reuse. |
| src/Opc.Ua.AutoID.Client/AutoIdClient.Read.cs | Implements snapshot-based refresh. |
| docs/AutoID.md | Explains polling costs and recovery. |
Review effort: Balanced
ARefreshedSnapshotCarriesTheCurrentStatusAsync expected LastScanStatus to be UncertainInitialValue, which holds only while no other test of the fixture has scanned the optical reader. The fixture shares one host through OneTimeSetUp, and AScanThatEndsOnItsOwnLeavesTheReaderIdleAsync and OcrAndOpticalReadersScanTheirCodesAsync scan that reader and leave LastScanData Good; neither clearing the provider nor the fault resets it. The test passed only because NUnit runs it first alphabetically. Compare the refreshed status with the StatusCode the hosted LastScanData variable holds, so the result no longer depends on the order the tests run in.
marcschier
enabled auto-merge (squash)
October 21, 2026 04:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
A follow-up to #4825. It adds
AutoIdClient.RefreshDeviceAsync(AutoIdDeviceSnapshot, CancellationToken), which reads the variables of a reader device that change at runtime again through the NodeIds a snapshot already carries. It makes one Read and no Browse.Why
ReadDeviceAsyncbrowses the children of the device on every call. OPC 30010 makes most device variables and methods optional, so the browse is how the client finds out what this device publishes.AutoIdReadOptions.StatusOnlyonly narrows the Read. This is the point the Copilot review raised on #4825 (discussion). 1458af9 documented the behaviour, but a client that polls the status of N readers still pays N Browse and N Read requests per cycle. One Read per reader would do.AutoIdDeviceSnapshotalready carries what a poll needs:DeviceStatusId,LastScanDataId,LastScanTimestampId,DeviceLocationIdandMethods, all taken from that browse.RefreshDeviceAsyncuses them.Change
RefreshDeviceAsync(snapshot)readsDeviceStatusand, when the device publishes them,LastScanData,LastScanTimestampandDeviceLocation. That is one Read of one to four variables and no Browse. It returns a copy of the snapshot (with), and every other member, includingMethodsand the NodeIds, is unchanged.Stateless. The client keeps no cache. The caller holds the snapshot, as with the other companion clients (
PumpsClient.ReadPumpAsync,ScalesClient.ReadSnapshotAsync, and Robotics'RefreshAsyncon its handles). A poller callsReadDeviceAsynconce and then passes the snapshot toRefreshDeviceAsyncon every cycle.Stale snapshot. The snapshot is not validated against the server. If it no longer matches the device (the device or a variable was deleted, or the server assigned other NodeIds after a restart), the status of the Read surfaces:
DeviceStatus(for exampleBadNodeIdUnknown) is thrown asServiceResultExceptionwith that status;LastScanDatais returned inLastScanStatuswith a null value;LastScanTimestamporDeviceLocationleaves that member at its default.In each case the caller reads the device again with
ReadDeviceAsync. That also picks up optional variables and methods the device published after the snapshot was taken.Arguments. A null snapshot throws
ArgumentNullException. A snapshot without aDeviceStatusNodeId (not obtained fromReadDeviceAsync) throwsArgumentException. Neither one makes a service call.Docs. Covered in the XML docs of
ReadDeviceAsync,RefreshDeviceAsync,AutoIdReadOptionsandAutoIdDeviceSnapshot, indocs/AutoID.mdand in the clientNugetREADME.md. The wording maintainers gaveAutoIdReadOptionsin 1458af9 stays as it is, with one added sentence that points toRefreshDeviceAsync.docs/AutoID.mdstates the cost of each call:ReadDeviceAsync(reader)ReadDeviceAsync(reader, AutoIdReadOptions.StatusOnly)DeviceStatus,DeviceName)RefreshDeviceAsync(snapshot)The change is additive. No existing member changes behaviour, and there are no new dependencies. The MCP
autoid_read_devicetool still usesReadDeviceAsync, because a single MCP tool call has no snapshot to refresh.Tests
tests/Opc.Ua.AutoID.Tests:AutoIdRefreshDeviceTests(new, 7 tests) uses aMockBehavior.StrictISessionwithVerifyNoOtherCalls, so any Browse, BrowseNext or second Read fails the test:maxAge0), with the values mapped and the other members (Methods,DeviceName, NodeIds) unchanged;DeviceStatusNodeId throws with the Read's status (BadNodeIdUnknown);LastScanDatasurfacesBadNodeIdUnknowninLastScanStatus, and a bad timestamp or location resets those members;BadUnexpectedError;AutoIdReaderEndToEndTests(2 new tests against the hosted AutoID server over opc.tcp):ARefreshedSnapshotCarriesTheCurrentStatusAsync: a reader is read once, then faulted on the server. The refreshed snapshot showsErrorand the methods from the original browse.ARefreshOfAStaleSnapshotSurfacesTheStatusOfTheReadAsync: snapshots whose NodeIds the server does not know (as after a deletion).LastScanStatuscarriesBadNodeIdUnknown, and an unknownDeviceStatusNodeId throwsBadNodeIdUnknown.RefreshDeviceAsync, every strict-mock test that reaches the Read fails.LastScanDatastatus masked toBadNotFound(theReadDeviceAsyncconvention for optional variables),AStaleOptionalVariableSurfacesItsStatusWithoutThrowingAsyncand the end-to-end stale-snapshot test fail.Verification (local, macOS arm64, SDK 10.0.402 from
global.json)Head 2118c24 on OPCFoundation/master ac24123 (#4852), which includes the NUnit 5 migration (#4840). The new tests follow the NUnit 5 conventions in
docs/DeveloperGuide.md:Assert.ThrowsAsyncandAssert.MultipleAsyncare awaited, and the enclosing test returnsTask.Opc.Ua.AutoID.Testson net10.0: 315 passed, 0 failed (9 of them new).Opc.Ua.AutoID.Testsbuilds with-p:CustomTestTarget=net48with 0 warnings and 0 errors. Running net48 needs Windows, so the fork CI covers it.dotnet formatwhitespace, style and analyzers at--severity info, verify-no-changes on the changed.csfiles: no findings in the new code.The branch is based on OPCFoundation/master
ac24123dd(Await NUnit 5 Assert.ThrowsAsync/CatchAsync in the #4759 tests; fixes the master build #4852, the last master commit with a green build). Fork CI was not repeated on this head: earlier fork runs of this branch failed only in test projects outside this PR (the master build was broken by the NUnit 5 migration Update NuGet dependencies and migrate tests to NUnit 5 #4840 and fixed in Await NUnit 5 Assert.ThrowsAsync/CatchAsync in the #4759 tests; fixes the master build #4852; master is currently broken again inOpc.Ua.Core.Testsby Client: fewer allocations per request (shared timeout timer, pooled state machines, fewer buffer collections) #4849). The upstream checks of this PR test it against the current master.Related Issues
AutoIdReadOptionsin AutoID: the OPC UA for AutoID Devices companion SDK (OPC 30010) #4825.docs/AutoID.md. There is no textual overlap with the client section changed here.Checklist