fix(minimateplus): a one-event download is whole or it is an error
BE9441 rebooted mid-download at the bench (2026-10-25): the chunk at 0x7D06 got one stray byte and then silence, the 5A loop logged "unexpected end-of- stream -- proceeding to TERM", the TERM got no reply either, and the short event (17,920 / 17,920 / 17,408 of 21,504 samples) was stored as a success. read_bulk_waveform_stream(strict=True) now raises on every early end: no STRT, a metadata page or chunk with no reply, a mid-stream terminator, the chunk cap, or no TERM reply. get_events passes it for the strict walks (headers_only, only_key) and, in strict mode, re-raises a 5A error instead of logging "metadata unavailable" and returning the event without frames. The legacy full walk is unchanged, call for call (strict passed only when on). Tests replay BE9441's recorded session through the real MiniMateClient: whole, event 1 comes back in full; with the 5A stream quiet from chunk 40 while the walk is still answered -- the bench's reboot -- it raises "ended early". No codec, store or DB change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
352f6944e7
commit
75d79ece6c
4 files changed
+247
-5
No files matched your search
@@ -497,6 +497,8 @@ class MiniMateClient:
|
||||
"""
|
||||
proto = self._require_proto()
|
||||
strict = headers_only or only_key is not None
|
||||
# Passed only when on, so the legacy walk's 5A call is unchanged.
|
||||
strict_5a = {"strict": True} if strict else {}
|
||||
|
||||
log.info("get_events: requesting first event (SUB 1E)")
|
||||
try:
|
||||
@@ -653,7 +655,7 @@ class MiniMateClient:
|
||||
)
|
||||
a5_frames = proto.read_bulk_waveform_stream(
|
||||
cur_key, stop_after_metadata=False, max_chunks=128,
|
||||
include_terminator=True,
|
||||
include_terminator=True, **strict_5a,
|
||||
)
|
||||
if a5_frames:
|
||||
a5_ok = True
|
||||
@@ -672,7 +674,7 @@ class MiniMateClient:
|
||||
cur_key, stop_after_metadata=True,
|
||||
include_terminator=True,
|
||||
extra_chunks_after_metadata=extra_chunks_after_metadata,
|
||||
max_chunks=128,
|
||||
max_chunks=128, **strict_5a,
|
||||
)
|
||||
if a5_frames:
|
||||
a5_ok = True
|
||||
@@ -684,6 +686,8 @@ class MiniMateClient:
|
||||
ev.project_info.operator if ev.project_info else None,
|
||||
)
|
||||
except ProtocolError as exc:
|
||||
if strict:
|
||||
raise # a one-event download is whole or it is an error
|
||||
log.warning(
|
||||
"get_events: 5A failed for key=%s: %s — metadata unavailable",
|
||||
cur_key.hex(), exc,
|
||||
|
||||
@@ -538,11 +538,19 @@ class MiniMateProtocol:
|
||||
max_chunks: int = 256, # safety cap only; loop is bounded by end_offset
|
||||
include_terminator: bool = False,
|
||||
extra_chunks_after_metadata: int = 1, # DEPRECATED — no-op
|
||||
strict: bool = False,
|
||||
) -> list[S3Frame]:
|
||||
"""
|
||||
Download the SUB 5A (BULK_WAVEFORM_STREAM) A5 frames for one event using
|
||||
Blastware's exact protocol. REWRITTEN 2026-05-02 (v0.14.0).
|
||||
|
||||
strict: the stream must arrive whole, or this raises ProtocolError -- a
|
||||
missing STRT, a metadata page or chunk with no reply, a mid-stream
|
||||
terminator, the chunk cap, or no TERM reply. The one-event download uses
|
||||
it: a short event must never be stored (BE9441 rebooted mid-download on
|
||||
2026-10-25 and its partial event was kept). Without strict the legacy
|
||||
tolerance stands: an early end proceeds to TERM and returns what arrived.
|
||||
|
||||
Algorithm (matches BW captures across 2-sec / 3-sec / event-2):
|
||||
|
||||
1. Probe
|
||||
@@ -645,6 +653,10 @@ class MiniMateProtocol:
|
||||
|
||||
# ── Step 2: parse STRT end_offset from probe response ────────────────
|
||||
end_offset = parse_strt_end_offset(rsp.data)
|
||||
if end_offset is None and strict:
|
||||
raise ProtocolError(
|
||||
f"5A probe for {key4.hex()} carried no STRT record, so the event's end "
|
||||
"is unknown -- not downloaded")
|
||||
if end_offset is None:
|
||||
log.warning(
|
||||
"5A probe response did not contain a STRT record; "
|
||||
@@ -683,7 +695,11 @@ class MiniMateProtocol:
|
||||
meta_rsp = self._recv_one(
|
||||
expected_sub=rsp_sub, reset_parser=False, timeout=10.0,
|
||||
)
|
||||
except TimeoutError:
|
||||
except TimeoutError as exc:
|
||||
if strict:
|
||||
raise TimeoutError(
|
||||
f"5A stream ended early: metadata page 0x{meta_counter:04X} got "
|
||||
"no reply -- the event was not kept") from exc
|
||||
log.warning(
|
||||
"5A metadata page 0x%04X TIMED OUT — continuing",
|
||||
meta_counter,
|
||||
@@ -728,12 +744,17 @@ class MiniMateProtocol:
|
||||
rsp = self._recv_one(
|
||||
expected_sub=rsp_sub, reset_parser=False, timeout=10.0,
|
||||
)
|
||||
except TimeoutError:
|
||||
except TimeoutError as exc:
|
||||
raw = self._parser.bytes_fed
|
||||
log.warning(
|
||||
"5A TIMEOUT chunk=%d counter=0x%04X raw_bytes=%d",
|
||||
chunks_fetched + 1, counter, raw,
|
||||
)
|
||||
if strict:
|
||||
raise TimeoutError(
|
||||
f"5A stream ended early: no reply for the chunk at 0x{counter:04X}; the "
|
||||
f"event ends at 0x{end_offset:04X} ({chunks_fetched} chunk(s) received) "
|
||||
"-- the event was not kept") from exc
|
||||
if raw > 0 and frames_data:
|
||||
log.warning(
|
||||
"5A unexpected end-of-stream — proceeding to TERM",
|
||||
@@ -748,6 +769,10 @@ class MiniMateProtocol:
|
||||
|
||||
if rsp.page_key == 0x0000:
|
||||
# Device terminated mid-stream unexpectedly.
|
||||
if strict:
|
||||
raise ProtocolError(
|
||||
f"5A stream ended early: the unit sent its terminator at 0x{counter:04X}, "
|
||||
f"before the event's end 0x{end_offset:04X} -- the event was not kept")
|
||||
log.warning(
|
||||
"5A unexpected page_key=0x0000 mid-stream at counter=0x%04X",
|
||||
counter,
|
||||
@@ -761,6 +786,10 @@ class MiniMateProtocol:
|
||||
counter += _BULK_COUNTER_STEP
|
||||
chunks_fetched += 1
|
||||
else:
|
||||
if strict:
|
||||
raise ProtocolError(
|
||||
f"5A reached the {max_chunks}-chunk cap at 0x{counter:04X} before the "
|
||||
f"event's end 0x{end_offset:04X} -- the event was not kept")
|
||||
log.warning(
|
||||
"5A reached max_chunks=%d at counter=0x%04X (end=0x%04X)",
|
||||
max_chunks, counter, end_offset,
|
||||
@@ -796,7 +825,11 @@ class MiniMateProtocol:
|
||||
)
|
||||
if include_terminator:
|
||||
frames_data.append(term_rsp)
|
||||
except TimeoutError:
|
||||
except TimeoutError as exc:
|
||||
if strict:
|
||||
raise TimeoutError(
|
||||
"5A stream ended early: no reply to the TERM request, which carries the "
|
||||
"event's tail and footer -- the event was not kept") from exc
|
||||
log.warning("5A no TERM response (timeout)")
|
||||
|
||||
return frames_data
|
||||
|
||||
Reference in new issue
Block a user