Incorrect battery charge display in Gnome

I’ve found that gnome often displays a low charge level (7-8%) on my laptop even though the battery seems to be fully charged (the charging light appears green rather than orange).

Here’s what the Gnome battery display looks like:

Screenshot from 2022-07-15 12-20-33

Computer is a late 2013 MacBook Air; battery is a replacement battery manufactured by ifixit.

Charge levels in /sys/class/power_supply/BAT0 reflect a fully charged battery:

[jhaiduce@picard ~]$ cat /sys/class/power_supply/BAT0/charge_now
5062000
[jhaiduce@picard ~]$ $ cat /sys/class/power_supply/BAT0/charge_full
5071000

Also, when I disconnect the battery Gnome warns “Battery low; approximately 3 hours 48 minutes remaining (8%)” (the reported time remaining varies, but it tends to reflect the actual charge level rather than the supposed low battery condition):

Screenshot from 2022-07-15 12-21-05

If I continue using the computer on battery power, Gnome forces a shutdown once the charge displayed charge level gets down to 1% or so, even though in reality a significant amount of charge remains on the battery.

The problem goes away when the system is rebooted, but recurs after a few hours of use following each reboot.

I’m fairly convinced this is a bug, but not sure whether it should be filed against gnome-shell or some other component, and also wondering if there is more information I can provide to help others reproduce this.

It seems to me a problem with the calibration of the battery charge on the replacement battery.

The solution I have seen that sometimes works is to force an almost complete discharge of the battery then with it installed do a full charge followed by several episodes of full charge and then run it on battery until it shuts down each time so the calibration is forced.

The discharge may require removal of the battery and discharge with it removed from the laptop.
It also may be done by a boot, then running it until it shuts down several times in a row before recharging.

I thought that might be the case at first, but /sys/class/power_supply/BAT0/charge_now shows a value that’s consistent with a full charge (it’s 99.8% of the value in /sys/class/power_supply/BAT0/charge_full). And /sys/class/power_supply/BAT0/capacity is 105. So it looks like the kernel has the correct battery state info, but Gnome is misinterpreting it.