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))
+9 -1
View File
@@ -33,9 +33,17 @@ class AuditUnavailable(DeviceError):
class AuditIncomplete(DeviceError):
"""The unit was dealt with, but its audit row could not be finished. The
message says what happened to the unit first, then names the row."""
message says what happened to the unit first, then names the row.
`release_line` is True when the path would have hung up had the finish
worked (a ring, a link fault, a refusal): the failed write to the audit log
must not turn that into a held line, which would block a call-home."""
http_status = 500
def __init__(self, message: str, *, release_line: bool = False) -> None:
super().__init__(message)
self.release_line = release_line
class ChangeUnconfirmed(DeviceError):
"""A change failed after its frame went out, or may have gone out.
+12 -3
View File
@@ -23,8 +23,8 @@ from micromate.writes import plan_start_monitoring, plan_stop_monitoring
from minimateplus.transport import BaseTransport, SerialTransport, TcpTransport
from .errors import (
CallHomeInProgress, ChangeUnconfirmed, DeviceError, EventNotFound, MalformedReply, StaleEvent,
WrongUnit, translate,
AuditIncomplete, CallHomeInProgress, ChangeUnconfirmed, DeviceError, EventNotFound,
MalformedReply, StaleEvent, WrongUnit, translate,
)
from .change import CALL_HOME_MESSAGE, run_change
from .events import iso_of, make_event_id, stamp_of
@@ -133,7 +133,8 @@ class Series4Session:
The exceptions: `CallHomeInProgress` and `WrongUnit` release the line,
because the line itself is the problem; so does `ChangeUnconfirmed`, which
the change core raises only after a link fault or a ring, once the frame
has gone out. `AuditIncomplete` is an ordinary verdict: the line is kept.
has gone out. `AuditIncomplete` keeps the line unless its `release_line`
says the path would have hung up anyway (a ring, a link fault, a refusal).
"""
def __init__(self, address: UnitAddress, serial: str,
@@ -192,6 +193,14 @@ class Series4Session:
log.warning("%s at %s -- released the line: %s", type(exc).__name__,
self.address.key, exc)
raise
except AuditIncomplete as exc:
# A finish that failed on a path that hangs up anyway (ring, link
# fault, refusal) must still hang up; on a healthy path, keep the line.
if exc.release_line:
self.hang_up()
log.warning("AuditIncomplete at %s -- released the line: %s",
self.address.key, exc)
raise
except DeviceError:
# The operation's own verdict (event not found, stale id): the line
# is healthy, so keep it. Library errors still hang up below.