Skip to content

fix(mpc): plan an out-of-band battery from the band edge for every planner - #2045

Merged
frahlg merged 1 commit into
masterfrom
2043-plan-from-band-edge
Nov 17, 2026
Merged

frahlg merged 1 commit into
masterfrom
2043-plan-from-band-edge

Conversation

@frahlg

@frahlg frahlg commented Nov 17, 2026

Copy link
Copy Markdown
Member

Problem

A support file from v0.164.0-beta.1 (#2043) shows a 20 kWh battery that Energyplan kept idle for a whole 115-slot horizon, 28 h. Night power cost about 104–133 öre/kWh and the next day 243–282 öre/kWh, so charging at night clearly paid. The battery had settled at SoC 0.097, under its 0.10 floor, and a car was in the plan.

Core clamps such a start onto the band edge, but only when Core DP is the planner (s.Optimizer == nil). Energyplan got the real start, and its fleet MILP never beat the idle seed.

A local replay of the exact request the box sent ran the shipped Linux worker in a container:

Start Night charge Day discharge
1940 Wh against a 2000 Wh floor (sent) 0 kWh 0 kWh
1999.9 Wh 0 kWh 0 kWh
2000 Wh (on the floor) 17.8 kWh 16.6 kWh
sent, without the car 15.7 kWh 16.6 kWh

The results are the same on 847936a (in the beta) and on 7ea7d998 (on master). A longer budget (60 s) does not help. The same thing happened on the site on the night of 11–12 Nov. The replay data stays local.

There is a second gap. When the worker failed in that state, Core kept the previous plan, because its DP "cannot model operating-bound recovery". A battery that dips under its floor should never stop planning.

Change

  • Replan clamps an out-of-band start onto the band edge for every planner, through the existing clampParamsIntoOperatingBand. It records the real reading in InitialSoCUnclamped.
  • The branches that only existed for an out-of-band worker request are removed. Shadows, baselines and the Core fallback now run as they do for any start.
  • The plan may believe it has up to (floor − real) × capacity more energy than the pack holds; about 60 Wh here. The dispatch clamp and the driver's floor stop any order for that energy, as they already do for Core DP. clampParamsIntoOperatingBand explains why clamping beats refusing.
  • What this does not change:
    • A site Core DP cannot model, such as two storages, still keeps its previous plan when the worker fails. That is a separate limit, unchanged here.
    • Energyplan still mishandles an out-of-band request with a car. A worker fix and release (0.7.1) follow in a paired Energyplan PR and a bundle PR.

Tests

  • New TestReplanGivesTheWorkerAnInBandStart covers three starts: 0.097, 0.01, and a fleet member at 0.05.
  • New TestReplanFallsBackToCoreWhenTheWorkerFailsBelowTheFloor covers 0.097 and 0.01, with a failing worker.
  • Both fail with the old gate restored (&& s.Optimizer == nil). An independent reviewer checked this too.
  • The rewritten tests encoded the old rule:
    • TestNativeEnergyplanPlansFromTheBandEdge (was …RecoveryKeepsRealBatteryEnergy)
    • TestNativeEnergyplanEVRecoveryFallbackFaults
    • TestImportCeilingWorkerPlanOverrunsAnHour: a battery below its floor now gets Core's plan inside the import hour, not the worker's overrun with a warning
    • TestNativeImportCeilingBelowTheFloor
  • Local runs:
    • make verify passed.
    • go test ./internal/mpc/ passed.
    • go test -race ./internal/mpc/ -run 'Replan|Recovery|Band|ImportCeiling' passed, per the reviewer.
    • Every Native* test passed against the bundled arm64 worker, run in a local Linux container (FTW_NATIVE_SOLVER wrapper).
  • Gap: no test in this repo plans the field case end to end with the worker. The replay above is local evidence. The paired Energyplan PR adds a worker regression test.

Refs #2043.

🤖 Generated with Claude Code

…anner

Core clamped a start below soc_min (or above soc_max) onto the band
edge only when Core DP was the planner. Energyplan got the real start.
On a v0.164.0-beta.1 site a Pixii settled at 0.097 under a 0.10 floor,
with a car in the plan; Energyplan's fleet MILP published an idle battery
for 28 h although cheap night power made charging pay. A replay of that
request with the start on the floor charges 17.8 kWh at night, on both
bundled workers (847936a and 7ea7d998). And when the worker failed in
that state, Core kept the previous plan, since its DP could not model
the out-of-band start.

Replan now clamps for every planner and records the real reading in
InitialSoCUnclamped, as it did for Core DP. The recovery-only branches
go: shadows, baselines and the Core fallback run as for any start. A
site Core DP cannot model, such as two storages, still keeps its
previous plan when the worker fails.

Refs #2043.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T20:00:52.252754Z 010aea5 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 8b3bd59 into master Nov 17, 2026
23 checks passed
@frahlg
frahlg deleted the 2043-plan-from-band-edge branch November 17, 2026 22:23
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