From 68b216644578ebe5208dc7315124758ea5f61bde Mon Sep 17 00:00:00 2001 From: MarekWo Date: Sat, 21 Feb 2026 08:09:28 +0100 Subject: [PATCH] fix: Use unstripped raw_text for pkt_payload computation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parser's .strip() was removing trailing whitespace from message text, but the encrypted radio payload includes those trailing spaces. This caused pkt_payload mismatches for messages ending with spaces (e.g., "DzieƄ dobry "). Use original unstripped text for raw_text. Also add debug logging for unmatched messages to help diagnose remaining edge cases. Co-Authored-By: Claude Opus 4.6 --- app/meshcore/parser.py | 5 +++-- app/routes/api.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/meshcore/parser.py b/app/meshcore/parser.py index 9192734..2db2c7d 100644 --- a/app/meshcore/parser.py +++ b/app/meshcore/parser.py @@ -37,7 +37,8 @@ def parse_message(line: Dict, allowed_channels: Optional[List[int]] = None) -> O return None timestamp = line.get('timestamp', 0) - text = line.get('text', '').strip() + raw_text = line.get('text', '') + text = raw_text.strip() if not text: return None @@ -72,7 +73,7 @@ def parse_message(line: Dict, allowed_channels: Optional[List[int]] = None) -> O 'channel_idx': channel_idx, 'sender_timestamp': line.get('sender_timestamp'), 'txt_type': line.get('txt_type', 0), - 'raw_text': text + 'raw_text': raw_text } diff --git a/app/routes/api.py b/app/routes/api.py index 5c7759e..17d47d4 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -378,6 +378,7 @@ def get_messages(): for msg in messages: if not msg.get('is_own') and msg.get('sender_timestamp') and msg.get('channel_idx') in channel_secrets: secret = channel_secrets[msg['channel_idx']] + matched = False for attempt in range(4): try: payload = compute_pkt_payload( @@ -390,7 +391,17 @@ def get_messages(): entry = incoming_by_payload[payload] msg['paths'] = entry.get('paths', []) msg['analyzer_url'] = compute_analyzer_url(payload) + matched = True break + if not matched and incoming_by_payload: + raw = msg.get('raw_text', '') + logger.debug( + f"Echo mismatch: ts={msg.get('sender_timestamp')} " + f"ch={msg.get('channel_idx')} " + f"text_bytes={len(raw.encode('utf-8'))} " + f"computed_payload={payload[:16]}... " + f"text_preview={raw[:40]!r}" + ) except Exception as e: logger.debug(f"Echo data fetch failed (non-critical): {e}")