Repository navigation
fix(planner): never plan zero house load while the forecast identity is pending - #2175
Merged
Merged
Conversation
…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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_wunset, 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.masterat a537f8c still has this.Change
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.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, thenplanner.base_load_wif 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.mpccould importloadmodelwithout a cycle, but change 1 already supplies that prior where the time zone and annual base are known, and a second copy inmpcwould hide an upstream fault instead of reporting it.main.goandforecast_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
TestForecastPendingIdentityCannotUseSavedModelsused 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.TestReplanSanitizesBadLoadInputexpected NaN and negative load to become 0 W. That was this bug. It now sets a base load and expects that value.service_persist_test.goplanned with no load source at all. They test decision ids and timelines, not load, so they now set a base load of 500 W, asshadowTestServicealready does.Evidence
TestPendingIdentityNeverPlansZeroHouseLoad(new,go/internal/mpc) replays the field inputs: no base load, an invalid household reading and the pending snapshot. Onorigin/masterit 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 onorigin/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 verifyfrom the repository root: pass ("verify: vet + test + build clean").🤖 Generated with Claude Code