Skip to content

fix(loadpoint): accept newer delayed car charge readings - #1648

Merged
frahlg merged 2 commits into
masterfrom
fix/vehicle-soc-source-time
Oct 15, 2026
Merged

frahlg merged 2 commits into
masterfrom
fix/vehicle-soc-source-time

Conversation

@frahlg

@frahlg frahlg commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

A delayed car reading measured at 10:10 and received at 10:40 made Core reject a later reading measured at 10:20. The first reading's receipt time had become the timestamp that the next car measurement needed to beat.

Keep the measurement time when confirming a vehicle anchor. The public update timestamp still records receipt, and the estimate still includes energy delivered since the measurement. A newer manual correction keeps precedence over older car measurements.

When restart or trimmed history leaves the earlier energy unknown, keep the same raw-SoC fallback that the control loop already used, but retain the measurement time. Only known energy after the reading advances the estimate; unknown earlier energy is not added.

Validation:

  • The new regression fails before the fix and passes after it. It checks two delayed readings, planning SoC, energy counted once, duplicate/older readings, receipt metadata and manual precedence.
  • New recovery tests cover missing history shortly before connection, readings before the connection window, and trimmed history. The missing-history regression fails on the first fix and passes after this follow-up.
  • Full loadpoint, telemetry and API suites passed. An independent agent reviewed the production fallback and reran the time/history/manual tests with no findings.
  • Loadpoint and telemetry race tests passed.
  • make verify passed, including the bundled native worker checks.

This change is independent of the forecast recovery and reserve pricing in #1644.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T17:53:20.581667Z 14e3e47 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: 14e3e47c33

ℹ️ 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 +1164 to +1166
if !observedAt.IsZero() {
// Compare car measurements by source time, not cloud delivery time.
lp.socConfirmedAt = observedAt

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 Preserve source time through the unknown-history fallback

After a mid-session restart, a delayed measurement from before the first retained energy sample makes deliveredAt fail, so go/cmd/ftw/main.go:2986-2987 falls back to AnchorVehicleSoC, which passes a zero timestamp and records the receipt time instead. A later cloud reading that was measured after the first but before that receipt is then rejected by VehicleSoCSupersedes, leaving the ordering bug in place for cold-start/recovery sessions; preserve the original observedAt even when anchoring must fall back to the current energy value.

AGENTS.md reference: AGENTS.md:L24-L25

Useful? React with 👍 / 👎.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg merged commit 9c8436b into master Oct 15, 2026
17 checks passed
frahlg added a commit that referenced this pull request Oct 15, 2026
Master's AnchorVehicleSoCAt now adopts a reading from before the
connection without adding energy. For the session's car a reading from
before the plug-in is the level the session started from, so it seeds
the session with all of its energy. A restored session keeps its real
plug-in time and whether it asked car.which. Master's new anchor-order
test reads the level instead of the removed PlanningStartSoC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frahlg added a commit that referenced this pull request Oct 15, 2026
Master's AnchorVehicleSoCAt now adopts a reading from before the
connection without adding energy. For the session's car a reading from
before the plug-in is the level the session started from, so it seeds
the session with all of its energy. A restored session keeps its real
plug-in time and whether it asked car.which. Master's new anchor-order
test reads the level instead of the removed PlanningStartSoC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frahlg added a commit that referenced this pull request Oct 15, 2026
Master's AnchorVehicleSoCAt now adopts a reading from before the
connection without adding energy. For the session's car a reading from
before the plug-in is the level the session started from, so it seeds
the session with all of its energy. A restored session keeps its real
plug-in time and whether it asked car.which. Master's new anchor-order
test reads the level instead of the removed PlanningStartSoC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frahlg added a commit that referenced this pull request Oct 15, 2026
Master's AnchorVehicleSoCAt now adopts a reading from before the
connection without adding energy. For the session's car a reading from
before the plug-in is the level the session started from, so it seeds
the session with all of its energy. A restored session keeps its real
plug-in time and whether it asked car.which. Master's new anchor-order
test reads the level instead of the removed PlanningStartSoC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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