Skip to content

fix(mpc): preserve charging periods across replans - #1344

Merged
frahlg merged 2 commits into
masterfrom
fix/planned-charging-periods
Sep 22, 2026
Merged

frahlg merged 2 commits into
masterfrom
fix/planned-charging-periods

Conversation

@frahlg

@frahlg frahlg commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Charging plans need to preserve an ongoing charge across replans and use useful periods at the charger's allowed current steps. Core now passes fresh observed charging duration to workers that advertise charging_periods. An observation gap, missing power or disconnect clears that history. Older workers receive the existing request.

The default favors periods of at least five minutes after departure energy and physical reserves, with a five-ore preference cost for an extra start. A final top-up may be shorter, and a time-limited plan may retain a short period when needed. The preference does not enter the electricity bill or override safety, manual control or the energy budget.

This pins compiled Energyplan 0.4.8 workers from private source commit c544d89277fc6a4e013a0b09867582e39b6115c0. Only compiled workers, their existing licenses and public integration metadata are included. Paired private change: srcfl/energyplan#40, stacked on its existing pre-beta fixes.

Validation:

  • Full make verify passed on macOS with Bash 5, including bundled-worker, forecast, timeout, invalid-plan and fallback tests. One run hit SQLITE_BUSY in the existing archive-resume test; three focused reruns and the full rerun passed.
  • New tests check fresh/stale charging, source cadence, observation gaps, disconnects, unknown or changed connection proof, reloads, request negotiation across worker changes, invalid preferences and a real worker continuing the measured run.
  • The exact ARM64 worker passed 277 private stress cases, 28 comparison cases and charging/replan simulations on an isolated Raspberry Pi 4. Private simulations also exercised Core's actual controller with five-second telemetry. This is not physical charger validation.

main.go has file overlap with #1003. This PR changes only loadpoint-spec creation; #1003 changes Modbus startup. Preserve those changes and recheck the base when either lands. No reviewers were requested. No merge or beta release is included.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-09-22T15:13:56.316964Z 80c4cb1 PR opened
ℹ️ 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.

@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: 80c4cb1d90

ℹ️ 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 changed {
lp.chargingPeriodSince = time.Time{}
}
observeChargingPeriod(lp, sample, m.now())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear charging history when connection proof is lost

When Controller.tickOne receives ConnectionUnknown, it calls observeConnectionProof and returns before reaching this observation, but that path never clears chargingPeriodSince, powerAt, or the cached power. A replan during the remaining power-freshness window therefore reports InitialCharging=true, and a fresh sample after a brief reconnect can continue the pre-gap duration, even though the socket gap means uninterrupted charging was not observed. Clear the charging-period evidence when connection proof becomes unknown or changes.

AGENTS.md reference: AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

@frahlg
frahlg merged commit 6855d85 into master Sep 22, 2026
16 checks passed
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