Repository navigation
fix(control,mpc): a battery that may not cover the car makes it no room - #2023
Conversation
Under a binding import limit, battery discharge that only covers the house still let the car charge a watt more for each watt discharged. A field site on a 20 A fuse lost about two thirds of a night's discharge into the car this way. The car now gets the room the grid gives beside the house with the battery idle: in the Core DP, the reserve plan, ValidatePlan, the EV pulse check and the charger's fuse limit. A battery boost or battery_covers_ev still lets the battery help the car. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: 30d1cb5488
ℹ️ 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".
| if s.batteryMayCoverEV() { | ||
| return s.evFuseReliefW(store) | ||
| } | ||
| byDriver := s.evFuseReliefByDriver(store) |
There was a problem hiding this comment.
Recognize an active battery boost before the car starts drawing
When a boosted car is idle and the house leaves less grid headroom than the car's minimum charging power, this check prevents the boost from starting it, even if the battery is already discharging enough to make room. batteryMayCoverEV() recognizes a boost only when BatteryBoostEVChargingW exceeds the active threshold, but ActiveBatteryBoostTotals in go/internal/loadpoint/battery_boost.go populates that value from actual CurrentPowerW, which is zero until charging starts. The new subtraction therefore removes the battery's room from stepEVIdleStart, keeping the car stopped and its boost draw permanently zero. Use active lease authorization, scoped to the relevant loadpoint, when deciding whether battery discharge may provide starting headroom rather than requiring an existing charging draw.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right: BatteryBoostEVChargingW is zero until the car draws, so this PR took the battery room from a boosted car that had not started. Fixed in 1b8f9fd: an active lease on a plugged-in, non-surplus-only loadpoint now counts from the start (BatteryBoostActive, from loadpoint.HasActiveBatteryBoost). TestABoostedCarStartsOnTheBatterysRoom failed on f08ba17 and passes now.
The lease still counts site-wide, as BatteryBoostEVChargingW did before; scoping the room to the boosted loadpoint alone is not in this PR.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The live boost watts that let the battery cover a car stay zero until the car draws, so the fuse limit removed Core's ordered discharge from the room of a boosted car that had not started. With the house near the line, that car never started. An active lease on a plugged-in loadpoint now counts from the start (BatteryBoostActive, HasActiveBatteryBoost). Found by the Codex review on #2023. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…2037) * fix(mpc): publish the worker's plan when only the car's room breaks Since #2023, Core rejects a worker plan in which the battery covers the house while a car it may not cover charges on the import room that frees. A single battery and car then get Core DP's plan. A site Core DP cannot model, such as two batteries or two cars, got no new plan: Core kept the previous one. The car's room now joins a clock hour's import as a rule live control holds by itself (planOverrun). When Core cannot plan the site, it publishes the worker's plan with a warning, as it already does for the hours; the charger's live room leaves battery discharge out (control.evBatteryDischargeW). The EV pulse check splits a battery that discharges past the house, which stays a hard rule, from the car's room. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]> * fix(mpc): mark a published point overrun as without caution A worker that plans the caution forecast first returns only its point plan's error once caution fails. When Core publishes that overrun's plan because it cannot plan the site itself, the plan leaves out a caution forecast that differed, yet CautionOff stayed false, so the plan view hid "Plan without extra forecast margin". Core now sets CautionOff and says why. This also covers an hour's overrun, which had the same gap. Found by the Codex review on #2037. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]> --------- Signed-off-by: Fredrik Ahlgren <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
The worker keeps a battery that may not cover the car out of the car's import room (srcfl/energyplan#83 for the library, #84 for the fleet model that plans every request where a car can charge), the rule Core enforces since #2023. The binaries are byte-identical to the ones Energyplan's local CI tested on 55118a38, which has the same tree as 7ea7d998. A native test plans the field night with the bundled worker and needs Core to accept the plan. With the bundle it replaces (847936a) Core rejects the plan in slot 0. Signed-off-by: Fredrik Ahlgren <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
A field site on v0.163.0-beta.1 (15 Nov 2026) had a 20 A fuse and 10 A of
house load on L1. From midnight to 11:00 L1 sat at 20 A while the car charged
63.5 kWh. Between 00:00 and 02:15 the plan discharged the battery 3.6 kWh to
cover the house. The grid room that freed went to the car: with the battery
discharging more than 1 kW the car drew 7.5 kW and the grid 7.4 kW; with the
battery idle the car drew 5.1 kW and the grid 8.8 kW (10 s data, slope −0.62,
r −0.82). About two thirds of the battery's energy charged the car, although
the battery may not cover the car on that site. The battery then sat at its
10 % floor until 11:15.
Every slot met the old rule,
BatteryDischargeFeedsEV: the discharge neverexceeded the house load. Under a binding import limit that rule does not hold
the line it is meant to hold, because any discharge lets the car charge a watt
more. The live charger limit had the same gap:
evHeadroomWread the room thedischarge made on the meter, and only the fuse guard's own relief was excluded.
Rule
Owner's decision (Fredrik, 15 Nov 2026): without a battery boost or the old
site-wide
battery_covers_ev, the battery never raises the car's charging. Acar the battery may not cover gets the room the grid gives beside the house
with the battery idle. This matches the app, where a boost is the one way to
let the home battery help the car.
Change
loadpoint.BatteryDischargeFeedsEVUnderImport: the conservation rule, plus"house and car exceed the import limit with the battery idle".
(
carImportLimitW).ValidatePlanrejects a worker plan whose cars only fit because the batterycovers the house (slot
MaxImportW).validateEVPulsechecks the pulse peakthe same way.
a car it may not cover, under the fuse or the hour's import limit. A covered
car keeps that room (
TestReservePlanLetsACoveredCarUseTheBatteryRoom).EVFuseBudget) no longer counts discharge Coreordered as room, unless the battery may cover the car
(
evBatteryDischargeW). Discharge Core did not order, such as one a batteryholds across a restart, stays room as before; the restart simulations
(
TestSiteSimRestart*) depend on that.BatteryBoostActive, set fromloadpoint.HasActiveBatteryBoost). The boost's live watts stay zero untilthe car draws, so without this a boosted car next to a house near the line
never started. Found by the Codex review; fixed in 1b8f9fd.
dispatch.gois untouched; its ceiling share only sizes battery charge andthe published
FuseEVMaxW, so this does not overlap #2012.Behaviour change
nearTargetReserveFixturehad a 500 W house and an 11 kW car on an 11,040 Wlimit; the old reserve plan discharged the battery 460 W so the car fit. Under
the new rule that car no longer fits, so the fixture now has an 11,600 W limit.
TestEVReserveUsesMinimumStepWhenHouseBlocksMaximumkeeps the 11,040 W limit,which is what it tests.
Paired change
srcfl/energyplan#83 (private) brings the rule to the worker's library path,
which plans a site with one storage and one car, the field case. The worker's
fleet model (several storages or cars) keeps the old rule for now. Until a
worker with the rule ships, and for fleet sites after that, Core rejects plans
that break it and the Core DP takes over (
primary optimizer failed; using Core DP fallback). This PR is safe on its own; merge it first.docs/energyplan-contract.mdgains the rule and is byte-identical withEnergyplan's copy in srcfl/energyplan#83.
Not covered:
ValidatePlanchecks the slot's import limit, not the hour'simport caps. The DP and the reserve plan apply both.
Tests
TestPlannedDischargeIsRoomOnlyForACarTheBatteryMayCover(control): thefield night on the site harness. Before: the car took 10,350 W beside a
4,000 W discharge, past the grid's 6,560 W of room. After: 6,210 W. With
battery_covers_evthe car still takes 10,350 W.TestABoostedCarStartsOnTheBatterysRoom(control): a 13 kW house, 3,560 Wof grid room, a car whose lowest step is 4,140 W and a 4 kW discharge. With
a boost lease the car starts (6,900 W, grid 15,900 W of 16,560 W); without
one it waits. The boosted case failed on f08ba17.
TestHasActiveBatteryBoostBeforeTheCarDraws(loadpoint).TestBatteryThatMayNotCoverTheCarLeavesItTheGridsRoomAlone,TestBatteryThatMayCoverTheCarStillHelpsItUnderTheLimit,TestValidatePlanRejectsBatteryMakingRoomForTheCar,TestReservePlanKeepsTheBatteryOutOfTheCarsRoom,TestReservePlanLetsACoveredCarUseTheBatteryRoom(mpc). The three thatcheck the strict rule failed on master.
TestBatteryDischargeFeedsEVUnderImport(loadpoint).make verifypassed locally on 30d1cb5 and on 1b8f9fd (vet, tests,build).
🤖 Generated with Claude Code