fix(sfm): a change that fails after the send says so; the audit row records sent + states; S3 unknown states refused

Final fix wave for phase 3 (start/stop monitoring), per the whole-phase review.

- I1 + M2: every failure after the send has started is a ChangeUnconfirmed
  (audit_id, sent = "acknowledged" | "unknown", the cause's HTTP status) whose
  message says the frame was sent and names the audit record -- the ring in
  place of the ack, the four lost-ack follow-ups, and the three read-back
  paths.  Series4Session releases the line on it.  Every audit finish goes
  through one helper; a finish that fails is AuditIncomplete (500) and still
  says what happened to the unit.  The line is kept.
- I2: device_commands gains `sent` (1 acknowledged, 0 nothing sent, NULL
  unknown) and `states` (before / seen / after), with an idempotent ADD COLUMN
  in _migrate for a table created earlier on this branch.
- M1: a RADIO RING already buffered is caught before 0x96/0x97 goes out
  (pre_send = read_unsolicited, one 10 ms transport read).  That is a
  CallHomeInProgress with sent=0, not ChangeUnconfirmed.
- M3: Series 3 reads the raw 0x1C flag (new MonitorStatus.state_flag); a byte
  other than 0x00/0x10, or a short section, is unknown(...) and refused.
- M8: even_if_already on a unit already in the state notes that the read-back
  proves nothing.
- M10: a scan pins `.protocol.execute(` to sfm/device_access/s4.py; both
  scans fail closed on a file that does not parse.
- M11: docs corrected (CLAUDE.md phase-2 sentence, phase-3 bullet, REST list;
  micromate/protocol.py scope and the 0x49 read_state docstring; s4.py; route
  docstrings).  "No command has ever been originated" is NOT retracted.
- M12: GET /db/device_commands normalises the serial.
- Minors: unused imports, S3 dry-run frames and 120 s timeout pinned, test
  rename, serial-cache and short-0x49 tests, _RUN_STATES comment.

Schema: two NULLable columns on the branch-new device_commands table, added
by _migrate on open; no backfill.  No codec change, TOOL_VERSION unchanged.

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-10-23 19:16:45 -04:00
1 parent ac33c8ffa4
commit 8f68b09f5e
18 files changed
+806 -107

No files matched your search

+24
View File
@@ -611,3 +611,27 @@ def test_serial_refresh_reads_the_unit_again():
mm._serial = "UM99999" # a stale cached serial
assert mm.serial(refresh=True) == "UM20147"
assert len(t.written) == 1
assert mm._serial == "UM20147" # the cache took the fresh read
assert mm.serial() == "UM20147" and len(t.written) == 1 # and a plain read sends nothing
@pytest.mark.parametrize("data", [b"", bytes(11)])
def test_an_empty_or_short_0x49_reply_raises(data):
mm, _t = client([frame(0xB6, data)])
with pytest.raises(ProtocolError, match="no content"):
mm.read_run_state()
def test_reading_unsolicited_bytes_keeps_executes_fresh_reply_precondition():
"""The change path drains the line between its state read and its send. A
raw transport read never goes through `_send`, so the trust `execute`
needs survives it."""
from micromate.protocol import ACK_DATA_LEN
from micromate.writes import plan_start_monitoring
mm, t = client([frame(0xB6, bytes(11) + bytes([0x00]) + bytes(4)), b"\x00\xff stray",
frame(0x69, bytes(ACK_DATA_LEN))])
assert mm.read_run_state().name == "idle"
assert mm.read_unsolicited() == b"\x00\xff stray"
assert mm.protocol.last_flags == FLAGS_CB
acks = mm.protocol.execute(plan_start_monitoring())
assert [a.sub for a in acks] == [0x69] and len(t.written) == 2