Repository navigation
Conversation
The battery model learns trusted limits per battery (#2068). On the owner's home box the inverter holds grid import near 4.32 kW while the battery charges, so a night hour gives the battery 4.32 kW less the house, and its DC current stops discharge near 22.4 A. The planner still expected 5 kW both ways, so night slots ended under-delivered and the plan replanned every quarter. Core now reads each battery's trusted plateaus for the temperature band it is in now (Plateaus.KnownAt) into learned limits: a DC current limit in W at the pack's voltage now, a power limit, and the grid import the inverter holds while charging. Each slot's charge limit is then that import plus the slot's PV less its house load, from the forecasts the plan uses, never above the configured limit; discharge takes the battery's own limit only. A worker that announces storage_slot_limits gets them as max_charge_w_by_slot and max_discharge_w_by_slot, and Core rejects a reply past them. Core's own planner holds each slot's actions to them too. A battery with nothing learned sends the same request as before. The site simulator's battery can hold grid import like the inverter. In a closed-loop night run every cheap quarter fell short of its plan without the learned hold and none with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Energyplan 0.9.0 (7bf34945) plans each storage within the per-slot power limits Core sends and announces storage_slot_limits. A request without them plans as 0.8.0 does. Protocol v1, site signs and the time budget are unchanged. Only the two Linux workers and manifest.json change; the bundle comes from the package stage of Energyplan's local CI on that commit. The health checks expect 0.9.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
The planner now reads the battery model's learned limits, so a change in go/internal/battery changes plans the rig runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e49eee333
ℹ️ 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".
| case battery.LimitBatteryPower: | ||
| w = k.Value |
There was a problem hiding this comment.
Distinguish battery limits from site-constrained power plateaus
When grid-limited charging coincides with steady household load, the learner can produce a trusted battery_power plateau that is not the battery's maximum power. For example, a 4.32 kW import hold and steady 1.5 kW load yield a flat 2.82 kW battery reading against a 5 kW order: Plateaus.Tick records that power because it exceeds the 50% share threshold, and repeated runs make it trusted. Converting it unconditionally into ChargeW now restricts every planning slot—including sunny slots where this battery can charge at 5 kW—to 2.82 kW. The existing learner identifies repeated shortfall levels, not their causal independence from site conditions; distinguish those cases before promoting them to unconditional planning limits.
Useful? React with 👍 / 👎.
The grid import hold belongs to the site, so two batteries that both learned it each got the whole room, and the fleet could plan twice what the inverter lets through. The batteries that learned a hold now share its room in proportion to their configured charge limits; the room is the least hold any of them learned plus the slot's PV less its house load. A battery without a hold keeps its own limits. Tests pin two cases the limits leave out. A car charging in the same slot takes import the battery then cannot get: the plan is optimistic for the battery only, and ValidatePlan still holds it to the site's import limit and the hourly ceiling. When the worker fails with numerical_failure or deadline_exceeded on a request with slot limits, Core's fallback plans within the same limits. The contract says a worker without storage_slot_limits gets no limits and is checked against the scalars only, that Core omits a field it does not send, and that [] and null are invalid. storage_limits.go notes that a current limit read at rest is a little optimistic under discharge sag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
The bundle now carries the review fixes: limit ratios that differ only by rounding stay on the battery library, and `[]` and `null` per-slot arrays are invalid. It comes from the package stage of Energyplan's local CI on 438aa26b. Only the two Linux workers and manifest.json change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Paired with srcfl/energyplan#87 (Energyplan 0.9.0, which takes the limits). Refs #2068.
Do not merge yet. The bundle should be pinned only after Energyplan's Linux and timed gates pass on the bundled commit; see "Not verified".
Why
#2068 taught Core each battery's real limits. On the owner's home box the inverter holds grid import near 4.32 kW while the battery charges from the grid, so a night hour gives the battery 4.32 kW less the house (about 2 to 3.8 kW). Its DC current stops discharge near 22.4 A (4.05 to 4.4 kW). With PV it charges at the full 5 kW. The planner still assumed 5 kW both ways, so night slots ended under-delivered (143 warnings in two weeks) and the plan changed every quarter.
What changed
onlineFleetParamsasksService.LearnedBatteryLimits(wired inmain.goto the battery models,Plateaus.KnownAt) for each battery's trusted plateaus in the 10 °C band its temperature is in now, or the no-temperature band. Abattery_currentlimit becomes W at the pack's voltage now. With no voltage it is left out. Under discharge the voltage sags, so that W is a little optimistic; the code says so. Abattery_powerlimit is its W, and the lower of the two wins. Agrid_importlimit while charging is the inverter's hold.grid_exportis not used, and a limit under 300 W (the least the learner samples) is left out.max_charge_w_by_slot/max_discharge_w_by_slotonly to a worker that announcesstorage_slot_limits, and only for a storage where some slot falls below its limit. Without learned limits the request is the same, byte for byte (tested). Core keeps the scalar check inexternal_optimizer.goand also rejects a reply more than 2 W past a slot limit it sent. A worker without the feature gets no limits and is checked against the scalars only. Core's own planner still holds the limits.[]andnullare invalid. It is byte-identical to Energyplan's copy.manifest.jsonchange.THIRD-PARTY-NOTICES.txtneeds no change: the package stage wrote the same bytes, since no dependency and no vendored microlp code changed (0.8.0's one-line change was the microlp note). Health checks expect 0.9.0.sitesim.Battery.GridImportCapWholds grid import like the inverter. The rig's watched paths now includego/internal/battery.minor(owner approved: "fixa ovan och ta det som behövs").Tests and results
The
KnownAtand site-sim battery tests were written first and failed first; the planner tests came with the code.TestCoreDPPlansTheHomeBoxNightWithinItsLearnedLimits(hold 4.32 kW, night load 0.6 to 1.5 kW, discharge 4.2 kW): without the limits the plan charges 4.5 + 4.5 kW in 2 night hours, past what the battery takes; with them 2.5 + 3.62 + 2.98 kW over 3 hours and −4.2 kW at the peak, all inside.TestNativeEnergyplanPlansTheHomeBoxNightWithinItsLearnedLimits(darwin build of 0.9.0): 4.1 + 5.0 kW in 2 hours without; 3.12 + 3.62 + 2.36 kW over 3 hours and −4.2 kW with. Core accepts the worker's own plan.TestSiteSimNightChargeWithinTheLearnedImportHold(closed loop, Core's planner and control): without the hold, 8 of 8 cheap quarters fell short (plan 1249 Wh, got 780); with it, 0 of 8.TestBatteriesShareTheSitesGridHold: two batteries behind one hold get 5/8 and 3/8 of its room and never more than it together; a third without a hold keeps its own limit.TestACarBesideTheGridHoldKeepsCoresImportLimits: with a car, 3 night slots charge the car and the battery together, so the battery's limit is optimistic there.ValidatePlanstill holds the plan to the 11 kW import limit and a 9 kW hourly ceiling.TestWorkerFailureFallsBackWithinTheSameSlotLimits: when the worker answersnumerical_failureordeadline_exceededon a request with slot limits, Core's DP fallback plans within the same limits it sent, and reaches one.KnownAtbands and param validation.GOFLAGS=-p=4 make verify: pass. On this Mac it skips native execution, so I also ran-run 'Native|RustForecastHost'with a darwin build of the bundled commit: pass.verify.py: bundle integrity passed.Not verified
Overlap
Open #1956 changes the DP loop in
mpc.go; there is a small text conflict atactionAt. #2017 and #2041 merge cleanly.🤖 Generated with Claude Code