Repository navigation
feat(control): DC-link protective PV curtail — pre-empt Ferroamp fault - #310
Conversation
Live incident 2026-05-25 14:53:20: Ferroamp EnergyHub tripped to
fault state 0x8030 (DC-link safety). Reconstructed trigger from
history: a 2.7 kW load step under 6 kW PV generation with battery
at 85 % SoC dragged grid from -5.5 kW export to -3 kW, fast enough
that the inverter's internal DC-link voltage couldn't ramp PV down
in time. Operator framing: \"prefer to lose a bit of PV revenue
over having the inverter trip and stop charging entirely.\"
This adds an opt-in PV-curtail trigger that engages on the
operator-tunable risk window: SoC at or above DCLinkProtectionSoC
Threshold (default 80 %) AND PV exceeds load by more than 2× the
margin (default 1000 W). When it engages the PV limit becomes
`load + margin`, so a load step inside `margin` lands without
re-curtail. Disabled by default; enable per-site via
`site.dc_link_protection_enabled: true`.
Composes safely with existing curtail sources:
- Operator manual hold: never relaxed (tightest cap wins).
- Planner directive: protection layered on top via min(...);
a tighter planner cap stays in force.
- Driver-scoped hold: bypassed (operator is explicitly forcing
one driver, don't auto-engage elsewhere).
- Sites with no PV-curtail-capable driver: no-op.
Config:
site.dc_link_protection_enabled (default false)
site.dc_link_protection_soc_threshold (default 0.80)
site.dc_link_protection_margin_w (default 1000)
All three hot-reload via the configreload watcher.
Tests:
- TestProtectivePVCurtailEngagesAtHighSoCWithSurplus — happy
path: 85 % SoC + 5.5 kW surplus → curtail to load + margin
- TestProtectivePVCurtailSkipsBelowSoCThreshold — 50 % SoC,
same surplus, no curtail
- TestProtectivePVCurtailNeverRelaxesManualHold — manual cap
tighter than protection wins
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94a4aad3a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for _, r := range store.ReadingsByType(telemetry.DerBattery) { | ||
| batW += r.SmoothedW | ||
| } | ||
| for _, r := range store.ReadingsByType(telemetry.DerPV) { | ||
| pvW += r.SmoothedW |
There was a problem hiding this comment.
Ignore stale offline DER readings in load estimator
siteLoadW computes load from every battery/PV sample returned by ReadingsByType, but it never checks DriverHealth.IsOnline(). Since the telemetry store retains last-known readings for offline drivers, stale kW-scale values can skew load and cause protectiveCurtailLimitW to either miss a real DC-link risk or clamp PV when it should not. This protection is live-state logic, so it should filter to online drivers (as other dispatch helpers do) before summing battery/PV power.
Useful? React with 👍 / 👎.
| loadW := siteLoadW(state, store) | ||
| if pvAbs < loadW+2*margin { | ||
| // Surplus already inside the safe margin — no need to engage. |
There was a problem hiding this comment.
Treat missing site-meter telemetry as no-decision
When the site meter reading is missing, siteLoadW returns 0, but protectiveCurtailLimitW still evaluates the surplus gate against that zero (pvAbs < loadW+2*margin). In practice, any high-PV period with SoC above threshold will trigger a curtail limit (margin watts) during meter outages, even though load is unknown. That is a behavior regression for this new feature because it turns missing telemetry into an active curtail decision instead of skipping protection until meter data is available.
Useful? React with 👍 / 👎.
* ci: stop new direct reads of cached telemetry outside the telemetry package A reading stays in telemetry.Store after its driver goes stale, offline or faulted. Every direct reader of RawW, SmoothedW, ReadingsByType or ReadingsByDriver must check driver health itself, and review caught the missing check in #36, #85, #310, #647, #664 and #740. The check counts those reads per file outside go/internal/telemetry and fails when a pull request adds one. Existing reads (147 today) may only go down. The error names the health-gated accessors to use instead. On the merged commits of #36, #85, #310 and #647 it fails. * ci: count telemetry reads across platforms and validate exceptions Signed-off-by: Fredrik Ahlgren <[email protected]> --------- Signed-off-by: Fredrik Ahlgren <[email protected]>
Live incident — 2026-05-25 14:53:20
Ferroamp EnergyHub tripped to fault state
0x8030(DC-link safety). Reconstructed trigger:A 2.7 kW load step under 6 kW PV + 85 % SoC dragged grid from -5.5 kW export to -3 kW; the inverter's DC-link couldn't ramp PV down in time. Operator framing: "prefer to lose a bit of PV revenue over having the inverter trip and stop charging entirely."
What this PR does
Adds an opt-in PV-curtail trigger that engages on the configurable risk window:
When it engages the PV limit becomes
load + margin, so a load step insidemarginlands without re-curtail recompute.Composes safely with existing curtail sources
Config
All three hot-reload via the configreload watcher.
Tests
TestProtectivePVCurtailEngagesAtHighSoCWithSurplus— 85 % SoC + 5.5 kW surplus → curtail to load + marginTestProtectivePVCurtailSkipsBelowSoCThreshold— 50 % SoC, same surplus, no curtailTestProtectivePVCurtailNeverRelaxesManualHold— manual cap tighter than protection winsActivation
After deploy, set
site.dc_link_protection_enabled: truevia the API (hot-reload). The fix only engages when the conditions hit — on a cloudy or low-SoC day it stays inert.🤖 Generated with Claude Code