generated from MetaMask/metamask-module-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Problem
The current wake detector (installWakeDetector in @metamask/kernel-utils) only works within a single running process. If the kernel restarts while the system was asleep, we don't detect the time discontinuity and don't reset reconnection backoffs, causing unnecessary delays.
Expected Behavior
- Store last known timestamp in persistent storage on shutdown
- On kernel startup, compare stored timestamp with current time
- If gap exceeds threshold (e.g., > 1 hour), treat as wake event and reset all reconnection backoffs
- Complement the existing runtime wake detector
Implementation
Files to Modify
| File | Changes |
|---|---|
platform/transport.ts |
Check timestamp on initTransport() startup, reset backoffs if needed |
platform/reconnection.ts |
Use existing resetAllBackoffs() method |
kernel/remote-comms.ts |
Persist timestamp on stop, pass to transport |
| Kernel store | Add lastNetworkActivityTimestamp storage |
Approach
-
Add timestamp storage to kernel store
- New key:
lastNetworkActivityTimestamp - Write timestamp periodically during operation (e.g., every 5 minutes)
- Write timestamp on
initTransportstop
- New key:
-
Check timestamp on startup (in
initTransportorinitRemoteComms)- Read
lastNetworkActivityTimestampfrom store - Compare with current time
- If gap > threshold (configurable, default 1 hour), call
reconnectionManager.resetAllBackoffs()
- Read
-
Handle edge cases
- Clock changes / timezone issues
- First startup (no previous timestamp)
- Timestamp in the future (clock was adjusted backward)
Acceptance Criteria
- Last timestamp stored on shutdown
- Timestamp updated periodically during operation
- Time discontinuity detected on startup
- Backoffs reset when discontinuity exceeds threshold
- Works alongside runtime wake detector (
installWakeDetector) - Unit tests verify cross-restart detection
- Handles clock adjustment edge cases gracefully
Metadata
Metadata
Assignees
Labels
No labels