fix(udpscope): bound accumulated-burst chaining so packet loss cannot displace the trace

Forward-chaining each accumulated burst onto the previous one suppresses
arrival jitter, but an unchecked chain never recovers: one lost datagram, or a
declared sampling rate that differs from the producer's real one, dates every
later sample early for the rest of the run. The chain is now a prediction,
compared each packet against the arrival anchor and abandoned beyond
kBurstResyncThresholdS, which bounds the error instead of accumulating it.

Plan amended so the hrt-fit fallback (unusable here: the fit needs 32 packets
and is itself corrupted by bursty arrivals) cannot come back.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino Ferrari
2026-08-27 20:08:05 +02:00
co-authored by Claude Opus 4.6
parent 5a8479cda9
commit 892e3eae28
4 changed files with 153 additions and 22 deletions
@@ -177,6 +177,45 @@ TEST(FrameDecoder, AccumulatedScalarSurvivesBurstyDelivery) {
}
}
// The counterweight to the test above. Suppressing arrival jitter by chaining
// each burst onto the previous one is only safe while the chain is checked: on
// UDP, packets are lost, and a chain that ignores arrival entirely closes the
// hole silently and dates every later sample a full second early — for the rest
// of the run, because nothing ever pulls it back. The prediction has to be
// abandoned once arrival contradicts it by more than a delivery backlog could.
TEST(FrameDecoder, AccumulatedScalarResynchronisesAfterLostPackets) {
FrameDecoder dec;
SignalMeta m;
m.name = "Acc";
m.typeCode = 9;
m.numRows = 1;
m.samplingRate = 1000.0; /* 10 samples = 10 ms per packet */
dec.setSignals({m});
std::vector<double> ts;
for (int p = 0; p < 10; p++) {
FrameBuilder fb;
fb.addSignal(std::vector<double>(10, 1.0));
const FrameView& f = fb.build(0, 500.0 + p * 0.010, 10);
dec.beginFrame(f);
ASSERT_TRUE(dec.timestamps(f, 0, ts));
}
/* Contiguous so far: burst 9 ends at 500.090. */
EXPECT_NEAR(ts[9], 500.090, 1e-9);
/* A full second of packets never arrives. The next one lands at 501.100. */
FrameBuilder fb;
fb.addSignal(std::vector<double>(10, 1.0));
const FrameView& f = fb.build(0, 501.100, 10);
dec.beginFrame(f);
ASSERT_TRUE(dec.timestamps(f, 0, ts));
/* Chaining blindly would put this burst at 500.091..500.100, overlapping
* the gap as though no data were missing. */
EXPECT_NEAR(ts[0], 501.091, 1e-9);
EXPECT_NEAR(ts[9], 501.100, 1e-9);
}
TEST(FrameDecoder, AccumulatedScalarDerivesDtFromTheHrtGapWhenNoRateIsDeclared) {
FrameDecoder dec;
SignalMeta m;