Repository navigation
fix(control): act only on new site-meter samples in battery dispatch - #1879
Conversation
A failed meter poll keeps the old reading, and the dispatch gate passes it until the 60 s watchdog expires. ComputeDispatch re-applied the same held error every tick and wound the battery to full power in the wrong direction. Track the meter sample the last dispatch used. Without a newer one, the PI path holds its targets and skips integration, and every other path may only move a battery toward 0 W. Item A1 of the stable plan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68bcf9ca24
ℹ️ 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".
| if meterHeld { | ||
| return fuseSaverEarlyExit(store, state, driverCapacities, fuseMaxW) |
There was a problem hiding this comment.
Apply safety reductions before returning on a held meter
If the meter stops updating while a battery is running, this unconditional exit also suppresses safety reductions based on fresh battery telemetry or configuration. For example, hot-reloading max_discharge_w: 0 while the battery is discharging now leaves its previous negative setpoint active until another meter sample arrives or the watchdog expires. fuseSaverEarlyExit only handles fuse relief and full-battery charging stops; it does not enforce the updated power limits or direction blocks. Previously, the explicit-zero and blocked-charge predicates below allowed these cases through to the safety pipeline even inside the deadband. Hold the PI integration without bypassing commands that reduce an existing target toward zero.
Useful? React with 👍 / 👎.
The held-meter exit in the PI path returned before the cuts the deadband exit keeps: a battery discharging under max_discharge_w=0, charging while blocked, or discharging against a no-discharge plan. While the meter was held, those cuts were not sent for up to 60 s. Share one condition with the deadband exit. When it fires on a held tick, skip the PI with no correction and let the clamps, holdTowardZero and the safety pipeline cut the battery. Also drop the startup clause that treated a failed latest read as held before the first dispatch. A poll that emits and then errors leaves that flag set on every tick, so a fresh start never dispatched although each tick brought a new sample. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A site meter that repeats its values after FTW's devices moved more than 500 W now counts as a held sample for battery dispatch from the first repeat, as #1879 does for a sample with an old timestamp. Seed 207537 wound the battery from +5 kW to -5 kW in the 30 s before the frozen verdict; the PI now holds it after its first followed move. The freeze check reads the meter and every battery and charger through health-gated telemetry accessors, so an offline driver's cached reading never counts. Setup's check before it enables control applies the same frozen verdict as the tick. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1921) * fix(control): a site meter that repeats one reading counts as stale A meter that answers every poll with the same values passed the dispatch gate, which checks only UpdatedAt. In seed 207537 it repeated one sample for 39.9 s; the battery wound from +4 kW to -5 kW on it and an EV rise went out. Track the meter's total and phase values against FTW's own batteries and chargers. A device's move counts as the smaller of its order's move and its own reading's move, so only orders a device followed count. Once they move more than 500 W and the meter repeats the same values for 3 more polls and 15 s, the gate reports site_meter_stale. Any changed value reopens it. 500 W is far above meter resolution and inverter dead bands; 15 s covers a 10 s HAN or DSMR 4 refresh plus a poll. Item C5 of the random-rig triage. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(control): frozen-meter check survives a lost telegram and sees every device Review of #1921: - Wait 30 s, not 15 s, after the move. A 10 s HAN or DSMR 4 meter that loses one telegram repeats its values for 20 s; 15 s tripped it. - Count every battery and charger in telemetry, with a missing order as 0 W. A meter frozen since start, or a car plugged in during a freeze, was never caught. - Sum the moves with their sign, as the meter sees them. Two batteries trading 1.5 kW no longer count as 3 kW. A move that comes back before the meter changes no longer counts. - One gate function, siteDispatchGateLocked, for the tick and operator setpoints, with a test that drives it to site_meter_stale. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(control): hold the battery on a meter repeat after FTW's own move A site meter that repeats its values after FTW's devices moved more than 500 W now counts as a held sample for battery dispatch from the first repeat, as #1879 does for a sample with an old timestamp. Seed 207537 wound the battery from +5 kW to -5 kW in the 30 s before the frozen verdict; the PI now holds it after its first followed move. The freeze check reads the meter and every battery and charger through health-gated telemetry accessors, so an offline driver's cached reading never counts. Setup's check before it enables control applies the same frozen verdict as the tick. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(changeset): say what the frozen-meter fix holds and what it waits for Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Item A1 of the stable plan.
Problem
A failed site-meter poll keeps the old reading and its
UpdatedAt(telemetry/store.go:222-229). The only gate before dispatch is the reading's age against the 60 s watchdog (site_dispatch_safety.go:43). Inside that windowComputeDispatchreadsSmoothedWagain on every tick (dispatch.go:1446-1449). The battery reports fresh power, so the meter clamp moves the target one more held error each tick, and the PI integrates the same error again.Scenario: P1 meter stalls while a Sungrow battery keeps reporting, 5 s ticks, 10 kW battery.
Change
Staterecords theUpdatedAtof the meter sample the last battery dispatch used. When no newer sample exists:max_discharge_w: 0, charges while blocked (charge_capable=false, charge cap 0, no-charge plan), or discharges against a no-discharge plan, the PI is skipped with no correction and the clamps,holdTowardZeroand the safety pipeline cut that battery.The EV fuse limit already follows this rule (ev_fuse_budget.go:375). Only the sample's age counts. A failed read whose sample is newer than the last dispatch still counts as new evidence, so a meter whose poll emits and then reports an error is not locked out, from a fresh start or later.
Three existing tests called
ComputeDispatchseveral times on one meter sample. They now write a new sample between calls, as a running meter does.Tests
go test ./internal/control/ -run 'Frozen|HeldMeter': fails on master (-10000 W / +11500 W, and new orders on a held sample), passes here.TestHeldMeterStillSendsExplicitZeroDischarge,TestHeldMeterStillStopsBlockedChargeandTestEmitThenErrorMeterIsNotHeldpass on master, failed on the first commit, and pass now.go test -race ./internal/control/...: okgo test ./cmd/ftw/ ./test/e2e/... ./internal/loadpoint/...: okgo vet ./...,go build ./...: okThe repro tests come from the audit (caa-51) under normal names, plus
TestHeldMeterOnlyCutsTowardZero.Risk
Medium. The battery now acts once per new meter sample rather than once per tick. Drivers write a sample on each poll, so this changes nothing for meters that poll at least as often as the control tick. A slower meter makes the battery react at the meter's pace. A manual hold that reverses direction waits for the next sample, normally one poll. Rig scenario R1 covers the stalled meter.
🤖 Generated with Claude Code