Skip to content

fix(planner): Codex review follow-ups from overhaul chain (P1+P2) - #103

Merged
frahlg merged 1 commit into
masterfrom
fix/planner-overhaul-codex-review
Apr 18, 2026
Merged

frahlg merged 1 commit into
masterfrom
fix/planner-overhaul-codex-review

Conversation

@frahlg

@frahlg frahlg commented Apr 18, 2026

Copy link
Copy Markdown
Member

Summary

Bundles the 8 issues Codex flagged across PRs #97-#101, ordered by how badly each blocks @erikarenhill's real-hardware testing on the v0.17.0 release.

P1 — critical

  1. Charger kept running after slot ended (from feat(ems): EV dispatch + Easee command wiring (Phase 4.1) #101). When the current MPC slot had no EV allocation, dispatch continued without sending anything — Easee kept drawing at its previous setpoint across a "stop" transition. Now we default cmdW=0 and always send the explicit command so the charger actively stands down.

  2. plugin_soc_pct never reached the runtime (from feat(ems): EV dispatch + Easee command wiring (Phase 4.1) #101). Added to loadpoint.Config in Phase 4.1 but never copied from YAML. Plumbed through config.Loadpoint and centralised YAML→runtime in a new buildLoadpointConfigs helper so boot + hot-reload share one path.

  3. TargetSlotIdx assumed 15-min slots (from feat(mpc): unified battery + EV MPC (Phase 4 — ONE system) #100). Nordic day-ahead prices come as 60-min slots, so a 2 h deadline mapped to slot 8 instead of slot 2 — DP saw 4× the time it actually had. LoadpointProbe now takes slotLenMin from the actual plan and the service passes in slots[0].LenMin.

  4. Race on lastLoadpointID (from feat(mpc): unified battery + EV MPC (Phase 4 — ONE system) #100). SlotDirectiveAt read s.last under RLock then s.lastLoadpointID outside — a concurrent replan could swap one without the other, routing a directive under the wrong driver. Snapshot both under the same lock.

  5. Infeasible DP states picked full-discharge fallback (from feat(mpc): PowerLimits per slot + Loadpoint observable skeleton #99). When mode + PowerLimits eliminated every action, bestPolicy defaulted to 0 which encodes (ba=0, ea=0) = full battery discharge, EV off — the worst fallback. Now overrides to the closest-to-idle action so forward-sim produces a sane plan even in operator-induced infeasibility.

  6. Persisted PV/load models misaligned after UTC switch (from fix(mpc): DST/timezone audit — coerce planner time indexing to UTC #97). pvmodel's β coefficients were fitted against local-zone harmonic features; loadmodel's buckets were indexed on local weekday+hour. After Phase 1's UTC coercion, restoring the old state silently misaligned both models. Bumped state keys (pvmodel/state → pvmodel/state_utc, loadmodel/state → loadmodel/state_utc) so old state is ignored on upgrade. Models retrain from telemetry over ~a day.

P2

  1. Config hot-reload didn't touch loadpoints (from feat(mpc): PowerLimits per slot + Loadpoint observable skeleton #99). configreload callback skipped newCfg.Loadpoints entirely. Now the manager reloads inside the callback — it preserves observed state across reloads, so live loadpoint edits no longer need a process restart.

  2. Session anchor lost on config reload (from feat(ems): EV dispatch + Easee command wiring (Phase 4.1) #101). loadpoint.Manager.Load preserved pluggedIn and delivered_wh_session but not sessionPluginSoCPct. A hot-reload mid-charge would reset the SoC inference baseline. Carry the anchor too.

Tests

  • New mpc.TestOptimizeInfeasibleStatePicksNearIdle — covers the DP fallback
  • All existing tests pass (incl. e2e, 27 s)
  • Build clean

What @erikarenhill should expect after this lands

  • Upgrade to whichever release includes this (will be v0.17.1+). First boot after upgrade: PV + load models start fresh — the twin quality badges go yellow for ~24 h while they retrain from telemetry. Not a regression; it's the correct behavior (old state was silently wrong).
  • Your plugin_soc_pct config value will now actually take effect.
  • Easee will cleanly pause at 0 W between charging slots instead of holding its last setpoint.
  • GET /api/mpc/diagnose now reliably reflects the loadpoint's driver even under concurrent replans.

🤖 Generated with Claude Code

Bundles 8 issues Codex flagged across PRs #97-#101. Ordered by what
blocks Erik's hardware testing most.

## P1 — charger kept running after slot ended (#101)

When the current MPC slot had no EV allocation, the dispatch loop
`continue`d without sending any command. Easee would keep drawing at
its previous setpoint — including across a "stop charging" slot
transition. Now we default cmdW=0 and always send the explicit
ev_set_current command so the charger actively stands down.

## P1 — plugin_soc_pct never reached the runtime (#101)

Added to loadpoint.Config in Phase 4.1 but never copied from YAML.
Config knob was a no-op. Plumbed through config.Loadpoint and
centralised the YAML→runtime mapping in a new buildLoadpointConfigs
helper so boot-time init and hot-reload can't drift.

## P1 — TargetSlotIdx assumed 15-min slots (#100)

Hard-coded `int(delta / (15 * time.Minute))` in main's LoadpointProbe,
but Nordic day-ahead prices come as 60-min slots. A 2-hour deadline
on hourly data mapped to slot 8, not slot 2 — DP thought it had 4×
the time it actually did. LoadpointProbe now takes slotLenMin from
the actual plan and mpc.Service passes it in from slots[0].LenMin.

## P1 — race on lastLoadpointID (#100)

SlotDirectiveAt read s.last under RLock then s.lastLoadpointID
outside. A concurrent replan could swap one without the other and
produce a directive keyed under the wrong driver. Snapshot both
under the same lock.

## P1 — infeasible DP states picked full-discharge fallback (#99)

When mode + PowerLimits eliminated every action at a (slot, soc, ev)
state, bestV stayed +Inf but bestPolicy defaulted to 0 — which
encodes (ba=0, ea=0) = "full battery discharge, EV off", the WORST
possible fallback. Now overrides bestPolicy to the closest-to-idle
action index ((A-1)/2 * EA), so forward-sim produces a sane plan
even in operator-induced infeasibility.

## P1 — persisted PV/load models misaligned after UTC switch (#97)

pvmodel's β coefficients were fitted against local-zone hour-of-day
harmonic features; loadmodel's buckets were indexed on local
weekday+hour. After the Phase 1 UTC coercion in Features /
HourOfWeek, restoring the old state silently misaligned both models
against the new coordinate system. Bumped state keys (`pvmodel/state`
→ `pvmodel/state_utc`, `loadmodel/state` → `loadmodel/state_utc`) so
old state is ignored on upgrade — model retrains from telemetry over
a day or so.

## P2 — config hot-reload didn't touch loadpoints (#99)

configreload callback skipped newCfg.Loadpoints entirely. Added a
Load() call on the manager inside the callback — the manager
preserves observed state across reloads, so adding / tuning
loadpoints live no longer needs a process restart.

## P2 — session anchor lost on config reload (#101)

loadpoint.Manager.Load preserved pluggedIn and delivered_wh_session
but not sessionPluginSoCPct. A hot-reload mid-charge would reset
the SoC inference baseline back to PluginSoCPct, making the
estimate jump backward even though the car kept getting energy.
Carry the anchor too.

## Tests

- Added `TestOptimizeInfeasibleStatePicksNearIdle` covering the DP
  fallback.
- All existing tests still pass incl. e2e (27s).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit d863420 into master Apr 18, 2026
1 check passed
@frahlg
frahlg deleted the fix/planner-overhaul-codex-review branch August 7, 2026 08:18
frahlg added a commit that referenced this pull request Aug 30, 2026
#1008)

Move the pin to srcfl/device-drivers@f98d5c5f (#103): easee_cloud emits
request_active (false on Easee reason 50 / op_mode 4), which turns on
the session-completion latch, manual-hold auto-release and
interruption-noise suppression for Easee sites. Part of #1002.


Claude-Session: https://claude.ai/code/session_01C1d4uknzs7QUv7nE9rW4fi

Co-authored-by: Claude Fable 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