Skip to content

fix(control): a full battery refusing charge is a limit, not a fault - #2091

Merged
frahlg merged 1 commit into
masterfrom
1993-full-battery-refusal
Nov 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
1993-full-battery-refusal

Conversation

@frahlg

@frahlg frahlg commented Nov 27, 2026

Copy link
Copy Markdown
Member

Refs #1993

Problem

A FoxESS H3-Smart refuses forced charge from 99 % (foxess_h3_smart, legacy driver_command returns "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 raised device_fault and control.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 within FullBandFract (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.
  • Control feedback: the same case reads limited / battery_full (info) instead of blocked / 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_full at 99 %, command_failed at 50 %.
  • TestAtFullUsesTheBatterysOwnCeiling: 99 % is full, 97 % is not, 89 % under a 90 % ceiling is full, and a stale 100 % is not.
  • make verify is 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

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T18:04:34.456132Z 904194b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +151 to +153
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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +288 to +290
if coreReason == "" && kind == telemetry.DerBattery && commanded && cmd.Result == "failed" &&
cmd.PowerW != nil && *cmd.PowerW > 0 && rd.AtFull(now) {
coreReason = "battery_full_refused"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@frahlg
frahlg merged commit 97b68ef into master Nov 27, 2026
22 checks passed
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