Skip to content

fix(mpc): publish the worker's plan when only the car's room breaks - #2037

Merged
frahlg merged 2 commits into
masterfrom
fix/fleet-car-room-keeps-worker-plan
Nov 17, 2026
Merged

frahlg merged 2 commits into
masterfrom
fix/fleet-car-room-keeps-worker-plan

Conversation

@frahlg

@frahlg frahlg commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Follows #2023. Core now 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. With one battery and one car, Core then plans the site with its own
DP. Core DP cannot model two batteries or two cars (coreDPModelError), so
such a site got no new plan: Core kept the previous one until a plan passed.

The bundled Energyplan worker hits this. It sends every request with a car
that can charge to its fleet model, which still makes that room.
srcfl/energyplan#83 changed only the battery library, which plans requests
in which no car can charge. On a two-battery site with the field night's
house and fuse, Core rejected the bundled worker's plan and published none.

Change

  • The car's room joins a clock hour's import as a rule live control holds by
    itself. importHourOverrun becomes planOverrun, with hours and
    carRoom. validatePlan records the first slot that breaks the car's room
    and checks every other rule before it returns the overrun.
  • When Core cannot plan the site itself (the condition the hours already
    use), it publishes the worker's plan with a warning: "Core cannot plan this
    site itself, so the plan lets the battery make room for the car; the
    charger still leaves that room out: …". The charger's live room leaves
    battery discharge out for the fuse and the import limit alike
    (control.evBatteryDischargeW, from fix(control,mpc): a battery that may not cover the car makes it no room #2023), so battery energy does not
    reach the car.
  • The EV pulse check splits the two rules. A battery that discharges past the
    house stays a hard error. A pulse that fits only beside the discharge
    returns errPulseCarRoom, which validatePlan counts as the car's room.
  • A site Core can plan keeps Core DP's plan, as since fix(control,mpc): a battery that may not cover the car makes it no room #2023.
  • When a downside worker planned a caution forecast that differed, the
    published overrun is the point plan, since planWithForecastMargin returns
    only a point solve's error. Core then sets CautionOff and says so. This
    also covers an hour's overrun, which had the same gap. Found by the Codex
    review (8fbceb6).

Not in this PR

  • The worker's fleet model still makes the room. That fix belongs in
    Energyplan, and its search needs work first.
  • The bundle stays as it is. A worker built from Energyplan's main would
    change nothing here, since fix(config): respect -drivers flag when resolving Lua paths #83 does not reach the fleet model.
  • docs/energyplan-contract.md states what the worker must do, not how Core
    handles a breach, so it does not change.

Tests

  • TestValidatePlanNamesTheCarRoomOverrun: a steady car and a pulsing car
    that break only the room give a planOverrun; a battery that discharges
    past the house gives a plain error. Before the fix both room cases gave
    plain errors.
  • TestCarRoomWorkerPlanWhenCoreCannotPlan: with one battery Core's plan
    stands, without the warning; with two batteries the worker's plan goes out
    with it. Before the fix the two-battery site published no plan.
  • TestCarRoomPointPlanIsWithoutCaution: a downside worker whose caution
    and point plans both break only the room; the published plan reads as
    without caution. Failed before 8fbceb6 (caution off = false).
  • TestNativeFleetCarRoomWhenCoreCannotPlan runs with the bundled worker:
    two batteries, a 3,800 W house, a 9,250 W fuse. On master Core rejected the
    plan and published none. With the fix the worker's fleet_milp_rust plan
    goes out with the warning. Run on Linux arm64.
  • make native-solver-test passed on Linux arm64 (Mac mini, Asahi Linux) at
    ce13516 and 8fbceb6. make verify passed locally on macOS at both.

Overlap

#1956 also changes service.go, at other lines.

Checklist

  • The change follows VISION.md and one selected scope.
  • I checked overlapping PRs and coordinated shared files/contracts.
  • Relevant checks cover the changed behaviour and failure paths.
  • A human reviewed changed UI in a browser, or no UI changed.
  • A Changeset is included, or the change is exempt.
  • Every commit has a DCO sign-off.

🤖 Generated with Claude Code

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]>
@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-17T07:13:02.378510Z ce13516 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: ce13516982

ℹ️ 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 on lines +2155 to +2157
if overrun.carRoom != nil {
heldCarRoom = true
warnings = append(warnings, "Core cannot plan this site itself, so the plan lets the battery make room for the car; the charger still leaves that room out: "+overrun.carRoom.Error())

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 Mark caution off when accepting a point-forecast overrun

For a multi-battery site using the bundled Energyplan worker with forecast caution enabled, this branch can publish a point-forecast plan while leaving CautionOff false. When the cautious solve fails and the point solve returns a car-room overrun, planWithForecastMargin returns that point error with withoutCaution false (pointErr == nil is false). Previously this car-room error prevented publication; accepting it here now publishes the point plan without the caution-off status, so web/plan-brief.js suppresses its “Plan without extra forecast margin” indicator. Preserve whether the accepted overrun used the point forecast and update the caution status and warning accordingly.

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, thanks. Fixed in 8fbceb6. When Core publishes an overrun's plan and a downside worker planned a caution forecast that differed, the plan came from the point solve, since planWithForecastMargin returns only a point solve's error. Core now sets CautionOff and adds "Forecast caution gave no plan Core could publish; using the point forecast." TestCarRoomPointPlanIsWithoutCaution failed before (caution off = false) and passes now.

This also covers an hour's overrun, which had the same gap before this PR.

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]>
@frahlg
frahlg merged commit acdc584 into master Nov 17, 2026
22 checks passed
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