Skip to content

fix(mpc,config): address Codex review on #119 #121 #122 #124 - #126

Merged
frahlg merged 1 commit into
masterfrom
fix/codex-followups-119-124
Apr 19, 2026
Merged

frahlg merged 1 commit into
masterfrom
fix/codex-followups-119-124

Conversation

@frahlg

@frahlg frahlg commented Apr 19, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to this morning's planner-overhaul batch (PRs #119 → #125). chatgpt-codex-connector flagged 4 P1 and 2 P2 issues across those PRs — all real, all verified by reading the code. This PR addresses them.

Fixes

PR Sev Issue Fix
#119 P2 reasonFor "absorb PV surplus" used !gridExports — labelled partial absorption as generic "charge" and over-charging as PV absorption Flipped to !gridImports; added two test cases
#121 P1 Hot-reload updated dispatch capacity map but planner kept startup snapshot — SoC % / terminal credit went stale until restart Hoisted capacity aggregation into helper + mpc.Service.UpdateCapacity(); reload closure now pushes new totals
#121 P2 Any non-empty loadpoints[].driver_name excluded a driver — malformed rows (missing id) silently dropped real batteries Require lp.ID != "" before using the reference; regression test
#122 P1 Strict-SC 3× bias applied to total import incl. EV; at slot price > 4/3 × mean, DP chose missing EV deadline over charging Rewrote as +2× effPrice additive on HOUSE-portion only; EV import keeps plain cost
#124 P1 Dropped use_energy_dispatch key entirely; operators who explicitly set it to false would silently flip to energy path Added back as *bool alias with deprecation WARN; honors prior intent

Test plan

  • Five new/updated test cases, one per issue
  • go test ./... incl. e2e stays green
  • Deploy to Fredrik's Pi; verify reload-path pushes new capacity into planner

🤖 Generated with Claude Code

Five issues surfaced by the chatgpt-codex-connector bot across the
batch of planner-overhaul PRs shipped earlier today. None
catastrophic on Fredrik's current Pi, but all real bugs we'd hit as
soon as a second deployment wanted to behave differently.

PR #119 P2 — reasonFor() "absorb PV surplus" branch
  Condition was `!gridExports` which missed both edges:
  - partial PV absorption (battery charges, grid still exports
    residual) got labelled generic "charge"
  - over-charging (battery pulls more than PV provides, grid
    actually imports) got labelled "absorb PV surplus"
  Flipped to `!gridImports`. Added two test cases tracing both
  scenarios (reason_test.go).

PR #121 P1 — hot-reload doesn't propagate capacity to MPC
  `buildMPC` computed totalCap/maxCharge/maxDischarge inline and
  stored them in `Service.Defaults`. Adding or removing an EV
  loadpoint via config-reload updated the dispatch-side capacity
  map but the planner kept optimising against the startup snapshot;
  SoC% and terminal credit went stale until process restart.
  - Hoisted the aggregation into `aggregateBatteryLimits()` in
    main.go so the reload closure can reuse it.
  - Added `mpc.Service.UpdateCapacity()` which takes the service
    mutex and swaps Defaults.CapacityWh / Max{Charge,Discharge}W.
  - Reload closure now calls it after the capacities map is
    rewritten.

PR #121 P2 — invalid loadpoints still exclude drivers
  `driverCapacitiesFrom` treated any non-empty `driver_name` as an
  EV reference, but `loadpoint.Manager.Load` rejects rows with
  empty `id`. Means a malformed config row could silently drop a
  real battery from the MPC pool. Now requires `lp.ID != ""`
  before using the driver_name. Same guard applied to
  `warnIfEVHasBatteryCapacity`. Added regression test.

PR #122 P1 — strict SC bias breaks EV deadline priority
  The 3× multiplier on self_consumption import cost applied to the
  TOTAL gridKWh (house + EV). Deadline shortfall is penalised at
  4× meanPrice. At slot price > 4/3 × meanPrice the DP preferred
  missing the deadline over charging the EV at peak-hour prices.
  Rewrote the bias as a +2× effPrice additive penalty on the
  HOUSE portion of grid import only (load + PV + battery). EV
  import keeps its plain cost so deadline math stays honest. New
  test reproduces a 3-slot peak-deadline scenario that starves
  under the old bias and succeeds under the new one.

PR #124 P1 — removed use_energy_dispatch without back-compat
  Renamed the opt-in field to an opt-out (`legacy_dispatch`) but
  dropped the old key entirely. Non-strict yaml.Unmarshal silently
  ignores unknown fields → an operator who explicitly set
  `use_energy_dispatch: false` (picked legacy on purpose) would
  silently flip to the energy path on upgrade. Added the field
  back as `*bool` so main.go can distinguish "unset" (nil) from
  "explicitly false" and honor prior intent, with a deprecation
  WARN on startup.

Full `go test ./...` incl. e2e stays green.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit 24368fd into master Apr 19, 2026
1 check passed
@frahlg
frahlg deleted the fix/codex-followups-119-124 branch April 19, 2026 09:03

@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: 816d972ee4

ℹ️ 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 +153 to +155
s.Defaults.CapacityWh = totalCapWh
s.Defaults.MaxChargeW = maxChargeW
s.Defaults.MaxDischargeW = maxDischargeW

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 Synchronize default-param reads with capacity updates

UpdateCapacity now writes s.Defaults.CapacityWh/MaxChargeW/MaxDischargeW under s.mu, but planner reads still access s.Defaults unlocked (for example replan() copies p := s.Defaults, and slot helpers read s.Defaults.Mode). When a config reload calls UpdateCapacity concurrently with scheduled/reactive replans, this introduces a real race and can produce mixed old/new limits in one optimization pass. Please snapshot all of s.Defaults under the same mutex before using it.

Useful? React with 👍 / 👎.

frahlg added a commit that referenced this pull request Apr 19, 2026
The squash commit for #126 used a comma-separated scope
`(mpc,config)` which the conventional-commits header regex
doesn't accept. Semantic-release treated it as no-type and
skipped the release. This empty commit re-triggers the
pipeline with a well-formed scope so the fixes from #126 ship.

Co-Authored-By: Claude Opus 4.7 (1M context) <[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