Skip to content

fix(planner): never plan zero house load while the forecast identity is pending - #2175

Merged
frahlg merged 1 commit into
masterfrom
zero-load-pending-identity
Dec 4, 2026
Merged

frahlg merged 1 commit into
masterfrom
zero-load-pending-identity

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

A box restarted while its solar inverter did not answer. The driver gives up on the inverter's serial register until the next restart, so the forecast identity stayed pending: the saved binding holds a serial id and the driver now reports only an endpoint id.

While the identity is pending, the forecast snapshot gave the planner no load predictor. With planner.base_load_w unset, every slot got 0 W of house load. The live overlay was skipped because the household reading carries the same identity reason, and load recovery let 0 W through because it only rejected NaN and negative values. The planner then solved an empty house with no solar, published an idle battery at zero cost, and held a 65 % battery idle for 12 hours while the house drew 1.4–4.8 kW. It ended at the next restart with the inverter awake. master at a537f8c still has this.

Change

  1. Pending identity still gets a household prior. While the identity is pending, the snapshot now hands the planner the load model's prior with nothing learned: the generic weekly shape in the site's time zone, scaled by the configured annual base (loadmodel.Service.PriorModel). It reads no learned bucket, heating fit or temperature. Saved models stay unused and untouched, and nothing is archived, as before. Solar stays out while pending (0 W): the inverter whose identity is unconfirmed is the solar source, so its rated scale may not match the hardware. Planning without solar errs toward keeping charge, not toward idling.
  2. The planner never plans zero house load silently. In mpc, a slot load of 0 W now counts as missing data, like NaN or a negative value. Recovery uses the older forecast if it is positive, then planner.base_load_w if it is positive. If neither gives a load, the plan stops before that slot. When the first slot has none, the replan fails with "No house load estimate from planning slot 0; an empty house cannot be planned" instead of publishing. The configured-prior retry after an infeasible forecast is skipped when that prior is 0, so it can no longer try an empty house either.
    I did not add a generic household prior inside mpc. mpc could import loadmodel without a cycle, but change 1 already supplies that prior where the time zone and annual base are known, and a second copy in mpc would hide an upstream fault instead of reporting it.
  3. Live house load in the in-flight slot while pending: not done. The household reading is marked invalid by the identity rule, which also covers the unconfirmed solar reading that the house balance subtracts. Using it would mean separating the identity reasons from meter quality in main.go and forecast_site.go. That widens the change and touches the identity rule, so I left it for a separate change if wanted.

No config defaults, registry names or settings change.

Tests changed on purpose

  • TestForecastPendingIdentityCannotUseSavedModels used to assert there was no load predictor while pending. It now restores a warm saved model that predicts over 100 kW and checks that the pending predictor is positive, equals an untrained model with the same annual base and time zone, differs from the unscaled generic prior, and leaves the learned model unchanged.
  • TestReplanSanitizesBadLoadInput expected NaN and negative load to become 0 W. That was this bug. It now sets a base load and expects that value.
  • Three persistence tests in service_persist_test.go planned with no load source at all. They test decision ids and timelines, not load, so they now set a base load of 500 W, as shadowTestService already does.

Evidence

  • TestPendingIdentityNeverPlansZeroHouseLoad (new, go/internal/mpc) replays the field inputs: no base load, an invalid household reading and the pending snapshot. On origin/master it fails with 0 W planned in every slot. With this change the replan refuses and names the missing house load.
  • TestForecastPendingIdentityCannotUseSavedModels (go/cmd/ftw) fails on origin/master (no load predictor while pending) and passes with this change.
  • TestZeroForecastLoadIsMissingData (new) covers the fallback order, the stop at a slot with no load, and the zero prior.
  • go test ./internal/mpc/... ./internal/loadmodel/... ./cmd/ftw/...: pass.
  • make verify from the repository root: pass ("verify: vet + test + build clean").

🤖 Generated with Claude Code

…is pending

After a restart with an unconfirmed device identity, the forecast snapshot
gave the planner no load predictor. With planner.base_load_w unset every
slot planned 0 W of house load, and the planner published an idle battery
while the house imported.

While pending, the snapshot now gives the load model's unlearned prior at
the configured annual level in the site time zone. Saved models stay unused
and untouched. In mpc a 0 W load is missing data: recovery takes a positive
legacy load, then a positive base load, and otherwise the plan stops before
that slot, or the replan fails when the first slot has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T17:44:22.952205Z f745e47 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit 9754e12 into master Dec 4, 2026
22 of 23 checks passed
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