persist EventNumber across restarts (Matter Core §7.14.1.1)#39
Merged
Conversation
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>
2 tasks
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.
Fixes #38.
Wires
Events::{load,reset}_persistintoMatterStack::{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
EventMinwatermark from the previoussession 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:
event_min: Some(N); deviceemits from
#1; controller filters everything; HA never sees buttonevents.
Loaded events counter from storageatboot; resubscribe Reports advance from the persisted epoch boundary;
all events
>= event_minso they reach HA.