docs(sfm): state the held-line invariant, pin the hang-up on a library error, correct the README
- Series4Session's docstring now states which errors keep the line: an op raises a DeviceError only for a verdict on a healthy link (not found, stale, unnameable), and _exchange keeps the line for those; any library error means the link is suspect and hangs up. DecodeMismatch is a library error and hangs up -- conservative. Later ops must keep to it. - Test: a micromate TimeoutError mid-download, on a fresh DeviceAccess (no retry path), is NoAnswer, closes the client once and leaves no held line. It pins existing behaviour; a mutation that keeps the line on library errors makes it fail. - README, event rows corrected in place: another unit's id is 422 (not 409); a stale id is 409 without downloading, both series; an event already stored -- including by THOR's watcher -- returns its row and changes nothing (detail.already_stored); MiniMate lists give record_type null, on the normal timeout, and fail on a lost reply. No code behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
4e1e6a9d5c
commit
2a70faf7b5
3 files changed
+27
-2
No files matched your search
@@ -179,8 +179,8 @@ via a thread-safe `_LiveCache` (plain Python dict + `threading.Lock`):
|
||||
| `POST` | `/device/call_home` | Reads, patches specified fields, writes back to device |
|
||||
| `GET` | `/device/settings` | Recording settings in the shared model, either series; serial required; never cached |
|
||||
| `POST` | `/device/hangup` | Releases a held Series-4 line now; `{"hung_up": bool}` |
|
||||
| `GET` | `/device/events?serial=` | Lists a unit's events, either series, each with an opaque `event_id` (`serial:key:timestamp`). A MiniMate list reads headers only (no bulk download) |
|
||||
| `POST` | `/device/events/download?serial=&event_id=` | Downloads one event, checks it, and stores it in SFM's database; returns `db_event_id` (file at `GET /db/events/{db_event_id}/blastware_file`). A stale `event_id` (unit erased or wrapped since the list) or one from another unit gets **409**, with no download. Re-downloading refreshes the stored row (same `db_event_id`, `inserted: false`). The unit is busy for the whole download; other requests to it get 423 |
|
||||
| `GET` | `/device/events?serial=` | Lists a unit's events, either series, each with an opaque `event_id` (`serial:key:timestamp`). A MiniMate list reads headers only (no bulk download), on the normal timeout, and gives `record_type: null` (its event record does not say waveform or histogram; not decoded yet). A lost reply fails the list rather than shortening it |
|
||||
| `POST` | `/device/events/download?serial=&event_id=` | Downloads one event, checks it, and stores it in SFM's database; returns `db_event_id` (file at `GET /db/events/{db_event_id}/blastware_file`). A stale `event_id` (unit erased or wrapped since the list) gets **409** without downloading, for both series; an `event_id` from another unit gets **422**, before any I/O. An event already stored — by an earlier download, or by THOR's watcher — returns its existing row and changes nothing (same `db_event_id`, `inserted: false`, `detail.already_stored: true`). The unit is busy for the whole download; other requests to it get 423 |
|
||||
|
||||
**Cache bypass** — All cached endpoints accept `?force=true` to skip the cache and
|
||||
force a fresh read from the device.
|
||||
|
||||
@@ -112,6 +112,15 @@ class Series4Session:
|
||||
`last_traffic` is any exchange, keep-alives included: the keep-alive
|
||||
schedule measures it. If keep-alives counted as use, the line would never
|
||||
go idle.
|
||||
|
||||
Invariant -- which errors keep the line. An operation raises a
|
||||
`DeviceError` only for a verdict reached over a healthy link: the event is
|
||||
not there, the id is stale, the record cannot be named. `_exchange` keeps
|
||||
the line for those. Anything the library raises means the link is
|
||||
suspect, and `_exchange` hangs up. `DecodeMismatch` is a library error,
|
||||
so it hangs up too -- conservative, since the link may be fine. Operations
|
||||
added in later phases must keep to this: never wrap a link failure in a
|
||||
`DeviceError` inside an op, or the line stays open on a broken link.
|
||||
"""
|
||||
|
||||
def __init__(self, address: UnitAddress, serial: str,
|
||||
|
||||
@@ -76,6 +76,22 @@ def test_a_ring_mid_download_releases_the_line_and_downloads_nothing():
|
||||
assert fake.closed == 1 and da.held_serial(ADDR) is None
|
||||
|
||||
|
||||
def test_a_library_error_mid_download_hangs_up():
|
||||
# Only a DeviceError verdict keeps the line; anything the library raises means
|
||||
# the link is suspect. A fresh DeviceAccess, so the held-line retry cannot apply.
|
||||
from micromate.protocol import TimeoutError as MicromateTimeout
|
||||
from sfm.device_access.errors import NoAnswer
|
||||
fake = FakeMicromateClient()
|
||||
|
||||
def quiet(*a, **kw):
|
||||
raise MicromateTimeout("quiet")
|
||||
fake.fetch_event = quiet
|
||||
da = access(s4=[fake])
|
||||
with pytest.raises(NoAnswer):
|
||||
da.download_event(ADDR, "UM20147", "UM20147:055d4a81:20250531135901")
|
||||
assert fake.closed == 1 and da.held_serial(ADDR) is None
|
||||
|
||||
|
||||
def test_a_stale_or_missing_event_keeps_the_line():
|
||||
# The operation's own verdict (404/409) says nothing is wrong with the link;
|
||||
# hanging up would cost a call-up for no reason.
|
||||
|
||||
Reference in new issue
Block a user