Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 10, 2025

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
Copy link

CLAassistant commented Oct 10, 2025

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 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 Copilot AI requested a review from romanett October 10, 2025 12:23
Copilot finished work on behalf of romanett October 10, 2025 12:23
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.71%. Comparing base (2bee7e1) to head (c3596e3).
⚠️ 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.74%   57.71%   -0.04%     
==========================================
  Files         365      365              
  Lines       79419    79443      +24     
  Branches    13865    13868       +3     
==========================================
- Hits        45862    45852      -10     
- Misses      29310    29331      +21     
- Partials     4247     4260      +13     

☔ 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
Copy link
Contributor

@romanett romanett left a comment

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
m_configuration);

// Initialize history capabilities and update Server EventNotifier accordingly
DiagnosticsNodeManager.GetDefaultHistoryCapabilities();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is already called in the next method

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