fix(sfm): retry once on a dropped held line; refuse Series-3 beside a held Series-4 line

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-21 01:23:57 -04:00
1 parent 96c7b31f4e
commit 73b6089012
2 files changed
+67 -7

No files matched your search

+29 -6
View File
@@ -9,7 +9,7 @@ import threading
import time
from typing import Any, Callable, Dict, Optional
from .errors import DeviceError
from .errors import ConnectFailed, DeviceError, NoAnswer, WrongUnit
from .locks import UnitLocks
from .models import UnitAddress, UnitInfo, UnitSettings, UnitStatus
from .s3 import Series3Adapter, default_s3_client_factory
@@ -75,17 +75,40 @@ class DeviceAccess:
series = series_for_serial(serial) # raises BadRequest before any I/O
with self._locks.hold(address.key):
if series == 3:
with self._sessions_guard:
held = self._sessions.get(address.key)
if held is not None and held.is_open:
raise WrongUnit(
f"a Series-4 line to {held.serial} is held at {address.key}; "
"a Series-3 unit cannot be there -- POST /device/hangup first "
"if the modem has moved")
return s3_op(address, serial)
session = self._session_for(address, serial)
was_held = session.is_open
try:
return session.run(lambda client: s4_op(client, serial))
except DeviceError:
if not session.is_open:
with self._sessions_guard:
if self._sessions.get(address.key) is session:
del self._sessions[address.key]
except DeviceError as exc:
self._forget_if_closed(address, session)
# A held line the peer dropped still reads open (the transport only
# learns at EOF), so the first request on it times out or fails.
# Call up fresh and retry ONCE. Safe only because phase 1a
# operations are reads (idempotent); writes (phase 3) must NOT
# inherit this -- a write whose ack was lost must never be sent twice.
if was_held and isinstance(exc, (NoAnswer, ConnectFailed)):
self._drop(address.key, session)
session.hang_up()
session = self._session_for(address, serial)
try:
return session.run(lambda client: s4_op(client, serial))
except DeviceError:
self._forget_if_closed(address, session)
raise
raise
def _forget_if_closed(self, address: UnitAddress, session: Series4Session) -> None:
if not session.is_open:
self._drop(address.key, session)
def _session_for(self, address: UnitAddress, serial: str) -> Series4Session:
with self._sessions_guard:
session = self._sessions.get(address.key)