Skip to content

fix(s2-rm): answer a PEBC revoke only after REVOKED (#122) - #135

Merged
dirkjanfaber merged 2 commits into
mainfrom
fix/122-pebc-revoke-reply
Nov 30, 2026
Merged

dirkjanfaber merged 2 commits into
mainfrom
fix/122-pebc-revoke-reply

Conversation

@dirkjanfaber

Copy link
Copy Markdown
Collaborator

Closes #122.

Tested with the unit tests: all 814 pass, and the 5 new session tests fail without the fix.

I checked the wiring of the We.Positive flow against this change: s2-pebc's output goes back into s2-rm, so a valid revoke still gets OK. Skip instruction status updates doesn't hold back REVOKED.

A flow that handles PEBC instructions without s2-pebc now gets PERMANENT_ERROR after 2 seconds, unless it sends InstructionStatus with REVOKED. The changelog says so.

s2-rm answered every revoke of a PEBC instruction with OK, also when
s2-pebc no longer held it. EN 50491-12-2 §9.3.6 allows OK only once the
instruction is REVOKED, and a rejection otherwise.

Only s2-pebc knows which instructions it holds, also from an earlier
session. The session now forwards a PEBC revoke and answers OK when
the instruction is reported REVOKED, or PERMANENT_ERROR when that
doesn't happen within 2 seconds. A flow that handles PEBC without
s2-pebc gets OK by sending InstructionStatus REVOKED.

Closes #122.

Copilot AI 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.

🟡 Changes recommended

Duplicate revoke message IDs leave an orphaned timer that can send PERMANENT_ERROR after OK and remain active after disposal.

1 open issue
What changed in this PR

This PR addresses #122 by making the shared S2 session wait for REVOKED before acknowledging a PEBC revoke, rather than returning OK merely because it was forwarded.

Changes:

  • Returns OK after REVOKED, or PERMANENT_ERROR after a two-second timeout.
  • Adds tests for confirmation, timeout, repeated revokes, and disposal.
  • Documents the required status response for custom PEBC flows.
File Description
test/​lib/​session.test.ts Adds coverage for deferred PEBC revoke replies and cleanup.
src/​lib/​s2/​session.ts Tracks pending revokes, handles confirmation and timeout, and clears timers on disposal.
docs/​S2_REFERENCE.md Explains PEBC revoke confirmation and timeout behavior.
CHANGELOG.md Records the fix and requirements for flows without s2-pebc.

Review effort: Balanced

Comment thread src/lib/s2/session.ts Resolved
A revoke resent with the same message_id while the first waited for
REVOKED replaced its pending entry but left the first timer running.
The CEM then got OK followed by PERMANENT_ERROR, and the timer
survived dispose(). Keep the first entry instead.

Copilot AI 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.

🔵 Needs a closer look

The duplicate guard drops completed revoke results, allowing a retransmission after REVOKED to be forwarded again and return PERMANENT_ERROR despite the original request succeeding.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Replay completed revoke results to prevent duplicate forwarding

src/​lib/​s2/​session.ts:488

The duplicate guard stops working once REVOKED removes the pending entry and sends OK. If the CEM retransmits the same message_id before receiving that reply, the revoke is forwarded again; s2-pebc no longer holds the instruction, so the timer returns PERMANENT_ERROR for a request that succeeded. Retain and replay completed reception results without forwarding the request again, and add a test for a resend after REVOKED.

1 resolved since last review

Review effort: Balanced

@dirkjanfaber

Copy link
Copy Markdown
Collaborator Author

On the "previously missed issue" (a revoke resent after it was answered): leaving this out. EN 50491-12-2 defines no retransmission of a message, only the retry after TEMPORARY_ERROR, which a revoke never gets here. The session does not deduplicate any other message either. Replaying answered message_ids would need a cache for every message type, which is a separate change if a CEM turns out to resend.

@dirkjanfaber
dirkjanfaber merged commit e7e5556 into main Nov 30, 2026
6 checks passed
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.

s2-rm answers OK to a revoke for a PEBC instruction that s2-pebc no longer holds

2 participants