Skip to content

fix(control,pvmodel): address Codex review on #131 #136 - #142

Merged
frahlg merged 1 commit into
masterfrom
142-codex-review-followups
Apr 20, 2026
Merged

frahlg merged 1 commit into
masterfrom
142-codex-review-followups

Conversation

@frahlg

@frahlg frahlg commented Apr 20, 2026

Copy link
Copy Markdown
Member

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

  • `TestPlannerSelfResetsEnergyBookkeepingOnEntry` — full cheap→self→cheap mode-hop exercise.
  • `TestUpdatePKeepsDeadInterceptFinite` — 2000 Updates, asserts every P cell + every β stays finite, row/col 0 stay at zero.

Full suite green.

🤖 Generated with Claude Code

## 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]>
@frahlg
frahlg merged commit 772df01 into master Apr 20, 2026
1 check passed
@frahlg
frahlg deleted the 142-codex-review-followups branch April 20, 2026 07:53
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