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

+10 -7
View File
@@ -85,20 +85,23 @@ def run_change(*, serial: str, series: int, start: bool, dry_run: bool, even_if_
def states(seen: List[str], after: Optional[str]) -> Dict[str, Any]:
return {"before": before, "seen": list(seen), "after": after}
def finish(unit: str, **fields: Any) -> None:
def finish(unit: str, *, release_line: bool = False, **fields: Any) -> None:
"""The only way a row is finished. `unit` says what happened to the
unit, so a finish that fails still says it."""
unit, so a finish that fails still says it. `release_line` says whether
this path hangs up anyway, so a failed finish does not hold the line."""
try:
audit.finish(cid, **fields)
except Exception as exc: # noqa: BLE001
raise AuditIncomplete(
f"{unit} -- but audit record {cid} could not be finished: {exc}") from exc
f"{unit} -- but audit record {cid} could not be finished: {exc}",
release_line=release_line) from exc
def unconfirmed(unit: str, cause: BaseException, *, went_out: str, status: int,
**fields: Any) -> NoReturn:
"""Finish the row, then say the change went out (or may have) and name it.
`went_out` is "acknowledged" or "unknown"; the row's `sent` follows it."""
finish(unit, sent=SENT_ACKNOWLEDGED if went_out == "acknowledged" else SENT_UNKNOWN,
finish(unit, release_line=True,
sent=SENT_ACKNOWLEDGED if went_out == "acknowledged" else SENT_UNKNOWN,
**fields)
raise ChangeUnconfirmed(f"{unit} -- audit record {cid}", audit_id=cid, sent=went_out,
http_status=status) from cause
@@ -119,12 +122,12 @@ def run_change(*, serial: str, series: int, start: bool, dry_run: bool, even_if_
pre_send() # sends nothing: drains what is already waiting
except Exception as exc: # noqa: BLE001
if is_ring(exc):
finish("nothing was sent (a call-home began before sending)",
finish("nothing was sent (a call-home began before sending)", release_line=True,
outcome="failed", verified="not_checked", ack=None,
error="a call-home began before sending -- nothing sent",
sent=NOTHING_SENT, states=states([before], None))
raise CallHomeInProgress(CALL_HOME_MESSAGE) from exc
finish(f"nothing was sent (the line failed before sending: {exc})",
finish(f"nothing was sent (the line failed before sending: {exc})", release_line=True,
outcome="failed", verified="not_checked", ack=None,
error=f"the line failed before sending -- nothing sent: {exc}",
sent=NOTHING_SENT, states=states([before], None))
@@ -134,7 +137,7 @@ def run_change(*, serial: str, series: int, start: bool, dry_run: bool, even_if_
ack = send() # the only send; nothing below can reach it again
except Exception as exc: # noqa: BLE001 -- recorded, never retried
if is_refusal(exc): # refused by the gate: nothing went out
finish(f"nothing was sent (refused before sending: {exc})",
finish(f"nothing was sent (refused before sending: {exc})", release_line=True,
outcome="failed", verified="not_checked", ack=None,
error=f"refused before sending: {exc}",
sent=NOTHING_SENT, states=states([before], None))