Skip to content

fix(mpc): active arbitrage can grid-charge beside a surplus-only EV - #953

Merged
cursor[bot] merged 4 commits into
masterfrom
cursor/arbitrage-surplus-grid-charge-0ecb
Aug 18, 2026
Merged

cursor[bot] merged 4 commits into
masterfrom
cursor/arbitrage-surplus-grid-charge-0ecb

Conversation

@frahlg

@frahlg frahlg commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

Accepted text proposal

Issue or Discussion: Slack thread 2026-08-18 (xorath: active arbitrage has not bought from the grid for 1–2 months).

Maintainer comment that accepted this scope: evaluate with parallel agents, merge, then beta. Version Packages #946 already has LAN-auth / mDNS / GitHub-outage patches; after this lands it should pick up the arbitrage changeset too.

What changed

Planner and dispatch were refusing home-battery import while a surplus-only EV was plugged in.

  1. Planner. Surplus-only (including auto deferGridPlan) forbade (battery charge AND site import) for the whole horizon. Removed from Go DP, Python optimizer, and ValidatePlan. The car still cannot import; the battery still cannot feed the car.

  2. Dispatch (found in evaluation). Even after the planner said “import 5 kW”, the EV-reserve charge ceiling treated “no live PV surplus” as a 0 W cap and zeroed Pixii on the tick. That ceiling now applies only to PV-soak slots, not to deliberate grid-charge (PlannedGridW ≥ 100 W).

  3. Unpublished prices persist the last known spot and e-fold toward climatology over ~6 h, so midnight does not fake a 200→70 öre crash.

  4. Load-twin overnight prior 300 W → 650 W for cold start / repaired night buckets.

Why

xorath: v2, active arbitrage, EV takes most PV, Pixii ~35 % by evening, no grid buy for 1–2 months. Default optimizer path is HiGHS; Core ValidatePlan then rejected any grid-charge plan and fell back to Go DP which had the same ban. Dispatch would have zeroed it anyway at night. Three locks, same symptom.

Boundaries and safety

  • Surplus-only EV still cannot import.
  • Battery still cannot feed a surplus-only EV.
  • PV-soak charge slots still leave EV reserve headroom (TestEnergyDispatchAbsorbsSurplusBeyondEVReserveActualDraw).
  • Forecast persistence only on source="forecast" rows. Day-ahead untouched.
  • Load prior retune does not discard stored twins.

After merge: wait for Version Packages #946 to include this changeset, merge it, then dispatch both beta.yml (v2.1.0-beta.1) and optimizer-release.yml (1.4.0-beta.4) from that commit. Core-only is not enough for the CVXPY fallback path; the HiGHS default is unblocked by Core alone.

Verification

  • GitHub CI was green on the planner commits; this dispatch fix is on cefde553.
  • Local: go test ./internal/mpc ./internal/control ./internal/loadmodel pass, including TestEnergyDispatchHonoursPlannedGridChargeWithIdleSurplusOnlyEV (the evaluation probe that failed before the dispatch fix).
  • Optimizer: pytest optimizer/tests/test_model.py — 120 passed.

Checklist

  • The diff implements one accepted scope and does not add follow-on work.
  • I checked open pull requests that touch the same files.
  • Tests cover the changed behaviour and its failure path.
  • A human reviewed every changed web/UI view in a browser, or no UI changed.
  • A Changeset is included, or the change is exempt.
  • Every commit has a DCO sign-off.
Open in Web Open in Cursor 

cursoragent and others added 4 commits August 18, 2026 08:26
Surplus-only already keeps the car off the grid and blocks battery→EV.
The extra site-wide ban on home-battery import while the charger is
occupied made Pixii sit at evening SoC instead of buying the cheap
hours. Persist last-known spot into unpublished prices so the
climatology does not invent an overnight crash, and raise the load
twin's overnight prior from 300 W to 650 W.

Co-authored-by: Fredrik Ahlgren <[email protected]>
The warm-up loop added 300+7i days, which landed on a different
hour-of-week than the Monday 03:00 prediction. It only passed while
the prior was 300 W, close to the 350 W target.

Co-authored-by: Fredrik Ahlgren <[email protected]>
The lift of the home-battery import ban must not let the car import
when it has a deadline and no PV. Unpublished prices must also leave
the last-known spot over the horizon, not only in the first hour.

Co-authored-by: Fredrik Ahlgren <[email protected]>
…y EV

The EV-reserve charge ceiling is a PV-sharing cap. On a slot the
planner already committed to importing, applying it at night (no
surplus → ceiling 0 W) cancelled the Pixii charge while the car sat
plugged and idle. Skip the ceiling on deliberate grid-charge slots.

Co-authored-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg marked this pull request as ready for review August 18, 2026 08:42

@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: cefde55350

ℹ️ 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".

hour := hourOfWeek % 24
isWeekend := weekday >= 5 // Saturday (5), Sunday (6)
base := 300.0 // overnight baseload
base := 650.0 // overnight baseload — typical Swedish house today, not 2010

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 Preserve valid low-load buckets after raising the prior

When an existing site's learned overnight mean is between roughly 75 W and 162.5 W, loading the model now classifies it as poisoned because repairPoisonedBuckets compares against typicalPrior * 0.25. It then replaces the learned value with 650 W and resets its samples, even though the adjacent comment explicitly treats a 150 W household as valid. Raising the prior therefore destroys legitimate persisted learning on restart; keep the repair cutoff at its previous absolute range or otherwise decouple it from this cold-start prior.

Useful? React with 👍 / 👎.

@cursor
cursor Bot merged commit 1be6c0c into master Aug 18, 2026
14 checks passed
@frahlg
frahlg deleted the cursor/arbitrage-surplus-grid-charge-0ecb branch November 11, 2026 09:15
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.

2 participants