Skip to content

fix(curtail): no spurious release on |PV|=0 + Ferroamp NAK observability - #372

Merged
frahlg merged 1 commit into
masterfrom
worktree-fix+curtail-no-spurious-release-and-nak-metric
May 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
worktree-fix+curtail-no-spurious-release-and-nak-metric

Conversation

@frahlg

@frahlg frahlg commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

Two independent defenses that close the remaining trigger paths to the 2026-05-27 Ferroamp brick. Combined with #367's driver-side hard fail on pplim arg=0, this is the full belt-and-suspenders.

1. Dispatcher — don't release on |PV|=0 drop-out

Old ComputePVCurtail logic emitted a curtail_disable for any previously-curtailed driver that dropped from the active proportional allocation. That fired wrongly when a curtailed driver's own |PV| crashed to ~0 — often a direct consequence of OUR prior curtail throttling that inverter. The spurious release then published pplim arg=0 to the driver. On Ferroamp's extapi: sticky-lock until portal reset.

New semantics — releases are emitted only when:

  • The curtail directive truly clears (no slot directive + no manual hold), OR
  • The driver was removed from state.SupportsPVCurtail (config change), OR
  • The driver went offline

A driver that drops from the active allocation while curtail is still active is kept in LastCurtailedDrivers (suppressed-track) so the next cycle's allocation reasoning stays accurate. The existing pplim on the inverter is left in place — it'll get refreshed when the driver's |PV| returns to a level the allocator can split.

Plus: per-driver allocation rounding to ≤ 1 W is suppressed — never publish a near-zero pplim that some inverters treat as a hard "limit to 0 W" lock.

2. Ferroamp driver — NAK observability

The driver subscribed to extapi/result (wrong topic — never received anything). It now subscribes to extapi/control/response and parses {"status":"ack|nak", ...} from each EMS response. Two new metrics:

  • extapi_nak_count — cumulative NAK counter
  • extapi_ack_count — cumulative ACK counter

NAK responses also log as warnings with transId + msg for correlation. The 2026-05-27 brick was preceded by minutes of nak: no available ESOs detected in system that we couldn't see through ftw telemetry — only mosquitto_sub revealed it. Operators can now alert on any non-zero NAK rate.

Tests

  • go/internal/control/pv_curtail_test.go — 4 new regressions:
    • TestComputePVCurtail_DroppedDueToZeroPVDoesNotEmitRelease (brick scenario)
    • TestComputePVCurtail_TinyShareSuppressedNotPublishedAsZero (rounding edge)
    • TestComputePVCurtail_RemovedFromSupportsStillEmitsRelease (config-change release)
    • TestComputePVCurtail_SlotClearReleasesEvenZeroPVDrivers (end-of-slot release)
  • go/internal/drivers/lua_ferroamp_curtail_test.go — NAK/ACK counter metric test

Out of scope (next PR)

Layer E from the brainstorming: self-healing watchdog that auto-publishes pplim release when the driver detects sso_pv_v > 200V + ipv == 0 for >10 min during daylight (sunpos elevation > 5°). Indicates a stuck pplim state — automatic recovery without portal intervention.

Test plan

  • make verify passes
  • All existing curtail + driver tests still pass
  • After merge + release, re-enable supports_pv_curtail: true on Ferroamp on the live SE4 site. During the next negative-spot slot, observe in /api/series:
    • extapi_ack_count increments on each pplim command
    • extapi_nak_count stays at 0 (or reveals an unexpected EMS issue early)
    • When Ferroamp's PV throttles down to the cap, dispatcher does NOT emit a spurious release (verifiable by absence of "curtail_disable" payload in driver logs)

🤖 Generated with Claude Code

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]>

@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: e004d0d343

ℹ️ 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 on lines +2142 to +2143
if w <= curtailMinPerDriverW {
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve tiny curtailed shares for later release

When a previously-curtailed driver is still present in next but its newly computed share is <= curtailMinPerDriverW, the release loop treats it as still active and skips adding it to suppressedTrack, then this continue drops it from out; the state update below can therefore remove it from LastCurtailedDrivers without ever sending a release. In a negative-price slot where an inverter's proportional share falls below 1 W after it already received a non-zero cap, the later slot-clear tick will not emit curtail_disable, leaving that inverter capped until an operator or another mechanism clears it.

Useful? React with 👍 / 👎.

@frahlg
frahlg merged commit 312e9ba into master May 27, 2026
2 checks passed
@frahlg
frahlg deleted the worktree-fix+curtail-no-spurious-release-and-nak-metric 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