Repository navigation
fix(ferroamp): refuse pplim arg=0 — sticky-lock trap on extapi - #367
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb32e17c39
ℹ️ 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".
| if PPLIM_RELEASE_W > 0 then | ||
| local payload = string.format( | ||
| '{"transId":"ems","cmd":{"name":"pplim","arg":%d}}', | ||
| PPLIM_RELEASE_W) | ||
| return host.mqtt_publish("extapi/control/request", payload) |
There was a problem hiding this comment.
Release configured pplim on restart paths
When Ferroamp is curtailed and the daemon is restarted or the driver is hot-reloaded before ComputePVCurtail emits curtail_disable, this new release branch is never reached: the registry shutdown path calls driver_default_mode/driver_cleanup, and those still only publish auto, which the incident notes does not release pplim. With config.pplim_release_w set, the inverter can therefore remain capped after a process restart while the in-memory curtail state is gone, so no release is sent until a later curtail cycle; please route cleanup/default/deinit through the same safe pplim arg=PPLIM_RELEASE_W release when it is configured.
Useful? React with 👍 / 👎.
Ferroamp's extapi treats {"cmd":{"name":"pplim","arg":0}} as
"limit PV output to 0 W" — same wire bytes as a naive release would
have, opposite semantics. The inverter sticks at 0 W PV until the
operator clears pplim from the Ferroamp portal or power-cycles the
EnergyHub.
On 2026-05-27 this fired against a live SE4 site after the dispatcher
allocated proportional curtail share = 0 to Ferroamp (its live PV was
already near zero, so the proportional split rounded its share away).
ComputePVCurtail then translated that empty share to a curtail_disable
action, which the Lua driver translated to pplim arg=0. The SSO locked
at 0 W PV; recovery needed a 30+ minute outage and a Ferroamp portal
reset. Reproduced via mosquitto_sub on extapi/control/response:
sending any battery dispatch returned NAK "no available ESOs detected
in system", confirming the inverter had tripped to a broader fault
state.
Defensive contract enforced by this change:
1. curtail with power_w <= 0 is a logged no-op (was: pplim arg=0)
2. curtail_disable is a logged no-op by default (was: pplim arg=0)
3. curtail_disable with config.pplim_release_w = N publishes
pplim arg=N (operator's nominal SSO max, e.g. 15000)
4. New unit tests guard the wire payload against any regression that
would reintroduce pplim arg=0
Docs in docs/configuration.md describe the trap, the new config field,
and the operator workflow when running supports_pv_curtail: true on
Ferroamp.
The dispatcher-side fix (don't route curtail through drivers with
|PV| == 0 in the first place, and don't translate a 0-share to a
curtail_disable on the release path) is tracked separately — this PR
hard-fails the unsafe wire payload as defence in depth.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
eb32e17 to
5931e2b
Compare
…ity (#372) Defense-in-depth against the 2026-05-27 Ferroamp brick. Combined with PR #367's driver-side hard fail on pplim arg=0, this eliminates every known trigger path: 1. ComputePVCurtail no longer emits curtail_disable when a previously- curtailed driver drops out of the proportional allocation only because its own |PV| crashed to ~0. That very thing often happens as a direct consequence of OUR prior curtail throttling the inverter — the spurious release would publish pplim arg=0 to Ferroamp (sticky-lock trap). Releases are now only emitted on: - directive truly cleared (no slot + no hold) - driver removed from SupportsPVCurtail (config change) - driver went offline Also: per-driver allocations rounding to ≤ 1 W are suppressed entirely — never publish a near-zero pplim. 2. The Ferroamp driver subscribes to extapi/control/response (was: extapi/result, a wrong topic that never received anything), parses {"status":"ack|nak", ...} responses, and exposes cumulative extapi_nak_count + extapi_ack_count metrics. NAK responses also log as warnings with transId + msg. The brick was preceded by minutes of "nak: no available ESOs detected in system" that we couldn't see through ftw telemetry — operator can now alert on any non-zero NAK rate. Test coverage: - control/pv_curtail_test.go: 4 new regression guards - drivers/lua_ferroamp_curtail_test.go: NAK + ACK counter test Out of scope (separate PR): the self-healing watchdog (E) that auto- publishes pplim release when sso_pv_v > 200V + ipv == 0 in daylight. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
When the SSO reports the post-incident signature — DC bus voltage > 200 V, zero PV current, no fault, relay closed — continuously for ten minutes, the driver auto-publishes `pplim arg=<pplim_release_w>` to release the lock. Operator opts in by setting `config.pplim_release_w > 0`; without it, the watchdog logs a warning but does not publish (we have no safe release value to send). State machine: - `stuck_pv_since_ms` latches on first stuck observation, clears as soon as the signature breaks (e.g. ipv goes non-zero). - After STUCK_PV_AFTER_MS (10 min) continuous, a recovery is eligible. - After a recovery publish, STUCK_PV_RECOVERY_COOLDOWN_MS (5 min) must elapse before another recovery — prevents command-spam if the release doesn't take. - `stuck_pv_recovery_count` is emitted every poll as a cumulative counter so ops dashboards can alert on rate. Tests (lua_ferroamp_stuck_pv_test.go): - Auto-publishes pplim arg=15000 after 10 min stuck + cooldown gate - Without pplim_release_w opt-in: log-only, no publish, counter at 0 - Resets when stuck signature clears (ipv > 0) This is layer 3 of the defense-in-depth set started by PR #367 (driver-side hard fail on pplim=0) and continued by the dispatcher fix in the parallel "fix(curtail): no spurious release" PR. Together they make the 2026-05-27 brick scenario both un-triggerable AND self-recoverable. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When the SSO reports the post-incident signature — DC bus voltage > 200 V, zero PV current, no fault, relay closed — continuously for ten minutes, the driver auto-publishes `pplim arg=<pplim_release_w>` to release the lock. Operator opts in by setting `config.pplim_release_w > 0`; without it, the watchdog logs a warning but does not publish (we have no safe release value to send). State machine: - `stuck_pv_since_ms` latches on first stuck observation, clears as soon as the signature breaks (e.g. ipv goes non-zero). - After STUCK_PV_AFTER_MS (10 min) continuous, a recovery is eligible. - After a recovery publish, STUCK_PV_RECOVERY_COOLDOWN_MS (5 min) must elapse before another recovery — prevents command-spam if the release doesn't take. - `stuck_pv_recovery_count` is emitted every poll as a cumulative counter so ops dashboards can alert on rate. Tests (lua_ferroamp_stuck_pv_test.go): - Auto-publishes pplim arg=15000 after 10 min stuck + cooldown gate - Without pplim_release_w opt-in: log-only, no publish, counter at 0 - Resets when stuck signature clears (ipv > 0) This is layer 3 of the defense-in-depth set started by PR #367 (driver-side hard fail on pplim=0) and continued by the dispatcher fix in the parallel "fix(curtail): no spurious release" PR. Together they make the 2026-05-27 brick scenario both un-triggerable AND self-recoverable. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
The Ferroamp Lua driver now refuses to publish
pplim arg=0from any path. The defaultcurtail_disableis a logged no-op; restore automatic release by settingconfig.pplim_release_wto the inverter's nominal max.The incident (2026-05-27)
Operator enabled
supports_pv_curtail: trueon Ferroamp to debug PV curtail end-to-end on a live SE4 site. ComputePVCurtail's proportional allocation gave Ferroamp share = 0 (its live |PV| was already low). The release path translated the empty share to acurtail_disableaction. The Lua driver translated that to{"cmd":{"name":"pplim","arg":0}}.Ferroamp's extapi treats
pplim arg=0as "limit PV output to 0 W" — same wire bytes as a naive release would have, opposite semantics. The SSO locked at 0 W PV. Recovery needed 30+ minutes:name=auto→ ACK'd but doesn't release pplimpplim arg=15000(manual hold) → no effectpplimwithoutarg→ no effectmosquitto_sub extapi/control/response:{"status":"nak","msg":"no available ESOs detected in system"}— the EMS had tripped to a wider fault state with open ESO contactors (ubat: 0.613Von a battery that should be at ~50 V)What changes
curtail power_w=0→pplim arg=0(locks SSO)curtail power_w=-50→pplim arg=0(locks SSO)curtail_disable→pplim arg=0(locks SSO)config.pplim_release_w: 15000→ publishespplim arg=15000on releaseFiles
drivers/ferroamp.lua— defensive guards indriver_command; newPPLIM_RELEASE_Wparsed fromconfig.pplim_release_windriver_initgo/internal/drivers/lua_ferroamp_curtail_test.go— 5 tests guarding the wire payload (zero / negative / disable-default / disable-with-release / normal)docs/configuration.md— operator-facing description of the trap and the new field.changeset/ferroamp-pplim-zero-trap-fix.md— patch bumpOut of scope (separate PR)
The dispatcher-side root cause —
ComputePVCurtailtranslating a 0-share allocation to acurtail_disablerelease — is filed separately. This PR is defence in depth: even if the dispatcher regresses again, the driver hard-fails the unsafe wire payload.Test plan
make verifypassessupports_pv_curtail: trueon Ferroamp WITHOUT settingpplim_release_w. Curtail engages correctly during a minus-spot slot; on release the inverter retains the last pplim until manual portal clear (acceptable safe-default)config.pplim_release_w: 15000and re-runs the same test. Curtail releases automatically and PV recovers without portal intervention🤖 Generated with Claude Code