Fix timeout observations, drop the last-rx feature and evict weak paths
- Record delivery observations with the path of the attempt the ACK belongs to, and skip ambiguous ACKs, so a late direct ACK is not learned as a flood delivery. - Remove secondsSinceLastRx from the timeout model: it measured time since any companion frame, which was near zero at train and predict. - When a contact's path history is full, evict the lowest-scoring path instead of silently dropping new discoveries.
This commit is contained in:
1 parent
6bc6143c4e
commit
82dcab1d92
8 files changed
+70
-31
No files matched your search
@@ -334,12 +334,6 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
ReceivedImageStore? _receivedImageStore;
|
||||
void Function(ImageChunkOutcome outcome)? _onImageChunk;
|
||||
void Function(int senderPrefix)? _onImageSenderPrefix;
|
||||
// Intentionally global (not per-contact): tracks overall network activity.
|
||||
// Frequent RX from any source indicates a busy network with more collisions.
|
||||
DateTime _lastRxTime = DateTime.now();
|
||||
// Snapshot of _lastRxTime taken before the ACK frame updates it, so that
|
||||
// onDeliveryObserved records the pre-ACK elapsed time (matching prediction).
|
||||
DateTime _lastRxBeforeFrame = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
DateTime _lastRadioRxTime = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
DateTime _lastContactMsgRxTime = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
DateTime _lastChannelMsgRxTime = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
@@ -1810,15 +1804,11 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
recentSelections: recentSelections,
|
||||
),
|
||||
onDeliveryObserved: (contactKey, pathLength, messageBytes, tripTimeMs) {
|
||||
final secSinceRx = DateTime.now()
|
||||
.difference(_lastRxBeforeFrame)
|
||||
.inSeconds;
|
||||
_timeoutPredictionService?.recordObservation(
|
||||
contactKey: contactKey,
|
||||
pathLength: pathLength,
|
||||
messageBytes: messageBytes,
|
||||
tripTimeMs: tripTimeMs,
|
||||
secondsSinceLastRx: secSinceRx,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -6073,8 +6063,6 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
|
||||
void _handleFrame(List<int> data) {
|
||||
if (data.isEmpty) return;
|
||||
_lastRxBeforeFrame = _lastRxTime;
|
||||
_lastRxTime = DateTime.now();
|
||||
|
||||
final frame = Uint8List.fromList(data);
|
||||
_receivedFramesController.add(frame);
|
||||
@@ -6834,12 +6822,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
final physicsMax = _physicsMaxTimeout(pathLength, airtime);
|
||||
|
||||
// Try ML-based prediction
|
||||
final secSinceRx = DateTime.now().difference(_lastRxTime).inSeconds;
|
||||
final mlTimeout = _timeoutPredictionService?.predictTimeout(
|
||||
contactKey: contactKey,
|
||||
pathLength: pathLength,
|
||||
messageBytes: messageBytes,
|
||||
secondsSinceLastRx: secSinceRx,
|
||||
);
|
||||
if (mlTimeout != null) {
|
||||
// Use device est_timeout as a baseline floor when available —
|
||||
|
||||
@@ -2,7 +2,6 @@ class DeliveryObservation {
|
||||
final String contactKey;
|
||||
final int pathLength;
|
||||
final int messageBytes;
|
||||
final int secondsSinceLastRx;
|
||||
final bool isFlood;
|
||||
final int deliveryMs;
|
||||
final DateTime timestamp;
|
||||
@@ -11,7 +10,6 @@ class DeliveryObservation {
|
||||
required this.contactKey,
|
||||
required this.pathLength,
|
||||
required this.messageBytes,
|
||||
required this.secondsSinceLastRx,
|
||||
required this.isFlood,
|
||||
required this.deliveryMs,
|
||||
required this.timestamp,
|
||||
@@ -22,7 +20,6 @@ class DeliveryObservation {
|
||||
'contact_key': contactKey,
|
||||
'path_length': pathLength,
|
||||
'message_bytes': messageBytes,
|
||||
'seconds_since_last_rx': secondsSinceLastRx,
|
||||
'is_flood': isFlood,
|
||||
'delivery_ms': deliveryMs,
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
@@ -34,7 +31,6 @@ class DeliveryObservation {
|
||||
contactKey: json['contact_key'] as String,
|
||||
pathLength: json['path_length'] as int,
|
||||
messageBytes: json['message_bytes'] as int,
|
||||
secondsSinceLastRx: json['seconds_since_last_rx'] as int? ?? 0,
|
||||
isFlood: json['is_flood'] as bool? ?? false,
|
||||
deliveryMs: json['delivery_ms'] as int,
|
||||
timestamp: DateTime.parse(json['timestamp'] as String),
|
||||
|
||||
@@ -843,9 +843,12 @@ class MessageRetryService extends ChangeNotifier {
|
||||
tripTimeMs,
|
||||
);
|
||||
}
|
||||
// Learn from the attempt this ACK belongs to, not the latest one: a
|
||||
// late ACK for a direct attempt can land after a retry went flood.
|
||||
if (config?.onDeliveryObserved != null &&
|
||||
tripTimeMs > 0 &&
|
||||
message.pathLength != null) {
|
||||
selection != null &&
|
||||
!ambiguousPath) {
|
||||
final outboundTextForObserved =
|
||||
config!.prepareContactOutboundText?.call(contact, message.text) ??
|
||||
message.text;
|
||||
@@ -854,7 +857,7 @@ class MessageRetryService extends ChangeNotifier {
|
||||
.length;
|
||||
config.onDeliveryObserved!(
|
||||
contact.publicKeyHex,
|
||||
message.pathLength!,
|
||||
selection.useFlood ? -1 : selection.hopCount,
|
||||
messageBytesForObserved,
|
||||
tripTimeMs,
|
||||
);
|
||||
|
||||
@@ -357,8 +357,9 @@ class PathHistoryService extends ChangeNotifier {
|
||||
|
||||
updatedPaths.removeWhere((p) => _pathsEqual(p.pathBytes, pathBytes));
|
||||
|
||||
// Make room by dropping the weakest path so new discoveries still land.
|
||||
if (existing == null && updatedPaths.length >= _maxHistoryEntries) {
|
||||
return;
|
||||
updatedPaths.remove(_lowestScoredPath(updatedPaths));
|
||||
}
|
||||
|
||||
updatedPaths.insert(0, newRecord);
|
||||
@@ -540,6 +541,17 @@ class PathHistoryService extends ChangeNotifier {
|
||||
return ranked;
|
||||
}
|
||||
|
||||
PathRecord _lowestScoredPath(List<PathRecord> paths) {
|
||||
final fastestTripMs = _getFastestKnownTripMs(paths);
|
||||
final highestRouteWeight = _getHighestKnownRouteWeight(paths);
|
||||
double score(PathRecord p) => _scorePathRecord(
|
||||
p,
|
||||
fastestTripMs: fastestTripMs,
|
||||
highestRouteWeight: highestRouteWeight,
|
||||
);
|
||||
return paths.reduce((a, b) => score(b) < score(a) ? b : a);
|
||||
}
|
||||
|
||||
int? _getFastestKnownTripMs(List<PathRecord> paths) {
|
||||
final knownTrips = paths
|
||||
.where((path) => path.tripTimeMs > 0)
|
||||
|
||||
@@ -65,7 +65,6 @@ class TimeoutPredictionService extends ChangeNotifier {
|
||||
required int pathLength,
|
||||
required int messageBytes,
|
||||
required int tripTimeMs,
|
||||
int secondsSinceLastRx = 0,
|
||||
}) {
|
||||
if (recordingSuspended) return;
|
||||
final isFlood = pathLength < 0;
|
||||
@@ -75,7 +74,6 @@ class TimeoutPredictionService extends ChangeNotifier {
|
||||
// only; isFlood carries the flood signal as a separate feature.
|
||||
pathLength: isFlood ? 0 : pathLength,
|
||||
messageBytes: messageBytes,
|
||||
secondsSinceLastRx: secondsSinceLastRx,
|
||||
isFlood: isFlood,
|
||||
deliveryMs: tripTimeMs,
|
||||
timestamp: DateTime.now(),
|
||||
@@ -110,7 +108,6 @@ class TimeoutPredictionService extends ChangeNotifier {
|
||||
String? contactKey,
|
||||
required int pathLength,
|
||||
required int messageBytes,
|
||||
int secondsSinceLastRx = 0,
|
||||
}) {
|
||||
if (_model == null) return null;
|
||||
|
||||
@@ -123,7 +120,6 @@ class TimeoutPredictionService extends ChangeNotifier {
|
||||
// prediction see the same pathLength values; isFlood carries the signal.
|
||||
'pathLength': flood ? 0.0 : pathLength.toDouble(),
|
||||
'messageBytes': messageBytes.toDouble(),
|
||||
'secSinceRx': secondsSinceLastRx.toDouble(),
|
||||
'isFlood': flood ? 1.0 : 0.0,
|
||||
};
|
||||
final row = _activeFeatures.map((f) => allFeatures[f]!).toList();
|
||||
@@ -174,13 +170,12 @@ class TimeoutPredictionService extends ChangeNotifier {
|
||||
try {
|
||||
// Build feature columns, then exclude any with zero variance
|
||||
// (ml_algo's OLS produces all-zero coefficients for singular matrices)
|
||||
final allNames = ['pathLength', 'messageBytes', 'secSinceRx', 'isFlood'];
|
||||
final allNames = ['pathLength', 'messageBytes', 'isFlood'];
|
||||
final allExtractors = <double Function(DeliveryObservation)>[
|
||||
// pathLength is already clamped to >=0 in recordObservation, but guard
|
||||
// here as well for any observations loaded from older persisted data.
|
||||
(o) => o.pathLength < 0 ? 0.0 : o.pathLength.toDouble(),
|
||||
(o) => o.messageBytes.toDouble(),
|
||||
(o) => o.secondsSinceLastRx.toDouble(),
|
||||
(o) => o.isFlood ? 1.0 : 0.0,
|
||||
];
|
||||
|
||||
|
||||
Reference in new issue
Block a user