fix(sfm): an audit finish that fails on a hang-up path still releases the line

The final fix wave's AuditIncomplete landed in _exchange's `except DeviceError`,
which keeps the line -- so on the nine ring / link-fault paths (and a refusal) a
failed audit write turned a hang-up into a held Series-4 line, blocking a THOR
call-home for up to the 5-minute idle hang-up and making "SFM hung up" false.
AuditIncomplete now carries release_line, set by every finish whose path hangs
up anyway, and _exchange honours it.  Also pins the Series-3 change path's
retry=False again (the rewritten lost-ack test no longer could).

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:36:00 -04:00
1 parent 8f68b09f5e
commit cdc6360ec0
4 files changed
+102 -12

No files matched your search

+71 -1
View File
@@ -15,7 +15,7 @@ from device_access_fakes import FakeMicromateClient # no
from sfm.device_access.access import DeviceAccess # noqa: E402
from sfm.device_access.errors import ( # noqa: E402
AuditIncomplete, AuditUnavailable, CallHomeInProgress, ChangeUnconfirmed, ConnectFailed, DeviceError,
NotSupported, UnitStateUnknown, WrongUnit,
NoAnswer, NotSupported, UnitStateUnknown, WrongUnit,
)
from sfm.device_access.models import UnitAddress # noqa: E402
@@ -694,3 +694,73 @@ def test_series3_monitor_status_decode_keeps_the_raw_flag():
assert (st.state_flag, st.is_monitoring) == (flag, monitoring)
assert _decode_monitor_status(bytes(12)).state_flag is None # no section[1]
assert _decode_monitor_status(b"").state_flag is None
# ── an audit finish that fails must not turn a hang-up into a held line ───────
def _reads_then(fake, exc):
"""read_run_state answers once (the state before the send), then raises."""
orig, n = fake.read_run_state, []
def flaky():
n.append(1)
if len(n) > 1:
raise exc
return orig()
fake.read_run_state = flaky
return fake
def _drain_raises(fake, exc):
def drain():
raise exc
fake.read_unsolicited = drain
return fake
_LOST = mm_proto.TimeoutError("no ack")
_HANG_UP_PATHS = {
"ring in place of the ack":
lambda: FakeMicromateClient(run_states=[0x00], execute_error=RingDetected("RADIO RING")),
"lost ack, ring on the follow-up":
lambda: _reads_then(FakeMicromateClient(run_states=[0x00], execute_error=_LOST),
RingDetected("RADIO RING")),
"lost ack, follow-up reads calling_home":
lambda: FakeMicromateClient(run_states=[0x00, 0x03], execute_error=_LOST),
"lost ack, follow-up unreadable":
lambda: _reads_then(FakeMicromateClient(run_states=[0x00], execute_error=_LOST),
mm_proto.TimeoutError("silent")),
"read-back raises":
lambda: _reads_then(FakeMicromateClient(run_states=[0x00]), mm_proto.TimeoutError("silent")),
"read-back rings":
lambda: _reads_then(FakeMicromateClient(run_states=[0x00]), RingDetected("RADIO RING")),
"read-back reads calling_home":
lambda: FakeMicromateClient(run_states=[0x00, 0x03]),
"ring before the send":
lambda: _drain_raises(FakeMicromateClient(run_states=[0x00]), RingDetected("RADIO RING")),
"link fault before the send":
lambda: _drain_raises(FakeMicromateClient(run_states=[0x00]), OSError("connection reset")),
"refused by execute":
lambda: FakeMicromateClient(run_states=[0x00], execute_error=OpcodeRefused("nope")),
}
@pytest.mark.parametrize("path", sorted(_HANG_UP_PATHS))
def test_a_finish_that_fails_on_a_hang_up_path_still_releases_the_line(path):
fake = _HANG_UP_PATHS[path]()
da = access(fake, audit=FinishFails())
with pytest.raises(AuditIncomplete) as e:
da.start_monitoring(ADDR, "UM20147")
assert e.value.release_line is True
assert "could not be finished: disk full" in str(e.value)
assert len(fake.executed) <= 1
assert released(fake, da)
def test_series3_a_cold_unit_during_a_change_is_not_retried():
fake = FakeMiniMateClient(fail=[mmp_proto.TimeoutError("cold")])
da = access3(fake)
with pytest.raises(NoAnswer):
da.start_monitoring(TCP3, "BE18193")
assert fake.writes == []
assert len(da.factory_calls) == 1 # the change path never takes _run's retry