fix(#589): late replies go to the app log, not the user's screen

#528 surfaced unmatched and late replies in the UI because they were
previously destroyed in silence. Once #529 widened the window, late
arrivals stopped being the exception and the on-screen output became
noise during ordinary use. Owner's call: log it, keep it off the screen.

Removed: the CLI screen's late-response history entry and its renderer
branch, the settings screen's snackbar, and the four l10n strings that
only those two used.

Also removed the settings screen's silent late-apply. A field changing
value seconds after the fact with no explanation is the same problem as
the snackbar, only quieter, and applying while saying nothing would be
worse than either showing or not showing. One line to re-enable if that
turns out to be wanted.

Kept: the service still detects every unmatched reply and writes it to
the app log via appLogger, now including the payload as well as the
repeater, the originating command when known, and how late it arrived.
That is the diagnostics channel and is what keeps this from being a
silent drop.

onUnmatchedResponse and UnmatchedRepeaterResponse stay on the service.
They are the seam the no-silent-drop guarantee is tested through; the
#528 and #532 tests exercise them directly and pass unchanged, which is
the evidence the service contract did not move.

807 tests pass, analyze clean, format clean.
pull/701/head
Strycher 3 months ago committed by Benjamin Wiechel
parent 9741c3399d
commit 9a12794487

@ -1606,20 +1606,6 @@
}
}
},
"repeater_cliLateResponse": "Late response to \"{command}\" (arrived {seconds}s after timeout)",
"@repeater_cliLateResponse": {
"placeholders": {
"command": {
"type": "String"
},
"seconds": {
"type": "String"
}
}
},
"repeater_cliUnmatchedResponse": "Unrequested response from repeater",
"repeater_lateResponseDiscarded": "A late response arrived but was not applied, because you have unsaved changes.",
"repeater_lateResponseReceived": "A late response arrived after the command timed out. See the CLI screen.",
"repeater_cliQuickGetName": "Get Name",
"repeater_cliQuickGetRadio": "Get Radio",
"repeater_cliQuickGetTx": "Get TX",

@ -5180,30 +5180,6 @@ abstract class AppLocalizations {
/// **'Command timed out after {seconds} seconds'**
String repeater_cliCommandTimeout(String seconds);
/// No description provided for @repeater_cliLateResponse.
///
/// In en, this message translates to:
/// **'Late response to \"{command}\" (arrived {seconds}s after timeout)'**
String repeater_cliLateResponse(String command, String seconds);
/// No description provided for @repeater_cliUnmatchedResponse.
///
/// In en, this message translates to:
/// **'Unrequested response from repeater'**
String get repeater_cliUnmatchedResponse;
/// No description provided for @repeater_lateResponseDiscarded.
///
/// In en, this message translates to:
/// **'A late response arrived but was not applied, because you have unsaved changes.'**
String get repeater_lateResponseDiscarded;
/// No description provided for @repeater_lateResponseReceived.
///
/// In en, this message translates to:
/// **'A late response arrived after the command timed out. See the CLI screen.'**
String get repeater_lateResponseReceived;
/// No description provided for @repeater_cliQuickGetName.
///
/// In en, this message translates to:

@ -2942,23 +2942,6 @@ class AppLocalizationsBg extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Получи име';

@ -2945,23 +2945,6 @@ class AppLocalizationsDe extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Name erhalten';

@ -2886,23 +2886,6 @@ class AppLocalizationsEn extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Get Name';

@ -2936,23 +2936,6 @@ class AppLocalizationsEs extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Obtener Nombre';

@ -2958,23 +2958,6 @@ class AppLocalizationsFr extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Obtenir le nom';

@ -2949,23 +2949,6 @@ class AppLocalizationsHu extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Kapcsold össze a nevet';

@ -2942,23 +2942,6 @@ class AppLocalizationsIt extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Ottieni Nome';

@ -2822,23 +2822,6 @@ class AppLocalizationsJa extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => '名前を取得する';

@ -2820,23 +2820,6 @@ class AppLocalizationsKo extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => '이름을 알려주세요';

@ -2922,23 +2922,6 @@ class AppLocalizationsNl extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Naam opvragen';

@ -2950,23 +2950,6 @@ class AppLocalizationsPl extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Pobierz nazwę';

@ -2934,23 +2934,6 @@ class AppLocalizationsPt extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Obter Nome';

@ -2940,23 +2940,6 @@ class AppLocalizationsRu extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Получить имя';

@ -2921,23 +2921,6 @@ class AppLocalizationsSk extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Zísť meno';

@ -2920,23 +2920,6 @@ class AppLocalizationsSl extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Pridobi ime';

@ -2906,23 +2906,6 @@ class AppLocalizationsSv extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Hämta namn';

@ -2938,23 +2938,6 @@ class AppLocalizationsUk extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => 'Отримати ім\'я';

@ -2774,23 +2774,6 @@ class AppLocalizationsZh extends AppLocalizations {
return 'Command timed out after $seconds seconds';
}
@override
String repeater_cliLateResponse(String command, String seconds) {
return 'Late response to \"$command\" (arrived ${seconds}s after timeout)';
}
@override
String get repeater_cliUnmatchedResponse =>
'Unrequested response from repeater';
@override
String get repeater_lateResponseDiscarded =>
'A late response arrived but was not applied, because you have unsaved changes.';
@override
String get repeater_lateResponseReceived =>
'A late response arrived after the command timed out. See the CLI screen.';
@override
String get repeater_cliQuickGetName => '获取名称';

@ -52,31 +52,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
super.initState();
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
_commandService = RepeaterCommandService(connector);
_commandService!.onUnmatchedResponse = _handleUnmatchedResponse;
_setupMessageListener();
}
/// A reply the command future never received, because its window had already
/// closed. It is still the repeater's real answer, so it goes into the
/// history instead of being dropped (#528).
void _handleUnmatchedResponse(UnmatchedRepeaterResponse unmatched) {
if (!mounted) return;
setState(() {
_commandHistory.add({
'type': 'late',
'text': unmatched.response,
'command': unmatched.command ?? '',
'seconds': unmatched.sinceTimeout == null
? ''
: (unmatched.sinceTimeout!.inMilliseconds / 1000).toStringAsFixed(
1,
),
'timestamp': DateTime.now().toString(),
});
});
_scrollToBottom();
}
@override
void dispose() {
_frameSubscription?.cancel();
@ -125,9 +103,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
if (parsed == null) return;
if (!_matchesRepeaterPrefix(parsed.senderPrefix)) return;
// The service routes this either to the waiting command's future, which
// _sendCommand appends to history, or to onUnmatchedResponse when the
// window has already closed. Both paths reach the transcript (#528).
// Goes to the waiting command's future, which _sendCommand appends to the
// transcript. A reply whose window already closed is logged by the service
// to the app log and deliberately not shown here (#589).
_commandService?.handleResponse(widget.repeater, parsed.text);
}
@ -213,15 +191,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
_scrollToBottom();
}
String _lateResponseLabel(Map<String, String> entry) {
final command = entry['command'] ?? '';
final seconds = entry['seconds'] ?? '';
if (command.isEmpty || seconds.isEmpty) {
return context.l10n.repeater_cliUnmatchedResponse;
}
return context.l10n.repeater_cliLateResponse(command, seconds);
}
void _scrollToBottom() {
Future.delayed(const Duration(milliseconds: 100), () {
if (_scrollController.hasClients) {
@ -488,25 +457,15 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
itemBuilder: (context, index) {
final entry = _commandHistory[index];
final isCommand = entry['type'] == 'command';
final isLate = entry['type'] == 'late';
final scheme = Theme.of(context).colorScheme;
final Color badgeColor;
final Color badgeIconColor;
final IconData badgeIcon;
if (isCommand) {
badgeColor = scheme.primaryContainer;
badgeIconColor = scheme.onPrimaryContainer;
badgeIcon = Icons.chevron_right;
} else if (isLate) {
badgeColor = scheme.tertiaryContainer;
badgeIconColor = scheme.onTertiaryContainer;
badgeIcon = Icons.history;
} else {
badgeColor = scheme.secondaryContainer;
badgeIconColor = scheme.onSecondaryContainer;
badgeIcon = Icons.arrow_back;
}
final badgeColor = isCommand
? scheme.primaryContainer
: scheme.secondaryContainer;
final badgeIconColor = isCommand
? scheme.onPrimaryContainer
: scheme.onSecondaryContainer;
final badgeIcon = isCommand ? Icons.chevron_right : Icons.arrow_back;
return Padding(
padding: const EdgeInsets.only(bottom: 12),
@ -526,18 +485,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (isLate)
Padding(
padding: const EdgeInsets.only(bottom: 2),
child: Text(
_lateResponseLabel(entry),
style: TextStyle(
fontSize: 11,
fontStyle: FontStyle.italic,
color: scheme.tertiary,
),
),
),
SelectableText(
entry['text']!,
style: TextStyle(

@ -183,34 +183,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
super.initState();
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
_commandService = RepeaterCommandService(connector);
_commandService!.onUnmatchedResponse = _handleUnmatchedResponse;
_setupMessageListener();
_loadSettings();
}
/// A repeater reply whose command had already timed out. This screen has no
/// transcript to append it to, so it is applied like any other response and
/// the user is told it arrived late rather than the reply being dropped
/// (#528).
void _handleUnmatchedResponse(UnmatchedRepeaterResponse unmatched) {
if (!mounted) return;
// A late reply is stale by definition. Applying it over edits the user
// made while waiting would silently discard their input, so it only lands
// when nothing is unsaved (Gemini review).
final applied =
!_hasChanges &&
unmatched.command != null &&
_handleGetResponse(unmatched.command!, unmatched.response);
showDismissibleSnackBar(
context,
content: Text(
applied
? context.l10n.repeater_lateResponseReceived
: context.l10n.repeater_lateResponseDiscarded,
),
);
}
@override
void dispose() {
_frameSubscription?.cancel();

@ -77,9 +77,16 @@ class RepeaterCommandService {
/// its window can still be presented with the request it answers.
static const Duration lateReplyRetention = Duration(minutes: 2);
/// Invoked when a reply cannot be handed to a waiting command. Consumers
/// must surface this to the user: the reply is a real answer from the
/// repeater and dropping it silently loses it for good (#528).
/// Invoked when a reply cannot be handed to a waiting command.
///
/// Every such reply is already written to the app log by
/// [_surfaceUnmatchedResponse], which is the diagnostics channel and is what
/// keeps this from being a silent drop (#528).
///
/// This sink exists for tests and for any future diagnostics view. **No
/// screen wires it.** Late arrivals became ordinary noise once #529 widened
/// the window, and the owner asked for them off the UI: log them, do not put
/// them in front of users (#589).
void Function(UnmatchedRepeaterResponse)? onUnmatchedResponse;
RepeaterCommandService(this._connector);
@ -245,13 +252,14 @@ class RepeaterCommandService {
if (expired != null) {
appLogger.warn(
'Late reply to "${expired.command}" from $repeaterKey arrived '
'${sinceTimeout!.inMilliseconds}ms after its window closed',
'${sinceTimeout!.inMilliseconds}ms after its window closed: '
'$responsePayload',
tag: 'RepeaterCommand',
);
} else {
appLogger.warn(
'Reply from $repeaterKey matched no pending or recently expired '
'command (prefix: ${prefix ?? 'none'})',
'command (prefix: ${prefix ?? 'none'}): $responsePayload',
tag: 'RepeaterCommand',
);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.