From e2a0f8d58f83d099b4e1b5795c45a2847f1b358d Mon Sep 17 00:00:00 2001 From: serversdown Date: Fri, 4 Dec 2026 17:46:08 -0500 Subject: [PATCH] docs: re-assess SFM as a tool (2026-12-04, v0.36.0) The 2026-09-20 assessment had gone stale: the 64 KB download bug, "no live Series-4 path", the failing suite and the 8x Sensitive reading are all fixed, and the SFM / SDM split it was framed on is retired. Rewritten on the same plan, each claim re-checked against today's code: decoding and the store are production; the device side, both series by serial, is bench-proven behind the safety core but has no login, runs synchronously behind Terra-View's 60 s proxy, and is not used in the field yet; the lab tools left the image. Known issues now list the open Gitea issues (#6 first) and the overlay. The old text is `git show v0.36.0:docs/sfm_tool_status.md`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ALX2R9LdWawLzUxwewZGA1 --- docs/sfm_tool_status.md | 223 +++++++++++++++++++++++----------------- 1 file changed, 127 insertions(+), 96 deletions(-) diff --git a/docs/sfm_tool_status.md b/docs/sfm_tool_status.md index 4924e6e..c030388 100644 --- a/docs/sfm_tool_status.md +++ b/docs/sfm_tool_status.md @@ -1,30 +1,28 @@ # SFM — where it actually stands as a tool -**Status as of 2026-09-20 (v0.31.0).** This is the honest assessment, not the +**Status as of 2026-12-04 (v0.36.0).** This is the honest assessment, not the roadmap — `README.md § Roadmap` covers where it is *going*. Expect this file to -go stale; re-date it when you revise it. +go stale; re-date it when you revise it. The previous assessment (2026-09-20, +v0.31.0) is `git show v0.36.0:docs/sfm_tool_status.md`. --- ## The framing -SFM is **three different things wearing one name**, at three very different -levels of maturity: +SFM is one module (Terra-View's ADR 0003 retired the old SFM / SDM split), but its +parts sit at very different levels of maturity: -| | what it is | maturity | +| part | what it is | maturity | |---|---|---| -| **The codec library** | `minimateplus/`, `micromate/` — bytes in, `Event` out | **Production.** Verified per-sample at scale. | -| **SDM — the data side** | the DB, waveform store, `/db/*`, ingest | **Production.** Terra-View depends on it daily. | -| **SFM — the device side** | `/device/*`, live connections to units | **Emergency-grade.** Works, but manual, unauthenticated, and thinly tested. | -| **The lab** | `seismo_lab.py`, `scratch/`, the Inspector | **Research artifacts.** Useful, not products. | +| **Decoding** | `minimateplus/`, `micromate/`: bytes in, events out | **Production, measured.** Checked field by field against Blastware and Thor at archive scale. | +| **The store and ingest** | the DB, the waveform store, `/db/*`, `/db/import/*` | **Production.** Terra-View depends on it daily. | +| **The device side** | `/device/*`, live connections to units, both series | **Bench-proven, not field-proven.** Every feature works on a bench unit of each series, behind an audited safety core. No login, and nothing in production uses it yet. | +| **The lab** | `bridges/`, `scratch/`, `seismo_lab.py` | **Research tools.** Kept out of the production image since v0.36.0. | -Brian's own description — *"right now it's an emergency tool and a research -project"* — is accurate, and it applies specifically to the **device side**. -The data side is not an emergency tool; it has been carrying production for -months. - -Most confusion about "is SFM reliable?" comes from answering for the wrong -tier. +In September the device side was "an emergency tool and a research project" +(Brian). That has changed more than anything else here: it now speaks both +series by serial, with dry runs, an audit table and read-backs. What it lacks is +not protocol work but **a login, long-running jobs, and field use**. --- @@ -32,42 +30,69 @@ tier. ### Production-grade — trust it -- **Series-3 decode.** 14,338 / 14,338 files decode per-sample exact against - preserved Blastware ASCII exports, 45 units, files back to 2018. -- **Series-4 (Thor) decode.** 1,057,536 / 1,057,536 geo samples exact against - Thor's own CSV exports; production IDFW 575/575 with zero truncations. -- **Histogram decode.** 1,211 / 1,211 production histograms exact, including - 842,442 per-interval frequency comparisons with zero mismatches. -- **The ingest path.** `/db/import/blastware_file` and `/db/import/idf_file` - fed by the watchers — this is how prod actually gets its data, and it has - been running unattended for months. -- **`/db/*` read API.** Always-on, consumed by Terra-View for every fleet - listing, event detail and report. -- **The waveform store** — `.h5` + `.sfm.json` sidecars + retained raw - binaries, with operator review state preserved across regeneration. -- **`bridges/ach_server.py`** — speaks the full BW protocol to calling units. - Proven in the field, including as a rescue tool (see the runbook). +- **Series-3 decode.** The checker (`scratch/check_s3_decode.py`) decodes all + 70,042 DL2 events (2016–2026) from their bytes alone and compares every field, + sample and interval with Blastware's own `_XML.XML` report. + - **80 of 88 fields match on every event**; every other field matches or is + accepted under a carve-out with its evidence. + - **Geophone samples** are exact on 6,524 / 6,524 waveforms; **histogram** + interval peaks have 0 mismatches on every file. + - Left, by Brian's decision (2026-11-11): the vector sum's last digit on 4 + waveform/histogram twins, and 4 accelerations. +- **Series-4 (Thor) decode.** 3,807,158 / 3,807,165 samples exact across 459 + files and three corpora of Thor's own CSV exports (the 7 others are Thor's own + rounding); production IDFW 575 / 575 with zero truncations. Since v0.36.0 a + Thor file's settings, notes and event time come from the file itself (2,027 / + 2,027 against Thor's reports). +- **The ingest path.** The watchers forward each unit's files to + `/db/import/blastware_file` and `/db/import/idf_file`. This is how prod gets + its data, and it has run unattended for months. +- **`/db/*` read API.** Always on; Terra-View reads every fleet listing, event + detail and report from it. +- **The waveform store**: `.h5` + `.sfm.json` sidecars + the retained original + files, with operator review state preserved across regeneration. Events are + keyed unit + time + type. -### Emergency-grade — works, but you are the error handling +### Bench-proven — works, not yet trusted in the field -- **`/device/*` live endpoints.** They do what they say. But they are - synchronous, unauthenticated, and a single cellular download can exceed the - 60 s timeouts that sit in front of them. -- **The rescue ladder** (`rescue`, `stop_monitoring_*`, `events/erase`). - Each has worked in a real incident — but each has been used a handful of - times, by one person, with the runbook open. -- **The standalone webapp.** Perfectly usable, and as of v0.31.0 the cheap - probes and rescue actions are reachable without curl. No auth of any kind. +- **Live device control by serial, both series** (`sfm/device_access/`, merged + 2026-11-04): identify, status, settings read and change, event list and + download, start/stop monitoring, call-home on/off. + - Every write goes through one safety core: a fresh identity read, the run + state, a dry run showing the exact frames, a row in the `device_commands` + audit table, one send never retried, and a read-back. + - Verified on one bench unit per series (UM20147, BE9441); settings and + call-home changes were confirmed on the unit's own screen. MiniMate downloads + match Blastware's files byte for byte, including the 64 KB page crossings + that broke in September. + - Used from SFM's own page (`sfm/sfm_webapp.html`, Serial field). No Terra-View + page uses `/device/*` yet. +- **The `.MLG` monitor log and each unit's timeline** (v0.35.0). Every record's + checksum held on the files examined (3,329 / 3,329), and it builds sessions, + gaps and call-ins. The DL2 archive is not imported yet. + In prod, but its tables are **empty** until the watcher forwards `.MLG`s. -### Research artifacts — useful, not products +### Emergency-grade — you are the error handling -- **`seismo_lab.py`** — 2,789 lines of Tkinter (Bridge / Analyzer / Query DB / +- **The rescue ladder.** Runbook Method A (`docs/runbooks/wedged_unit_recovery.md`: + point a wedged unit's modem at `bridges/ach_server.py` and answer its call) + and the blind stop tools (`/device/stop_monitoring_*`; `scripts/blind_stop.sh`, + `slow_drip.sh`, `spam_stop.sh`). + Each has worked in a real incident, used a handful of times by one person with + the runbook open. Method A runs from a checkout on the dev box, not the image. +- **The legacy, serial-less `/device/*` routes** (MiniMate only). Kept for the + rescue tools; the serial-named routes replace them for everything else. + +### Research tools — useful, not products + +- **`seismo_lab.py`**: 2,882 lines of Tkinter (Bridge / Analyzer / Query DB / Inspector). Desktop-only, single-user, no tests. -- **`scratch/`** — the verification harnesses (`verify_against_ascii.py`, - `verify_thor_against_csv.py`) and the offset detector (`offset_scan3.py`). - These produced the numbers the production claims rest on, so they matter — - but they are analysis scripts, not maintained code. -- **`docs/offset_investigation.md`** — an open investigation, not a feature. +- **`scratch/`**: the checker and the verification harnesses + (`verify_thor_against_csv.py`, `verify_against_ascii.py`) and the offset + detector (`offset_scan3.py`). The production numbers above rest on them, so + they matter, but they are analysis scripts. +- **`bridges/`**: probes, relays and recording bridges for the bench. +- **`docs/offset_investigation.md`**: an open investigation, not a feature. --- @@ -75,17 +100,19 @@ tier. | you want to… | use | notes | |---|---|---| -| Know if a unit is monitoring / its battery / memory | `GET /device/monitor/status?force=true` | ~2 s | -| Know whether ACH is on | `GET /device/call_home` | ~2 s. **Not** `/device/events`. | -| See how full a unit's buffer is | `GET /device/events/storage_range` | ~2 s, no chain walk | -| Stop a runaway unit | Diagnostics tab → Stop Monitoring | see the runbook first | -| Reach a unit that will not answer | **point its modem at an `ach_server` and answer its call** | runbook Method A — do not race it | -| List a unit's stored events | Events tab → Load events | **slow**, and broken past 64 KB (below) | -| Get event data into the DB | the watcher → `/db/import/*` path | not the live walk | +| Know if a unit is monitoring, its battery, its memory | SFM page → Serial → Status, or `GET /device/monitor/status?serial=…` | both series | +| Know whether call-home is on | `GET /device/call_home/state?serial=…` | both series | +| See how full a MiniMate's buffer is | `GET /device/events/storage_range` | MiniMate only; no event walk | +| List a unit's stored events | Events tab with a Serial, or `GET /device/events?serial=…` | a MiniMate's list reads headers only | +| Pull one event into the store | the Download button per event, or `POST /device/events/download?serial=…&event_id=…` | checked against the unit's own peaks before it is stored | +| Start or stop monitoring | the Live tab with a Serial, or `POST /device/monitor/start\|stop?serial=…` | try `dry_run=true` first; audited, read back | +| Change a unit's settings | Config tab: Preview, then Send (`POST /device/settings/change`) | refused while monitoring; nobody in the unit's menus while it sends | +| Reach a unit that will not answer | runbook Method A: **answer its call** | do not race its call-home | +| Get event data into the DB | the watchers → `/db/import/*` | not the live walk | +| Know whether a unit was monitoring at a time | `GET /db/units/{serial}/monitoring_at?at=…` | answers "unknown" until `.MLG`s are forwarded | -The single most useful habit: **the cheap probes are cheap and the event walk -is not.** Reaching for `/device/events` to answer a yes/no question about a -unit is the mistake that motivated the v0.31.0 webapp changes. +The single most useful habit still holds: **the cheap probes are cheap and the +event walk is not.** Do not list events to answer a yes/no question about a unit. --- @@ -93,58 +120,62 @@ unit is the mistake that motivated the v0.31.0 webapp changes. | issue | impact | status | |---|---|---| -| **5A walk dies once a unit's buffer crosses 64 KB** | `/device/events` 500s; event body never downloads | Known, documented in `CLAUDE.md`. Needs a BW capture of a spanning event to fix properly. | -| **No auth on SFM at all** | 21 `/device/*` endpoints, including destructive ones, open to anything that reaches the port | Design agreed (Terra-View as authenticated jump host); not built. | -| **Swagger try-it-out is live on destructive endpoints** | `POST /device/events/erase` is one click away at `:8200/docs` | Partially mitigated: the webapp's erase now requires typing the serial. `/docs` itself is unguarded. | -| **`SUB 0x08` lifetime counter reads 0** | `/device/events/index` returns a meaningless number | Suspected field-offset bug. Surfaced in the UI as "unreliable". | -| **Long device operations are synchronous** | 60 s timeouts in `routers/sfm.py` and the reverse proxy; a full download exceeds both | Known design constraint. Must be POST-starts-job / GET-polls before any remote lab. | -| **`backfill_sidecars.py --force` silently inserts DB rows** | store files with no DB row get one; the dry-run does not report the count | Known. Avoid `--force` — `TOOL_VERSION` gates regeneration anyway. | -| **14 sensitive-range files show an exact 8× discrepancy** | 10.0 / 1.25 — a units problem, not a decode problem | Open, not blocking. | -| **16 failing tests on `dev`** | 15 need gitignored fixture bundles; 1 is real (`sc["peak_values"]["transverse"]` returns `None` where `0.0` is expected) | The real one shipped in v0.31.0. | +| **No login on SFM at all** | 27 `/device/*` routes (16 of them POSTs) plus `/db/restore` and `/db/events/delete_bulk`, open to anything that reaches port 8200 | Design agreed (Terra-View as the authenticated jump host); not built. Terra-View's `docker-compose.yml` still publishes `8200:8200`. | +| **The API's try-it-out page is live** | `:8200/docs` can send any of the above, erase included | Unguarded. The SFM page's erase asks you to type the serial; `/docs` does not. | +| **Long device operations are synchronous** | Terra-View's `/api/sfm/*` proxy times out at 60 s; a long download over cellular can exceed it | Known design constraint. Must become start-a-job / poll before Terra-View drives units remotely. | +| **THOR and SFM contend for a Micromate's modem** | a call-home is lost while SFM holds the line | Brian (2026-10-29): keep the hold as is; the long-term fix is SFM answering call-ins itself. | +| **#6: a MiniMate stays connected after a call-in unless its events are deleted** | it does not resume monitoring | Open, Priority/High, from April. May be stale; triage first. | +| **#32: some events decode to ramps or garbage** | corrupts shape-based false-trigger detection | Open, needs more information. | +| **Prod still overlays Blastware's ASCII report** | where a report arrives, its peaks, notes, sample rate and record time replace SFM's decode | By design until the overlay is retired. Some decoded fields (displacement, time of peak, acceleration, sensor checks, the Monitor Log line, over-range flags) are not stored yet. | +| **`SUB 0x08` lifetime counter reads a meaningless number** | `/device/events/index` | Labelled "unreliable" on the SFM page. | +| **`backfill_sidecars.py --force` silently inserts DB rows** | store files with no DB row get one; the dry run does not count them | Known. Avoid `--force`; `TOOL_VERSION` gates regeneration anyway. | +| **Smaller open issues** | #52 (restamp follow-ups), #53 (unknown regions of Series-3 files), #55 (PDF footer), #57 (detect a unit's series from its reply) | Open, low to medium. | + +**Fixed since September:** the 64 KB download bug (2026-10-26); the 8× reading on +Sensitive-range events (v0.34.0); the test suite now passes on a fresh checkout +(1,806 passed, 0 skipped). --- ## 4. What stands between this and a real tool -Roughly in dependency order — each unblocks the ones below it. +Roughly in dependency order. -**1. Authentication.** Everything else is gated on this. SFM has none, and -the modem IP whitelist gives zero protection because SFM *is* the whitelisted -origin. The agreed design delegates rather than builds: Terra-View becomes the -authenticated jump host (`/api/sfm/*` already inherits deny-by-default operator -auth), and the `8200:8200` publish is dropped so Terra-View is the only door. +**1. A login.** Everything remote is gated on this. SFM has none, and the +modem IP whitelist gives no protection because SFM *is* the whitelisted origin. +The agreed design delegates rather than builds: Terra-View becomes the +authenticated jump host (`/api/sfm/*` already sits behind its operator login and +passes any path through), and the `8200:8200` publish is dropped so Terra-View is +the only door. -**2. Async long operations.** POST starts a job, GET polls. Retrofitting this -after building a remote lab on top of synchronous endpoints would be far worse -than designing for it now. +**2. Long operations as jobs.** POST starts a job, GET polls. Retrofitting +this after Terra-View drives units through synchronous calls would be far worse +than designing for it first. -**3. Confirm-guards on the remaining destructive endpoints.** Auth answers -*who*, not *did you mean it*. The webapp's erase is guarded; the other seven -destructive POSTs and `/docs` are not. +**3. Field use of the device side.** It has been proven on one bench unit per +series. Using it on deployed units, a little at a time, is what turns "works" +into "trusted". -**4. The 5A page-boundary fix.** Until this lands, live event download is -unreliable on exactly the units most likely to need attention — the ones that -have been recording heavily. Wants a Blastware capture of an event spanning a -page boundary before the chunk-addressing half is trustworthy. +**4. SFM answering call-ins itself** (ADR 0003's call-in server, after its staged +proof). It replaces Blastware's ACH and THOR as the receivers and ends the +modem contention. -**5. A live Thor / Micromate client.** The device side is MiniMate-only. -Series-4 units can only be read from forwarded files, so half the fleet has no -live path at all. +**5. Retiring the Blastware report overlay.** The decoder is ready; the +remaining work is storing the decoded fields listed above and letting SFM's own +report read them. -**6. Test coverage that runs from a clean checkout.** 15 of 16 current -failures are missing fixture bundles. A test suite that cannot go green on a -fresh clone cannot gate anything. - -**7. The SDM rename.** Cosmetic relative to the above, but the longer `sfm/` -holds the data-side code the more the tiers blur. ~30–50 files here, ~10–15 in -Terra-View, plus a Docker volume migration. Do it when the codebase is quiet. +**Done since September:** the 64 KB fix; a live Series-4 client and both series +by serial; confirmation on every serial-named write (dry run, preview, audit, +read-back); a suite that goes green on a fresh checkout. The planned "SDM +rename" is dropped: the repo becomes `sfm` instead (ADR 0003). --- ## The short version -The **data side is a real tool already**. The **device side is a set of sharp -instruments** that work in the hands of the person who wrote them, with the -runbook open. The gap between those two states is mostly **auth, async, and -guardrails** — not protocol work. The protocol is the part that is actually -finished. +The **data side is a real tool** and has been for months; the decoder now +matches Blastware field by field across ten years of files. The **device side +has grown from sharp instruments into a bench-proven tool for both series**, +with the safety core a real tool needs. The gap to using it on the fleet from +Terra-View is **a login, jobs instead of long calls, and field time** — not +protocol work.