fix(grpc-data): a demand disposed mid-publish no longer re-publishes a fresh baseline (#920)

Root cause of the Failed_sdk_item_construction flake: a failed SDK item
construction disposes its demand while the stream pump publishes that
registration's snapshot. The duplicate-baseline check read the dying demand's
IsValid as 'cache not fresh', so the same acquisition was re-published as a new
complete baseline to every item on the node, leaving an orphan proof candidate
(and shared budget charge) the SDK never consumes. HasFreshCachedLocked no
longer depends on demand validity; Publish re-checks the demand after it.
Regression test with a pump seam: red without the fix, green with it.

Bad_null different_timestamp flake is a test race: SDK 2.0.1 delivers node
changes to items asynchronously (MonitoredNode2 channel), so the published
sample could land after the mode cycle and overwrite the injected
notification. The test now waits until the SDK queued it.
This commit is contained in:
Joseph Doherty
2026-11-28 10:10:20 -05:00
parent cb672ea060
commit 4cf06261f1
3 changed files with 94 additions and 1 deletions
@@ -19,6 +19,8 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
public TimeProvider Clock { get; }
internal Func<TimeSpan, TimeSpan>? RetryJitterForTests { get; set; }
internal Action? BeforeSuccessorAdoptionForTests { get; set; }
/// <summary>#920: runs on the stream pump after a publish passed its demand check, before the duplicate-baseline check.</summary>
internal Action<IProjectedDemandLease>? AfterPublishDemandCheckForTests { get; set; }
private readonly IFederatedProjectionCatalog _catalog;
private readonly IProjectedNodeLookup _nodes;
private readonly Func<string, string?> _connectionForMapping;
@@ -568,7 +570,11 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
internal bool HasFreshCachedLocked(Demand demand)
{
var sample = _cachedSample;
if (sample is null || _cachedVersion != LastVersion || !sample.SourceProof.IsValid || !demand.IsValid || !IsValid) return false;
// #920: deliberately NOT gated on demand.IsValid. This answers "is the sample already published for this version
// still fresh at this demand's age limit" — the duplicate-baseline suppression in Publish. A demand disposed
// concurrently (a failed SDK item construction) used to turn the answer into "not fresh", so a dying
// registration re-published the same acquisition as a new complete baseline to every item on the node.
if (sample is null || _cachedVersion != LastVersion || !sample.SourceProof.IsValid || !IsValid) return false;
try
{
return sample.OriginAgeBounds.Advance(_owner.Clock.GetElapsedTime(sample.ReceivedTimestamp,
@@ -1658,6 +1664,7 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
{
validated = false;
if (registration.Removed || !registration.Demand.IsValid || update.SourceProof is not AttemptProof proof) { ProjectedStreamDiagnostics.Count(ProjectedStreamDiagnostics.Event.PublishDemand); return false; }
_owner.AfterPublishDemandCheckForTests?.Invoke(registration.Demand);
var source = proof.Source;
if (!source.TryPrepareSuccessor(registration.Demand, out var successor)) return false;
try
@@ -1675,6 +1682,8 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
validated = update.IsCompleteSnapshot;
if (version == source.LastVersion && update.IsCompleteSnapshot && !registration.Recovery &&
source.HasFreshCachedLocked(registration.Demand)) return false;
// A demand disposed since the check above publishes nothing (it is no longer anyone's subscription).
if (!registration.Demand.IsValid) { validated = false; ProjectedStreamDiagnostics.Count(ProjectedStreamDiagnostics.Event.PublishDemand); return false; }
if (_owner._publisher.TryPublish([update]))
{
if (successor is not null)