Repository navigation
feat(ferroamp): self-healing watchdog for stuck-pplim trap (layer 3) - #373
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1086f2af4
ℹ️ 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 stuck then | ||
| if stuck_pv_since_ms < 0 then | ||
| stuck_pv_since_ms = now | ||
| elseif (now - stuck_pv_since_ms) > STUCK_PV_AFTER_MS then |
There was a problem hiding this comment.
Reset stuck timer when SSO data goes stale
Because stuck_pv_since_ms is only cleared when a fresh SSO payload evaluates stuck == false, an SSO/MQTT outage keeps the previous stuck start time alive even after the existing stale-cache logic drops sso_data at 30s. If one stuck-looking SSO message arrives after a 10+ minute telemetry gap, this branch treats the condition as continuous and publishes the release immediately, contrary to the documented “continuously for ten minutes” guard. Clear the timer when sso_data is stale/missing, or require fresh consecutive samples before using the elapsed time.
Useful? React with 👍 / 👎.
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]>
e1086f2 to
61bfaef
Compare
Summary
Third and final layer of defense against the 2026-05-27 Ferroamp brick. When the SSO reports the post-incident signature continuously for ten minutes, the driver auto-publishes
pplim arg=<pplim_release_w>to release the lock.pplim arg=0Together: the brick scenario is both un-triggerable (1, 2) AND self-recoverable (3).
Detection signature
All four must be true continuously for ≥ 10 minutes:
sso_pv_v > 200 V(DC bus voltage = panels active = daylight)sso_pv_a == 0 A(no MPPT current)sso_faultcode == 0(no hardware fault)sso_relaystatus == 1(relay closed)That's exactly the live signature from the 2026-05-27 incident:
upv=489.176 V, ipv=0.0 A, faultcode=0, relaystatus=1while the inverter was bricked at pplim=0.State machine
stuck_pv_since_ms: latches on first stuck poll; cleared the moment the signature breaks (e.g.ipv > 0).STUCK_PV_AFTER_MS = 10 min: threshold before any recovery is eligible.STUCK_PV_RECOVERY_COOLDOWN_MS = 5 min: between successive recoveries — prevents command-spam if the release doesn't take.stuck_pv_recovery_count: cumulative counter emitted every poll. Ops dashboards alert on any non-zero rate.Operator opt-in
Reuses the existing
config.pplim_release_wfield — same value, dual purpose:curtail_disableaction publishespplim arg=<release_w>when the slot ends.Without
pplim_release_w(default0), the watchdog only logs a per-incident warning — no MQTT publish, because we don't have a safe release value to send.Tests (
lua_ferroamp_stuck_pv_test.go)TestFerroampStuckPVWatchdogAutoPublishesRelease— full cycle: detect → wait → recover → cooldown blocks → cooldown expires → recover againTestFerroampStuckPVWatchdogNoPublishWithoutPplimReleaseW— log-only path, no MQTT publishTestFerroampStuckPVWatchdogResetsWhenSignatureClears—ipv > 0cancels the stuck timerUses
env.Start.Add(-N * time.Minute)to advancehost.millis()without burning wall-clock — same pattern asTestFerroampDriverStopsEmittingWhenMQTTStalls.Out of scope
faultcode != 0). Those need operator attention regardless.🤖 Generated with Claude Code