fix(sfm): a MiniMate start's read-back reconnects once when the modem dropped the line (#9)

BE9441 over a modem, 2026-10-29: the start was acked, but the modem closed the
line during the ~30 s sensor check, so the read-back's first wake hit
'[Errno 32] Broken pipe' and the change was reported 503 'not checked' although
the unit was monitoring.  On an OSError in the read-back, a TCP unit is now
reconnected once, its serial checked against the named unit, and its state read.
Nothing is re-sent: the start still goes out exactly once.  A serial cable is
never reconnected (opening a MiniMate's port reboots it), a second failure or a
silence (a cleanly closed line) ends 'not checked' as before, and a different
unit after the reconnect is refused (409, change unconfirmed).

Store consequence: none.

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-29 23:21:27 -04:00
1 parent b320a534bc
commit ce441a0911
3 files changed
+81 -2

No files matched your search

+21 -1
View File
@@ -227,10 +227,30 @@ class Series3Adapter:
settle.append(S3_SENSOR_CHECK_S) # the first read waits out the check settle.append(S3_SENSOR_CHECK_S) # the first read waits out the check
return {"subs": [f"0x{ack_sub:02X}"]} return {"subs": [f"0x{ack_sub:02X}"]}
reconnected: list = []
def read_state() -> str: def read_state() -> str:
if settle: if settle:
sleep(settle.pop()) sleep(settle.pop())
return _woken_state(client) try:
return _woken_state(client)
except OSError as exc:
# The modem can drop the line while the unit sensor-checks
# after a start: BE9441's first wake hit "[Errno 32] Broken
# pipe" (2026-10-29), and a fresh connection read it as
# monitoring. Reconnect once, TCP only (opening a MiniMate's
# serial port reboots it), check it is still the same unit,
# and read. A read -- nothing is re-sent.
if reconnected or not address.host:
raise
reconnected.append(True)
log.warning("Series 3 at %s: the line dropped during the read-back (%s) -- "
"reconnecting to read the state; nothing is re-sent",
address.key, exc)
client.close()
client.open()
self._check(client.read_serial(), serial, address)
return _woken_state(client)
return run_change( return run_change(
serial=serial, series=3, start=start, dry_run=dry_run, serial=serial, series=3, start=start, dry_run=dry_run,
+11 -1
View File
@@ -75,9 +75,13 @@ def default_s3_events():
class FakeMiniMateClient(_Base): class FakeMiniMateClient(_Base):
def __init__(self, serial="BE18193", *, monitoring=False, compliance="default", events=None, def __init__(self, serial="BE18193", *, monitoring=False, compliance="default", events=None,
monitor_states=None, write_error=None, **kw): monitor_states=None, write_error=None, serial_reported=None, wake_errors=None, **kw):
super().__init__(**kw) super().__init__(**kw)
self.serial = serial self.serial = serial
# read_serial()'s answer (connect() keeps answering `serial`), and errors
# raised by wake() once a write has gone out -- the read-back's wakes.
self.serial_reported = serial if serial_reported is None else serial_reported
self.wake_errors = list(wake_errors or [])
self.monitoring = monitoring self.monitoring = monitoring
self.monitor_states = list(monitor_states) if monitor_states else [monitoring] self.monitor_states = list(monitor_states) if monitor_states else [monitoring]
self.write_error = write_error self.write_error = write_error
@@ -107,6 +111,12 @@ class FakeMiniMateClient(_Base):
def wake(self, **kw) -> None: def wake(self, **kw) -> None:
self._step("wake") self._step("wake")
if self.writes and self.wake_errors:
raise self.wake_errors.pop(0)
def read_serial(self) -> str:
self._step("read_serial")
return self.serial_reported
def get_monitor_status(self) -> MonitorStatus: def get_monitor_status(self) -> MonitorStatus:
self._step("get_monitor_status") self._step("get_monitor_status")
+49
View File
@@ -797,3 +797,52 @@ def test_series3_a_start_waits_out_the_sensor_check_before_its_first_read():
da = access3(fake, sleep=slept.append) da = access3(fake, sleep=slept.append)
(da.start_monitoring if start else da.stop_monitoring)(TCP3, "BE18193") (da.start_monitoring if start else da.stop_monitoring)(TCP3, "BE18193")
assert (S3_SENSOR_CHECK_S in slept) is waited assert (S3_SENSOR_CHECK_S in slept) is waited
# ── #9: the read-back after a start survives a dropped modem line ─────────────
# BE9441 over a modem, 2026-10-29: the start was acked, and the read-back's first
# wake after the sensor check hit "[Errno 32] Broken pipe" -- the modem had closed
# the line. A fresh connection read the unit as monitoring a second later.
SERIAL3 = UnitAddress(host=None, tcp_port=None, port="/dev/ttyUSB0", baud=38400)
def test_series3_start_read_back_reconnects_after_a_dropped_line():
fake = FakeMiniMateClient(monitor_states=[False, True],
wake_errors=[BrokenPipeError(32, "Broken pipe")])
r = access3(fake).start_monitoring(TCP3, "BE18193")
assert (r.outcome, r.verified, r.state_after) == ("sent", "ok", "monitoring")
assert fake.writes == ["start_monitoring"]
assert fake.opened == 2 and "read_serial" in fake.calls
def test_series3_read_back_reconnects_only_once():
fake = FakeMiniMateClient(monitor_states=[False],
wake_errors=[BrokenPipeError(32, "x"), BrokenPipeError(32, "x")])
with pytest.raises(ChangeUnconfirmed):
access3(fake).start_monitoring(TCP3, "BE18193")
assert fake.writes == ["start_monitoring"] and fake.opened == 2
def test_series3_read_back_reconnect_refuses_a_different_unit():
fake = FakeMiniMateClient(monitor_states=[False], wake_errors=[BrokenPipeError(32, "x")],
serial_reported="BE11529")
with pytest.raises(ChangeUnconfirmed) as e:
access3(fake).start_monitoring(TCP3, "BE18193")
assert e.value.http_status == 409 and fake.writes == ["start_monitoring"]
def test_series3_read_back_does_not_reconnect_on_a_serial_cable():
# Opening a MiniMate's serial port reboots it (measured 2026-10-25).
fake = FakeMiniMateClient(monitor_states=[False], wake_errors=[BrokenPipeError(32, "x")])
with pytest.raises(ChangeUnconfirmed):
access3(fake).start_monitoring(SERIAL3, "BE18193")
assert fake.opened == 1 and fake.writes == ["start_monitoring"]
def test_series3_read_back_silence_is_not_a_dropped_line():
# A cleanly closed line reads as silence, not an OSError: no reconnect.
fake = FakeMiniMateClient(monitor_states=[False], wake_errors=[NoAnswer("quiet")])
with pytest.raises(ChangeUnconfirmed):
access3(fake).start_monitoring(TCP3, "BE18193")
assert fake.opened == 1 and fake.writes == ["start_monitoring"]