Skip to content

fix(calibration): implement the grid power safety guard#3

Open
bvweerd wants to merge 1 commit into
devfrom
fix/calibration-grid-guard
Open

fix(calibration): implement the grid power safety guard#3
bvweerd wants to merge 1 commit into
devfrom
fix/calibration-grid-guard

Conversation

@bvweerd

@bvweerd bvweerd commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Problem

CALIB_MAX_GRID_W ("Abort if |grid_w| exceeds this") was defined in const.py but never referenced — the documented safety guard did not exist. During calibration normal control is suspended and the array under test is forced to a 20–30% limit, so a consumption or production spike could drive a large uncontrolled grid exchange with nothing watching for it.

Fix

  • ArrayCalibrator accepts an optional async read_grid callable; the coordinator wires it to its own grid reading.
  • On every settling poll the grid is checked; when |grid| exceeds CALIB_MAX_GRID_W (3000 W) the array's calibration fails with a clear message (Aborted: |grid| exceeded 3000 W during calibration).
  • The existing finally block guarantees the original setpoint is restored on abort.
  • Unavailable grid reads are ignored (fail-open), so a flaky sensor cannot break calibration.
  • Removes the dead CALIB_BASELINE_SAMPLES and CALIB_STEP_* constants left over from the earlier grid-based calibration approach.

Tests

Two new tests in tests/test_calibration.py: abort with setpoint restore when the limit is exceeded, and no abort when the grid read returns None. Full suite: 128 passed.

https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz


Generated by Claude Code

CALIB_MAX_GRID_W ("abort if |grid_w| exceeds this") was defined but
never used — the documented safety check did not exist. During
calibration the controller is suspended and arrays are forced to
20-30%, so a consumption spike could drive a large uncontrolled grid
exchange with nothing watching.

The calibrator now accepts an async read_grid callable (wired to the
coordinator's grid reading) and checks it on every settling poll; when
|grid| exceeds the limit the array's calibration fails with a clear
message and the original setpoint is restored via the existing finally
block. Unavailable grid reads are ignored (fail-open).

Also removes the dead CALIB_BASELINE_SAMPLES and CALIB_STEP_* constants
left over from the previous grid-based calibration approach.

https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz
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.

1 participant