Skip to content

Remote comms: Cross-incarnation wake detection #690

@sirtimid

Description

@sirtimid

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

  1. Add timestamp storage to kernel store

    • New key: lastNetworkActivityTimestamp
    • Write timestamp periodically during operation (e.g., every 5 minutes)
    • Write timestamp on initTransport stop
  2. Check timestamp on startup (in initTransport or initRemoteComms)

    • Read lastNetworkActivityTimestamp from store
    • Compare with current time
    • If gap > threshold (configurable, default 1 hour), call reconnectionManager.resetAllBackoffs()
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions