Skip to content

fix(ferroamp): refuse pplim arg=0 — sticky-lock trap on extapi - #367

Merged
frahlg merged 1 commit into
masterfrom
worktree-fix+ferroamp-curtail-disable-no-pplim-zero
May 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
worktree-fix+ferroamp-curtail-disable-no-pplim-zero

Conversation

@frahlg

@frahlg frahlg commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

The Ferroamp Lua driver now refuses to publish pplim arg=0 from any path. The default curtail_disable is a logged no-op; restore automatic release by setting config.pplim_release_w to the inverter's nominal max.

The incident (2026-05-27)

Operator enabled supports_pv_curtail: true on 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 a curtail_disable action. The Lua driver translated that to {"cmd":{"name":"pplim","arg":0}}.

Ferroamp's extapi treats pplim arg=0 as "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 pplim
  • pplim arg=15000 (manual hold) → no effect
  • pplim without arg → no effect
  • Verified via mosquitto_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.613V on a battery that should be at ~50 V)
  • Final recovery: Ferroamp portal reset

What changes

Before After
curtail power_w=0 → pplim arg=0 (locks SSO) logged no-op
curtail power_w=-50 → pplim arg=0 (locks SSO) logged no-op
curtail_disable → pplim arg=0 (locks SSO) logged no-op (default)
no operator escape valve config.pplim_release_w: 15000 → publishes pplim arg=15000 on release

Files

  • drivers/ferroamp.lua — defensive guards in driver_command; new PPLIM_RELEASE_W parsed from config.pplim_release_w in driver_init
  • go/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 bump

Out of scope (separate PR)

The dispatcher-side root cause — ComputePVCurtail translating a 0-share allocation to a curtail_disable release — 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 verify passes
  • 5 new unit tests cover zero / negative / curtail_disable default / curtail_disable with release_w / normal positive curtail
  • Existing e2e + ferroamp tests still pass (no behavioural regression for non-curtail paths)
  • After merge + release, operator re-enables supports_pv_curtail: true on Ferroamp WITHOUT setting pplim_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)
  • Operator then adds config.pplim_release_w: 15000 and re-runs the same test. Curtail releases automatically and PV recovers without portal intervention

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread drivers/ferroamp.lua
Comment on lines +849 to +853
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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]>
@frahlg
frahlg force-pushed the worktree-fix+ferroamp-curtail-disable-no-pplim-zero branch from eb32e17 to 5931e2b Compare May 27, 2026 16:38
@frahlg
frahlg merged commit 322ffe2 into master May 27, 2026
2 checks passed
frahlg added a commit that referenced this pull request May 27, 2026
…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]>
frahlg added a commit that referenced this pull request May 27, 2026
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]>
frahlg added a commit that referenced this pull request May 27, 2026
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]>
@frahlg
frahlg deleted the worktree-fix+ferroamp-curtail-disable-no-pplim-zero branch August 7, 2026 08:19
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