fix(framing): an escaped checksum no longer leaves its 0x10 in a reply's data (#58)

A MiniMate sends a checksum of 02, 03 or 04 as `10 X`.  S3FrameParser kept
both bytes and _finalise took only the last as the checksum, so the frame's
data ended in a stray 0x10.  It now takes the pair.

Measured on every recorded reply (60 captures, March to October 2026): SUM8
of the unescaped payload is the checksum on 7,747 of 7,747; 272 arrived
escaped, all valid as an escape pair.

What the stray byte did:
- 1C status: battery and memory are counted from the end; 12 of 760 recorded
  status replies read 419.84 V / 251,654,656 bytes (6.76 V / 983,026).
- 2C call-home read: one byte long, refused as "monitoring".
- 1A, 09 reads: already trimmed (bench 2026-11-04); the trims stay as guards.
- 5A file builder: compensated in _frame_body_bytes; that pairing is removed,
  else a real 0x10 ending a chunk (one in ten do) would be dropped.

Stored .a5.pkl frames: A5_PICKLE_VERSION 2; load_a5 drops the stray 0x10
from version-1 frames.  All 28 pickles on this box rebuild byte-identical
to dev's build.

Operational consequence: none for prod's stored events (S3 events arrive
through save_imported_bw, which keeps no frames); no schema change, no
TOOL_VERSION bump, no backfill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-06 14:52:50 -05:00
1 parent d2fe675650
commit 89c5234ac0
6 files changed
+214 -71

No files matched your search

+8 -6
View File
@@ -196,10 +196,11 @@ def assemble_compliance_content(frames: "list[bytes]", lengths: "Optional[tuple]
`lengths`: the content each frame was asked for (SFM's read: 1024, 1024, 42).
Each frame then gives exactly that. Measured at the bench 2026-11-04 (BE9441):
when a frame's checksum byte is itself escaped (02 / 03 / 04), the parser keeps
the escape's 0x10 and strips only the byte after it, so the frame arrives one
byte long, ending in a lone 0x10. That one byte is dropped; any other leftover
is kept, and the block then fails is_compliance_content."""
when a frame's checksum byte was itself escaped (02 / 03 / 04), the parser kept
the escape's 0x10, so the frame arrived one byte long, ending in a lone 0x10.
The parser drops it since #58; this trim stays as a guard. That one byte is
dropped; any other leftover is kept, and the block then fails
is_compliance_content."""
parts = [unescape_reply(bytes(f))[11:] for f in frames]
parts = [p[1:] for p in parts[:-1]] + parts[-1:]
if lengths is not None and len(lengths) == len(parts):
@@ -633,8 +634,9 @@ class MiniMateProtocol:
data_rsp = self._recv_one(expected_sub=rsp_sub)
raw = unescape_reply(data_rsp.data)[11:] # unescaped, as read_event_index
# An escaped checksum byte leaves its 0x10 behind (bench 2026-11-04; see
# assemble_compliance_content): one stray byte beyond what was asked is dropped.
# An escaped checksum byte left its 0x10 behind until #58 (bench 2026-11-04;
# see assemble_compliance_content): kept as a guard, one stray byte beyond
# what was asked is dropped.
if len(raw) == length + 1 and raw[-1:] == b"\x10":
raw = raw[:-1]
log.debug("read_waveform_data_raw: got %d bytes", len(raw))