Repository navigation
fix(control): a full battery refusing charge is a limit, not a fault - #2091
Conversation
A FoxESS H3 refuses forced charge from 99 % (#1993). Core counted three such refusals as a device that cannot actuate: it dropped the battery from dispatch and the plan, sent it its default and raised not_following / device_fault. - telemetry: DerReading.AtFull, a fresh SoC within two points of the battery's own ceiling, or of 100 %. - dispatch: a refused charge order to a battery at full is not counted; the streak of real refusals is left as it was. - control feedback: the same case reads limited / battery_full (info) instead of blocked / command_failed. A refused discharge, or a refusal below full, counts as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 904194b40a
ℹ️ 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".
| err := sendDriverCommand(ctx, reg, kind, name, payload, timeout) | ||
| if t != nil && t.tel != nil && isCommandRefusal(err) && isChargeOrder(payload) && | ||
| t.tel.Get(name, telemetry.DerBattery).AtFull(now) { |
There was a problem hiding this comment.
Evaluate fullness against the clock after command completion
If a battery poll completes after the control tick starts but before the command returns, this reads the new SoC using the older tickNow passed by main.go. UpdateFromPoll stamps SoC with time.Now(), and AtFull explicitly rejects SoCUpdatedAt.After(now), so a genuinely fresh 99% reading fails this exemption. This can also occur when the command queues behind an ongoing poll in the driver's actor. Repeated occurrences still accumulate three refusals and exclude the full battery—the failure this change is intended to prevent. Evaluate the reading using the current clock after the send, rather than the tick's start time.
Useful? React with 👍 / 👎.
| if coreReason == "" && kind == telemetry.DerBattery && commanded && cmd.Result == "failed" && | ||
| cmd.PowerW != nil && *cmd.PowerW > 0 && rd.AtFull(now) { | ||
| coreReason = "battery_full_refused" |
There was a problem hiding this comment.
Recognize full-battery refusals for clamped charge targets
When a positive charge target is clamped, coreReason is already core_limit, so this condition skips the full-battery exemption. For example, clampWithSoC marks a target clamped when it exceeds the battery's charge-power cap while retaining a positive charging setpoint. If a 99% battery refuses that order, the tracker now correctly ignores the refusal, but classifyControlFeedback still reports blocked / command_failed because it only recognizes battery_full_refused. Allow this refusal classification for positive clamped orders too, while retaining the later safety overrides.
Useful? React with 👍 / 👎.
Refs #1993
Problem
A FoxESS H3-Smart refuses forced charge from 99 % (
foxess_h3_smart, legacydriver_commandreturns "battery is full; refusing forced charge"). Core reads any returned string as a refusal. After three refusals in a row it judged that the battery could not act. It dropped the battery from dispatch and the plan, sent it its autonomous default, and raiseddevice_faultandcontrol.not_following. Leitet saw this on a real site on v0.163.0-beta.1.#2083 (in v0.169.0-beta.1) stops charge orders at the battery's own ceiling. That ceiling can sit at 100 % while the device stops at 99 %, so the refusal can still come.
Change
telemetry.DerReading.AtFull(now): true when the battery's fresh SoC is withinFullBandFract(2 points) of its full level. The full level is the device's own ceiling (SoCCeilingNow) when it reports one, or else 100 %. A stale or missing SoC is never full.driverActuationTracker.dispatchCommand: when a battery charge order (battery, positive watts) is refused and the battery is at full, the refusal is not counted. The streak of real refusals stays as it was. The battery stays in dispatch and in the plan, and it can still discharge.limited/battery_full(info) instead ofblocked/command_failed(warning).A refused discharge, or a refusal below full, counts as before. No driver change is needed, and the rule covers any driver that refuses charge at full.
Evidence
TestFullBatteryRefusingChargeIsALimitNotAFault: a charge refused at 99 % keeps the battery in control after five refusals. A discharge refused at 99 %, or a charge refused at 50 %, still excludes it.TestControlFeedbackFullBatteryRefusalIsALimit:battery_fullat 99 %,command_failedat 50 %.TestAtFullUsesTheBatterysOwnCeiling: 99 % is full, 97 % is not, 89 % under a 90 % ceiling is full, and a stale 100 % is not.make verifyis green locally.Not covered: a run against a real FoxESS. The planner part of #1993 (stop planning charge near full) comes from #2083's device ceiling where the driver reports one.
🤖 Generated with Claude Code