feat(alarms): structural degraded-status signal for truncated alarm snapshots
The truncation-cliff fix made alarm transitions truncation-safe but silent:
when GetXmlCurrentAlarms2 returns exactly maxAlmCnt records the worker
suppresses absence-implies-Clear inference and says so only in a rate-limited
stderr warning. No client and no operator could tell a complete active set
from a capped one.
Two additive proto3 booleans carry the verdict out:
- QueryActiveAlarmsReplyPayload.snapshot_truncated = 2 (worker IPC reply)
- ActiveAlarmSnapshot.from_truncated_snapshot = 16 (per record)
The per-record field is not an aesthetic choice. QueryActiveAlarms returns a
bare `stream ActiveAlarmSnapshot` with no envelope, header, or trailer, so a
per-record boolean is the only carrier that stays wire-compatible; an envelope
message would change every existing client's stream element type. The reply
payload states it too because a prefix filter can leave zero records and a
truncated fetch with nothing to report still has to say so. The flag means
"this set may be incomplete", never "this record is unreliable" — it is
independent of the subtag-fallback `degraded` field.
Detection is deliberately UNCHANGED: IsTruncatedFetch remains
`fetchedRecordCount >= maxAlarmsPerFetch`. The live probe (docs/AlarmProbeFindings.md,
ce5d8ae) could not verify whether ALARM_RECORDS/@COUNT reports the total active
count or only the records in the reply, so @COUNT is not parsed for detection;
switching to it stays blocked on probe evidence. The probe's comment
annotations in WnWrapAlarmConsumer.cs are preserved.
Reset semantics: not latched. WnWrapAlarmConsumer.FoldFetch replaces the
verdict on every poll under the same lock as the snapshot merge, so the first
sub-cap fetch clears it; GatewayAlarmMonitor.ClearCache drops it with the cache
generation it describes. A caveat that never turns off is one operators learn
to ignore.
Flow: WnWrapAlarmConsumer.LastSnapshotTruncated -> AlarmDispatcher (stamps every
record) / IAlarmCommandHandler (payload) -> MxAccessCommandExecutor reply ->
GatewayAlarmMonitor._snapshotTruncated -> IGatewayAlarmService.SnapshotTruncated
-> DashboardAlarmQueryResult -> AlarmsPage warning banner (render-side only; the
poll loop and DisposeAsync drain are untouched). The public QueryActiveAlarms
RPC forwards worker snapshots unmodified, so the per-record flag needed no
mapper change — a test pins that.
Parity: this describes OUR fetch mechanics — additive gateway metadata — not
MXAccess provider behavior. No event is synthesized and no MXAccess-observable
semantics change, so it is not a parity deviation.
Tests: worker LastSnapshotTruncated set/reset/consecutive-burst (windev-run);
gateway end-to-end truncated reply -> monitor -> public stream, with the
complete-reply control as the load-bearing assertion; AlarmsPage banner
present/absent. Docs: gateway.md alarm surface, docs/DesignDecisions.md entry.
This commit is contained in:
@@ -93,6 +93,7 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
|
||||
private long lastTruncationWarningMilliseconds = -TruncationWarningIntervalMilliseconds;
|
||||
private long truncatedFetchCount;
|
||||
private bool lastSnapshotTruncated;
|
||||
private wwAlarmConsumerClass? client;
|
||||
private wwAlarmConsumerClass? ackClient;
|
||||
private bool subscribed;
|
||||
@@ -125,6 +126,23 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
: DefaultMaxAlarmsPerFetch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// COM-free construction, for exercising the retained-snapshot state
|
||||
/// machine (<see cref="FoldFetch"/> / <see cref="LastSnapshotTruncated"/>
|
||||
/// / <see cref="SnapshotActiveAlarms"/>) on a machine without AVEVA
|
||||
/// installed. <see cref="Subscribe"/> throws and <see cref="PollOnce"/>
|
||||
/// no-ops on an instance built this way — both need the wnwrap coclass,
|
||||
/// which cannot be instantiated on the macOS/Linux test matrix. Internal
|
||||
/// rather than public so it cannot be reached from production wiring.
|
||||
/// </summary>
|
||||
/// <param name="maxAlarmsPerFetch">Maximum alarms per fetch call.</param>
|
||||
internal WnWrapAlarmConsumer(int maxAlarmsPerFetch)
|
||||
{
|
||||
this.maxAlarmsPerFetch = maxAlarmsPerFetch > 0
|
||||
? maxAlarmsPerFetch
|
||||
: DefaultMaxAlarmsPerFetch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the per-fetch cap from the launcher-provided environment
|
||||
/// variable. A missing, unparseable, or out-of-range value falls back
|
||||
@@ -373,6 +391,18 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>
|
||||
/// Read without the disposed guard <see cref="SnapshotActiveAlarms"/>
|
||||
/// carries: this is degraded-status metadata a reply builder stamps
|
||||
/// alongside a snapshot, and throwing from it would fail a query whose
|
||||
/// snapshot half succeeded.
|
||||
/// </remarks>
|
||||
public bool LastSnapshotTruncated
|
||||
{
|
||||
get { lock (syncRoot) { return lastSnapshotTruncated; } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sink for the rate-limited truncated-fetch warning. Defaults to
|
||||
/// <see cref="Console.Error"/>, the stream
|
||||
@@ -413,14 +443,8 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
// docs/AlarmProbeFindings.md.)
|
||||
bool truncated = IsTruncatedFetch(fetchedRecordCount, maxAlarmsPerFetch);
|
||||
|
||||
IReadOnlyList<MxAlarmTransitionEvent> transitions;
|
||||
int retainedCount;
|
||||
lock (syncRoot)
|
||||
{
|
||||
transitions = ComputeTransitions(latestSnapshot, next);
|
||||
ApplySnapshotUpdate(latestSnapshot, next, truncated);
|
||||
retainedCount = latestSnapshot.Count;
|
||||
}
|
||||
IReadOnlyList<MxAlarmTransitionEvent> transitions =
|
||||
FoldFetch(next, truncated, out int retainedCount);
|
||||
|
||||
if (truncated)
|
||||
{
|
||||
@@ -436,6 +460,37 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Folds one fetch into the retained state under a single lock: the
|
||||
/// transition diff, the snapshot merge/replace, and the truncation
|
||||
/// verdict move together. Splitting them would let a concurrent
|
||||
/// <see cref="SnapshotActiveAlarms"/> / <see cref="LastSnapshotTruncated"/>
|
||||
/// pair read a capped snapshot alongside the previous poll's "complete"
|
||||
/// verdict — precisely the false all-clear the signal exists to prevent.
|
||||
/// The verdict is replaced, never latched: a sub-cap fetch is complete
|
||||
/// and restores absence authority, so leaving the flag set would strand
|
||||
/// the operator banner on after a single burst.
|
||||
/// </summary>
|
||||
/// <param name="next">The snapshot just parsed from the fetch.</param>
|
||||
/// <param name="truncated">Whether the fetch hit the per-fetch cap.</param>
|
||||
/// <param name="retainedCount">Size of the retained snapshot after the fold.</param>
|
||||
/// <returns>The transitions the fetch implies.</returns>
|
||||
internal IReadOnlyList<MxAlarmTransitionEvent> FoldFetch(
|
||||
Dictionary<Guid, MxAlarmSnapshotRecord> next,
|
||||
bool truncated,
|
||||
out int retainedCount)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
IReadOnlyList<MxAlarmTransitionEvent> transitions =
|
||||
ComputeTransitions(latestSnapshot, next);
|
||||
ApplySnapshotUpdate(latestSnapshot, next, truncated);
|
||||
lastSnapshotTruncated = truncated;
|
||||
retainedCount = latestSnapshot.Count;
|
||||
return transitions;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decides whether a fetch that came back holding
|
||||
/// <paramref name="fetchedRecordCount"/> records hit the cap.
|
||||
|
||||
Reference in New Issue
Block a user