Skip to content

persist EventNumber across restarts (Matter Core §7.14.1.1)#39

Merged
ivmarkov merged 1 commit into
sysgrok:nextfrom
snabb:events/persist-event-counter
May 21, 2026
Merged

persist EventNumber across restarts (Matter Core §7.14.1.1)#39
ivmarkov merged 1 commit into
sysgrok:nextfrom
snabb:events/persist-event-counter

Conversation

@snabb
Copy link
Copy Markdown
Contributor

@snabb snabb commented May 21, 2026

Fixes #38.

Wires Events::{load,reset}_persist into MatterStack::{load,reset}
for both the Eth and Wireless variants, so the EventNumber counter is
restored on boot and cleared on factory reset alongside the existing
fabrics / basic-info persistence.

Without this, the counter restarts at 1 after every reboot.
Subscribers that cached an EventMin watermark from the previous
session then filter out the early events of the new session — on a
GenericSwitch endpoint this manifests as button presses silently
dropped until the device catches up past the stored watermark.

rs-matter already implements the +EVENT_NUMBER_EPOCH_SIZE (10000)
bump-on-load strategy and exposes Events::{load,reset}_persist;
this PR is the missing call site in rs-matter-stack.

Verification

ESP32-C6 Thread device against Home Assistant's matter.js Matter Server:

  • Before: post-reboot resubscribe carries event_min: Some(N); device
    emits from #1; controller filters everything; HA never sees button
    events.
  • After: device-side log shows Loaded events counter from storage at
    boot; resubscribe Reports advance from the persisted epoch boundary;
    all events >= event_min so they reach HA.

Matter Core spec R1.5.1 §7.14.1.1 requires that EventNumber be
monotonically increasing for the life of the node, and that this
monotonicity be preserved across restarts. rs-matter has the
persistence infrastructure in place — `Events::{load,reset}_persist`
plus the epoch-bump-on-emit logic inside `next_event_number`
(EVENT_NUMBER_EPOCH_SIZE = 10000) — but rs-matter-stack's
`MatterStack::{load,reset}` only call `Matter::{load,reset}_persist`,
which covers fabrics and basic-info settings but not events.

Symptom: subscribers that previously saw events 1..49 record
EventMin=50 as their watermark; after a device restart the event
counter resets to 1, so 1..49 of the new session are filtered out by
the subscriber and effectively never delivered. On a Generic Switch
endpoint this manifests as button-press events not reaching the
controller at all until the device has emitted ~50 events from the
new boot.

Wire `Events::{load,reset}_persist` into `MatterStack::{load,reset}`
for both the Eth and Wireless variants. The events wiring is
duplicated across eth.rs and wireless.rs mirroring the pre-existing
duplication of the `matter.load_persist` call.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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