Skip to content

fix(plc-modbus): RegisterData drops every named VFD register — match REGISTER_NAMES (#161) - #197

Merged
Mikecranesync merged 3 commits into
mainfrom
fix/161-registerdata-named-vfd-fields
Aug 2, 2026
Merged

fix(plc-modbus): RegisterData drops every named VFD register — match REGISTER_NAMES (#161)#197
Mikecranesync merged 3 commits into
mainfrom
fix/161-registerdata-named-vfd-fields

Conversation

@Mikecranesync

Copy link
Copy Markdown
Owner

Fixes #161 — the isolated bug-fix PR required by PR 2 of MIRA PRD #3048 (machine-evidence handoff, canonical-source correctness).

The bug — verified live against current main before fixing

read_io() (backend/services/plc_connection.py) builds its registers dict from REGISTER_NAMES:

ItemCount, ConveyorHz, MotorCurrentX10, MotorTempX10, VFDStatus, ErrorCode

but RegisterData (backend/models/plc_models.py) declared placeholder register_101..105 fields. Pydantic v2 silently drops unknown fields, so every named VFD value was stripped from /api/plc/io and replaced with the 0 default — diagnosis read zeros while the PLC reported real data.

The fix

RegisterData now declares exactly the names read_io() produces. Repo-wide grep confirms the placeholder names had zero consumers outside the model itself, so this is a pure correction — no caller that worked before changes behavior.

Regression coverage (tests/unit/test_backend_models.py, new)

  • Drift guard: model fields pinned equal to REGISTER_NAMES parsed from plc_connection.py source (parsed, not imported, so the pure-model test carries no pymodbus dependency) — the two can never silently diverge again
  • Round-trip test proving named values survive the model
  • Guard against reintroducing register_* placeholders

154 unit tests pass (151 pre-existing + 3 new), run locally on the PLC laptop.

Slice coordination

Claimed on MIRA #3048: PLC laptop (LAPTOP-0KA3C70H), session f985f0fe. Next in this slice: rebase/test the canonical-tag mapping from #188, then generate factorylm.machine-snapshot.v1 fixtures. BRAVO holds MIRA-side PR 1.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dgej4vU7mMnYTmU6QXsH3n

… placeholder fields to match REGISTER_NAMES (#161)

read_io() builds its registers dict from PLCConnection.REGISTER_NAMES
(ItemCount, ConveyorHz, MotorCurrentX10, MotorTempX10, VFDStatus,
ErrorCode), but RegisterData declared placeholder register_101..105
fields. Pydantic v2 silently drops unknown fields, so every named VFD
value was stripped from /api/plc/io and replaced with the 0 default —
diagnosis read zeros while the PLC reported real data.

Fix: RegisterData now declares exactly the names read_io() produces.
The placeholders had zero consumers anywhere else in the repo (grep),
so this is a pure correction, not an API break for any caller that
worked.

Adds tests/unit/test_backend_models.py:
- field parity pinned against REGISTER_NAMES parsed from
  plc_connection.py source (parsed, not imported, so the pure-model
  test does not depend on pymodbus)
- round-trip test proving named values survive
- guard against reintroducing register_* placeholders

154 unit tests pass (151 pre-existing + 3 new).

Context: PR 2 of MIRA PRD #3048 (machine-evidence handoff) — this is
the canonical-source correctness prerequisite.

Closes #161

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dgej4vU7mMnYTmU6QXsH3n
Fixes #204: CLAUDE.md said holding registers 101-105 were unused while
the #161 fix wired them to named VFD telemetry — the table now documents
ConveyorHz/MotorCurrentX10/MotorTempX10/VFDStatus/ErrorCode, and the
session history no longer claims only register 100 is used.

Also adds the optional #161 acceptance test: the serialized IOResponse
(the /api/plc/io boundary) keeps every named VFD register value, built
from the exact registers dict shape read_io()/mock mode produce, with
no plc_connection/pymodbus import.

155 unit tests pass (was 154).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dgej4vU7mMnYTmU6QXsH3n
@Mikecranesync

Copy link
Copy Markdown
Owner Author

Repair pass complete for #161 docs drift (commit 59abf9a):

Tests (local, since only brain-ingest runs on PRs until #205):

PYTHONPATH=src pytest tests/unit/test_backend_models.py -q
4 passed in 0.36s

PYTHONPATH=src pytest tests/unit -q
155 passed in 0.46s   (baseline on this branch: 154)

No behavior beyond the #161 model correction.

@Mikecranesync
Mikecranesync merged commit 74a5d52 into main Aug 2, 2026
2 checks passed
@Mikecranesync
Mikecranesync deleted the fix/161-registerdata-named-vfd-fields branch August 2, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(plc-modbus): RegisterData model strips named VFD register fields → diagnosis reads zeros

1 participant