Repository navigation
fix(control): stop one late poll from reading as lost readings - #2067
Merged
Merged
Conversation
The control journal samples at its ticker's time, and GET /api/status takes its clock before it waits for the controller's lock. A battery poll the store took in between was newer than that clock, so the verdict called the reading stale, and a stale reading became readings_lost (no_contact, alarm) at once. On a Sungrow hybrid polled once a second this gave about 23 one-sample alarms a day. Judge each device at the latest of the caller's clock and the store's own stamps on what it read. Count readings as lost once no measured power has come for 30 s, or 2 min for a charger, the same grace a new order gets, bounded by the driver's last good poll so cached values from a driver the watchdog gave up on do not hold off the alarm. Dispatch and the stale site meter stop are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Codex Review Summary: ✅ CompletedThis 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. |
Drop the last-good-poll cap: every emit records a good poll, so it never differed from the last measured power in production. Stale readings now use the rule every other lost-proof path uses: lost once both the last measured power and the current order step are older than the grace. Measured proof restarts its 10 s window after a reading without power or a new step of 500 W or more, so it can lag healthy readings; counting from the step keeps one late poll under a stepping target from alarming. Add repeated one-poll gap tests and rename the new-step test row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
While Core keeps stepping a dead driver's order by 600 W every 10 s, each step restarts the 30 s wait, so readings_lost comes 30 s after the last step. The verdict says no contact (telemetry_stale, warning) the whole time. In the field the watchdog hands the battery back to its own control after 60 s, so the steps stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
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.
Problem
On the owner's home box (Sungrow SH-RT hybrid, battery polled once a second), the control journal for 8–22 Nov 2026 holds 341
readings_lostalarm spans forbattery:sungrow, about 23 a day, and 171 forev:easee. Each is one 5 s journal sample; none lasted over 40 s. They are noise, not lost control, but they show as "Lost control" (no_contact, alarm).Root cause
Two ways one sample turned into
readings_lostat once. Both fail on master in the newTestOnePollGapIsNotReadingsLost:controlFeedback(now)treats a reading stamped afternowas not fresh (!rd.UpdatedAt.After(now)). The journal passes its ticker's time, andGET /api/statustakes its clock before it waits forCtrlMu. A driver can store a poll in between, so that sample sees a "reading from the future" and calls ittelemetry_stale. The battery polls once a second and the Easee stream about every 2 s, and the battery had about twice as many spans, which fits.is_online:false). Among bundled drivers onlyeasee_cloudsends it (Easeeop_mode 0), so this can add to the charger's spans, not the battery's.In both cases
controlVerificationLostturnedtelemetry_staleintoreadings_lostat once, with none of the grace every other lost-proof path has. The other one-poll gaps (a failed Modbus read,control_power_available=falseonce, power older than its max age once) do not givereadings_loston master; they stay in the test as guards.Change
rowClock: each device is judged at the latest of the caller's clock and the store's own stamps on what it read (UpdatedAt, the command's last observation). The store stamps with the box's clock, so this never runs ahead of the present.controlVerificationLost:telemetry_staleno longer jumps the queue. It uses the rule every other lost-proof path already uses: readings are lost once both the last measured power and the current order step are older than the grace, 30 s for a battery and 2 min for a charger (cloud chargers re-read about once a minute). These are the graces already in this function. Measured proof needs 10 s of distinct fresh readings, and a reading without power or a new ≥ 500 W step restarts that window. Counting from the order step too means a target that steps every few seconds cannot make one late poll an alarm.readings_lostwaits until 30 s after the last step. The verdict saystelemetry_stale(no_contact, warning) the whole time, so the owner still sees no contact. In the field the 60 s watchdog hands such a battery back to its own control, and the steps stop.Safety is separate and unchanged: dispatch, the stale site-meter stop and the watchdog's autonomous fallback do not read this verdict. Changeset
patch.Tests
New
go/internal/api/api_control_readings_lost_test.go(synctest, fake clock):TestOnePollGapIsNotReadingsLost: five one-poll gaps on a following battery; no sample alarms and the verdict comes back to following. The "stored after the sample's clock" and "driver says offline once" cases fail on master.TestRepeatedOnePollGapsAreNotReadingsLost: the gaps above, repeated every 25 s and every 8 s for 5 min, and every 12 s under 600 W steps every 4 s; no sample alarms. The stepping case failed on this PR's first head (36 s: no_contact/readings_lost/alarm).TestSustainedGapIsReadingsLost: a driver that stores nothing, and one that says offline on every poll while its polls still count as good, are both lost from 30 s.TestDeadDriverUnderSteppingOrders: a dead driver under 600 W steps every 10 s showsno_contact/telemetry_stale/warningthroughout (after its last reading is a minute old) and never alarms; 30 s after the steps stop it isreadings_lost.TestCloudChargerOfflineIsLostAfterItsGrace: Easeeop_mode 0(is_online:false, unconfirmed power) is a warning for 2 min, thenreadings_lost.TestControlVerificationLossAlarmgains rows for the new rule. Its old "device offline 20 s → alarm" row now reads "one stale sample → no alarm", and "stale just after a new step waits for its grace" covers the order step.Run locally:
go test ./internal/api/ -run 'ReadingsLost|PollGap|SustainedGap|CloudChargerOffline|VerificationLoss|FailedCall' -count=1: okmake verify(GOFLAGS=-p=4):verify: vet + test + build cleannpm test: 956 pass, 0 failNot verified on hardware
Not run on the home box yet. The way to check it on a beta:
GET /api/control/journal?subject=battery:&severity=alarmshould stop showing 5 sreadings_lostspans, while a pulled network cable still givesreadings_lostafter about 30 s.Overlap
Touches the row loop and
controlVerificationLostinapi_control_feedback.go, near the hunks of #2017, #2065 and #2050 but not on their lines.controlVerificationLostkeeps its signature.🤖 Generated with Claude Code