Repository navigation
fix(replay): log the learned rate grids and the battery temperature forecast the plan reads - #6243
chalfontchubby wants to merge 3 commits into
Conversation
…orecast the plan reads Since #6212 the plan reads each step's charge and discharge ceilings from the rate grids, by that step's forecast battery temperature. Neither reached the log, so a forward replay kept the yaml's learned grids through the daily refit and held the yaml's temperature forecast (minutes from its own moment) still while the clock moved on. - "Replay input: rate grids learned changed {...}": both learned grids on a change, rows as runs; zero_row is derived on read as fit_rate_grid does. - "Replay input: battery temperature forecast changed, whole degrees ...": the whole degree rate_grid_curve reads at each step (the plan reads the forecast only through it, so degrees plan exactly as readings), written only when moving the last line on to now would not give the live forecast. - The replay applies both, carries them past dropped runs and across midnight, and moves the yaml's own forecast on with the clock until the first line. - The two replay signatures are left out of debug dumps. PV calibration (#6231/#6233) needs nothing: the PV line already logs the calibrated forecast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… compared over their own length Review follow-ups: the rate-grid change check compares the learned grid objects instead of encoding both grids every cycle; a battery temperature forecast shorter than the horizon no longer logs a line every cycle; the replay's temperature line is set only once there are runs to replay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Reviewed 68841aaa against main. No correctness defects found: 1 inline finding (low, documentation), none in this body.
What I checked, and why I believe the design holds:
- Degrees plan as readings.
battery_temperature_predictionhas only two consumers -Prediction.run_prediction()and the kernel mirror inprediction_kernel.py- and both reach it only throughrate_curves()->rate_grid_curve(), which appliesgrid_temperature_index()itself. So the exact-0 branch (zero_row), the -1..1 non-zero mapping to +/-1, and the clamping past both ends of the grid all agree on both sides. The new equivalence test coversNone, manual-only, combined and single-row grids across both ends of the range. - The logged grids can reach the plan. Every
Predictiontakes its grids frombase.rate_grids(), which rebuilds when the learned object identity changes;apply_logged_rate_grids()installs new objects, so the install is not dead state. The "grids are replaced, never mutated" premise the signature comparison relies on holds at the one place they are assigned (battery_rate_grid_learned[kind] = learned). - Ordering in the live loop.
log_replay_rate_grids()runs afterfetch_inverter_data()(which performs the refit) and before the plan, so the logged grids are the ones that cycle planned with. The temperature logger readsbattery_temperature_predictionafterfetch_sensor_data()refreshed it. - Carry, dropped runs and midnight. Both new stores are keyed on
is not None, so a logged{"charge": None, "discharge": None}and an emptied[]forecast propagate (they are changes, not absences).roll_over_midnight()shiftsreplay_temperature_lineandapply_run()re-anchors a carried line by at most one day; bothstartvalues derive fromminutes_now, whichupdate_time()rounds to a multiple ofPREDICT_STEP, soshift_grid_temperatures()' floor division is always exact rather than approximate. replay_clock()rendersmidnight_utc + minutes_now, andminutes_nowis recomputed against a midnight carrying the current offset, so the loggedHH:MMround-trips on ordinary days; the clocks-back case is the one the PR body already calls out.- Debug dump. Both new attributes are in
DEBUG_EXCLUDE_LIST, and both needed to be (one holds references to the learned grids). - Tests are red without the change (the helpers and appliers do not exist on
main), and they cover midnight, a dropped run, a carried line, a short forecast and an emptied one. Both runners were already registered inTEST_REGISTRY.
| if degrees and shift_grid_temperatures(logged[2], self.minutes_now - logged[1], len(degrees) * PREDICT_STEP, PREDICT_STEP) == current: | ||
| return | ||
| self.replay_temperature_logged = (self.midnight_utc, self.minutes_now, degrees) | ||
| self.log("Replay input: battery temperature forecast changed, whole degrees every {} minutes from {} {}".format(PREDICT_STEP, self.replay_clock(self.minutes_now), value_runs(degrees))) |
There was a problem hiding this comment.
Automated comment from the triage bot.
This is the only Replay input: ... changed line that does not go through log_replay_changed(), and it can repeat many times in a day - which makes tools/debug-journal.md's documented rule ("the signature includes midnight_utc, so each line logs once a day at most") wrong for it.
log_replay_changed() puts midnight_utc in the signature, so rates, sessions, dispatches, cars, inverter state and the new rate grids are all content-signature compared and forced to re-log once per day. This one instead content-compares the shifted previous line against the current forecast. That is required for the suppression to work (a plain signature of degrees would differ every cycle), but it has two consequences worth writing down:
- A repeated line here means "some step's degree differs from the shifted last line", not "the value changed" and not "a new day". A future log reader applying the journal's rule will misread it.
- The shared day-rollover and warn-once behaviour in
log_replay_changed()does not reach this line, so a later fix to either will silently miss it - which is how the journal rule became wrong here in the first place.
Failure scenario: someone triaging a replay mismatch counts hundreds of battery temperature forecast changed lines and concludes the forecast moved materially hundreds of times that day, or treats a repeated line as a midnight boundary and mis-orders the day's runs.
Cheapest fix: amend the journal sentence (and/or this docstring) to say this line is compared against its own shifted predecessor rather than a signature, so unlike every other Replay input: ... changed line it may repeat within a day.
What I could not confirm: the real-world frequency, as I did not run the code. predict_battery_temperature() seeds step 0 from the newest reading with a backward difference (history[0] - history[step]) while later steps use the 24h-ago profile, so consecutive forecasts are not exact shifts; the per-step difference is roughly the size of the recent trend, small while the battery temperature is flat and larger during a warm-up.
Opened by Claude on behalf of @chalfontchubby.
Summary
Forward replay (
tests/replay_forward.py) replans a day ofpredbat.logfrom a debug yaml. Two inputs that the plan now reads were not in the log, so a replay that ran past them planned with different battery ceilings from live:Replay input: rate grids learned changed {...}line is written whenever either grid object is replaced (and once a day). The replay installs it.Replay input: battery temperature forecast changed, whole degrees every 5 minutes from HH:MM [[deg, n], ...]line now records it.rate_grid_curve, which gives a reading and its whole degree the same curve (an exact 0 stays 0). A test checks this across freezing and past both ends of the grid. Logging raw readings would mean a new line nearly every cycle, because the trend moves each step.shift_grid_temperatures) would not give the live forecast, plus once a day. The replay rebuilds each run's forecast with the same function, so the two agree by construction.PV calibration (#6231/#6233) needs no change: it runs upstream in the Solcast component, and the existing PV forecast line already logs the calibrated forecast.
The two "last logged" copies are added to
DEBUG_EXCLUDE_LIST, so they stay out of debug dumps.Testing
./run_all --quickpasses apart fromweb_pv_calibration_chart. That test also fails on unmodifiedmaintoday: test 10 expects2026-11-17 00:00as the next scan and gets03:00, so it depends on the wall clock. It is not touched here.replay_roundtrip_dayanddebug_casespass, and all pre-commit lint hooks pass.Known limit
On the day the clocks go back, a line carried past a dropped run within the repeated hour can be taken for the previous day's. The existing rates and dispatch carry has the same limit.
🤖 Generated with Claude Code