Repository navigation
fix(history): derive household Load from interval source energy - #1741
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01cc8e3d02
ℹ️ 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".
| if sourceTables != 0 && sourceTables != 3 { | ||
| return errors.New("incomplete history source tables; restore a verified full backup") |
There was a problem hiding this comment.
Allow interrupted source-schema creation to resume
If the process or host stops during the first upgrade after one or two of the three new source tables have been created, ensureHistorySchema has committed those CREATE TABLE statements separately. On every subsequent startup this pre-schema check sees a partial set and aborts before the remaining CREATE TABLE IF NOT EXISTS statements can run, unnecessarily making Core unrecoverable without restoring a backup. Create the related tables transactionally or distinguish an interrupted additive migration from a genuinely incomplete restored dataset.
AGENTS.md reference: AGENTS.md:L24-L25
Useful? React with 👍 / 👎.
* fix(history): bridge short source gaps instead of losing the day's Home use Since #1741 a Core restart (18-20 s), a source unknown for a few seconds or a writer pause over 15 s made the whole day's load_wh null, and an unknown PV also nulled pv_wh. The source writer now holds an episode that starts at the last fully known snapshot. If every source is known again with the same topology within LoadEstimateRecoveryWindow (2 min), the episode is written as an estimate marked EstimatedLoad: measured sources keep their snapshots, unknown ones hold the anchor's values. Otherwise it is written exactly as before. Pending time stays out of totals and expected coverage, and the day waits for it before closing. On open Core marks the cursor as stopped instead of deleting it, so a brief stop is bridged as an estimate and a longer one starts a new period as before. Older Cores still delete the cursor on open. Relates to #1750. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(history): forgiving Home use display, strict marker for training Follows Fredrik's two-layer direction (19 October). Display is forgiving: an unknown PV, battery or EV source holds its last known value; the site meter, a writer pause or a restart holds for at most two minutes; a topology change no longer stops integration. A day's flow is unknown only when it is unknown or unrecorded for more than a tenth of the range. Only two fully measured snapshots a safe tick apart, of one topology and one process, make a measured interval. Every other interval keeps EstimatedLoad, and quarter-hour retention now keeps that bit, so the training layer can skip it. Replaces the pending episodes of the first version. Closed source-era days cached under the old rule are recomputed once. Relates to #1750. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(history): stop holding a source that would make the house negative A held value that turns the household residual negative cannot be right: the source changed while unknown, such as a charger that finished. That interval leaves the held flows unknown instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(history): a failed source leaves only its own flow unknown historySources set MissingLoad for every reason except invalid_balance. Telemetry puts a source's own failure there too, such as "offline:sma:pv" or "stale:easee:ev", so a real snapshot with a silent inverter or charger voided the whole balance and the source writer held nothing. Only configuration and duplicate-flow reasons now set MissingLoad; a failed source is unknown on its own flag. Found by the #1755 session through historySources. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Recorded household Load depended on a valid instantaneous balance, so different meter and charger reporting times could erase otherwise usable history. The app's consumer ledger and the web/day readers also followed different paths.
Core now stores independently qualified source energy in common UTC minutes and balances signed energy over the requested chart, day or price interval. App and web use the same historical Load. Live display, forecast qualification and hardware control keep their current behavior.
Validation: the original reporting-cadence regression failed before the change. Targeted SQLite, native-history and same-server API regressions pass, including negative-minute cancellation, zero/missing, restart, timestamp origin, method transitions, V2X, query truncation, tariffs, midnight cache, retention and full backup/restore. Full
make verifyand targeted race checks pass on exact head01cc8e3d02b5b39c331d016a8db5125579ad38c6, including the merged MCP base. A local OCPP listener timed out while full and race suites overlapped; the unchanged test passed three isolated runs and the full suite then passed alone. GitHub CI is green on the same exact head: 19 successful checks and four intentional skips. No formal GitHub review is claimed; the owner authorized beta fast-track after green CI.This is receipt-integrated source energy, not an exact correction of device clocks. Normal rollback keeps the source tables in the database, but an older Core's portable backup does not know these new tables; use the matching new helper for exports. No general migration or stable qualification is claimed.