fix(grpc-data): an unknown value/element kind or per-item metadata status from a newer origin fails one item, not the whole browse/metadata response (#956)

DataProtoMapper.DecodeMetadata decodes an undefined ValueKind / ArrayElementKind number to an unknown-kind
marker (DataMetadata.HasUnknownKind, ValidateDecoded) instead of throwing; Validate/Encode still refuse it.
The resolver's #941 IsMaterialisable skips the marker whatever its node kind (a Folder included); a remote
root carrying it is refused. An undefined per-item metadata status decodes to Unavailable (no value, no lease).
Unspecified (0), bad array shape, unknown realm and unknown branch status still fail closed.
This commit is contained in:
Joseph Doherty
2026-12-01 20:20:15 -05:00
parent 92da56c071
commit e66f072121
7 changed files with 195 additions and 5 deletions
@@ -274,8 +274,11 @@ public static class DataProtoMapper
if (x.Dimensions.Count > TypedValueCodec.MaxDimensions)
throw new ArgumentException("Too many dimensions.");
Preflight(x, 1, null);
// #956: a value-kind number this build does not define (a newer origin's data type) is NOT a decode failure — it
// decodes to an unknown-kind marker (DataMetadata.HasUnknownKind) that ValidateDecoded accepts and Validate refuses,
// so the resolver skips that one item (#941) instead of the whole browse page / metadata batch failing here.
// Unspecified (0) is still malformed and throws (ValidateDecoded).
var kind = (DataValueKind)x.ValueKind;
DataContractValidation.Required(kind);
var metadata = new DataMetadata(
DecodeView(x.View),
x.BrowseName,
@@ -296,7 +299,7 @@ public static class DataProtoMapper
null,
x.History is { } history ? new DataHistoryInfo(history.Historizing) : null
);
metadata.Validate();
metadata.ValidateDecoded();
return metadata;
}
@@ -1249,6 +1252,12 @@ public static class DataProtoMapper
{
Preflight(item, 1, limits);
var status = (DataItemStatus)item.Status;
if (item.Status != 0 && !System.Enum.IsDefined(status))
// #956 version skew: a per-item status a newer origin added is that item's failure, not the batch's. It grants
// nothing (no value, no lease) and reads as transient (Unavailable), so the consumer retries rather than caching
// a permanent refusal. Unspecified (0) is still malformed and fails the response below.
return new(item.CorrelationId, DataItemStatus.Unavailable, null,
$"Origin item status {item.Status} is not understood by this build.", null);
DataContractValidation.Required(status);
MetadataLease? lease = item.Lease is { } itemLease
? new(itemLease.CatalogEpoch, itemLease.AuthorityEpoch, TimeSpan.FromTicks(itemLease.DurationTicks)) : null;
@@ -356,6 +356,37 @@ public sealed record DataMetadata(DataView View, string BrowseName, string NodeK
string? StableSourceId, string? EngineeringUnits, bool IsStale, DataValueKind? ArrayElementKind = null, ServingIdentity? Serving = null,
DataHistoryInfo? History = null)
{
/// <summary>
/// #956 version skew: the value kind (or the array element kind) is a number this build does not define — a data type
/// a newer origin added. Such an item is an <em>unsupported marker</em>: it decodes (so one item never fails a whole
/// browse page or metadata batch), it fails <see cref="Validate"/> (so it can never be re-encoded, materialised or
/// granted), and the consumer's resolver skips it like any other unmaterialisable kind (#941).
/// </summary>
public bool HasUnknownKind => !Enum.IsDefined(ValueKind) || ArrayElementKind is { } element && !Enum.IsDefined(element);
/// <summary>
/// Validation of an item decoded from a peer (#956): <see cref="Validate"/> for every item of a kind this build defines;
/// for a <see cref="HasUnknownKind"/> marker, everything that does not depend on the unknown kind's meaning — the view,
/// a nonzero kind, a positive catalog revision, non-negative dimensions and, for a known <c>Array</c> whose element kind
/// is the unknown one, the array shape. Unspecified (0) is a malformed item, never version skew, and still throws.
/// </summary>
public void ValidateDecoded()
{
if (!HasUnknownKind) { Validate(); return; }
ArgumentNullException.ThrowIfNull(View);
View.Validate();
ArgumentNullException.ThrowIfNull(Dimensions);
if (ValueKind == DataValueKind.Unspecified || ArrayElementKind == DataValueKind.Unspecified)
throw new ArgumentOutOfRangeException(nameof(ValueKind), ValueKind, "A defined nonzero value is required.");
if (CatalogRevision <= 0 || Dimensions.Any(d => d < 0)) throw new ArgumentOutOfRangeException(nameof(CatalogRevision));
if (Enum.IsDefined(ValueKind))
{
// The value kind is known, so the unknown one is the element kind: only an array may carry one, with its shape.
if (ValueKind != DataValueKind.Array) throw new ArgumentException("Only arrays may specify an element kind.", nameof(ArrayElementKind));
if (ValueRank <= 0 || Dimensions.Count != ValueRank) throw new ArgumentException("Array rank and dimensions must agree.", nameof(ValueRank));
}
}
public void Validate()
{
ArgumentNullException.ThrowIfNull(View);
@@ -139,9 +139,11 @@ public sealed class ProjectedCatalogCache
/// that is not materialisable (an <c>UnsupportedVariable</c> from a pre-#917 origin, a node kind a newer origin adds, a
/// value type the consumer cannot represent) is SKIPPED by the resolver; it used to fail the whole page, making the
/// folder <c>BadNoCommunication</c>. A malformed item of a supported kind (rank / dimensions / element kind that do
/// not agree) still fails the page closed — that is a protocol violation, not an unknown kind.
/// not agree) still fails the page closed — that is a protocol violation, not an unknown kind. #956: an item whose value
/// or element kind is a number this build does not define (<see cref="DataMetadata.HasUnknownKind"/>, decoded as a
/// marker rather than failing the response) is never materialisable, whatever its node kind.
/// </summary>
internal static bool IsMaterialisable(DataMetadata metadata) => metadata.NodeKind switch
internal static bool IsMaterialisable(DataMetadata metadata) => !metadata.HasUnknownKind && metadata.NodeKind switch
{
"Folder" => true,
"Variable" or "Tag" => HasBuiltInType(metadata.ValueKind == DataValueKind.Array ? metadata.ArrayElementKind : metadata.ValueKind),
@@ -207,7 +207,7 @@ public sealed class RemoteNamespaceResolver : IFederatedProjectionCatalog, IDisp
{
var originView = new DataView(request.Parent.Address, request.Parent.Realm, null, 0, binding.Mapping.RemoteRootEntityId);
var metadata = await connection.Connection.GetMetadataAsync(new([originView], request.Budget with { Timeout = remaining }), route.Token).ConfigureAwait(false);
if (metadata.Count != 1 || metadata[0].Status != DataItemStatus.Good || metadata[0].Value is not { } root || root.View.Address != originView.Address || root.View.MappingId is not null || root.Serving is null)
if (metadata.Count != 1 || metadata[0].Status != DataItemStatus.Good || metadata[0].Value is not { } root || root.HasUnknownKind || root.View.Address != originView.Address || root.View.MappingId is not null || root.Serving is null)
return PreparedPage.Failed(ProjectionPageStatus.Unavailable);
originParent = root;
}