Skip to content

Fix HistoryRead bit not set in Server object EventNotifier when history capabilities are enabled#3252

Merged
marcschier merged 6 commits into
masterfrom
copilot/fix-historyread-bit-server-object
Oct 22, 2025
Merged

Fix HistoryRead bit not set in Server object EventNotifier when history capabilities are enabled#3252
marcschier merged 6 commits into
masterfrom
copilot/fix-historyread-bit-server-object

Conversation

Copilot AI commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Problem

When implementing an OPC UA server with event history support, the HistoryRead bit (0x04) in the EventNotifier attribute of the Server object was not being set, even when AccessHistoryEventsCapability was configured to true in the ServerCapabilities. This prevented OPC UA clients from discovering that the server supports historical event reads on the Server object.

According to the OPC UA specification, when a server supports history read capabilities, the Server object's EventNotifier should have the HistoryRead bit set to indicate this capability to clients.

Solution

This PR implements a systematic approach to synchronize the Server object's EventNotifier with the configured history capabilities:

1. New Virtual Method in DiagnosticsNodeManager

Added UpdateServerEventNotifier() method that:

  • Reads the HistoryServerCapabilities configuration
  • Sets the HistoryRead bit (0x04) when AccessHistoryEventsCapability or AccessHistoryDataCapability is enabled
  • Sets the HistoryWrite bit (0x08) when any insert/update/replace event or data capability is enabled
  • Clears these bits when the corresponding capabilities are disabled
  • Is declared as public virtual to allow customization in derived classes

2. Automatic Initialization in ServerInternalData

Modified CreateServerObject() to:

  • Call GetDefaultHistoryCapabilities() to ensure history capabilities are initialized
  • Call UpdateServerEventNotifier() to update the Server EventNotifier based on the configured capabilities
  • This ensures the Server object's EventNotifier is properly set during server startup

3. Integration Test

Added ServerEventNotifierHistoryReadBit test in ReferenceServerTest.cs that verifies:

  • The Server object's EventNotifier can be read correctly
  • The correlation between history capabilities and EventNotifier bits
  • Proper handling of both AccessHistoryEventsCapability and AccessHistoryDataCapability

Example Usage

After this fix, servers with history capabilities enabled will automatically have the correct EventNotifier bits set:

// Configure history capabilities
var historyCapabilities = diagnosticsNodeManager.GetDefaultHistoryCapabilities();
historyCapabilities.AccessHistoryEventsCapability.Value = true;

// During server initialization, UpdateServerEventNotifier() is called automatically
// The Server object's EventNotifier will now have bit 0x04 (HistoryRead) set

For runtime updates:

// Modify capabilities after initialization
historyCapabilities.AccessHistoryDataCapability.Value = true;

// Manually trigger update
diagnosticsNodeManager.UpdateServerEventNotifier();

Compatibility

  • ✅ Backward compatible - no breaking changes to existing APIs
  • ✅ Virtual method allows for customization in derived classes
  • ✅ Automatic initialization works transparently for existing servers
  • ✅ All existing tests pass (23/23 ReferenceServerTests)
  • ✅ No security vulnerabilities detected

Addresses

Fixes the issue described in the original problem statement where setting AccessHistoryEventsCapability to true should result in the HistoryRead bit being set on the EventNotifier attribute of the Server object.

Co-authored-by: @romanett

Original prompt

This section details on the original issue you should resolve

<issue_title>HistoryRead bit in EventNotifier attribute not set in Server object in NETStandard SDK</issue_title>
<issue_description>### Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

We're implementing an OPC UA Server using the NETStandard SDK.
Event history is implemented and we set the HistoryRead bit on the
EventNotifier attribute on our "own" objects.
ServerCapability AccessHistoryEventsCapability is set to true.

From a connected UA client I can detect that the HistoryRead bit is set
on our own objects but not on the Server object.

Does anyone know what must be done to set this bit on the Server object?

Expected Behavior

I think setting ServerCapability AccessHistoryEventsCapability to true should result in the HistoryRead bit being set on the EventNotifier attribute on the Server object

Steps To Reproduce

No response

Environment

- OS:
- Environment:
- Runtime:
- Nuget Version:
- Component:
- Server:
- Client:

Anything else?

No response</issue_description>

<agent_instructions>Please fix this Issue in the ServerLibrary the File to modifiy is DiagnosticsNodeManager </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@romanett You need to override in the DiagnosticsNodeManager: https://github.com/OPCFoundation/UA-.NETStandard/blob/6dcee7ebf1f790d34c94883ff7572852086494f2/Libraries/Opc.Ua.Server/Diagnostics/DiagnosticsNodeManager.cs#L509

public HistoryServerCapabilitiesState GetDefaultHistoryCapabilities()

There seems to be a call missing to GetDefaultHistoryCapabilities. It would be apreciated to add this call in a PR and maybe make it a virtual method so you can override it in your sever.</comment_new>

Fixes #2081


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant

CLAassistant commented Oct 10, 2025

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ romanett
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix HistoryRead bit in EventNotifier for Server object Fix HistoryRead bit not set in Server object EventNotifier when history capabilities are enabled Oct 10, 2025
Copilot AI requested a review from romanett October 10, 2025 12:23
@codecov

codecov Bot commented Oct 10, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.00%. Comparing base (8152fee) to head (cebed75).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...pc.Ua.Server/Diagnostics/DiagnosticsNodeManager.cs 81.81% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3252      +/-   ##
==========================================
+ Coverage   57.85%   58.00%   +0.15%     
==========================================
  Files         365      365              
  Lines       79806    79829      +23     
  Branches    13882    13885       +3     
==========================================
+ Hits        46171    46307     +136     
+ Misses      29490    29387     -103     
+ Partials     4145     4135      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@romanett
romanett marked this pull request as ready for review October 13, 2025 04:41

@romanett romanett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The History Read / Write bits are correctly set now in the Server Object

@romanett
romanett requested a review from marcschier October 13, 2025 04:52
Comment thread Libraries/Opc.Ua.Server/Server/ServerInternalData.cs Outdated
@marcschier
marcschier merged commit 2d09e0f into master Oct 22, 2025
142 of 144 checks passed
@marcschier
marcschier deleted the copilot/fix-historyread-bit-server-object branch October 22, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HistoryRead bit in EventNotifier attribute not set in Server object in NETStandard SDK

4 participants