Skip to content

fix(ocpp): cross-check OCPP 1.6 trigger cases against per-station lifecycle flags - #1987

Merged
jerome-benoit merged 1 commit into
mainfrom
fix/ocpp16-trigger-message-cross-check-lifecycle
Jul 9, 2026
Merged

jerome-benoit merged 1 commit into
mainfrom
fix/ocpp16-trigger-message-cross-check-lifecycle

Conversation

@jerome-benoit

@jerome-benoit jerome-benoit commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1973

Bug

Four related manifestations of the same anti-pattern (stationInfo.*Status treated as authoritative in-progress signal, or lifecycle-entry with no concurrent-invocation guard):

  1. Trigger stale-status leak — the TriggerMessage handler cases for DiagnosticsStatusNotification and FirmwareStatusNotification read stationInfo.diagnosticsStatus / stationInfo.firmwareStatus directly. 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 of Idle.
  2. handleRequestUpdateFirmware re-entry guard suppression — the re-entry guard consulted stationInfo.firmwareStatus. A stale non-terminal value after an exception unwind suppressed legitimate new firmware update requests.
  3. updateFirmwareSimulation concurrent-invocation duplication — the base-class event dispatcher fans out UPDATE_FIRMWARE emits unconditionally; the listener spawned updateFirmwareSimulation on every emit with no in-flight check, so a second UpdateFirmware.req spawned a concurrent updateFirmwareSimulation emitting duplicate FirmwareStatusNotification progress messages to the CSMS.
  4. handleRequestGetDiagnostics concurrent-invocation duplication — two GetDiagnostics.req messages arriving close together produced concurrent handleRequestGetDiagnostics invocations. Both piped the same ${chargingStationId}_logs.tar.gz archive filename, opened concurrent FTP clients, and emitted duplicate DiagnosticsStatusNotification(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 of handleRequestGetDiagnostics (after the concurrent-invocation guard), cleared in a finally block that guarantees release on every exit path.
  • firmwareUpdateInProgress — set at the top of updateFirmwareSimulation's body (after the early-return guards and the concurrency check), cleared in a finally block wrapping the body.

Five consumers cross-check the flags:

  1. TriggerMessage(DiagnosticsStatusNotification) case → emits Idle when no upload is active.
  2. TriggerMessage(FirmwareStatusNotification) case → emits Idle unless the flag is set AND stationInfo.firmwareStatus is in the §4.5 / §7.25 pass-through set {Downloading, Downloaded, Installing}.
  3. handleRequestUpdateFirmware re-entry guard → warn-logs and returns the empty UpdateFirmware.conf when the flag is set.
  4. updateFirmwareSimulation entry guard → early-returns before the try/finally when the flag is already set.
  5. handleRequestGetDiagnostics FTP-branch entry guard → early-returns the empty GetDiagnostics.conf payload 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

Charge Point sends a notification to inform the Central System about the status of a diagnostics upload. The Charge Point SHALL send a DiagnosticsStatusNotification.req PDU to inform the Central System that the upload of diagnostics is busy or has finished successfully or failed. The Charge Point SHALL only send the status Idle after receipt of a TriggerMessage for a Diagnostics Status Notification, when it is not busy uploading diagnostics.

§4.5 Firmware Status Notification

A Charge Point sends notifications to inform the Central System about the progress of the firmware update. The Charge Point SHALL send a FirmwareStatusNotification.req PDU for informing the Central System about the progress of the downloading and installation of a firmware update. The Charge Point SHALL only send the status Idle after receipt of a TriggerMessage for a Firmware Status Notification, when it is not busy downloading/installing firmware.

§7.24 DiagnosticsStatus — Idle

Charge Point is not performing diagnostics related tasks. Status Idle SHALL only be used as in a DiagnosticsStatusNotification.req that was triggered by a TriggerMessage.req

§7.25 FirmwareStatus — Idle

Charge Point is not performing firmware update related tasks. Status Idle SHALL only be used as in a FirmwareStatusNotification.req that was triggered by a TriggerMessage.req

Touchpoints (5 fix + 1 comment cleanup)

# File Symbol Anchor Change
1 src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts interface OCPP16StationState L154; new fields diagnosticsUploadInProgress?: boolean at L180 and firmwareUpdateInProgress?: boolean at L199.
2 same file handleRequestTriggerMessage switch cases DiagnosticsStatusNotification case at L460; FirmwareStatusNotification case at L486.
3 same file handleRequestGetDiagnostics FTP branch Entry guard at L1248; lifecycle set at L1254; finally clear at L1358.
4 same file handleRequestUpdateFirmware re-entry guard Guard at L1896.
5 same file updateFirmwareSimulation Entry guard at L1966; lifecycle set at L1972; finally clear at L2086.
6 tests/charging-station/ocpp/OCPPIncomingRequestService-StationState.test.ts File JSDoc L1-15 Codebase-wide anti-narration audit finding (see Round 8 below) — removed stale forward-reference "no-op contract that companion PRs (#1971, #1972, #1973) will replace" (factually stale: resetStationState no 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 requestId

OCPP 1.6 core-profile GetDiagnostics.req and UpdateFirmware.req payloads carry no requestId:

$ grep -c requestId src/assets/json-schemas/ocpp/1.6/GetDiagnostics.json \
                   src/assets/json-schemas/ocpp/1.6/UpdateFirmware.json
0
0

OCPP 2.0.1 uses requestId-presence sentinels because its GetLog / UpdateFirmware payloads do carry requestId. Boolean flags are the minimal representation for OCPP 1.6 that expresses "is a lifecycle currently active?"

Verification

  • pnpm format — clean
  • pnpm typecheck — 0 errors
  • pnpm lint — 0 errors, 0 warnings on modified files
  • pnpm 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
  • Zero #1971 / #1972 / #1973 / #1984 PR-history evolution narration in the modified files
  • Zero as any / @ts-ignore / @ts-expect-error / ! non-null assertions in new code
  • Diff scope: exactly 4 files vs origin/main

Companion scope

  • Supersession semantics for GetDiagnostics (abort-in-flight, AbortController plumbing) remain out of scope — tracked by open #1971.
  • OCPP 2.0.1 last-sent-driven trigger pattern shipped in #1981 is the spec-quoting rigour reference.

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 #1972 marker; 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

  • F6-1 [MAJOR] — handleRequestGetDiagnostics entry guard added (mirror of O5-1). Rapatriated in-scope per user directive on bug-fix deferral policy.
  • F6-2 [MINOR] — test count refreshed. F6-3 [REJECTED] — issue closing comment SHA non-critical.

Round 7

  • Oracle : zero new findings (exhaustive bug hunt on OCPP 1.6 handler surface — only two multi-phase status-emission lifecycles exist, both guarded).
  • F7-1 [NIT] [FIXED] @ dd029a1ea — worktree noise: package.json / pnpm-lock.yaml in diff due to upstream origin/main having advanced with an eslint-plugin-jsdoc ^63.0.11 → ^63.0.12 bump. Rebased onto latest origin/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 docs docs/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 evolution was refactored/renamed/moved/added-in, previously (empty/contained), no longer (empty/contained/needed), used to (be/contain); (C) placeholder narration eventually 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 (resetStationState no longer no-op since PR #1984 added deferredFirmwareUpdateTimer cancellation), (2) evolution narration companion 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.

@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The 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 flags

PR Checklist

  • Please add a description of your changes.
  • Please ensure title follows conventional commits.
  • We need your changes to come with unit tests in order to keep this project in quality and easy to maintain.
  • If your changes contain any new feature please be sure to document it.
  • Please add a link to the open issue or task that this pull request will resolve.

Does this PR introduce a breaking change?

  • Yes
  • No

Bug Fix

The OCPP 1.6 TriggerMessage handler cases for DiagnosticsStatusNotification and FirmwareStatusNotification read stationInfo.diagnosticsStatus / stationInfo.firmwareStatus directly with no in-progress guard. When an exception or lifecycle drift leaves these values at a stale non-terminal state (e.g. Uploading / Downloading), the trigger faithfully reports that stale value to the CSMS — violating OCPP 1.6 §4.4 / §7.24 and §4.5 / §7.25, which mandate emitting Idle when no operation is actually active.

Fix

Two per-station boolean flags are added to OCPP16StationState:

  • diagnosticsUploadInProgress — set at the top of the FTP branch in handleRequestGetDiagnostics, cleared in a finally block guaranteeing release on every exit path.
  • firmwareUpdateInProgress — set after the two early-return guards in updateFirmwareSimulation, cleared in a finally block wrapping the entire body.

The TriggerMessage switch cases for both notifications now cross-check the lifecycle flag before honouring stationInfo.*Status. When no lifecycle is active, the status collapses to Idle regardless of what stationInfo holds.

Key Changes (OCPP16IncomingRequestService.ts)

# 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; stale stationInfo but no active lifecycle → Idle (regression guard)
  • Firmware: no update in progress → Idle; active lifecycle with Downloading / Downloaded / Installing → same; stale stationInfo but no active lifecycle → Idle (regression guard)
  • Terminal status (DownloadFailed) with active flag → Idle
  • finally clears 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

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

) ?? errorResponse
)
} finally {
delete stationState.diagnosticsUploadInProgress

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

… 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
@jerome-benoit
jerome-benoit force-pushed the fix/ocpp16-trigger-message-cross-check-lifecycle branch from dd029a1 to 8846bd2 Compare July 9, 2026 16:10
@jerome-benoit
jerome-benoit merged commit 0ed90b1 into main Jul 9, 2026
44 checks passed
@jerome-benoit
jerome-benoit deleted the fix/ocpp16-trigger-message-cross-check-lifecycle branch July 9, 2026 18:21
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
jerome-benoit added a commit that referenced this pull request Jul 9, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant