Skip to content

fix: Codex review follow-ups for v0.107.0 (P1 + P2) - #383

Merged
frahlg merged 1 commit into
masterfrom
fix-codex-followups
May 28, 2026
Merged

frahlg merged 1 commit into
masterfrom
fix-codex-followups

Conversation

@frahlg

@frahlg frahlg commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

Four Codex review findings on the dispatch / loadmodel changes that shipped in v0.107.0. Two P1 + two P2.

P1 — Heating coefficient survives restarts (#377 review)

main.go called loadSvc.SetHeatingCoef(cfg.Weather.HeatingWPerDegC) at startup, unconditionally overwriting the persisted online-fit value. Every binary update wiped the adaptive learning. New SeedHeatingCoef(w) is a no-op when the model has samples; operator config is the cold-start prior, observation drives the value once learning has begun.

P1 — Cover-load carve-out forces grid_target=0 (#378 review)

The cover-load carve-out only set useEnergyPath=false; production wires both SlotDirective and PlanTarget, so !useEnergyPath called PlanTarget and SetGridTarget(plannedImportW). A cover-load slot with +1.7 kW planned import then made PI try to import 1.7 kW — the opposite of the carve-out's purpose. Fix routes both carve-out predicates (passiveArbitrageIdleSlot, coverLoadDischargeSlot) to SetGridTarget(0) and skips the legacy PlanTarget block.

P2 — Predicate tightened to true idle (#375 review)

passiveArbitrageIdleSlot used BatteryEnergyWh <= idleWhGate, true for any negative-energy slot. Tightened to |BatteryEnergyWh| <= idleWhGate. The planned-discharge case folds into coverLoadDischargeSlot, which is now extended to planner_passive_arbitrage too (was arbitrage-only). The live-export gate fires on either predicate.

P2 — SlotDeliveryStats catches sign mismatches (#379 review)

Planned -425 Wh vs actual +425 Wh would have scored |actual|/|planned| = 1.0 = on-target — the largest possible miss, invisible on /api/status. New SignMismatchCount fires when planned and actual have opposite signs (and both above idle cutoff); magnitude over/under counters then only fire on same-sign cases.

Test plan

  • TestSeedHeatingCoefDoesNotOverwriteLearnedValue
  • TestSeedHeatingCoefAppliesOnColdStart
  • TestPlannerArbitrageCoverLoadChasesGridZeroNotPlannedImport
  • TestCoverLoadDischargeDoesNotAbsorbLiveSurplus/{arbitrage,passive_arbitrage}
  • TestSlotMetricsDetectsSignMismatch
  • Full go test ./... green (unit + e2e)
  • make verify-all clean

🤖 Generated with Claude Code

Four findings from Codex on the dispatch / loadmodel changes shipped in
v0.107.0. Two are P1 (regressions that defeat their own PR's purpose);
two are P2 (defensive predicate + observability gap).

P1 (PR #377): SeedHeatingCoef preserves learned value across restarts.
main.go called SetHeatingCoef unconditionally at startup, clobbering
the persisted online-fit value with the config seed. Every binary
update wiped the adaptive learning. New SeedHeatingCoef is a no-op when
the model already has samples; operator config is the cold-start prior,
observation drives the value once learning has begun. SetHeatingCoef
remains for explicit operator override (eg. API endpoint, manual reset).

P1 (PR #378): Cover-load carve-out forces grid_target=0. The carve-out
only set useEnergyPath=false; production wires PlanTarget alongside
SlotDirective, so the !useEnergyPath branch called PlanTarget and then
SetGridTarget(plannedImportW). A cover-load slot with 1.7 kW planned
import then made PI try to import 1.7 kW — the opposite of the
carve-out's purpose. Fix routes both carve-out predicates to
SetGridTarget(0) and skips the legacy PlanTarget block.

P2 (PR #375): passiveArbitrageIdleSlot predicate tightened. Was
`dir.BatteryEnergyWh <= idleWhGate` which matched any negative-energy
slot (planned discharge). Tightened to |BatteryEnergyWh| ≤ idleWhGate.
The planned-discharge case folds into coverLoadDischargeSlot, which is
now extended to planner_passive_arbitrage too (was arbitrage-only). The
live-export gate fires on either predicate.

P2 (PR #379): SlotDeliveryStats.SignMismatchCount. Planned -425 Wh
vs actual +425 Wh would have scored |ratio|=1.0=on-target — the
largest possible miss, invisible. New counter fires when planned and
actual have opposite signs for non-idle slots; the magnitude over/under
counters then only fire on same-sign cases, keeping their semantics
clean.

Tests:
- TestSeedHeatingCoefDoesNotOverwriteLearnedValue
- TestSeedHeatingCoefAppliesOnColdStart
- TestPlannerArbitrageCoverLoadChasesGridZeroNotPlannedImport
- TestCoverLoadDischargeDoesNotAbsorbLiveSurplus (both modes)
- TestSlotMetricsDetectsSignMismatch

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit 55fb0c3 into master May 28, 2026
2 checks passed
@frahlg
frahlg deleted the fix-codex-followups branch May 28, 2026 07:21
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