Low-battery warnings latch once per discharge; only a charger re-arms - #549
Merged
Conversation
The 2026-07-24 bench discharges fired the 10%/5% warning earcon ~90 times per run (93 and 86 on the two units, every 30-90 s for the final ~90 minutes). The 2-point climb-clear hysteresis was no match for the real signal: near the discharge curve's flat knee one BATV LSB (20 mV) is ~3 SoC points, and under the varying load the published estimate bounced across 4-23% — every two-step upward bounce re-armed a threshold and the next dip re-fired it. No percent-based hysteresis clears noise that large while still re-arming on any genuine recovery a single-cell battery can produce, so crossings now latch for the whole discharge and only external power re-arms them. The blind-twilight guard (None never re-arms) is unchanged and was confirmed working in the same runs. battery_fake gains a two-poll charging phase between laps so the -fh -fb dev loop still demos the warnings on every lap, not just the first. Regression tests replay the actual pf4-dev discharge tail (one sample per minute, 20:00-21:15): exactly one 10% and one 5% warning, and the same again after a charge. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
brickbots
marked this pull request as ready for review
July 25, 2026 22:36
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.
The bug (heard in the field)
During the 2026-07-24 bench discharge runs the 10%/5% low-battery warning earcon fired ~90 times per run (replaying the telemetry through
LowBatteryWarnerreproduces 93 fires on one unit, 86 on the other — every 30–90 s for the final ~90 minutes). Design intent was once at 10% and once at 5%.Why the hysteresis failed
The shipped guard re-armed a threshold when the estimate climbed 2 points clear of it. But near the discharge curve's flat knee, one BATV ADC step (20 mV) is worth ~3 SoC points, and under the varying solve load the published estimate bounced across 4–23% for the whole tail of the discharge. Every two-step upward bounce re-armed a threshold; the next dip re-fired it. The published SoC values in that window were
{4, 6, 8, 10, 13, 16, 19, 23}— swings of 6+ points between 5-second samples. No percent-based hysteresis clears quantisation noise that large while still re-arming on any genuine recovery a single-cell battery can produce.The fix
Crossings latch for the whole discharge; thresholds re-arm only on external power (so the next discharge warns afresh). Nothing within a discharge re-arms them — not a climbing estimate, not a blind (
None) sample. The blind-twilight guard from #541 is unchanged (and the field data confirmed it worked — zero re-fires from blind samples).battery_fakegains a two-poll charging phase between laps, since with the latch a-fh -fbdev run would otherwise demo the warnings on the first lap only.Tests
test_field_discharge_tail_warns_exactly_twice— replays the actual pf4-dev discharge tail (one sample per minute, 20:00–21:15, embedded as a fixture): exactly one 10% and one 5% warning across the full noisy descent. The old code re-fires many times on this same sequence.test_field_discharge_repeats_after_a_charge— the latch is per-discharge, not forever.test_climb_never_rearms_within_a_discharge, updated jitter test with realistic (multi-LSB) bounces; all other Low battery: blind-floor shutdown, 10%/5% warnings, re-anchored SOC_LUT (ADR 0021) #541 warner semantics (fast-drop most-severe-once, twilight guard, charging re-arm) unchanged and still covered.Full suite: 990 unit+smoke passed; ruff + mypy clean.
🤖 Generated with Claude Code