Skip to content

fix(history): derive household Load from interval source energy - #1741

Merged
frahlg merged 2 commits into
masterfrom
codex/history-source-load-20261018
Oct 18, 2026
Merged

frahlg merged 2 commits into
masterfrom
codex/history-source-load-20261018

Conversation

@frahlg

@frahlg frahlg commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

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.

  • Keep negative source intervals until the requested interval sums. Complete chart intervals can contain a negative minute; an invalid whole interval stays unknown.
  • Preserve missing sources, writer gaps, process stops, settings changes and hardware identity changes. Distinguish measured zero from missing data.
  • Keep older history and rollback writer periods separate. Do not retrofit old gaps using today's topology.
  • Copy and verify source tables in backup/restore, retain additive source totals, and gate RAM/durable day caches on committed progress. Keep signed V2X energy separate from EV charging cost.

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 verify and targeted race checks pass on exact head 01cc8e3d02b5b39c331d016a8db5125579ad38c6, 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.

@frahlg
frahlg marked this pull request as ready for review October 18, 2026 19:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T19:06:16.886421Z 01cc8e3 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit f3f6100 into master Oct 18, 2026
23 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +82 to +83
if sourceTables != 0 && sourceTables != 3 {
return errors.New("incomplete history source tables; restore a verified full backup")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant