Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
25 KiB
Phase 4 — Call-home enable/disable Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Turn a unit's automatic call-home on or off from SFM, for both series, through the audited change path start/stop already uses: identity check → audit → one send → read back → audit.
Architecture: run_change (sfm/device_access/change.py) becomes kind-agnostic: a ChangeKind says what the change is called and which state means it took. Each series supplies a call-home state read ("enabled" / "disabled", plus Series 4's "calling_home") and a send built from the block it read moments before. Series 4 sends micromate.writes.plan_call_home_enabled (frames already equal to THOR's). Series 3 patches byte 5 of the unescaped 0x2C image and sends it through the existing 0x7E/0x7F path. A gate keeps that send refused until its frame is reproduced from a Blastware capture. New serial-keyed routes, and the page's Call Home tab by serial gets On/Off buttons.
Tech Stack: Python 3 / FastAPI (SFM), pytest; page JS in sfm/static/ tested with Node.
Spec: docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md — row 9 of the job table, "The safety layer" (tiers, read-back: "call-home → re-read 0x2C and compare the edited bytes"), the per-operation table (call-home enable/disable | read 0x2C → 0x7E (126 B content, offset 0x007E) → 0x7F | re-read 0x2C), build phase 4.
Global Constraints
- Branch
feat/series4-sfm-parity, worktree~/seismo-relay-parity. Never commit tomain. Push every commit. NoCHANGELOG.mdedits (written ondevat merge). - No live write without Brian's explicit go, per send. Dry runs and tests only, until the bench task.
- A write is never retried (
DeviceAccess._dispatch(change=True)); never send0xA2; never write modem baud or modem type. - File boundary with the decode-checker session: do not edit
minimateplus/event_file_io.py,histogram_codec.py,waveform_codec.py,bw_xml_report.py,decode_check*.py. - No inline JavaScript: new page logic goes in
sfm/static/device_routing.js(DOM-free, Node-tested);sfm/static/sfm_webapp.jsonly applies it (stack-wide rule, 2026-11-02). - Series 4: read-modify-write. Send back every byte of the block as read except bit 0 of
content[5]. Never synthesise or zerocontent[118:120](unit-maintained; it changes after a config write). - Series 3: read the enable byte from the unescaped block (the lesson of bench finding #1).
0x00off,0x01on (measured April 2026, BE11529). Any other value isunknown(0xNN)and nothing is sent. - Speed is secondary to reliability: no new round trips beyond the reads the change needs.
- Test command:
/home/serversdown/seismo-relay/.venv/bin/python -m pytest -q -p no:cacheprovider. Baseline: exactly 16 known failures (15 intests/test_bw_ascii_report.py,tests/test_event_file_io.py::test_save_imported_bw_without_report_works_unchanged). Read the failure list before committing.
Review Focus
- A change requested while a Micromate is calling home (run state
0x03) → 503, nothing sent, the line released (the existingCallHomeInProgresspath). - A MiniMate whose unescaped byte 5 is neither
0x00nor0x01→ stateunknown(0xNN): a dry run still shows it, a live change sends nothing (UnitStateUnknown, 409). - A read-back where other bytes changed (Series 4
[118:120]always does) → verified on the edited bit alone; the changed offsets are recorded in the result and the audit row, never a mismatch. - Already in the requested state → skipped with no send, unless
even_if_already(the bench's no-op write is exactly that experiment). - A live Series-3 call-home change before its frame has been reproduced from a Blastware capture → 501 before any connection. A dry run works.
Task 1: run_change takes a ChangeKind
Files:
- Modify:
sfm/device_access/change.py(signature and the three derived names at the top ofrun_change; the finish paths that builddetailandstates) - Modify:
sfm/device_access/s3.py(change_monitoring),sfm/device_access/s4.py(s4_change_monitoring) — call sites only - Test:
tests/test_device_access_change_kind.py(new)
Interfaces:
-
Produces:
@dataclass(frozen=True) class ChangeKind: action: str; want: str; became: strinchange.py.monitoring_change(start: bool) -> ChangeKindgives exactly today's values:("start monitoring", "monitoring", "started")/("stop monitoring", "idle", "stopped").call_home_change(enabled: bool) -> ChangeKindgives("enable call-home", "enabled", "enabled")/("disable call-home", "disabled", "disabled").run_change(*, kind: ChangeKind, serial, series, dry_run, even_if_already, audit, address, caller, sleep, verify_timeout_s, verify_interval_s, read_serial, read_state, describe_plan, send, is_refusal=_never, is_ring=_never, pre_send=None, snapshot: Optional[Callable[[], Dict[str, Any]]] = None) -> ChangeResult.startis gone.snapshot: called once, after the read-back loop, on the two normal finish paths (verifiedokormismatch). Its dict goes indetail["snapshot"]and the audit row'sstates["snapshot"]. A snapshot that raises is recorded as{"error": str(exc)}and does not change the outcome.
-
Step 1: Write the failing tests (fake callables, no device, the
Auditfake pattern fromtests/test_device_access_change.py):test_monitoring_kinds_are_todays_names:monitoring_change(True) == ChangeKind("start monitoring", "monitoring", "started"), and likewise for stop.test_a_call_home_change_is_verified_by_its_own_state:kind=call_home_change(False), states["enabled", "disabled"]→(outcome, verified, state_after) == ("sent", "ok", "disabled"), andresult.action == "disable call-home".test_a_call_home_read_back_that_did_not_change_is_a_mismatch: states["enabled", "enabled", "enabled", "enabled"]with verify(3.0, 1.0)→("failed", "mismatch").test_the_snapshot_is_kept_in_the_result_and_the_audit:snapshot=lambda: {"after": "ab"}→result.detail["snapshot"] == {"after": "ab"}and the audit row'sstates["snapshot"] == {"after": "ab"}.test_a_failing_snapshot_does_not_change_the_outcome: a snapshot raisingRuntimeError("x")→ still("sent", "ok"),detail["snapshot"] == {"error": "x"}.
-
Step 2: Run
pytest tests/test_device_access_change_kind.py -v. Expected: FAIL (ImportError: cannot import name 'ChangeKind'). -
Step 3: Implement. Replace
startwithkindinrun_change, derivingaction,wantandbecamefromkind. Add the snapshot as specified. Update the two call sites tokind=monitoring_change(start), keeping their ownstartparameter. -
Step 4: Run the new file plus
tests/test_device_access_change.py tests/test_device_access_s3_events.py tests/test_server_device_access.py. Expected: all pass, with the existing start/stop tests unchanged. -
Step 5: Commit
refactor(sfm): run_change takes a ChangeKind -- start/stop unchanged, call-home next (phase 4).
Task 2: Series 4 — read call-home, change it
Files:
- Modify:
micromate/opcodes.py(ENABLEABLE_WRITES),micromate/client.py(new method) - Modify:
sfm/device_access/models.py(newCallHomeState),sfm/device_access/s4.py(two new functions) - Modify:
tests/device_access_fakes.py(FakeMicromateClientcall-home support),tests/test_micromate_execute.py:37(the ceiling assertion) - Test:
tests/test_device_access_s4_call_home.py(new)
Interfaces:
-
Consumes: Task 1's
ChangeKind,call_home_change,run_change(snapshot=…). -
Produces:
ENABLEABLE_WRITES = frozenset({0x96, 0x97, 0x7E, 0x7F}).MicromateClient.get_call_home_content() -> bytes: the 126-byte content,_content(self.protocol.read_call_home_config()).@dataclass class CallHomeState: serial: str; series: int; enabled: Optional[bool]; dial_string: Optional[str]; detail: Dict[str, Any](detail["byte5"]as"0xNN",detail["block"]as hex).s4_call_home_state(client, serial) -> CallHomeState: enabled is bit 0 ofcontent[5]; the dial string iscontent[6:46]up to its first NUL, decoded as ASCII.s4_change_call_home(client, serial, *, enabled, dry_run, even_if_already, audit, address, caller, sleep, verify_timeout_s, verify_interval_s) -> ChangeResult:read_statereturns"calling_home"whenclient.read_run_state().name == "calling_home", else"enabled"/"disabled"fromcontent[5] & 1. It keeps the last content it read.describe_plan:plan_call_home_enabled(last_content, enabled).describe(), so the plan is built from the readrun_changemade just before.sendexecutes that same plan object.snapshotreturns{"before": hex, "after": hex, "changed_offsets": [...]}, comparing the first and last content read.pre_send,is_refusalandis_ringare as ins4_change_monitoring.
-
Step 1: Fake support.
FakeMicromateClient(call_home=<126-byte content>), defaulting to UM12947's enabled read fromtests/fixtures/micromate-writes(the readstests/test_micromate_writes.py::_call_home_readsuses), plus aread_call_home_config()on_FakeProtocolreturningbytes(11) + content.execute(plan)applies a0x7Estep's data as the new content, then replaces[118:120]with its bitwise complement, mimicking the unit-maintained field (the default read already holds2e 5e, so a fixed value would not change it).
-
Step 2: Write the failing tests:
test_s4_call_home_state_reads_the_enable_bit_and_dial_string: on the default content (UM12947,[5] = 0x05) →enabled is True,dial_string == "RADIO RING",detail["byte5"] == "0x05".test_s4_dry_run_shows_thors_frames: dry runenabled=False→result.planframes equalplan_call_home_enabled(content, False).describe()["steps"]frames, andfake.executed == [].test_s4_disable_sends_7e_7f_and_verifies: liveenabled=False→("sent", "ok", "disabled"); executed plan subs[0x7E, 0x7F].test_s4_unit_maintained_bytes_do_not_make_a_mismatch: same run →verified == "ok"anddetail["snapshot"]["changed_offsets"] == [5, 118, 119].test_s4_no_change_while_calling_home:run_states=[0x03]→CallHomeInProgress, nothing executed.test_s4_already_enabled_is_skipped:enabled=Trueon enabled content →outcome == "skipped", nothing executed. Witheven_if_already=True→ executed once, and the plan carries the "changes nothing" warning.- Update
test_micromate_execute.py:37to the new four-SUB set.
-
Step 3: Run the new file. Expected: FAIL (
ImportError: s4_call_home_state). -
Step 4: Implement as specified in Interfaces.
-
Step 5: Run the new file plus
tests/test_micromate_execute.py tests/test_micromate_writes.py tests/test_device_access_change.py. Expected: pass. -
Step 6: Commit
feat(sfm): Series-4 call-home state and audited enable/disable (phase 4).
Task 3: Series 3 — read call-home, change it (live send gated)
Files:
- Modify:
minimateplus/protocol.py(two pure functions next towrite_image),minimateplus/client.py(two methods) - Modify:
sfm/device_access/s3.py(gate constant + two adapter methods) - Modify:
tests/device_access_fakes.py(FakeMiniMateClientcall-home support) - Test:
tests/test_s3_call_home.py(new)
Interfaces:
-
Consumes: Task 1, and Task 2's
CallHomeState. -
Produces:
call_home_enabled(raw: bytes) -> Optional[bool]inminimateplus/protocol.py:unescape_reply(raw)[5],0x01→ True,0x00→ False, else None.call_home_image(raw: bytes, enabled: bool) -> bytes:write_image(SUB_CALL_HOME_WRITE, raw)with byte 5 set to0x01/0x00and every other byte unchanged. RaisesValueErrorwhen the image's byte 5 is not0x00/0x01.MiniMateClient.read_call_home_raw() -> bytes(the protocol'sread_call_home_config()) andMiniMateClient.write_call_home_image(image: bytes) -> None(the protocol'swrite_call_home_config(image):0x7Ethen0x7F, each ack checked).S3_CALL_HOME_FRAME_VERIFIED = Falseinsfm/device_access/s3.py. Task 4 flips it.Series3Adapter.call_home_state(address, serial) -> CallHomeState:wake, thenread_call_home_raw(). The dial string is the unescaped[6:46]up to its first NUL.detailcarriesbyte5,block(raw hex) andserial_verified: False, as status does.Series3Adapter.change_call_home(address, serial, *, enabled, dry_run, even_if_already, audit, caller, sleep, verify_timeout_s, verify_interval_s) -> ChangeResult:- When
not dry_run and not S3_CALL_HOME_FRAME_VERIFIED, raiseNotSupported("a MiniMate call-home write waits until its frame has been reproduced from a Blastware capture -- nothing sent")before_run. - Otherwise use
run_change(kind=call_home_change(enabled), retry=False)with:read_serial=client.connect(), as for start/stop;read_state=wake+read_call_home_raw(), givingenabled/disabled/unknown(0xNN)and keeping the last raw;describe_plan= the steps[{"sub": "0x7E", "frame": build_bw_write_frame(0x7E, image).hex()}, {"sub": "0x7F", "frame": build_bw_write_frame(0x7F, b"").hex()}];send=client.write_call_home_image(image), returning{"subs": ["0x81", "0x80"]};snapshotas in Task 2, over unescaped images.
- When
-
Step 1: Fake support.
FakeMiniMateClient(call_home_raw=<125 B>). The default is built from the documented 4-20-26 layout:00 7C DC 00 00,[5] = 0x01,[6:46] = b"RADIO RING"NUL-padded,[117:119] = 10 03, zeros elsewhere to 125 bytes.read_call_home_raw()steps and returns it.write_call_home_image(image)recordsself.writes.append("call_home")and stores the image for the next read.
-
Step 2: Write the failing tests:
test_s3_enable_byte_reads_from_the_unescaped_block: on the default raw →call_home_enabled(raw) is True. A raw with an escape spliced in before byte 5 (00 7C 10 03 00 00 01 …) still reads True.test_s3_image_changes_only_byte_5:call_home_image(raw, False)differs fromwrite_image(0x7E, raw)at index 5 only, and its length is 126 (N0x7C+ 2).test_s3_image_refuses_an_unknown_byte_5: raw with unescaped[5] = 0x07→ValueError.test_s3_call_home_state: throughSeries3Adapterwith the fake →enabled is True,dial_string == "RADIO RING",detail["serial_verified"] is False; the calls include"wake"before"read_call_home_raw".test_s3_live_change_is_refused_until_the_frame_is_verified:dry_run=False→NotSupported(501), the factory never called.test_s3_dry_run_shows_both_frames:dry_run=True→ plan steps0x7E/0x7F,fake.writes == [].test_s3_change_once_verified(monkeypatchS3_CALL_HOME_FRAME_VERIFIED = True): liveenabled=False→("sent", "ok", "disabled"),fake.writes == ["call_home"],detail["snapshot"]["changed_offsets"] == [5].test_s3_unknown_byte_5_sends_nothing(gate open): raw with[5] = 0x07→UnitStateUnknown, no write.
-
Step 3: Run the new file. Expected: FAIL (
ImportError: call_home_enabled). -
Step 4: Implement as specified.
-
Step 5: Run the new file plus
tests/test_device_access_change.py tests/test_server_series3_guard.py. Expected: pass. -
Step 6: Commit
feat(sfm): Series-3 call-home state and audited enable/disable, live send gated until its frame is verified (phase 4).
Task 4: Reproduce Blastware's Series-3 call-home write (opens the gate)
Precondition: Brian has found a capture of Blastware changing call-home settings, from the BW VM (CLAUDE.md names it 4-20-26/call home settings/, BE11529), and copied the BW-TX and S3-RX files into tests/fixtures/s3-call-home-bw/. If no capture exists, skip this task. The gate stays shut, the Series-3 half of the bench (Task 7) starts by recording one, and this task runs after it.
Files:
-
Create:
tests/fixtures/s3-call-home-bw/(Brian's files, added withgit add -fif they match an ignore rule) andtests/test_s3_call_home_bw_frames.py -
Modify:
sfm/device_access/s3.py(S3_CALL_HOME_FRAME_VERIFIED = True, with a comment naming the test) -
Step 1: Write the test
test_sfm_builds_blastwares_call_home_write:- Parse the S3-RX file with
S3FrameParser, taking each0xD3data reply (data[11:]) in order. Parse the BW-TX file for the0x7Eand0x7Frequest frames, using the #46 parser intests/test_minimate_write_frames.py(_frames,_payload; import or copy them). - For each
0x7E, work out what Blastware asked for: the unescaped byte 5 of its image. - Assert
build_bw_write_frame(0x7E, call_home_image(prev_read, wanted)) == bw_7e_frameandbuild_bw_write_frame(0x7F, b"") == bw_7f_frame. - If Blastware also changed fields other than byte 5 in that write, assert only on writes where byte 5 is the sole difference from the read, and record the count.
- Parse the S3-RX file with
-
Step 2: Run it. Expected: PASS, with at least one write asserted. A FAIL means SFM's frame is not Blastware's: stop, record the byte differences in the spec's phase-4 notes, and leave the gate shut.
-
Step 3: Flip the gate, then run
tests/test_s3_call_home.py. The "refused until verified" test now fails by design: change it to assert the gate's comment names this test, and keep the monkeypatched tests. -
Step 4: Commit
test(s3): SFM's call-home write equals Blastware's, frame for frame -- opens the live send.
Task 5: DeviceAccess and the serial routes
Files:
- Modify:
sfm/device_access/access.py(two methods, two constants),sfm/server.py(three routes,_SERIAL_AWARE_PATHS) - Test:
tests/test_device_access_call_home.py, plus additions totests/test_server_device_access.py
Interfaces:
-
Consumes: Tasks 2 and 3.
-
Produces:
DeviceAccess.call_home_state(address, serial) -> CallHomeState(a read, via_dispatch).DeviceAccess.set_call_home(address, serial, *, enabled: bool, dry_run=False, even_if_already=False, caller="api") -> ChangeResult(change=True). It uses_CALL_HOME_VERIFY_TIMEOUT_S = 3.0and_CALL_HOME_VERIFY_INTERVAL_S = 1.0, at most 3 read-backs one second apart, not the monitoring window.- Routes:
GET /device/call_home/state?serial=&host=&tcp_port=→ theCallHomeStateas a dict.POST /device/call_home/enableand/device/call_home/disable, takingserial(required),host,tcp_port,dry_run,even_if_alreadyandcaller, through_change_response. The statuses are the start/stop route's, including Batch 2'ssent/audit_idon an unconfirmed change.
- All three go in
_SERIAL_AWARE_PATHS. The legacyGET/POST /device/call_homestay unchanged, and outside that set.
-
Step 1: Write the failing tests:
test_set_call_home_dispatches_by_series: aUMserial reaches the S4 function and aBEserial the S3 adapter, using the fakes from Tasks 2 and 3.test_set_call_home_is_never_retried: an S4 held line that drops → raised, executed once.test_call_home_routes_need_a_serial: noserial→ 422.test_enable_route_returns_the_change_result: a fake access → 200 and the body'saction == "enable call-home".test_legacy_call_home_post_still_refuses_a_micromate_serial:_device_guard("/device/call_home", {"serial": "UM20147"})→ 501, unchanged.test_call_home_routes_are_serial_aware: the three new paths are in_SERIAL_AWARE_PATHS.
-
Step 2: Run. Expected: FAIL (
AttributeError: set_call_home). -
Step 3: Implement, mirroring
start_monitoring/device_monitor_start. -
Step 4: Run the new and modified test files plus
tests/test_server_series3_guard.py. Expected: pass. -
Step 5: Commit
feat(sfm): call-home state and enable/disable by serial -- GET /device/call_home/state, POST /device/call_home/{enable,disable} (phase 4).
Task 6: The page — Call Home by serial
Files:
- Modify:
sfm/static/device_routing.js(routes,controlsFor,serialPanes,changeErrorText, newcallHomeRows),sfm/static/sfm_webapp.js(glue),sfm/sfm_webapp.html(a state box and two buttons in the Call Home tab) - Test:
tests/test_webapp_device_routing.py, plus a jsdom run ofpage_files_load.jsin the scratchpad (not committed)
Interfaces:
- Consumes: Task 5's routes and Batch 2's
serialPanes/changeErrorText. - Produces:
DEVICE_ROUTES:call_home_state: ['GET', '/device/call_home/state', true]call_home_on: ['POST', '/device/call_home/enable', true]call_home_off: ['POST', '/device/call_home/disable', true]
controlsFor(unit).callHomeChange = serialMode && (series === 3 || series === 4).callHomeWrite(the legacy multi-field form) staysfalse, withreasons.callHomeWrite = 'By serial: use Call-home On / Off (audited). Other call-home fields wait for the THOR round.'serialPanes(...)gainscallHomeForm: !bySerialandcallHomeBox: bySerial. Batch 2's existing test gets the two keys added.changeErrorText(label, status, body, unit, statusText)takes the whole label ("Start monitoring","Enable call-home") and returns`${label} not confirmed: …`/`${label} failed: …`. Update its two callers and Batch 2's test.callHomeRows(state) -> [[label, value], …]returns:['Call-home', 'On' | 'Off' | 'Unknown (byte 5 = 0xNN)']['Dial string', … or '—']['Series', 3 | 4]
- Step 1: Write the failing Node tests:
test_call_home_routes_need_a_serial:deviceUrl('call_home_on', BLANK)→ null; with S4 →{method: 'POST', path: '/device/call_home/enable?serial=UM20147&host=h&tcp_port=9034'}.test_call_home_change_needs_a_confirmed_series: typed but unconfirmed → false; confirmed 3 → true; confirmed 4 → true; legacy → false.test_call_home_rows:{enabled: true, dial_string: 'RADIO RING', series: 4}→[['Call-home','On'],['Dial string','RADIO RING'],['Series',4]];{enabled: null, detail: {byte5: '0x07'}, series: 3}→ first row['Call-home','Unknown (byte 5 = 0x07)'].- Update the
changeErrorTextandserialPanestests to the new shapes.
- Step 2: Run
pytest tests/test_webapp_device_routing.py. Expected: FAIL (callHomeRowsis not defined). - Step 3: Implement the routing functions, then the glue:
- By serial, the Call Home tab hides the legacy form and shows the state box via
serialPanes, inapplyControls. readCallHome()usescall_home_stateand renderscallHomeRows.changeCallHome(on)asksconfirm()with the serial and on/off, sendscall_home_on/call_home_off, reports withchangeSummary/changeErrorText('Enable call-home' | 'Disable call-home', …), then re-reads the state.- The buttons are enabled by
controlsFor().callHomeChange. - HTML:
#ch-state(adev-table),#ch-on-btnand#ch-off-btninside a#ch-serialbox; the existing form goes in#ch-legacy.
- By serial, the Call Home tab hides the legacy form and shows the state box via
- Step 4: Run the Node tests (pass), then the jsdom check. Extend
page_files_load.jswith:- S4: Call Home read → rows shown, legacy form hidden;
- Off →
POST /device/call_home/disable?serial=UM20147…sent after confirm, status fromchangeSummary; - legacy mode: form shown;
- no script errors.
- Step 5: Commit
feat(sfm): the page's Call Home tab by serial -- state and audited On / Off (phase 4).
Task 7: Docs, and the bench session (Brian's go per send)
Files:
-
Modify: the spec (a "Phase 4" entry after phase 3's under Build phases),
CLAUDE.md("Where things stand"), anddocs/micromate_protocol_reference.md/docs/instantel_protocol_reference.md(CRLF: Edit tool or byte-safe writes) for whatever the bench measures -
Step 1: Docs before the bench.
- Spec: what was built, with commit IDs; the gate's state; the bench questions below.
- CLAUDE.md: one status line.
- Commit
docs: phase 4 built -- call-home enable/disable by serial; bench questions.
-
Step 2: Bench, UM20147 on its modem, idle. One send per go:
- (a) dry run
disable, showing frames and warnings, including "0x00 is unobserved"; - (b)
enablewitheven_if_already(the no-op write: does a Micromate accept it?); - (c)
disable: read-back, the unit's screen, and the snapshot's changed offsets; - (d)
enable, back to how it was. - Record each audit id and
[118:120]before/after.
- (a) dry run
-
Step 3: Bench, BE9441 on its modem, idle.
- If Task 4 did not run: first record Blastware changing call-home on BE9441 through the bridge, then run Task 4.
- Then (a) to (d) as above.
-
Step 4: One unit monitoring (Brian picks which): a dry run, then one
disable/enablepair. This settles whether a unit accepts a call-home write while monitoring. Unmeasured; nothing in the code assumes either answer. -
Step 5: Record the results in the spec and the protocol references (measured, with audit ids), and commit
docs: phase 4 bench -- call-home on/off on both series.