Skip to content

fix(ocpp): take up a running 1.6 transaction after a Core restart - #1787

Merged
frahlg merged 3 commits into
masterfrom
fix/ocpp-resume-transaction
Oct 28, 2026
Merged

frahlg merged 3 commits into
masterfrom
fix/ocpp-resume-transaction

Conversation

@frahlg

@frahlg frahlg commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Item E1 of the stable plan (27 Oct 2026). OCPP 1.6 only; 2.0.1 Updated and Ended follow in a separate PR.

Problem

Core restarts on every update. An OCPP 1.6 charger keeps its transaction through the restart and goes on naming it in MeterValues. Core started every charger with no transaction (transactionID −1) and handed out ids from 1 again. For a session that spans a restart:

  • session_wh stayed at 0 until unplug, because OnMeterValues counts energy only while a transaction is known. Rig s7-25 with fix(loadpoint): Charge now keeps charging after a restart #1778 ended with ev_session_wh 0 while the car drew 11 kW.
  • The stop computed MeterStop − 0, the charger's lifetime register. Example: a car on transaction 42 finishes at a register of 12,345,678 Wh; Core reported a 12.3 MWh session to the loadpoint, the UI, the cloud link and the ev_session_wh metric.
  • A new transaction could get id 1 while another charger still held 1.
  • A stop naming any id ended the running transaction. With transaction 1 running at 2 kWh, a stop for id 999 with MeterStop 9,000,000 set transactionID to −1, charging to false and session_wh to 8,999,000.
  • strconv.ParseFloat accepts "NaN" and "Inf". Taken up as the start reading, one would spoil every later session value, and pushReading cannot marshal a non-finite value (Codex P2 on this PR).

Change

All in go/internal/ocpp/handlers.go:

  • The first MeterValues that names a transaction while none is known takes it up. Energy counts from that reading. A transaction the charger already stopped is not taken up again.
  • A stop for a transaction Core never saw keeps session_wh and records no ev_session_wh metric. It still ends charging and clears measured power as before.
  • A stop that names another id than the running transaction is logged and confirmed, and changes nothing. Status notifications still drive charging and connected.
  • MeterValues skips a sampled value that is NaN or ±Inf.
  • Transaction ids start at the seconds since 1 January 2026, so a restart starts above the last run's ids, and ids stay far inside 32 bits. A taken-up id also moves the next id past it.

What this does not fix

  • Energy from before the restart is still lost; the start reading lived only in the old process.
  • FTW's saved last order (restoreOffers) is still not restored for OCPP.
  • OCPP 2.0.1 has the same gap in OnTransactionEvent. It comes next.

Tests

  • transaction_resume_test.go: eight tests. The take-up, unseen-stop, id and lifetime-register tests fail on master. TestOCPP16StopForAnotherTransactionKeepsTheRunningOne and TestOCPP16NonFiniteRegisterIsNotTakenUp fail on this PR's previous head and pass now. The last two are the audit's repro tests (TestReproStopNotMatchedToTransaction, TestReproRestartStop16ReportsLifetimeRegister) under normal names.
  • cd go && go test -race ./internal/ocpp/... -count=1: ok.
  • go vet ./... and go build ./...: ok.
  • Rig s7-25 on the earlier head (20 s Core restart while Charge now runs): without this change ev_session_wh read 0 after the restart; with it the log says OCPP running transaction taken up txid=25371034 meter_wh=3337 and ev_session_wh counts again. Rig R4 in the stable plan covers it on this head.

Risk

Low. Nothing here touches dispatch, fuse math, signs or the command path. The one new state rule keeps a running transaction when a stop names another id. If a charger sends a wrong id for the real stop, Core keeps the transaction id until the next StartTransaction replaces it, and that session records no ev_session_wh metric. charging, connected and measured power still follow the status notifications and meter values, so control sees the car stop.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-27T13:26:03.741882Z 92230c0 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.

@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: 89f2cceea6

ℹ️ 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 +609 to +610
s.transactionID = txID
s.sessionStartMeterWh = meterWh

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 Reject non-finite readings before adopting a transaction

If the first energy register received after restart contains "NaN" or "Inf", strconv.ParseFloat accepts it without an error, and this assignment permanently stores a non-finite session baseline. Every subsequent valid reading then produces non-finite session energy, and pushReading cannot marshal its telemetry payload because JSON rejects these values. Unlike a bad sample during an ordinarily started transaction, later valid samples cannot recover this session. Check that the converted meter reading is finite before adopting the transaction so a later valid reading can establish its baseline.

Useful? React with 👍 / 👎.

@frahlg
frahlg marked this pull request as draft October 21, 2026 16:20
@frahlg
frahlg force-pushed the fix/ocpp-resume-transaction branch from 89f2cce to f5ca0f6 Compare October 21, 2026 16:23
frahlg and others added 2 commits October 27, 2026 14:21
A charger keeps its transaction while Core restarts and keeps naming it in
MeterValues. Core started every charger with no transaction, so session
energy stayed at 0 until unplug and the stop reported the lifetime meter
total. Take the transaction up from its first meter value, count energy
from that reading, and start transaction ids from the clock so a restart
does not hand out an id a charger still holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eter readings

A stop that names another transaction than the running one, such as a
queued stop from before a restart, ended the running transaction and
took MeterStop as its session energy. Keep the running one and confirm
the stop. ParseFloat accepts NaN and Inf; taken up as the start reading
of a resumed transaction, one spoiled every later session value. Skip
non-finite sampled values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg force-pushed the fix/ocpp-resume-transaction branch from f5ca0f6 to 92230c0 Compare October 27, 2026 13:24
@frahlg
frahlg marked this pull request as ready for review October 27, 2026 13:24
frahlg added a commit that referenced this pull request Oct 28, 2026
Start sets the settle wait next to bootLimit instead of in NewHandler,
which keeps this branch from touching the line #1787 changes there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frahlg added a commit that referenced this pull request Oct 28, 2026
After a Core restart a two-socket 1.6 charger may report socket 1
Available and then send socket 2's meter values for its running
transaction before socket 2's status. Without #1787 FTW holds no
transaction id then, so the 0 A start limit went to the whole charger
and paused that car. A 1.6 meter value that names a transaction or
measures power above zero now cancels the pending limit, as a status
with a car does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg merged commit f427f21 into master Oct 28, 2026
23 checks passed
frahlg added a commit that referenced this pull request Oct 28, 2026
* fix(ocpp): a managed charger starts at 0 A on boot

Until FTW's first order lands, an OCPP charger runs at its own default,
usually its rating. In random rig seed 207534 the charger booted at
5.0 s, a car plugged in at 7.3 s and drew 11040 W from 10 s until FTW's
first 0 A took effect at 13.5 s, with 18.9 A on a 16 A fuse.

On BootNotification (1.6 and 2.0.1) from a charger a loadpoint names,
send the same 0 A TxDefaultProfile FTW sends to pause: profile id 1,
stack level 0, connector or EVSE 0, with the usual connector-1 retry.
FTW's first order has the same id, purpose and stack level, so it
replaces the boot profile.

Skip chargers listed only under ocpp.chargers (FTW never orders them),
pending chargers, a boot that answers FTW's own identity probe, and a
boot on a socket that already reported a car. A refusal is logged once
and not retried until the next boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ocpp): no start limit in measurement mode or mid-session reconnect

Setup measurement mode blocks every charger write, standdowns included.
The boot limit went straight to setLimit, so a charger named by a
loadpoint saved during setup got 0 A and kept it until restart. Both
the start and the hot-reload paths now pass no managed chargers while
Core runs in the mode it booted in.

Much firmware sends its own BootNotification on every reconnect. The
car guard read only the new socket, so a Wi-Fi drop mid-session paused
the car. The guard now reads the last status FTW holds, which survives
the reconnect, and any open transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ocpp): wait for a status before the 0 A start limit

Rig s7s-restart-short-25A failed twice on 964643e: after a Core
restart the charger sent its own BootNotification at once, the new
process held no status or transaction, and FTW sent the 0 A start
limit mid Charge now. The car went to SuspendedEVSE for a second.

A boot now only marks the charger. The first connector status after it
decides: no car and no transaction sends the 0 A limit; a car sends
nothing. Connector 0 Available on 1.6 does not decide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ocpp): start limit waits for every socket's status

The 0 A start limit goes to connector or EVSE 0, the whole charger. It
went out on the first connector status after a boot that showed no car.
On a two-socket 1.6 charger or a two-EVSE 2.0.1 station, a Core restart
while a car charged on socket 2 sent 0 A as soon as socket 1 reported
Available, and paused that car.

FTW now waits until the statuses after the boot have been quiet for one
second. Any status that shows a car or a transaction cancels the limit
as it arrives, since the last status wins in FTW's one state per
charger. An order from FTW during the wait also cancels it, so the 0 A
cannot land after that order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(ocpp): set the boot-limit wait beside the boot-limit sender

Start sets the settle wait next to bootLimit instead of in NewHandler,
which keeps this branch from touching the line #1787 changes there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ocpp): meter values showing a car cancel the start limit

After a Core restart a two-socket 1.6 charger may report socket 1
Available and then send socket 2's meter values for its running
transaction before socket 2's status. Without #1787 FTW holds no
transaction id then, so the 0 A start limit went to the whole charger
and paused that car. A 1.6 meter value that names a transaction or
measures power above zero now cancels the pending limit, as a status
with a car does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

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