A slow cycle acts on the time it started: a charge slot that begins during a 10-minute restart cycle is planned but not started
Opened by Claude on behalf of @chalfontchubby.
Summary: Predbat reads the clock once, at the start of each cycle, and acts on that time at the end. A normal cycle takes under a minute, so this doesn't matter. The first cycle after a restart takes 10–12 minutes, though. If a charge slot starts while that cycle is running, Predbat plans the slot correctly, still believes it is before the slot, and doesn't start the charge. The charge then waits for the next cycle. On one Intelligent Octopus Go install this morning, an add-on update and two apps.yaml edits cost 21 minutes of a 60-minute car slot, and a battery charge that should have started at 09:00 started at 09:21.
What happened (25 Nov 2026, Sigenergy, Intelligent Octopus Go, v9.10.0 plus a work-in-progress branch)
Octopus had published two dispatches, 09:00–09:30 and 09:30–10:00. From the add-on log:
| Time | Event |
|---|---|
| 08:52:00 | Restart (an update of the code, plus an apps.yaml edit) |
| 08:55:33 – 08:58:53 | Charge rate grid: 28 days of history re-read (3.3 min) |
| 08:58:56 – 09:02:34 | Discharge rate grid: 28 days re-read (3.6 min) |
| 09:02:42 | Plan finished, with a charge in 09:00–10:00 to 100% |
| 09:02:47 | Inverter 0 configuring charge window now (now 11-25 08:50:00 ... – execution still uses the cycle's start time |
| 09:03:09 | Completed run status Demand. The window was written, but the inverter was left in Demand because "now" was 08:50 |
| 09:03:09 | Stopping: apps.yaml had been edited again at 08:59 and 09:00 |
| 09:09:04 | Started again |
| 09:21:15 | Completed run status Charging, Hold for car. The battery charges at last |
So the two restarts cost about 30 minutes between them (08:52–09:21). Twenty-one of those minutes were inside the slot. Had execution checked the clock at 09:02, the charge would have started then, and the loss would have been about 3 minutes plus the second restart.
Why
plan_once() calls update_time() once at the start of the cycle (predbat.py, self.update_time(now=plan_at)). Fetch, plan and execute_plan() all use the minutes_now it sets. execute_plan() decides whether a charge or export window is active by comparing the window with minutes_now, so after a long cycle that decision is as old as the cycle.
Possible fixes
- Before
execute_plan(), notice that the clock has crossed a window boundary since the cycle started (or simply that the cycle took more than a few minutes), and run a quick replan before executing. The plan's arrays are indexed fromminutes_now, so moving the clock forward under an existing plan is not safe on its own. - Or, after a cycle that took longer than the 5-minute run interval, start the next cycle straight away instead of waiting for the next aligned run time.
Option 2 is the smaller change. Either one bounds the loss at one quick cycle rather than one slow cycle.
Related
- #6287 / PR #6307: the 28-day rate grid re-read on restart, about 7 of the 12 minutes here.
- #6308: long history reads and ML training inside the cycle.
Those make the first cycle shorter. This issue is about what the cycle does when it is long anyway: on a first install, after a rating or config change, or when a forced full re-read is needed.
🤖 Generated with Claude Code
Automated first-pass triage — a maintainer will review before any action is taken.
Type: bug · Priority: medium (labels already present; kept as they are)
The bug: execute_plan() decides whether a charge or export window is active from minutes_now, which plan_once() set from the clock at the start of the cycle and nothing refreshes before execution. A cycle that overruns a window boundary therefore plans the slot correctly, then executes against a pre-slot time and leaves the inverter out of the window.
What I checked, against main (a21a5143, v9.10.0-7-g)
The mechanism is exactly as described, and it is a property of the code rather than of this install:
plan_once()callsself.update_time(now=plan_at)once, at the top (apps/predbat/predbat.py:1473).update_pred()then callsexecute_once()→execute_plan()with no further clock read (predbat.py:1610);execute_once()re-fetches the inverter data "as time passes during calculations" but not the clock.- Every window decision in
execute_plan()is onself.minutes_now: the alert/manual-SoC lookups (apps/predbat/execute.py:712-714), the charge-window tests (execute.py:860,883,888), the target-SoC charge test (execute.py:1114), the discharge/export tests (execute.py:1131,1172). Your log line isexecute.py:1059. - Two contributions to the staleness, worth separating: (a)
update_time()roundsnow_utcdown toPREDICT_STEP(predbat.py:871), so even an instant cycle acts on a clock up to ~5 minutes behind, which is inherent to the plan's indexing and not a defect; (b) the elapsed cycle time on top of it, which is the 10–12 minutes here. - Nothing bounds the gap after the overrun either. The next run is the next aligned 5-minute boundary (
next_aligned_run()thenrun_every,predbat.py:2647-2655), and the 15-second loop cannot cover it: while a cycle runsprediction_startedis True, so its polls are skipped, and afterwards it only runs the dynamic-load/car and Octopus-cap polls — a full update comes only fromrun_time_loop().
No duplicate found. Related, and both shorten the first cycle rather than this behaviour: #6287 / PR #6307 (28-day rate grid re-read on restart) and #6308 (long history reads inside the cycle). #6352 (merged, planner ~27% faster) helps only in proportion.
On the two suggested fixes
Option 2 (start the next cycle immediately after an overrun) is the smaller change and is worth having, but on its own it does not bound the loss to one quick cycle: the overrunning cycle still executes on its stale clock and still misses the slot, so the charge starts one cycle later than it otherwise would — the difference is only that "one cycle later" becomes ~1 minute instead of up to 5.
Option 1 is the one that actually starts the slot in the same cycle, and the caution in the issue is right: charge_*_best, export_*_best and the *_keep arrays are indexed from minutes_now, so the clock cannot be moved under an existing plan. The narrow form of it is a re-plan, not a re-time: before execute_plan(), re-read the wall clock, and if it has crossed a PREDICT_STEP boundary beyond some threshold (or the cycle exceeded RUN_EVERY), call calculate_plan(recompute=True) and then execute — which is close to what update_pred() already does in its late-recompute branch for an ageing plan, just triggered by a long cycle as well as by plan age. A maintainer should decide the threshold and whether the extra re-plan is always worth it, since every overrunning cycle would then pay for two plans.
I did not run a test: no test module covers this, and what the code does here is settled by reading it. I also did not have your predbat.log / predbat_debug.yaml — the diagnosis does not depend on them, but if you can attach both (the debug yaml from the Debug panel and the log covering 08:52–09:21) a maintainer can replay the runs and confirm timings before changing anything.
Bot - option 1