Repository navigation
fix(ocpp): cross-check OCPP 1.6 trigger cases against per-station lifecycle flags - #1987
Conversation
SummaryThe following content is AI-generated and provides a summary of the pull request: fix(ocpp): cross-check OCPP 1.6 trigger cases against per-station lifecycle flagsPR Checklist
Does this PR introduce a breaking change?
Bug FixThe OCPP 1.6 FixTwo per-station boolean flags are added to
The Key Changes (
|
| # | Region | Change |
|---|---|---|
| 1 | OCPP16StationState interface |
Add diagnosticsUploadInProgress?: boolean and firmwareUpdateInProgress?: boolean |
| 2 | handleRequestTriggerMessage switch cases |
Rewrite DiagnosticsStatusNotification and FirmwareStatusNotification to cross-check the per-station flag before reporting non-Idle status |
| 3 | handleRequestGetDiagnostics FTP branch |
Set flag on entry; clear in new finally block |
| 4 | updateFirmwareSimulation |
Set flag after early-return guards; wrap body in try/finally to clear on all exit paths |
Test Coverage (+11 new tests)
New describe('lifecycle-flag cross-check') block in OCPP16IncomingRequestService-TriggerMessage.test.ts:
- Diagnostics: no upload in progress →
Idle; active lifecycle +Uploading→Uploading; stalestationInfobut no active lifecycle →Idle(regression guard) - Firmware: no update in progress →
Idle; active lifecycle withDownloading/Downloaded/Installing→ same; stalestationInfobut no active lifecycle →Idle(regression guard) - Terminal status (
DownloadFailed) with active flag →Idle finallyclears flag on throw path- Two-station isolation: trigger on B unaffected by A's active flag
Closes #1973. Related: #1963, #1971.
- 🔄 Regenerate and Update Summary
- ✏️ Insert as PR Description (deletes this comment)
- 🗑️ Delete comment
PR Bot Information
Version: 1.27.2
- Event Trigger:
pull_request.opened - File Content Strategy: Full file content
- Output Template: Repository PR Template
- GithubContextProvider: [BUG] OCPP 1.6: DiagnosticsStatusNotification and FirmwareStatusNotification triggers read stale stationInfo status #1973
- GithubContextProvider: [FEATURE] OCPP 1.6: introduce per-station state WeakMap (prerequisite for supersession + timer-cancel + trigger cross-check) #1963
- Summary Prompt: Default Prompt
- GithubContextProvider: fix(ocpp): drive FirmwareStatusNotification trigger from last-sent notification (L01.FR.26) #1981
- LLM:
anthropic--claude-4.6-sonnet - GithubContextProvider: [BUG] OCPP 1.6: handleRequestGetDiagnostics lacks supersession semantics and abort infrastructure #1971
- GithubContextProvider: fix(ocpp): cancel deferred OCPP 1.6 firmware setTimeout on stop() #1984
- GithubContextProvider: refactor(ocpp): extract per-station state plumbing into shared OCPPIncomingRequestService base #1983
- Correlation ID:
7eb420a0-7b20-11f1-83a1-35aa61082bdb
There was a problem hiding this comment.
The PR is well-structured and the core fix is correct: both lifecycle flags are set before their respective try blocks and reliably cleared in finally, the trigger cases properly cross-check the flags against stationInfo.*Status, and the 11 new tests comprehensively cover the specified OCPP 1.6 §4.4/§4.5/§7.24/§7.25 constraints. One observation worth noting: resetStationState cancels the deferred firmware timer but does not explicitly clear firmwareUpdateInProgress or diagnosticsUploadInProgress — if stop() is called while an async operation is mid-flight, the WeakMap entry is deleted but any concurrent trigger check that cached the state reference before deletion would still observe the stale true flag; adding delete stationState.firmwareUpdateInProgress and delete stationState.diagnosticsUploadInProgress to resetStationState would close this race and make the cleanup contract fully explicit.
PR Bot Information
Version: 1.27.2
- Event Trigger:
pull_request.opened - File Content Strategy: Full file content
- Agent Instructions:
- LLM:
anthropic--claude-4.6-sonnet - Correlation ID:
7eb420a0-7b20-11f1-83a1-35aa61082bdb
| ) ?? errorResponse | ||
| ) | ||
| } finally { | ||
| delete stationState.diagnosticsUploadInProgress |
There was a problem hiding this comment.
Bug: diagnosticsUploadInProgress flag is set before early-return paths inside the try block, but the finally always clears it even when those early returns fire through the catch/finally path.
More critically: the finally block will also execute if the handler returns early from the non-FTP else branch path — but wait, stationState is only in scope inside the if (uri.protocol.startsWith('ftp:')) block, so that is fine structurally.
The real issue is subtler: if the FTP try block hits one of the early return OCPP16Constants.OCPP_RESPONSE_EMPTY statements (lines ~1240), it returns from inside the try, the finally runs and correctly clears the flag. That part is correct.
However there is a missing reset of stationInfo.diagnosticsStatus in the finally block. The finally clears diagnosticsUploadInProgress, signalling no lifecycle is active — but it does NOT reset stationInfo.diagnosticsStatus back to a non-Uploading value. After an exception unwind the catch block sets it to UploadFailed (line 1321), which is correct. But if a future early-return path is added inside the try (without updating diagnosticsStatus first), the stale status would persist. More concretely: if the return OCPP16Constants.OCPP_RESPONSE_EMPTY on line ~1240 is reached after the trackProgress callback has fired once (setting diagnosticsStatus = Uploading), the flag is cleared but diagnosticsStatus stays at Uploading with no UploadFailed status sent to CSMS.
Consider also resetting stationInfo.diagnosticsStatus to a terminal value in the finally block if it is still Uploading when the flag is about to be cleared, to make the invariant self-contained.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
86ba0c4 to
dd029a1
Compare
… and simulation entry The OCPP 1.6 TriggerMessage handler cases for DiagnosticsStatusNotification and FirmwareStatusNotification read stationInfo.diagnosticsStatus and stationInfo.firmwareStatus directly. When an exception, abort, or lifecycle drift left stationInfo.*Status at a stale non-terminal value, the trigger faithfully reported that stale value to the CSMS instead of Idle. The identical anti-pattern was present in handleRequestUpdateFirmware's re-entry guard (which suppressed legitimate new UpdateFirmware.req when stationInfo.firmwareStatus was stuck at Downloading / Downloaded / Installing) and in the base-class event dispatcher's unconditional fan-out of UPDATE_FIRMWARE emits (which spawned duplicate concurrent updateFirmwareSimulation invocations emitting duplicate progress notifications to the CSMS). Track lifecycle progress with two per-station boolean flags on OCPP16StationState (diagnosticsUploadInProgress, firmwareUpdateInProgress), set on lifecycle entry and cleared in a finally block on every exit path (happy, return, throw). The flags are consumed at four sites: the two TriggerMessage cases, the handleRequestUpdateFirmware re-entry guard, and the updateFirmwareSimulation entry guard. OCPP 1.6 GetDiagnostics.req and UpdateFirmware.req core-profile payloads do not carry a requestId (unlike OCPP 2.0.1 GetLog and UpdateFirmware), so lifecycle progress is tracked with boolean flags rather than requestId-presence sentinels. Satisfies OCPP 1.6 SHALL clauses in section 4.4 (Diagnostics) and section 4.5 (Firmware), and the Idle enumeration definitions in section 7.24 and section 7.25. Closes #1973
dd029a1 to
8846bd2
Compare
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-old-then-start-new: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and aborts the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1378 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the abort-before-clear ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-old-then-start-new: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and aborts the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1378 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the abort-before-clear ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-old-then-start-new: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and aborts the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1378 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the abort-before-clear ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-then-install: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and rejects the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1386 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the abort-before-clear ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-then-install: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and rejects the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1386 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the abort-before-clear ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-then-install: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and rejects the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1390 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the cancel-before-delete ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-then-install: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and rejects the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1390 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the cancel-before-delete ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
…ntroller (#1991) Closes #1971 The entry guard added by PR #1987 at handleRequestGetDiagnostics prevented concurrent FTP uploads racing on the same ${chargingStationId}_logs.tar.gz archive by silently dropping the second GetDiagnostics.req with an empty GetDiagnostics.conf. That mitigated the concrete race but was not the OCPP 1.6 supersession semantic: the new request needed to abort the in-flight upload and start a fresh one, with a terminal DiagnosticsStatusNotification emitted for the superseded upload. Refactor the entry guard from skip-second into abort-then-install: - Add `activeDiagnosticsAbortController?: AbortController` to `OCPP16StationState` (alphabetical, above the existing fields). - On supersession, the entry guard calls `stationState.activeDiagnosticsAbortController?.abort()` and installs a fresh controller. `diagnosticsUploadInProgress` stays `true` across the handoff so the §4.4 / §7.24 trigger cross-check never observes a false-idle window. - `basic-ftp` v6 does not natively consume `AbortSignal`; the documented interruption path is `Client.close()`, which invokes `FtpContext.close()` and rejects the pending `uploadFrom` task with `User closed client during task`. The handler wires `signal.addEventListener('abort', () => ftpClient?.close(), { once: true })`. - The existing `catch` at L1390 already emits `DiagnosticsStatusNotification(UploadFailed)` for any thrown error, so a close-triggered rejection flows through unchanged — no second emission needed. OCPP 1.6 `DiagnosticsStatusNotification.req` (§6.17) does not carry a `requestId`; the terminal for the superseded upload is uncorrelated by design, only its temporal position tells the CSMS which upload it belonged to. - The `finally` clause identity-guards its cleanup (`if (stationState.activeDiagnosticsAbortController === abortController)`) so a superseded handler's late unwind cannot clobber the new lifecycle's state. Cleaner than the microtask-yield primitive sketched in the initial design because it removes the ordering dependency between the two handlers' async continuations. - `resetStationState` aborts the in-flight controller before the base template deletes the WeakMap entry, following the cancel-before-delete ordering documented on `OCPP20IncomingRequestService.resetStationState`. Mirrors the OCPP 2.0.1 log-upload supersession pattern (commits 29a8330, ac6ed21, 64f384f, be29b4c) but does not import `AcceptedCanceled` — that response semantic is a 2.0.1 concept absent from OCPP 1.6 `GetDiagnostics.conf` (§6.26).
Closes #1973
Bug
Four related manifestations of the same anti-pattern (
stationInfo.*Statustreated as authoritative in-progress signal, or lifecycle-entry with no concurrent-invocation guard):TriggerMessagehandler cases forDiagnosticsStatusNotificationandFirmwareStatusNotificationreadstationInfo.diagnosticsStatus/stationInfo.firmwareStatusdirectly. When an exception, abort, or lifecycle drift left the status at a stale non-terminal value, the trigger reported that stale value to the CSMS instead ofIdle.handleRequestUpdateFirmwarere-entry guard suppression — the re-entry guard consultedstationInfo.firmwareStatus. A stale non-terminal value after an exception unwind suppressed legitimate new firmware update requests.updateFirmwareSimulationconcurrent-invocation duplication — the base-class event dispatcher fans outUPDATE_FIRMWAREemits unconditionally; the listener spawnedupdateFirmwareSimulationon every emit with no in-flight check, so a secondUpdateFirmware.reqspawned a concurrentupdateFirmwareSimulationemitting duplicateFirmwareStatusNotificationprogress messages to the CSMS.handleRequestGetDiagnosticsconcurrent-invocation duplication — twoGetDiagnostics.reqmessages arriving close together produced concurrenthandleRequestGetDiagnosticsinvocations. Both piped the same${chargingStationId}_logs.tar.gzarchive filename, opened concurrent FTP clients, and emitted duplicateDiagnosticsStatusNotification(Uploading)per progress tick.Fix
Track lifecycle progress with two per-station boolean flags on
OCPP16StationState:diagnosticsUploadInProgress— set at the top of the FTP branch ofhandleRequestGetDiagnostics(after the concurrent-invocation guard), cleared in afinallyblock that guarantees release on every exit path.firmwareUpdateInProgress— set at the top ofupdateFirmwareSimulation's body (after the early-return guards and the concurrency check), cleared in afinallyblock wrapping the body.Five consumers cross-check the flags:
TriggerMessage(DiagnosticsStatusNotification)case → emitsIdlewhen no upload is active.TriggerMessage(FirmwareStatusNotification)case → emitsIdleunless the flag is set ANDstationInfo.firmwareStatusis in the §4.5 / §7.25 pass-through set{Downloading, Downloaded, Installing}.handleRequestUpdateFirmwarere-entry guard → warn-logs and returns the emptyUpdateFirmware.confwhen the flag is set.updateFirmwareSimulationentry guard → early-returns before thetry/finallywhen the flag is already set.handleRequestGetDiagnosticsFTP-branch entry guard → early-returns the emptyGetDiagnostics.confpayload when a prior lifecycle is still in flight.OCPP 1.6 spec anchors (verbatim,
OCPP-1.6-edition2 §4.4/§4.5/§7.24/§7.25)§4.4 Diagnostics Status Notification
§4.5 Firmware Status Notification
§7.24 DiagnosticsStatus —
Idle§7.25 FirmwareStatus —
IdleTouchpoints (5 fix + 1 comment cleanup)
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.tsinterface OCPP16StationStatediagnosticsUploadInProgress?: booleanat L180 andfirmwareUpdateInProgress?: booleanat L199.handleRequestTriggerMessageswitch casesDiagnosticsStatusNotificationcase at L460;FirmwareStatusNotificationcase at L486.handleRequestGetDiagnosticsFTP branchfinallyclear at L1358.handleRequestUpdateFirmwarere-entry guardupdateFirmwareSimulationfinallyclear at L2086.tests/charging-station/ocpp/OCPPIncomingRequestService-StationState.test.tsno-opcontract that companion PRs (#1971, #1972, #1973) will replace" (factually stale:resetStationStateno longer no-op since PR #1984; narratively "story of code" evolution phrasing that violates the project's documentation-timeliness convention).Rationale — boolean flags rather than a synthetic
requestIdOCPP 1.6 core-profile
GetDiagnostics.reqandUpdateFirmware.reqpayloads carry norequestId:OCPP 2.0.1 uses requestId-presence sentinels because its
GetLog/UpdateFirmwarepayloads do carryrequestId. Boolean flags are the minimal representation for OCPP 1.6 that expresses "is a lifecycle currently active?"Verification
pnpm format— cleanpnpm typecheck— 0 errorspnpm lint— 0 errors, 0 warnings on modified filespnpm test— 3014 pass / 0 fail / 6 skipped (baseline 2999; +15 net new tests)Mechanical invariants (verified post-review @
8846bd255)diagnosticsUploadInProgress— 5 canonical usages (interface L180 / trigger read L467 / entry guard read L1248 / lifecycle set L1254 / finally clear L1358)firmwareUpdateInProgress— 6 canonical usages (interface L199 / trigger read L493 / re-entry guard L1896 / entry guard L1966 / lifecycle set L1972 / finally clear L2086)deferredFirmwareUpdateTimer— untouched from PR fix(ocpp): cancel deferred OCPP 1.6 firmware setTimeout on stop() #1984#1971/#1972/#1973/#1984PR-history evolution narration in the modified filesas any/@ts-ignore/@ts-expect-error/!non-null assertions in new codeorigin/mainCompanion scope
GetDiagnostics(abort-in-flight,AbortControllerplumbing) remain out of scope — tracked by open #1971.Review rounds — cumulative register
Eight rounds of review with ≥2 parallel reviewers each. 0 BLOCKER, 2 MAJOR (both [FIXED]). Zero remaining [DEFERRED].
Rounds 1-5
Six [FIXED] items (F1
#1972marker; F2 rapatriated → closes #1988; F3 rapatriated → closes #1989; F4 JSDoc scoping; O5-1 MAJOR firmware entry guard; multiple NIT touch-ups on PR body / commit title / test AAA labels). Six [REJECTED] with justification.Round 6
handleRequestGetDiagnosticsentry guard added (mirror of O5-1). Rapatriated in-scope per user directive on bug-fix deferral policy.Round 7
[FIXED]@dd029a1ea— worktree noise:package.json/pnpm-lock.yamlin diff due to upstreamorigin/mainhaving advanced with aneslint-plugin-jsdoc ^63.0.11 → ^63.0.12bump. Rebased onto latestorigin/main(6cacba312) — diff now scoped strictly to fix + test files.Round 8 (codebase-wide anti-narration audit per user request)
Audit scope: 730 authored files (git-tracked, excluding
dist/,coverage/,logs/,CHANGELOG.md, external OCPP spec docsdocs/ocpp*/, OCPP JSON schemas, lockfiles,.snap).Eight pattern groups grepped: (A)
companion PR/will (populate/extend/replace/consume/introduce)/still pending/deferred to follow-up/in a subsequent PR; (B) past-tense evolutionwas refactored/renamed/moved/added-in,previously (empty/contained),no longer (empty/contained/needed),used to (be/contain); (C) placeholder narrationeventually will,for now,temporarily,no-op contract,empty for now,initially empty/no-op/stub; (D) forward-reference(#XXXX)+ future-verb couplings; (E) JSDoc "incremental" / "will be" phrasing; (F) Python narration; (G) authored-markdown narration; (H) broad forward-reference(pending/awaiting/scheduled/planned) (PR/commit/change/patch).Result: one violation —
tests/charging-station/ocpp/OCPPIncomingRequestService-StationState.test.ts:4-5—[FIXED]@8846bd255. Both symptoms addressed: (1) stale factual claim (resetStationStateno longer no-op since PR #1984 addeddeferredFirmwareUpdateTimercancellation), (2) evolution narrationcompanion PRs (#1971, #1972, #1973) will replace(the exact "story of code" phrasing pattern the audit targets).All other
(#XXXX)/(issue #XXXX)refs across the codebase (~16 hits inventoried) are brief traceability anchors documenting design context or bug-fix provenance, which is the project's established documentation convention — kept.Zero remaining violations codebase-wide. Ready to squash.