diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/IDataServices.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/IDataServices.cs index 575b0ecc3..cf9514bf7 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/IDataServices.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/IDataServices.cs @@ -262,6 +262,14 @@ public sealed record DataHistoryReadResult(string CorrelationId, uint StatusCode string? Diagnostic = null, bool ChunkContinues = false) : IDisposable { + /// + /// Consumer-side only, never on the wire (H3 review round 3): this BadTooManyOperations is the CONSUMER's own + /// assembly-budget refusal (the gRPC connection's chunk assembly or sub-batch split ran out of the request's byte + /// budget) — not an origin's refusal (e.g. its remainder budget), whose text may also mention a budget. A caller that + /// stops the request on a spent budget keys on this flag, never on . + /// + internal bool ConsumerBudgetRefused { get; init; } + public void Dispose() { foreach (var sample in Samples) sample.Dispose(); diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/ZB.MOM.WW.OtOpcUa.Core.Abstractions.csproj b/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/ZB.MOM.WW.OtOpcUa.Core.Abstractions.csproj index 4d2e7ef50..7eef12725 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/ZB.MOM.WW.OtOpcUa.Core.Abstractions.csproj +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/ZB.MOM.WW.OtOpcUa.Core.Abstractions.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.History.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.History.cs index fd0811b01..365da1766 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.History.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.History.cs @@ -259,7 +259,7 @@ public sealed partial class GrpcDataConnection : IDataHistoryService { // The per-request assembly budget is exhausted: this and every later node is BadTooManyOperations. _ = ReleaseOnEndpointAsync(selected, result.Continuation); - final[target] = new(result.CorrelationId, BadTooManyOperations, [], null, "History assembly budget exceeded."); + final[target] = new(result.CorrelationId, BadTooManyOperations, [], null, "History assembly budget exceeded.") { ConsumerBudgetRefused = true }; continue; } if (result.ChunkContinues) diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs index 9ef6da40e..987634c86 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedHistoryAccess.cs @@ -304,10 +304,13 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl continue; // its token (if any) is released in the finally } - if (answer.StatusCode == BadTooManyOperations && answer.Diagnostic?.Contains("budget", StringComparison.OrdinalIgnoreCase) == true) + if (answer.StatusCode == BadTooManyOperations && answer.ConsumerBudgetRefused) { - assemblyRefused[i] = true; // the connection's own share of the assembly budget ran out: - budgetExhausted = true; // no further origin call in this request (H3 review round 2) + // The connection's own share of the assembly budget ran out: no further origin call in this + // request (H3 review round 2). A typed marker, never the diagnostic text — an ORIGIN's refusal + // ("remainder budget is full") is a per-node answer, not a spent request (round 3, S4). + assemblyRefused[i] = true; + budgetExhausted = true; } long nodeBytes = 0; foreach (var sample in answer.Samples) nodeBytes += sample.Value.EstimatedRetainedBytes; diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs index eb624f742..da07939cb 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryWireTests.cs @@ -443,6 +443,34 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests }, localPermissions: 15, allowHistory: true, connectionSource: connections); } + [Fact(Timeout = 90000)] + [Trait("Phase", "H3")] + public async Task An_origins_budget_refusal_is_a_per_node_answer_and_never_stops_the_request() + { + // H3 review round 3 (S4): the stop keys on the consumer's typed marker, not on "budget" in the diagnostic — the origin's + // "remainder budget is full" refusal of A must not refuse B (sent in the next run) nor a Good answer after it. + await using var originServer = await HistoryOrigin.StartAsync(7, extra: 1); + using var origin = new LocalDataFixture(additionalRawNodes: 1, servingGeneration: 1, history: originServer.Port); + var connections = new HistorySwitchConnections(origin); + await WithComposedServer(origin, origin.Root, async (session, _, _, _, _, _, anchor) => + { + var client = (SessionClient)session; + var children = (await BrowseAll(client, anchor, 10)).Select(r => ExpandedNodeId.ToNodeId(r.NodeId, session.NamespaceUris)).ToArray(); + var first = await RawHistory(client, children[1], 3, default); + connections.Mode = HistoryMode.OriginRefusedFresh; + var calls = connections.HistoryCallSizes.Count; + var response = await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(RawDetails(3)), TimestampsToReturn.Both, false, + [new HistoryReadValueId { NodeId = children[0] }, new HistoryReadValueId { NodeId = children[1], ContinuationPoint = first.ContinuationPoint }], + TestContext.Current.CancellationToken); + var results = response.Results.ToArray()!; + results[0].StatusCode.Code.ShouldBe(StatusCodes.BadTooManyOperations.Code, "the origin refused A"); + StatusCode.IsGood(results[1].StatusCode).ShouldBeTrue("B is still read: an origin refusal is not a spent consumer budget"); + Values(results[1]).Count.ShouldBeGreaterThan(0); + (connections.HistoryCallSizes.Count - calls).ShouldBe(2, "both runs are sent"); + connections.Mode = HistoryMode.Pass; + }, localPermissions: 15, allowHistory: true, connectionSource: connections); + } + // ------------------------------------------------------------------------------------------------------------------ private static ReadRawModifiedDetails RawDetails(uint count) => new() @@ -481,7 +509,7 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests } } - public enum HistoryMode { Pass, Hang, Throw, Retired, Poison, BudgetRefused } + public enum HistoryMode { Pass, Hang, Throw, Retired, Poison, BudgetRefused, OriginRefusedFresh } /// /// One long-lived origin connection whose HISTORY path can be switched to never answer (then fault as a cancelled gRPC call, @@ -549,7 +577,11 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests throw new OperationCanceledException("lease retired"); case HistoryMode.BudgetRefused: return request.Items.Select(i => new DataHistoryReadResult(i.CorrelationId, 0x80100000u, [], null, - "History assembly budget exceeded.")).ToArray(); + "History assembly budget exceeded.") { ConsumerBudgetRefused = true }).ToArray(); + case HistoryMode.OriginRefusedFresh when request.Items.All(i => i.Continuation is null): + // The ORIGIN's own refusal, whose text also mentions a budget (LocalDataServices.History). + return request.Items.Select(i => new DataHistoryReadResult(i.CorrelationId, 0x80100000u, [], null, + "Origin history remainder budget is full; retry with a lower NumValuesPerNode.")).ToArray(); } var answers = await ((IDataHistoryService)inner).ReadAsync(request, cancellationToken); if (owner.Mode == HistoryMode.Poison)