Skip to content

hardening: critical fixes + edge-case guards + tests + docs - #52

Merged
frahlg merged 2 commits into
masterfrom
hardening-batch
Apr 16, 2026
Merged

frahlg merged 2 commits into
masterfrom
hardening-batch

Conversation

@frahlg

@frahlg frahlg commented Apr 16, 2026

Copy link
Copy Markdown
Member

Systematic quality pass: 3 critical fixes, 4 medium hardening guards, 6 new tests, 5 doc updates. go test ./... green.

frahlg and others added 2 commits April 16, 2026 07:12
Add three tests for the fsnotify config watcher:
- TestWatcherFiresOnChange: verifies the applier callback fires with
  the updated config after modifying config.yaml on disk
- TestWatcherIgnoresInvalidYAML: verifies invalid YAML is rejected
  silently (applier not called, old config preserved)
- TestWatcherStopIsIdempotent: verifies Stop() can be called twice
  without panic

The idempotent-stop test exposed a real bug: Stop() did a bare
close(w.stop) which panics on double-close. Fixed by wrapping the
close+fsw.Close in sync.Once.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comprehensive quality pass across the codebase:

Critical fixes:
- currency.go: guard division-by-zero when FX rate is missing
- mpc/service.go: guard NaN/Inf in both forecastPVW and predictedPVW
- api.go: log.Warn on SaveConfig/SaveBatteryModel failures (was silent)
- dispatch.go: safer SoC default (0.1 not 0.5) when battery never reports
- dispatch.go: log.Warn when MPC plan goes stale

Hardening:
- mpc.go: defensive η check in forward-simulation loop
- telemetry/store.go: clamp negative rawLoad to 0 in UpdateLoad
- ocpp/server.go: 5s shutdown timeout prevents deadlock
- prices.go: ENTSOE stub returns explicit error instead of empty slice

New tests:
- telemetry: TestUpdateLoadClampsNegative
- mpc: TestOptimizeWithNaNPVW, TestOptimizeZeroCapacity,
       TestOptimizeZeroActionLevels, TestBuildSlotsEmptyForecast,
       TestSelectPlannerPVWBothNaN

Documentation:
- docs/api.md: document energy.today nested structure
- docs/driver-catalog.md: add solaredge_pv.lua (18th driver)
- docs/host-api.md: clarify covers both Lua + WASM
- control/CLAUDE.md: add PlanStale, PlanTargetFunc signature, holdoff
- docs/battery-models.md: document saturation curve seed guard

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@frahlg
frahlg merged commit 432f443 into master Apr 16, 2026
@frahlg
frahlg deleted the hardening-batch branch April 16, 2026 05:14

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

ℹ️ 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".

state.SetGridTarget(gridW)
state.PlanStale = false
} else {
slog.Warn("mpc plan stale — falling back to self_consumption")

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 Rate-limit stale-plan warning in dispatch loop

This warning is emitted on every control-cycle when planner mode has no current plan (PlanTarget is nil or returns ok=false), which is common during startup or extended price/forecast gaps; with the default 5s loop this produces continuous warn-level spam and can drown out actionable alerts while growing logs unnecessarily. Consider logging only on the PlanStale state transition (false→true) or adding throttling.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.0.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant