fix(grpc-data): projected Processed values keep their aggregate's type

Found by the H3 live gate (H02): a Double Average of a UInt16 node was decoded
against the node's catalog kind and came back null + BadTypeMismatch per
interval (the result status stayed Good, which is why the wire test missed
it). Raw/AtTime values are still checked against the catalog kind; Processed
values accept any scalar kind. The wire test now asserts the interval's value.
Gate: re-browse the projected leaves after every deploy (a deploy retires cold
projected nodes; the same opaque ids come back).
This commit is contained in:
Joseph Doherty
2026-11-24 01:04:04 -05:00
parent 0a83c10ef6
commit af06183412
3 changed files with 49 additions and 11 deletions
@@ -271,7 +271,7 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl
target, callerKey, key.Details, nodes[i].Resume is RemoteCursor prior ? prior.AggregateId : nodes[i].AggregateId);
}
outcomes[i] = new ProjectedHistoryOutcome(answer.StatusCode, Convert(answer.Samples, target.OriginMetadata), next);
outcomes[i] = new ProjectedHistoryOutcome(answer.StatusCode, Convert(answer.Samples, target.OriginMetadata, key.Details is DataHistoryProcessedDetails), next);
}
}
finally
@@ -326,8 +326,12 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl
private static string CallerKey(RoleCarryingUserIdentity caller) =>
string.Join('\0', caller.Principal ?? "", caller.ApiKeyId ?? "", caller.CredentialVersion ?? "");
/// <summary>Values verbatim (status, absent timestamps); a value kind that disagrees with the catalog is <c>BadTypeMismatch</c>.</summary>
private static OriginHistorySample[] Convert(IReadOnlyList<DataHistorySample> samples, DataMetadata metadata)
/// <summary>
/// Values verbatim (status, absent timestamps). Raw and AtTime values are the node's own values: a kind that disagrees
/// with the catalog is <c>BadTypeMismatch</c> (plan §3.3), never coerced. A Processed value has its AGGREGATE's type (a
/// Double Average or an Int32 Count of a UInt16 node), so only its shape is checked: any scalar kind is accepted.
/// </summary>
private static OriginHistorySample[] Convert(IReadOnlyList<DataHistorySample> samples, DataMetadata metadata, bool processed)
{
var converted = new OriginHistorySample[samples.Count];
for (var i = 0; i < samples.Count; i++)
@@ -335,7 +339,13 @@ public sealed class ProjectedHistoryAccess : IProjectedHistoryAccess, IDisposabl
var sample = samples[i];
object? value;
var status = sample.StatusCode;
try { value = ProjectedDataAccess.DecodeValue(sample.Value, metadata); }
try
{
var expected = processed && sample.Value.Kind is not (DataValueKind.Null or DataValueKind.Array)
? metadata with { ValueKind = sample.Value.Kind, ValueRank = -1, Dimensions = [], ArrayElementKind = null }
: metadata;
value = ProjectedDataAccess.DecodeValue(sample.Value, expected);
}
catch (Exception ex) when (ex is ArgumentException or InvalidCastException or InvalidOperationException)
{
value = null;