Skip to content

fix(control,mpc): a battery that may not cover the car makes it no room - #2023

Merged
frahlg merged 3 commits into
masterfrom
fix/battery-relief-not-car-room
Nov 17, 2026
Merged

frahlg merged 3 commits into
masterfrom
fix/battery-relief-not-car-room

Conversation

@frahlg

@frahlg frahlg commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

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 never
exceeded 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: evHeadroomW read the room the
discharge 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. A
car 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".
  • Core DP uses it with the slot's limit and the hour's caps
    (carImportLimitW).
  • ValidatePlan rejects a worker plan whose cars only fit because the battery
    covers the house (slot MaxImportW). validateEVPulse checks the pulse peak
    the same way.
  • The reserve plan no longer lets the battery cover the house to make room for
    a car it may not cover, under the fuse or the hour's import limit. A covered
    car keeps that room (TestReservePlanLetsACoveredCarUseTheBatteryRoom).
  • The charger's fuse limit (EVFuseBudget) no longer counts discharge Core
    ordered as room, unless the battery may cover the car
    (evBatteryDischargeW). Discharge Core did not order, such as one a battery
    holds across a restart, stays room as before; the restart simulations
    (TestSiteSimRestart*) depend on that.
  • An active boost lease counts from the start (BatteryBoostActive, set from
    loadpoint.HasActiveBatteryBoost). The boost's live watts stay zero until
    the 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.go is untouched; its ceiling share only sizes battery charge and
the published FuseEVMaxW, so this does not overlap #2012.

Behaviour change

nearTargetReserveFixture had a 500 W house and an 11 kW car on an 11,040 W
limit; 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.
TestEVReserveUsesMinimumStepWhenHouseBlocksMaximum keeps 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.md gains the rule and is byte-identical with
Energyplan's copy in srcfl/energyplan#83.

Not covered: ValidatePlan checks the slot's import limit, not the hour's
import caps. The DP and the reserve plan apply both.

Tests

  • TestPlannedDischargeIsRoomOnlyForACarTheBatteryMayCover (control): the
    field 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_ev the car still takes 10,350 W.
  • TestABoostedCarStartsOnTheBatterysRoom (control): a 13 kW house, 3,560 W
    of 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 that
    check the strict rule failed on master.
  • TestBatteryDischargeFeedsEVUnderImport (loadpoint).
  • make verify passed locally on 30d1cb5 and on 1b8f9fd (vet, tests,
    build).

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 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-11-15T18:32:43.180789Z 30d1cb5 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.

@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: 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".

Comment thread go/internal/control/ev_fuse_budget.go Outdated
Comment on lines +1075 to +1078
if s.batteryMayCoverEV() {
return s.evFuseReliefW(store)
}
byDriver := s.evFuseReliefByDriver(store)

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 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

frahlg and others added 2 commits November 15, 2026 19:38
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]>
@frahlg
frahlg merged commit 68292a2 into master Nov 17, 2026
23 checks passed
frahlg added a commit that referenced this pull request Nov 17, 2026
…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]>
frahlg added a commit that referenced this pull request Nov 17, 2026
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]>
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