Repository navigation
fix(mpc,config): address Codex review on #119 #121 #122 #124 - #126
Conversation
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]>
There was a problem hiding this comment.
💡 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".
| s.Defaults.CapacityWh = totalCapWh | ||
| s.Defaults.MaxChargeW = maxChargeW | ||
| s.Defaults.MaxDischargeW = maxDischargeW |
There was a problem hiding this comment.
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 👍 / 👎.
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]>
Summary
Follow-up to this morning's planner-overhaul batch (PRs #119 → #125).
chatgpt-codex-connectorflagged 4 P1 and 2 P2 issues across those PRs — all real, all verified by reading the code. This PR addresses them.Fixes
reasonFor"absorb PV surplus" used!gridExports— labelled partial absorption as generic "charge" and over-charging as PV absorption!gridImports; added two test casesmpc.Service.UpdateCapacity(); reload closure now pushes new totalsloadpoints[].driver_nameexcluded a driver — malformed rows (missing id) silently dropped real batterieslp.ID != ""before using the reference; regression test+2× effPriceadditive on HOUSE-portion only; EV import keeps plain costuse_energy_dispatchkey entirely; operators who explicitly set it tofalsewould silently flip to energy path*boolalias with deprecation WARN; honors prior intentTest plan
go test ./...incl. e2e stays green🤖 Generated with Claude Code