From a130107fdf0927952d01df9acc49fbd5727cd5a6 Mon Sep 17 00:00:00 2001 From: serversdown Date: Wed, 21 Oct 2026 17:58:18 -0400 Subject: [PATCH] fix(sfm): a Series-4 record whose timestamp did not decode is not called stale Mirrors the Series-3 fix (F3): an unreadable 0C timestamp is a decode or comms fault, not proof the unit was erased. Nothing is downloaded. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44 --- sfm/device_access/s4.py | 4 ++++ tests/test_device_access_s4_events.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/sfm/device_access/s4.py b/sfm/device_access/s4.py index 4c9e277..a1ceada 100644 --- a/sfm/device_access/s4.py +++ b/sfm/device_access/s4.py @@ -282,6 +282,10 @@ def s4_download_event(client: Any, serial: str, key: bytes, stamp: Optional[str] if ref.key != key: continue found = stamp_of(ref.timestamp) + if stamp is not None and found is None: + raise MalformedReply( + f"could not read event {key.hex()}'s record (0C) timestamp to confirm it " + "is the one listed -- not downloaded; try again") if stamp is not None and found != stamp: raise StaleEvent( f"the event at {key.hex()} on {serial} is from {found}, not {stamp} -- " diff --git a/tests/test_device_access_s4_events.py b/tests/test_device_access_s4_events.py index 2a803b0..4b30136 100644 --- a/tests/test_device_access_s4_events.py +++ b/tests/test_device_access_s4_events.py @@ -69,3 +69,14 @@ def test_a_stale_id_is_refused_and_nothing_is_downloaded(): def test_a_key_that_is_not_stored_is_404(): with pytest.raises(EventNotFound): s4_download_event(FakeMicromateClient(), "UM20147", bytes.fromhex("deadbeef"), None) + + +def test_a_record_whose_timestamp_did_not_decode_is_not_called_stale(): + # Mirrors Series 3 (F3): an unreadable 0C timestamp is a comms/decode fault, + # not proof the unit was erased -- and nothing is downloaded. + from sfm.device_access.errors import MalformedReply + fake = FakeMicromateClient() + fake.event_refs[0].timestamp = None + with pytest.raises(MalformedReply, match="0C"): + s4_download_event(fake, "UM20147", W_KEY, "20250531135901") + assert fake.fetched == []