diff --git a/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md b/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md index 27b5e6b..f14758a 100644 --- a/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md +++ b/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md @@ -428,6 +428,21 @@ Each safety piece arrives with its first real use, so nothing sits untested. value during a call-home is unmeasured** -- the change path would refuse it as unknown. To measure: a MiniMate stop with ACH on, through the bridge. + - ⚠ **MiniMate config push (#46): framing fixed (`b5037b0`), NOT + usable yet.** Review 2026-10-27, measured on recorded reads: (C1) + `read_compliance_config` keeps three escape bytes from its reply + headers, so every real config is refused -- now before any frame is + sent (`push_config_raw` checks all four blocks first); (C2) fixing that + read alone lets the encoder write some fields to the wrong bytes while + the image still passes the N+2 guard (e.g. 4,096 sps written as 4,112). + The rework: read the compliance block logically (reply page bytes + + data, unescaped), encode at the measured logical offsets (mode [5], + rate [6:8], interval [8:10], record time [18:22], trigger Tran+30, + alarm Tran+38) -- with #48 --, diff-check that only the requested + fields changed, pin N per SUB, refuse unless 0x1C reads idle, give + `POST /device/config` the start/stop safeguards, and test + `apply_config` from recorded replies. Review findings I2-I4, M1-M4 + are in the #46 thread. - Still owed: - **before merging to dev, align `persist_download`'s already-stored check with what v0.32.0 shipped** (dev `04acb99`; restamp `5737168`, diff --git a/minimateplus/client.py b/minimateplus/client.py index 1269637..280e266 100644 --- a/minimateplus/client.py +++ b/minimateplus/client.py @@ -956,6 +956,17 @@ class MiniMateClient: """ proto = self._require_proto() + # Every block is checked before the first frame goes out (review of #46, + # 2026-10-27): a block refused after 68 + 73 had been sent left a partial + # write behind. write_image is the same check each write makes. + from .protocol import (SUB_COMPLIANCE_WRITE, SUB_EVENT_INDEX_WRITE, + SUB_TRIGGER_CONFIG_WRITE, SUB_WAVEFORM_DATA_WRITE, write_image) + for sub, data in ((SUB_EVENT_INDEX_WRITE, event_index_data), + (SUB_COMPLIANCE_WRITE, compliance_data), + (SUB_TRIGGER_CONFIG_WRITE, trigger_data), + (SUB_WAVEFORM_DATA_WRITE, waveform_data)): + write_image(sub, data) + # 68 → 73 log.info("push_config_raw: write event index (SUB 68)") proto.write_event_index(event_index_data) diff --git a/tests/test_minimate_write_frames.py b/tests/test_minimate_write_frames.py index 4f5997b..94683b5 100644 --- a/tests/test_minimate_write_frames.py +++ b/tests/test_minimate_write_frames.py @@ -247,3 +247,22 @@ def test_apply_config_writes_the_units_own_trigger_block(): trig = [a[0] for n, a in c._proto.writes if n == "write_trigger_config"] assert trig == [_image(0x82)[:-2]] assert trig[0][5] == 0x01 # BE9441's; the March copy had 0x03 + + +def test_a_bad_block_is_refused_before_the_first_write_goes_out(): + """Review of #46 (2026-10-27, measured on 12 recorded SFM reads): the compliance + read keeps three escape bytes from its reply headers and unescapes to + 00 + cfg[0:1024] + 00 00 + cfg[1024:2090]. That block was refused -- but only + after 68 and 73 had been sent. push_config_raw now checks all four first. + (The read is deliberately not 'fixed' on its own: the encoder would then write + some fields to the wrong bytes while the image still passes -- see #46.)""" + from minimateplus.client import MiniMateClient + cfg = _image(0x71)[:-2] + as_sfm_reads_it = b"\x00" + cfg[:1024] + b"\x00\x00" + cfg[1024:] + p, t = _proto() + c = MiniMateClient(transport=object()) + c._proto = p + with pytest.raises(ValueError, match="not a whole block"): + c.push_config_raw(_image(0x68)[:-2], as_sfm_reads_it + b"\x00\x00", + _image(0x82)[:-2], _image(0x69)) + assert t.sent == []