Remove debug print statements from MeshCoreConnector, MessageRetryService, and UsbSerialService and fix wrong retry being credited

This commit is contained in:
zjs81
2026-03-23 22:26:51 -07:00
parent 3754cf14ea
commit eca78453d6
4 changed files with 30 additions and 21 deletions
+1 -1
View File
@@ -2839,7 +2839,7 @@ class MeshCoreConnector extends ChangeNotifier {
_bleDebugLogService?.logFrame(frame, outgoing: false); _bleDebugLogService?.logFrame(frame, outgoing: false);
final code = frame[0]; final code = frame[0];
debugPrint('RX frame: code=$code len=${frame.length}'); // debugPrint('RX frame: code=$code len=${frame.length}');
switch (code) { switch (code) {
case respCodeOk: case respCodeOk:
+1 -1
View File
@@ -1697,7 +1697,7 @@ class _MessageBubble extends StatelessWidget {
child: Text( child: Text(
context.l10n.chat_retryCount( context.l10n.chat_retryCount(
message.retryCount, message.retryCount,
4, context.read<AppSettingsService>().settings.maxMessageRetries,
), ),
style: TextStyle( style: TextStyle(
fontSize: 10, fontSize: 10,
+17 -8
View File
@@ -21,11 +21,16 @@ class _AckHistoryEntry {
}); });
} }
/// (messageId, timestamp, attemptIndex) stored per ACK hash for O(1) lookup. /// (messageId, timestamp, attemptIndex, pathSelection) stored per ACK hash
/// for O(1) lookup. [pathSelection] snapshots the route used for this
/// specific attempt so that a late PUSH_CODE_SEND_CONFIRMED credits the
/// correct path even when the message has since been retried on a different
/// route.
typedef AckHashMapping = ({ typedef AckHashMapping = ({
String messageId, String messageId,
DateTime timestamp, DateTime timestamp,
int attemptIndex, int attemptIndex,
PathSelection? pathSelection,
}); });
class RetryServiceConfig { class RetryServiceConfig {
@@ -382,6 +387,7 @@ class MessageRetryService extends ChangeNotifier {
messageId: messageId, messageId: messageId,
timestamp: DateTime.now(), timestamp: DateTime.now(),
attemptIndex: message.retryCount, attemptIndex: message.retryCount,
pathSelection: _selectionFromMessage(message),
); );
// Add this ACK hash to the list of expected ACKs for this message (for history) // Add this ACK hash to the list of expected ACKs for this message (for history)
@@ -395,14 +401,11 @@ class MessageRetryService extends ChangeNotifier {
int actualTimeout = timeoutMs; int actualTimeout = timeoutMs;
if (config.calculateTimeout != null) { if (config.calculateTimeout != null) {
final calculated = config.calculateTimeout!( actualTimeout = config.calculateTimeout!(
pathLengthValue, pathLengthValue,
message.text.length, message.text.length,
contactKey: contact.publicKeyHex, contactKey: contact.publicKeyHex,
); );
if (timeoutMs <= 0 || calculated < timeoutMs) {
actualTimeout = calculated;
}
} }
final updatedMessage = message.copyWith( final updatedMessage = message.copyWith(
@@ -569,6 +572,7 @@ class MessageRetryService extends ChangeNotifier {
final config = _config; final config = _config;
String? matchedMessageId; String? matchedMessageId;
int? matchedAttemptIndex; int? matchedAttemptIndex;
PathSelection? matchedPathSelection;
final ackHashHex = ackHash.toRadixString(16).padLeft(8, '0'); final ackHashHex = ackHash.toRadixString(16).padLeft(8, '0');
// Clean up old ACK hash mappings (older than 15 minutes) // Clean up old ACK hash mappings (older than 15 minutes)
@@ -588,6 +592,7 @@ class MessageRetryService extends ChangeNotifier {
if (mapping != null) { if (mapping != null) {
matchedMessageId = mapping.messageId; matchedMessageId = mapping.messageId;
matchedAttemptIndex = mapping.attemptIndex; matchedAttemptIndex = mapping.attemptIndex;
matchedPathSelection = mapping.pathSelection;
} else { } else {
config?.debugLogService?.warn( config?.debugLogService?.warn(
'PUSH_CODE_SEND_CONFIRMED: ACK hash $ackHashHex not found in direct mapping, trying fallback', 'PUSH_CODE_SEND_CONFIRMED: ACK hash $ackHashHex not found in direct mapping, trying fallback',
@@ -618,13 +623,13 @@ class MessageRetryService extends ChangeNotifier {
} }
final contact = _pendingContacts[matchedMessageId]; final contact = _pendingContacts[matchedMessageId];
final ackedAttempt = matchedAttemptIndex ?? message.retryCount; final ackedAttempt = matchedAttemptIndex ?? message.retryCount;
final selection = _selectionFromMessage(message); final selection = matchedPathSelection ?? _selectionFromMessage(message);
final shortText = message.text.length > 20 final shortText = message.text.length > 20
? '${message.text.substring(0, 20)}...' ? '${message.text.substring(0, 20)}...'
: message.text; : message.text;
config?.debugLogService?.info( config?.debugLogService?.info(
'PUSH_CODE_SEND_CONFIRMED: ACK hash $ackHashHex ✓ "$shortText" delivered to ${contact?.name ?? "unknown"} on retry ${ackedAttempt + 1} in ${tripTimeMs}ms', 'PUSH_CODE_SEND_CONFIRMED: ACK hash $ackHashHex ✓ "$shortText" delivered to ${contact?.name ?? "unknown"} on attempt $ackedAttempt in ${tripTimeMs}ms',
tag: 'AckHash', tag: 'AckHash',
); );
@@ -636,6 +641,8 @@ class MessageRetryService extends ChangeNotifier {
tripTimeMs: tripTimeMs, tripTimeMs: tripTimeMs,
); );
final wasAlreadyResolved = _resolvedMessages.contains(matchedMessageId);
_cleanupMessage(matchedMessageId); _cleanupMessage(matchedMessageId);
config?.updateMessage(deliveredMessage); config?.updateMessage(deliveredMessage);
@@ -658,7 +665,9 @@ class MessageRetryService extends ChangeNotifier {
tripTimeMs, tripTimeMs,
); );
} }
_onMessageResolved(matchedMessageId, contact.publicKeyHex); if (!wasAlreadyResolved) {
_onMessageResolved(matchedMessageId, contact.publicKeyHex);
}
} }
notifyListeners(); notifyListeners();
+11 -11
View File
@@ -273,7 +273,7 @@ class UsbSerialService {
throw StateError('USB serial port is not open'); throw StateError('USB serial port is not open');
} }
final packet = wrapUsbSerialTxFrame(data); final packet = wrapUsbSerialTxFrame(data);
_logFrameSummary('USB TX frame', data); // _logFrameSummary('USB TX frame', data);
if (_useAndroidUsbHost) { if (_useAndroidUsbHost) {
try { try {
await _androidMethodChannel.invokeMethod<void>('write', { await _androidMethodChannel.invokeMethod<void>('write', {
@@ -447,16 +447,16 @@ class UsbSerialService {
await _frameController.close(); await _frameController.close();
} }
void _logFrameSummary(String prefix, Uint8List bytes) { // void _logFrameSummary(String prefix, Uint8List bytes) {
if (bytes.isEmpty) { // if (bytes.isEmpty) {
_debugLogService?.info('$prefix len=0', tag: 'USB Serial'); // _debugLogService?.info('$prefix len=0', tag: 'USB Serial');
return; // return;
} // }
_debugLogService?.info( // _debugLogService?.info(
'$prefix code=${bytes[0]} len=${bytes.length}', // '$prefix code=${bytes[0]} len=${bytes.length}',
tag: 'USB Serial', // tag: 'USB Serial',
); // );
} // }
/// Returns an ordered list of port paths to try for [portName]. /// Returns an ordered list of port paths to try for [portName].
/// ///