Skip to content

fix: harden optimizer and energy runtime recovery - #647

Merged
frahlg merged 2 commits into
masterfrom
agent/optimizer-energy-runtime-recovery
Jul 24, 2026
Merged

frahlg merged 2 commits into
masterfrom
agent/optimizer-energy-runtime-recovery

Conversation

@frahlg

@frahlg frahlg commented Jul 24, 2026

Copy link
Copy Markdown
Member

What changed

  • make the optimizer sidecar timeout and transport fallback reliable
  • stop stale site, EV, V2X, PV, and battery readings from entering legacy energy history or residual load
  • preserve scalar samples and independent energy-ledger observations when legacy history is unavailable
  • let Modbus drivers recover when TCP or DNS/mDNS becomes available after Core starts, while rejecting invalid endpoint configuration immediately

Root causes

Core coupled legacy history to the atomic sample/ledger write and could reuse cached readings after their source reading had aged out. Initial Modbus dialing also failed driver registration before the existing reconnect loop could run. The optimizer sidecar used separate timeout defaults and transport behavior that made process fallback less reliable.

Validation

  • make verify
  • make verify-all through the pre-push hook
  • go test -race ./cmd/ftw ./internal/state ./internal/modbus
  • focused history, ledger, Modbus retry, DNS/mDNS, backoff, recovery, and rollback regressions

Both user-visible changes include Changesets.

@frahlg
frahlg merged commit 2a036d7 into master Jul 24, 2026
13 checks passed

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

ℹ️ 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 go/cmd/ftw/main.go
Comment on lines +3635 to +3636
if h == nil || h.Status == telemetry.StatusOffline {
return false

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 Exclude faulted drivers from history usability

When a driver reports a device fault but still emits fresh readings, DriverHealth.Status remains ok while IsOnline() is false. The old EV/V2X history totals used SumOnlineEVW/SumOnlineV2XW, which skipped those faulted drivers; this new predicate only rejects StatusOffline, so a faulted charger or V2X device is counted in ev_w, v2x_w, and load_house_w until it stops emitting. Please use !h.IsOnline() here so faulted-but-fresh devices do not corrupt history totals.

Useful? React with 👍 / 👎.

@frahlg
frahlg deleted the agent/optimizer-energy-runtime-recovery branch August 7, 2026 08:14
frahlg added a commit that referenced this pull request Oct 17, 2026
* ci: stop new direct reads of cached telemetry outside the telemetry package

A reading stays in telemetry.Store after its driver goes stale, offline
or faulted. Every direct reader of RawW, SmoothedW, ReadingsByType or
ReadingsByDriver must check driver health itself, and review caught the
missing check in #36, #85, #310, #647, #664 and #740.

The check counts those reads per file outside go/internal/telemetry and
fails when a pull request adds one. Existing reads (147 today) may only
go down. The error names the health-gated accessors to use instead.
On the merged commits of #36, #85, #310 and #647 it fails.

* ci: count telemetry reads across platforms and validate exceptions

Signed-off-by: Fredrik Ahlgren <[email protected]>

---------

Signed-off-by: Fredrik Ahlgren <[email protected]>
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