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:
zjs81 committed 2026-10-25 11:36:13 -07:00
1 parent 6bc6143c4e
commit 82dcab1d92
8 files changed
+70 -31

No files matched your search

+5 -2
View File
@@ -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,
);
+13 -1
View File
@@ -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)
+1 -6
View File
@@ -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,
];