Skip to content

refactor(control): centralize dispatch post-processing + tighten host/store boundary validation - #353

Merged
frahlg merged 2 commits into
masterfrom
codex/refactor-safety-boundaries-20260527
May 27, 2026
Merged

frahlg merged 2 commits into
masterfrom
codex/refactor-safety-boundaries-20260527

Conversation

@frahlg

@frahlg frahlg commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

This follows up on the bug-hunt refactor items after the earlier hardening PRs landed.

  • Centralizes the control dispatch post-processing path so manual and charge paths share the same fuse guard, sign-floor, no-self-discharge, fuse-discharge, EV cap republish, and target bookkeeping logic.
  • Adds finite/sign validation at the Lua host and telemetry-store boundaries so invalid PV, EV, battery SoC, missing required w, and non-finite metrics/readings are rejected before they mutate live state.
  • Cleans up Lua Modbus write helpers that used pcall as if host write errors throw, and updates the Ferroamp Modbus smoke test for the now-surfaced default-mode failure behavior.

Validation

  • go vet ./...
  • go test ./internal/control ./internal/drivers ./internal/telemetry
  • go test -count=1 -timeout 180s ./...

@frahlg frahlg changed the title [codex] harden safety boundary refactors refactor(control): centralize dispatch post-processing + tighten host/store boundary validation May 27, 2026
@frahlg
frahlg marked this pull request as ready for review May 27, 2026 05:05
@frahlg
frahlg merged commit 2d50618 into master May 27, 2026
1 check passed
@frahlg
frahlg deleted the codex/refactor-safety-boundaries-20260527 branch May 27, 2026 05:08

@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: 892eaab485

ℹ️ 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 +235 to +237
case DerPV:
if rawW > 0 {
return fmt.Errorf("pv power must be <= 0 in site convention, got %.3f W", rawW)

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 Allow PV standby/import readings

When a PV inverter is consuming standby power, the site convention can produce a small positive PV reading (the existing control test TestInverterAffinity_IgnoresNonGeneratingPVTelemetry uses DerPV, 500 for this case, and several drivers derive PV from signed inverter AC power). Rejecting every positive PV sample here makes host.emit return an error and Store.Update drop the sample, leaving the last negative generation reading in place and preventing the driver health success from being recorded until the watchdog marks it offline. That corrupts PV/load accounting during night or standby periods instead of recording non-generating PV telemetry and simply excluding it from generation-only logic.

Useful? React with 👍 / 👎.

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