Skip to content

fix(2.0.1): close CSMS-deauthorized transactions - Ended was sent without triggerReason - #462

Open
kaizen8501 wants to merge 1 commit into
matth-x:mainfrom
kaizen8501:fix/v201-deauthorized-ended-triggerreason
Open

kaizen8501 wants to merge 1 commit into
matth-x:mainfrom
kaizen8501:fix/v201-deauthorized-ended-triggerreason

Conversation

@kaizen8501

Copy link
Copy Markdown

Summary

When the CSMS deauthorizes a running OCPP 2.0.1 transaction (the Started TransactionEvent response carries an idTokenInfo.status other than Accepted), MicroOcpp builds the Ended TransactionEvent without a triggerReason. triggerReason is a required property in the 2.0.1 schema, so a conformant CSMS rejects the TransactionEvent with CallError FormatViolation ("must have required property 'triggerReason'") and rejects every retry identically. The transaction can never be closed: it stays Active on the CSMS and its record is never trimmed on the device, so the per-connector transaction store fills up (MO_TXRECORD_SIZE) and beginTransaction() then refuses to start new transactions on that connector.

There are two linked defects. Fixing the first resolves the user-visible problem; the second is a latent asymmetry fixed defensively.

1. Ended built with triggerReason = UNDEFINED (TransactionService.cpp)

TransactionEvent::processConf() ends a deauthorized transaction by clearing transaction->active directly, without going through Evse::endTransaction() — the only place that records stopTrigger/stoppedReason. On the next Evse::loop(), the "stop running tx" branch (started && !stopped && !active) builds the Ended event with the local triggerReason still UNDEFINED. The serializer maps UNDEFINED to nullptr and createReq() omits the field.

Fix: before committing the Ended event, if triggerReason / stoppedReason are still UNDEFINED, fill them from the transaction state: Deauthorized / DeAuthorized when transaction->isDeauthorized, else AbnormalCondition / Other. This mirrors the existing dedicated deauthorization stop-point, which cannot fire here because active was already cleared out from under it.

2. triggerReason flash round-trip asymmetry (TransactionStore.cpp)

deserializeTransactionEvent() defaults a missing triggerReason to the sentinel string "_Undefined":

deserializeTransactionEventTriggerReason(txEventJson["triggerReason"] | "_Undefined", triggerReason)

deserializeTransactionEventTriggerReason() does not recognize "_Undefined" and returns false, so the whole event fails to deserialize and the send queue stalls at the front. The sibling stopTrigger read a few lines above already uses (const char*)nullptr, which maps an absent field to UNDEFINED cleanly — this read is the only one using the bad sentinel.

Fix: use | (const char*)nullptr to match the stopTrigger read, so an absent triggerReason reads back as UNDEFINED instead of failing.

Reproduction

  • CSMS: CitrineOS 2.0.0-beta3 endpoint that answers the Started TransactionEvent with an idTokenInfo.status other than Accepted.
  • Device: ESP32 (ESP-IDF) client, MO_ENABLE_V201=1.
  • Start a transaction with an idToken the CSMS does not accept; observe the Ended TransactionEvent on the wire has no triggerReason, the CSMS returns FormatViolation, and after MO_TXRECORD_SIZE such cycles new transactions on the connector fail to start.

Testing

On real hardware over 6 consecutive deauthorized start/stop cycles after the fix: deserialization error 0, serialization error 0, transaction queue full 0, CSMS FormatViolation 0, every Ended carries triggerReason:"Deauthorized", all events confirmed, and every cycle ends with the connector Idle (record freed).

…hout triggerReason

When the CSMS deauthorizes a running 2.0.1 transaction (the Started
TransactionEvent response carries an idTokenInfo.status other than
Accepted), the Ended TransactionEvent was built with triggerReason
UNDEFINED. triggerReason is required by the 2.0.1 schema, so a conformant
CSMS rejects it with CallError FormatViolation and rejects every retry
identically: the transaction can never be closed, stays Active on the CSMS,
and its on-device record is never trimmed, eventually filling the
per-connector store (MO_TXRECORD_SIZE) so beginTransaction() refuses new
transactions.

Two linked defects:

1. TransactionService.cpp: TransactionEvent::processConf() ends a
   deauthorized transaction by clearing `active` directly, bypassing
   Evse::endTransaction() (the only place that records stopTrigger). The
   following Evse::loop() then builds the Ended event with the local
   triggerReason still UNDEFINED. Fill a valid reason before committing the
   event: Deauthorized/DeAuthorized when isDeauthorized, else
   AbnormalCondition/Other.

2. TransactionStore.cpp: deserializeTransactionEvent() defaulted a missing
   triggerReason to the sentinel "_Undefined", which
   deserializeTransactionEventTriggerReason() rejects, failing the whole
   event and stalling the send queue. Use (const char*)nullptr to match the
   sibling stopTrigger read, so an absent field reads back as UNDEFINED.

Reproduced on ESP32 (ESP-IDF, MO_ENABLE_V201=1) against CitrineOS
2.0.0-beta3; verified over 6 consecutive deauthorized cycles (0
FormatViolation, every Ended carries triggerReason, store freed each cycle).

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

This branch has not been deployed

No deployments
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.

2 participants