fix: harden control loop against write failures and initialisation edge cases#12
Merged
Conversation
…ge cases Four small robustness fixes found in a non-happy-flow review: - Switch-array toggles were the only actuator write not wrapped in try/except: a service exception (e.g. a timeout) escalated to UpdateFailed and aborted the whole control cycle. Failures are now logged and the toggle retried next cycle. - The back-calculation anti-windup compared the PID output direction against the raw grid signal, while the PID acts on the residual (grid minus the pending battery response). While a battery absorbs an export the two can legitimately differ in sign, wrongly resetting a valid integrator. The check now uses the residual. - _discharge_allowed treated loads the engine had not seen yet as off, so right after a restart the battery could discharge into a load that was actually running and reducible. Unknown loads are now read from their entity state. - A configured-but-unavailable SoC sensor silently disabled the SoC limits (fail-open). That is still the behaviour — the BMS protects the battery — but a warning is now logged once until the sensor recovers. https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz
40e3234 to
546d559
Compare
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.
Problem / Fix
Four small robustness fixes from the non-happy-flow review:
UpdateFailedand aborted the entire control cycle. Failures are now logged and the toggle retried the next cycle; internal state is only updated after a successful write.filtered), while the PID acts on the residual (grid minus the pending battery feedforward). While a battery absorbs an export the two can legitimately differ in sign, wrongly resetting a valid integrator. The check now uses the residual._discharge_allowedtreated loads the engine had not seen yet as off, so right after a restart the battery could discharge to cover an import caused by a load that was actually running and reducible. Unknown loads are now read from their entity state before the last-resort decision.Tests
tests/test_robustness.py: switch-array write failure keeps the cycle alive and retries, a running-but-uninitialised load blocks discharge, and the SoC-unavailable warning fires exactly once. Full suite: 242 passed.https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz
Generated by Claude Code