Repository navigation
fix(2.0.1): close CSMS-deauthorized transactions - Ended was sent without triggerReason - #462
Open
kaizen8501 wants to merge 1 commit into
Open
kaizen8501 wants to merge 1 commit into
kaizen8501 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the CSMS deauthorizes a running OCPP 2.0.1 transaction (the Started
TransactionEventresponse carries anidTokenInfo.statusother thanAccepted), MicroOcpp builds theEndedTransactionEventwithout atriggerReason.triggerReasonis a required property in the 2.0.1 schema, so a conformant CSMS rejects theTransactionEventwithCallError FormatViolation ("must have required property 'triggerReason'")and rejects every retry identically. The transaction can never be closed: it staysActiveon the CSMS and its record is never trimmed on the device, so the per-connector transaction store fills up (MO_TXRECORD_SIZE) andbeginTransaction()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.
Endedbuilt withtriggerReason = UNDEFINED(TransactionService.cpp)TransactionEvent::processConf()ends a deauthorized transaction by clearingtransaction->activedirectly, without going throughEvse::endTransaction()— the only place that recordsstopTrigger/stoppedReason. On the nextEvse::loop(), the "stop running tx" branch (started && !stopped && !active) builds theEndedevent with the localtriggerReasonstillUNDEFINED. The serializer mapsUNDEFINEDtonullptrandcreateReq()omits the field.Fix: before committing the
Endedevent, iftriggerReason/stoppedReasonare stillUNDEFINED, fill them from the transaction state:Deauthorized/DeAuthorizedwhentransaction->isDeauthorized, elseAbnormalCondition/Other. This mirrors the existing dedicated deauthorization stop-point, which cannot fire here becauseactivewas already cleared out from under it.2.
triggerReasonflash round-trip asymmetry (TransactionStore.cpp)deserializeTransactionEvent()defaults a missingtriggerReasonto the sentinel string"_Undefined":deserializeTransactionEventTriggerReason()does not recognize"_Undefined"and returnsfalse, so the whole event fails to deserialize and the send queue stalls at the front. The siblingstopTriggerread a few lines above already uses(const char*)nullptr, which maps an absent field toUNDEFINEDcleanly — this read is the only one using the bad sentinel.Fix: use
| (const char*)nullptrto match thestopTriggerread, so an absenttriggerReasonreads back asUNDEFINEDinstead of failing.Reproduction
TransactionEventwith anidTokenInfo.statusother thanAccepted.MO_ENABLE_V201=1.EndedTransactionEventon the wire has notriggerReason, the CSMS returnsFormatViolation, and afterMO_TXRECORD_SIZEsuch cycles new transactions on the connector fail to start.Testing
On real hardware over 6 consecutive deauthorized start/stop cycles after the fix:
deserialization error0,serialization error0,transaction queue full0, CSMSFormatViolation0, everyEndedcarriestriggerReason:"Deauthorized", all events confirmed, and every cycle ends with the connectorIdle(record freed).