G2: F21/M01 — fix send_msg_with_retry fallthrough to KeyError on ERROR

Why: When send_msg() returned an ERROR event (e.g. firmware rejected
the send), the error-check logged the failure but did not return or
continue.  Execution fell through to result.payload["expected_ack"],
which raised KeyError because the ERROR payload is {"reason": "..."}.
The retry loop — the entire purpose of this function — never ran.
Now the ERROR path increments attempt counters and continues the
loop, preserving the retry semantics the function name promises.

Refs: Forensics report findings F21, M01
This commit is contained in:
Matthew Wolter 2026-04-11 20:03:49 -07:00
parent 6a74f07da7
commit 1e508a3636

View file

@ -144,8 +144,12 @@ class MessagingCommands(CommandHandlerBase):
logger.info(f"Retry sending msg: {attempts + 1}")
result = await self.send_msg(dst, msg, timestamp, attempt=attempts)
if result.type == EventType.ERROR:
logger.error(f"⚠️ Failed to send message: {result.payload}")
if result.is_error():
logger.error(f"Failed to send message: {result.payload}")
attempts += 1
if flood:
flood_attempts += 1
continue
exp_ack = result.payload["expected_ack"].hex()
timeout = result.payload["suggested_timeout"] / 1000 * 1.2 if timeout==0 else timeout
@ -255,7 +259,7 @@ class MessagingCommands(CommandHandlerBase):
elif path_hash_len == 8 :
flags = 3
else :
logger.error(f"Invalid path format: {e}")
logger.error(f"Invalid path format: unknown path_hash_len {path_hash_len}")
return Event(EventType.ERROR, {"reason": "invalid_path_format"})
else:
flags = 0