fix(grpc-data): A3a review r1 — buffered in-stream re-snapshots, late completion + stale-on-incomplete + bounded retry, Primary-pinned condition streams, node-wide host-cap ledger, runner hand-over after stop, metadata failure Unavailable; NM: revalidation through the imported gate, demand released first, rebuild unwires, instance-keyed promotion, incremental folder index, verdict TTL + expiry, removal RefreshRequired, chunked refresh/replay, folder-only demand

Runtime tests: B1 multi-frame + capacity re-snapshot, B2 late completion / stale-on-incomplete / refused retry, B4 cross-connection / reverse order / records>total / delta growth, S3/S4 hand-over, S6, deviation 9, S2 IsActive generation; absence assertions now follow must-arrive controls.
This commit is contained in:
Joseph Doherty
2026-11-24 18:38:07 -05:00
parent 3c941458f5
commit 69aeeb770b
11 changed files with 1242 additions and 529 deletions
@@ -23,7 +23,7 @@ public interface IDataConnectionSecurityProvider
public sealed record DataConnectionChannelIdentity(string ConnectionId, Uri Endpoint, string CredentialVersion, string TrustFingerprint);
/// <summary>Caller-bound remote facade. All channels and requests are bounded by configured local limits.</summary>
public sealed partial class GrpcDataConnection : IDataConnection
public sealed partial class GrpcDataConnection : IDataConnection, IDataPrimarySubscriptionSource
{
private sealed class ChannelEntry(DataConnectionChannelIdentity identity, GrpcChannel channel, string bearer)
{
@@ -531,7 +531,14 @@ public sealed partial class GrpcDataConnection : IDataConnection
actual == expected || actual.NodeId == expected.NodeId && actual.Incarnation == expected.Incarnation &&
results.Count > 0 && results.All(x => x.Outcome.State == DataWriteState.RejectedBeforeDispatch);
public async Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken)
public Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken) => SubscribeCoreAsync(primaryOnly: false, cancellationToken);
/// <inheritdoc />
/// <remarks>A3 review r1 (deviation 9): condition streams skip a ReadyReplica Secondary. An endpoint refused only for its
/// role is not a discovery failure (no probe backoff for the value path).</remarks>
public Task<IDataSubscription> SubscribePrimaryAsync(CancellationToken cancellationToken) => SubscribeCoreAsync(primaryOnly: true, cancellationToken);
private async Task<IDataSubscription> SubscribeCoreAsync(bool primaryOnly, CancellationToken cancellationToken)
{
EnterWork();
var reserved = false;
@@ -546,11 +553,18 @@ public sealed partial class GrpcDataConnection : IDataConnection
}
var budget = new DataBudget(TimeSpan.FromSeconds(5), 1000, _maxMessageBytes);
var start = Clock.GetTimestamp(); Exception? failure = null;
var roleOnly = primaryOnly;
foreach (var endpoint in _endpoints)
{
try
{
var selected = await SelectAsync(endpoint, start, budget, false, cancellationToken).ConfigureAwait(false);
if (primaryOnly && !string.Equals(selected.Capabilities.Serving.Role, "Primary", StringComparison.OrdinalIgnoreCase))
{
failure = new InvalidOperationException("Endpoint is not the Primary.");
continue;
}
roleOnly = false;
if ((selected.Capabilities.Operations & DataOperations.Subscribe) == 0 ||
Volatile.Read(ref _activeStreams) > selected.Capabilities.Limits.MaxStreams)
throw new InvalidOperationException("Subscriptions unavailable or peer stream capacity exhausted.");
@@ -593,10 +607,10 @@ public sealed partial class GrpcDataConnection : IDataConnection
}
}
catch (Exception ex) when (ex is RpcException or InvalidOperationException or UnauthorizedAccessException or HttpRequestException)
{ failure = ex; RecordFailure(ex); }
{ failure = ex; RecordFailure(ex); roleOnly = false; }
}
ProbeFailed();
throw new InvalidOperationException("No ready subscription endpoint.", failure);
if (!roleOnly) ProbeFailed();
throw new InvalidOperationException(roleOnly ? "No Primary subscription endpoint." : "No ready subscription endpoint.", failure);
}
finally
{