Skip to content

feat(ferroamp): self-healing watchdog for stuck-pplim trap (layer 3) - #373

Merged
frahlg merged 1 commit into
masterfrom
worktree-feat+ferroamp-stuck-pplim-watchdog
May 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
worktree-feat+ferroamp-stuck-pplim-watchdog

Conversation

@frahlg

@frahlg frahlg commented May 27, 2026

Copy link
Copy Markdown
Member

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.

Layer PR Status
1. Driver hard-fail on pplim arg=0 #367 ✅ Merged
2. Dispatcher: no spurious release on |PV|=0 + NAK observability #372 🟡 Open
3. Self-healing watchdog (this PR) #373 (this) —

Together: 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=1 while the inverter was bricked at pplim=0.

State machine

not stuck → stuck (timer starts) → stuck for ≥ 10 min → recover (cooldown starts) → cooldown (5 min) → recover again if still stuck
                ↓ signature breaks at any point → not stuck (timer resets)
  • 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_w field — same value, dual purpose:

  • Dispatcher's curtail_disable action publishes pplim arg=<release_w> when the slot ends.
  • Watchdog publishes the same payload on stuck-signature detection.

Without pplim_release_w (default 0), 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 again
  • TestFerroampStuckPVWatchdogNoPublishWithoutPplimReleaseW — log-only path, no MQTT publish
  • TestFerroampStuckPVWatchdogResetsWhenSignatureClears — ipv > 0 cancels the stuck timer

Uses env.Start.Add(-N * time.Minute) to advance host.millis() without burning wall-clock — same pattern as TestFerroampDriverStopsEmittingWhenMQTTStalls.

Out of scope

  • Multi-SSO sites (per-SSO state tracking) — single-SSO cache is the current limitation; multi-SSO needs a separate refactor.
  • Auto-recovery from non-sticky brick states (e.g. faultcode != 0). Those need operator attention regardless.

🤖 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: 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".

Comment thread drivers/ferroamp.lua
Comment on lines +752 to +755
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

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 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]>
@frahlg
frahlg force-pushed the worktree-feat+ferroamp-stuck-pplim-watchdog branch from e1086f2 to 61bfaef Compare May 27, 2026 17:06
@frahlg
frahlg merged commit 9638c78 into master May 27, 2026
2 checks passed
@frahlg
frahlg deleted the worktree-feat+ferroamp-stuck-pplim-watchdog 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