Repository navigation
fix(control,pvmodel): address Codex review on #131 #136 - #142
Merged
Merged
Conversation
## control — slot-energy bookkeeping reset on planner_self (Codex P2 on #131) The new planner_self branch bypasses the energy-allocation path but previously left state.currentDirective / slotDelivered / lastTickTs untouched. A mode hop cheap → self → cheap within the same 15-minute slot would find SlotStart still matching on the return, skip its own rollover-reset, and compute remainingWh off a stale slotDelivered — over-commanding battery power for the rest of the slot. Clear the three fields whenever the planner_self branch fires so a later energy-path cycle always takes its intended rollover-reset branch. Regression test: TestPlannerSelfResetsEnergyBookkeepingOnEntry in control_test.go exercises the three-step mode hop and asserts the state is clean after the self cycle. ## pvmodel — freeze row/column 0 of covariance matrix (Codex P1 on #136) With Features[0] pinned to 0.0 (dead slot since #134), the standard RLS covariance update still divided P[0][0] by λ=0.995 every tick. Growth compounds at ~1.005× per sample, so after ~140k successful Updates P[0][0] overflows to +Inf; the next tick computes Px[0] = sum_k P[0][k] * x[k] = Inf * 0 = NaN and the poison cascades to K, β, and every downstream prediction. At the 1-minute daytime cadence that's months — long enough to bite in production but easy to miss in CI. Skip i=0 and j=0 in the covariance update loop. The two dead arrays naturally decay to zero (the newP zero value), which matches the desired invariant (a dead feature's covariance is zero). No growth, no NaN, no coupling into the live coefficients. Regression test: TestUpdatePKeepsDeadInterceptFinite runs 2000 Updates and asserts every P cell + every β coefficient stays finite; also asserts row 0 and column 0 stay at zero so a future refactor can't silently re-introduce the growth path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two legit Codex findings on recently-merged PRs.
Fix 1 — planner_self slot-energy reset (Codex P2 on #131)
`ControlSwitch cheap → self → cheap` within one slot would leak stale `slotDelivered` past the self hop, over-commanding battery for the rest of the slot. Reset the three energy-path fields when planner_self fires so a return to the energy path always takes its rollover-reset branch cleanly.
Fix 2 — pvmodel covariance overflow on dead intercept (Codex P1 on #136)
With `Features[0]=0`, the standard RLS covariance update still grows `P[0][0]` by 1/λ each tick. ~140k successful Updates (months of daytime training) overflows to Inf → `Px[0] = Inf*0 = NaN` → poison cascades into β. Freeze row/column 0 in the update loop so the dead slot stays numerically dead.
Tests
Full suite green.
🤖 Generated with Claude Code