Repository navigation
fix(control): reset energy-path bookkeeping inside reactive carve-outs - #386
Conversation
Mirror what preparePlannerSelf already does (dispatch.go:797-804): when the planner_arbitrage cover-load or planner_passive_arbitrage idle carve- out fires, call resetEnergyDispatchBookkeeping alongside the existing SetGridTarget(0). Otherwise slotDelivered / lastTickTs / currentDirective keep values left over from a previous energy-path tick in the same slot, and a future mid-slot transition back to the energy path (plan refine, mode hop) miscomputes remainingWh. Pure defence-in-depth — no change in steady-state cover-load reactive behaviour. Same forward-transition risk preparePlannerSelf has guarded against since PR #131. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
3ba074e to
8e0ec44
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ba074e04c
ℹ️ 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".
| // within the same slot would then read those and | ||
| // miscompute remainingWh. Reset on every carve-out | ||
| // tick (idempotent). | ||
| resetEnergyDispatchBookkeeping(state) |
There was a problem hiding this comment.
Preserve delivered Wh when leaving carve-outs
When a carve-out fires after this slot has already run on the energy path, this unconditional reset discards the valid slotDelivered accumulated earlier in the same SlotStart. If a later mid-slot replan flips the same slot back to the energy path, the rollover check at currentDirective.SlotStart treats it as a brand-new slot and remainingWh is computed from the full directive budget, ignoring energy already delivered before the carve-out; that can over-discharge/over-charge and bypass the existing same-slot rebase protections for plan changes.
Useful? React with 👍 / 👎.
Summary
Defence-in-depth follow-up to #383 / #378. The carve-out gate added in #383 calls
SetGridTarget(0)but does not callresetEnergyDispatchBookkeeping.preparePlannerSelfdoes both (dispatch.go:797-804) for the same reason: when the slot was previously on the energy-allocation path — directly or via an operator mode-hop earlier in the same 15-min window —slotDelivered/lastTickTs/currentDirectivehold stale values. A subsequent transition back to the energy path within the same slot would then read those and miscomputeremainingWh.Symmetric with the comment at dispatch.go:798-803:
Adding the reset to the carve-out branch gives
planner_arbitragecover-load andplanner_passive_arbitrageidle the same guarantee.What does NOT change
preparePlannerSelfdoesn't reset the PI either, and resetting per tick would prevent the integral from doing its job.Test plan
TestPlannerArbitrageCoverLoadResetsEnergyPathBookkeeping— RED before fix (slotDelivered=-200 / non-zero ts / non-zero directive), GREEN after.TestPlannerPassiveArbitrageIdleResetsEnergyPathBookkeeping— same for passive idle.🤖 Generated with Claude Code