From 6f31eca36606831a7a0bfef5245e270b8352c72a Mon Sep 17 00:00:00 2001 From: serversdown Date: Mon, 26 Oct 2026 14:44:11 -0400 Subject: [PATCH] docs: the 64 KB page bug is fixed; the 5A 'non-standard frame' model retracted in place CLAUDE.md: the KNOWN BUG entry marked fixed (887e75d) with what settled it, and retraction notes under the 5A sections that described the misreading (partial stuffing, offset_hi 0x10 raw, 11-byte params, metadata pages 0x1002/0x1004). Series-III reference: a 2026-10-26 (3) row. Spec: the MiniMate check updated. Code comments that called the page bug open, updated; the adapter's struct.error mapping kept as a defence, its message and test no longer naming the old bug. Verified live on BE9441 the same day: all 8 events downloaded by serial, the 4 that cross a 64 KB page included, each whole and matching the unit's own peaks. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44 --- CLAUDE.md | 37 ++++++++++++++++++- docs/instantel_protocol_reference.md | 1 + .../2026-10-20-sfm-series4-parity-design.md | 13 ++++--- micromate/protocol.py | 5 ++- sfm/device_access/s3.py | 9 ++--- tests/test_device_access_s3_events.py | 6 ++- 6 files changed, 56 insertions(+), 15 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 439f547..ab14535 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -244,7 +244,23 @@ Read this first when picking the project back up. 4th-decimal tick and are Thor's own rounding — no single linear LSB can reproduce every printed value (the constraints are infeasible by 7e-5 relative), so do NOT retune `_GEO_LSB_IPS`. -- **⚠ KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB.** +- **✅ FIXED 2026-10-26 (`887e75d`) — was: "KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB."** + Kept below as history. The fix came from a recording of Blastware downloading all 8 of + BE9441's events, 3 crossing a page (`tests/fixtures/minimate-bench-10-26-26-blastware/`): + - **Every MiniMate request DLE-escapes 02, 03, 04 and 10**, payload and checksum alike + (748/748 re-encode). `build_bw_frame` had escaped only 0x10. + - **A 5A request is an ordinary request carrying a LENGTH and a 4-byte linear ADDRESS.** + The walk: the event's start, +0x200 carrying into the page byte, then TERM at the + next boundary for the remainder. + - **The old model misread the same bytes.** The "offset 0x1002" is length 0x0200 + escaped; the "metadata pages at 0x1002/0x1004" are event 0's chunks at 0x0200 and + 0x0400; the 16-bit counter could not leave its page. + - **Verified on BE9441**, live: all 8 events, including 4 page crossings, downloaded + whole and matched the unit's own peaks. + ⚠ Sections below that describe "partial DLE stuffing", "11-byte params", "offset_hi + 0x10 raw" and "metadata pages 0x1002/0x1004" are that misreading. They are retracted + here, not deleted. + ~~**⚠ KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB.**~~ `parse_strt_end_offset()` returns only `(end_key[2] << 8) | end_key[3]`, discarding the key's page byte. An event starting at `0x0111F2A2` and ending at `0x0112_1010` therefore reads `end_offset = 0x1010` — *behind* its own @@ -843,6 +859,14 @@ S3→BW (response): ## Critical protocol gotchas (hard-won — do not re-derive) ### SUB 5A — bulk waveform stream — NON-STANDARD frame format +> ⚠ **RETRACTED 2026-10-26 (measured): it is a standard frame.** The payload is +> `[10 00 5A 00][length BE][address BE 4][zeros 6]` with a SUM8 checksum, and every +> 02/03/04/10 is DLE-escaped (`s3_stuff`, `build_5a_request`). "offset_hi 0x10 raw" was +> the length 0x0200 escaped (`10 02 00`). The "DLE-aware checksum" is SUM8 of the +> unescaped payload. The "partial stuffing" carve-outs were the escape rule seen half. +> All 540 of Blastware's 5A requests rebuild byte for byte +> (`tests/test_5a_blastware_walk.py`). The text below is history. + **Always use `build_5a_frame()` for SUB 5A. Never use `build_bw_frame()` for SUB 5A.** @@ -883,6 +907,9 @@ the 1-2-26 BW TX capture (10 frames). Difference (3) confirmed against the 5-1- "bwcap3sec" capture (17 frames, all match byte-for-byte after fix). ### SUB 5A — chunk counter formula (REWRITTEN 2026-05-01 — see 5-1-26 captures) +> ⚠ **SUPERSEDED 2026-10-26:** a chunk is addressed by a full 32-bit address, stepping +> +0x200 across page boundaries; no event-1 special case (see `read_bulk_waveform_stream`). + > ⚠️ **Everything that came before this rewrite was WRONG in important ways.** The previous > formula `max(key4[2:4], 0x0400) + (chunk_num - 1) * 0x0400` happened to *work* for events @@ -1031,6 +1058,11 @@ are wrong; the device's response under that path is a tiny 101-byte device-side (arrived only after we walked the entire post-event buffer), not the proper file footer. ### SUB 5A — fixed metadata pages 0x1002 and 0x1004 (NEW 2026-05-01) +> ⚠ **RETRACTED 2026-10-26 (measured):** these are not fixed global pages. They are the +> first event's own chunks at addresses 0x0200 and 0x0400, which escape to `10 02 00` and +> `10 04 00` on the wire. A non-first event has no such reads because it does not start at +> 0x0000. Their strings are still read as described below. + Two chunk addresses are GLOBAL device/session metadata, not event-specific: @@ -1055,6 +1087,9 @@ locates the ASCII strings via label scans (`Project:`, `Client:`, `User Name:`, dump the structural layout if more session-global fields need to be extracted. ### SUB 5A — params are 11 bytes for chunk frames, 10 for termination +> ⚠ **RETRACTED 2026-10-26:** every 5A request has the standard 10 params bytes (address + +> 6 zeros). The "11th byte" was the length's low byte, read as params. + `bulk_waveform_params()` returns 11 bytes (extra trailing `0x00`). The 11th byte was confirmed from the BW wire capture. `bulk_waveform_term_params()` returns 10 bytes. diff --git a/docs/instantel_protocol_reference.md b/docs/instantel_protocol_reference.md index bfe0129..04f0670 100644 --- a/docs/instantel_protocol_reference.md +++ b/docs/instantel_protocol_reference.md @@ -11,6 +11,7 @@ | Date | Section | Change | |---|---|---| +| 2026-10-26 (3) | §3, §7.8, §10 | **⚠ RETRACTS the 5A "non-standard frame" model; the 64 KB page bug is FIXED (measured).** A bridge recorded Blastware downloading all 8 of BE9441's events, 3 crossing a 64 KB page (`tests/fixtures/minimate-bench-10-26-26-blastware/`). **Every request** is the standard 16-byte payload with a SUM8 checksum and **every 02, 03, 04 and 10 DLE-escaped**, payload and checksum alike: 748/748 re-encode byte-identically. §10's "only 0x10 is stuffed" is half the rule. **A 5A request is an ordinary request** `[10 00 5A 00][length BE 2][address BE 4][zeros 6]`, where length is 0x0200 per chunk and the remainder for TERM. The walk: the event's start address, +0x200 at a time as plain 32-bit addresses (carrying into the page byte), then TERM at the next boundary for exactly the remainder, ending at STRT's full 32-bit end key. **Misreadings retracted:** the fixed "offset 0x1002" is length 0x0200 escaped (`10 02 00`); the "metadata pages at 0x1002 / 0x1004, global, read once per session" are the first event's own chunks at 0x0200 and 0x0400; the "11-byte params" counted the length's low byte; the "partial DLE stuffing" carve-outs were the escape rule seen half; the 16-bit counter is why a walk could not leave its page. **Verified live on BE9441:** all 8 events downloaded whole, the 4 crossings included, each matching the unit's own 0C peaks. Code `887e75d`. | | 2026-10-26 (2) | §7.8 | **The 64 KB page bug, narrowed (measured, BE9441).** Blastware's own downloads of all 20 events (Brian, `example-events/10-25-26 - thumps`) give byte-exact ground truth. SFM's downloads of events 0, 1, 3, 4 and 10 are **byte-identical** to Blastware's. Importing Blastware's files first (the watcher route) makes SFM's downloads of the same events return `already_stored`: the unit's 0C and Blastware's file agree on (serial, timestamp). For an event that crosses a page (event 2, `0111c92c` → STRT end key `01122f06`, full 32 bits) a read-only test walk with the page byte carried (params `00 01 12 01 2c`) got a proper A5 reply for the first chunk in page 0x12, echoing `01 12 01 2c`. The second chunk, `00 01 12 03 2c`, got no reply frame: a raw 0x03 (ETX) inside the params. Page 0x11 never shows this, because event 1 skips 0x0000–0x05FF, so no counter there has a 02/03/04 byte. Every later page does. ⚠ How Blastware encodes a lone 02/03/04 inside params is unknown: §7.8 says `10 02/03/04` is kept as a literal pair, which would shift the address. A wire capture of Blastware downloading BE9441 event 2 or 19 settles it. Blastware's files are fixtures (`tests/fixtures/minimate-bench-10-25-26/blastware/`). | | 2026-10-26 | §7.8 | **5A requests must DLE-escape a checksum that is a framing byte (measured, BE9441).** The request for chunk 0x7D06 of event 01122f06 ends `… 02 03`: a bare 0x02 checksum (STX) before ETX. BE9441 never answered it, twice on two days, and rebooted ~11 s later each time; that was the 'mid-download reboot' of 2026-10-25 (row below). Sent as `… 10 02 03` it answered in 28 ms. So did chunk 0x7F06 (checksum 0x04 → `10 04`) and 0x8B06 (checksum 0x10 → `10 10`; sent bare, that reads as DLE+ETX), and the event downloaded whole and matched the unit's peaks. Escape set {02, 03, 04, 10}: a Micromate's for every byte (251/251 THOR requests), and consistent with §7.8's de-stuffing rule (`10 02/03/04` literal). About 1 chunk request in 64 has such a checksum. ⚠ Not known: whether standard (non-5A) requests need the same. No such keyed-read checksum has been sent. Also measured on the re-run: events that end in the next 64 KB page (BE9441 events 2 and 19) read an end offset lower than their start (the known page bug); every other event downloaded whole and verified. | | 2026-10-25 | §7.2, §7.8, §6 | **MiniMate bench check, BE9441 (S338.17, mic disabled, serial cable). SFM read its 24-entry event index, listed 20 events, and downloaded 4.** Measured: (1) **§7.2: the 0x15 serial is a C string.** `"BE9441\x00?"`: a six-character serial leaves a stray byte after its NUL. (2) **§7.8: every A5 reply echoes the address it answers at `data[2:6]`.** The metadata pages come back as `01 11 10 02` and `01 11 10 04`; sample chunks as their own address, e.g. `01 11 66 6a`. The event-1 walk fetches the metadata pages as frames 1 and 2. A non-first event's walk fetches none and goes straight from the probe to sample chunks. SFM's body builder assumed metadata pages in every stream, so every non-first event it assembled was 2 bytes short and decoded truncated; it now checks the echoed addresses. The bug was in SFM's assembly; the protocol was as already documented. (3) **§6: the unit boots when its serial port opens.** It sent `Operating System` ~3 s after the port opened (twice) and ignored a POLL sent before that. After a mid-download reboot it answered 8.8 s after its banner (one data point). (4) **The unit rebooted once mid-download.** The chunk at 0x7D06 got one stray `0x41`, then silence, then the banner 11 s later. Cause unknown, inferred not measured: battery 6.33–6.37 V, a firmware reset. ⚠ **RETRACTED 2026-10-26:** the cause is measured, and it was our request. The chunk request had a bare 0x02 checksum. See the 2026-10-26 row. (5) The event index said 24 while the header walk listed 20 full records. **Inferred:** the other 4 are monitor-log entries. Single-shot events at 4096 sps with a 5 s record give **21,504 samples per channel** (5 s record + 0.25 s pre-trigger = 5.25 s at 4096 sps), all three channels equal, peaks equal to the unit's own 0C values. | 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 70d8f82..bccd973 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 @@ -389,16 +389,19 @@ Each safety piece arrives with its first real use, so nothing sits untested. Blastware's. Importing Blastware's files first through the watcher route makes SFM's downloads return `already_stored`, with no duplicate rows. - - 🔶 **The 64 KB page bug** is narrowed. The page byte carries; a raw - 02/03/04 inside the params is the blocker. It needs a Blastware wire - capture of event 2 or 19 (CLAUDE.md, KNOWN BUG). + - ✅ **The 64 KB page bug is FIXED (`887e75d`).** A recording of + Blastware downloading all 8 events (4 crossing a page) showed every + request escapes 02/03/04/10, and that a 5A request is an ordinary one + carrying a length and a 32-bit linear address. Live on BE9441, all 8 + events downloaded whole and verified, the 4 crossings included. - Still owed: - a histogram event (this unit records single shot); - start/stop through the new path, with Brian present; - a dropped reply via fault injection. It happened for real on 10-25, but that was our checksum bug, not a lossy link; - - ⚠ whether standard (non-5A) requests need the same checksum - escape. No keyed read has had such a checksum yet. + - ~~whether standard (non-5A) requests need the same checksum + escape~~: settled 2026-10-26. Every request escapes 02/03/04/10 + (748/748 Blastware requests), and `build_bw_frame` now does. - **Download = fetch, check, store** in SFM's database, the same as Series 3's `blastware_file` route, and returns the stored row's id. The file and waveform are then served by the existing `/db/events/{id}/…` diff --git a/micromate/protocol.py b/micromate/protocol.py index ab5883f..6e4c4f4 100644 --- a/micromate/protocol.py +++ b/micromate/protocol.py @@ -231,8 +231,9 @@ def chunk_params(key4: bytes, byte_offset: int) -> bytes: ⚠ This is the **Series III 64 KB page-boundary bug in a new guise** — there, `parse_strt_end_offset()` discards the key's page byte and the `5A` walk - crashes once a unit's buffer crosses 64 KB, which is *still open* on that - side. The lesson that transfers: an address field whose high bytes are zero + crashed once a unit's buffer crossed 64 KB (fixed 2026-10-26: a Blastware + recording showed its 5A address is a plain 32-bit linear one, like this). + The lesson that transfers: an address field whose high bytes are zero in every capture is not a narrow field, it is an untested one. """ if byte_offset == 0: diff --git a/sfm/device_access/s3.py b/sfm/device_access/s3.py index c47a95e..e84c49e 100644 --- a/sfm/device_access/s3.py +++ b/sfm/device_access/s3.py @@ -322,12 +322,11 @@ class Series3Adapter: try: ev = client.download_event_by_key(key, expected_timestamp=iso) except struct.error as exc: - # Inferred, not measured here: the known 5A page bug. An event past the unit's - # first 64 KB drives TERM's offset negative, and struct.pack rejects it - # (seismo-relay CLAUDE.md, "KNOWN BUG"). + # Defensive. This once caught the 64 KB page bug (TERM's offset driven + # negative); the walk is 32-bit linear since 2026-10-26 and no longer + # produces it, so reaching here is a new fault. raise MalformedReply( - f"event {key.hex()}: its download could not be assembled ({exc}) -- most " - "likely the known bug with events past the unit's first 64 KB; not saved" + f"event {key.hex()}: its download could not be assembled ({exc}); not saved" ) from exc if ev is None: raise EventNotFound(f"no event {key.hex()} on {serial} -- list the events again") diff --git a/tests/test_device_access_s3_events.py b/tests/test_device_access_s3_events.py index e4ac8b7..9f17183 100644 --- a/tests/test_device_access_s3_events.py +++ b/tests/test_device_access_s3_events.py @@ -122,11 +122,13 @@ def test_a_failed_5a_is_a_clear_error(): adapter(fake).download_event(TCP, "BE18193", FIRST, None) -def test_the_64k_page_bug_is_named_not_a_bare_500(): +def test_an_assembly_fault_is_a_named_502_not_a_bare_500(): + # Once the 64 KB page bug's signature; that is fixed (2026-10-26), and the + # mapping stays as a defence against any struct.error in assembly. fake = FakeMiniMateClient() def boom(key4, **kw): raise struct.error("argument out of range") fake.download_event_by_key = boom - with pytest.raises(MalformedReply, match="64 KB"): + with pytest.raises(MalformedReply, match="could not be assembled.*not saved"): adapter(fake).download_event(TCP, "BE18193", FIRST, None)