fix(plc-modbus): RegisterData drops every named VFD register — match REGISTER_NAMES (#161) - #197
Merged
Merged
Conversation
… 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
This was referenced Aug 2, 2026
Merged
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
Owner
Author
|
Repair pass complete for #161 docs drift (commit 59abf9a):
Tests (local, since only No behavior beyond the #161 model correction. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
mainbefore fixingread_io()(backend/services/plc_connection.py) builds its registers dict fromREGISTER_NAMES:but
RegisterData(backend/models/plc_models.py) declared placeholderregister_101..105fields. Pydantic v2 silently drops unknown fields, so every named VFD value was stripped from/api/plc/ioand replaced with the0default — diagnosis read zeros while the PLC reported real data.The fix
RegisterDatanow declares exactly the namesread_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)REGISTER_NAMESparsed fromplc_connection.pysource (parsed, not imported, so the pure-model test carries no pymodbus dependency) — the two can never silently diverge againregister_*placeholders154 unit tests pass (151 pre-existing + 3 new), run locally on the PLC laptop.
Slice coordination
Claimed on MIRA #3048: PLC laptop (
LAPTOP-0KA3C70H), sessionf985f0fe. Next in this slice: rebase/test the canonical-tag mapping from #188, then generatefactorylm.machine-snapshot.v1fixtures. BRAVO holds MIRA-side PR 1.🤖 Generated with Claude Code
https://claude.ai/code/session_01Dgej4vU7mMnYTmU6QXsH3n