Skip to content

Persist auto-lock activity across worker restarts - #70

Merged
HDauven merged 1 commit into
mainfrom
fix/autolock-persist-activity
Jun 23, 2026
Merged

Persist auto-lock activity across worker restarts#70
HDauven merged 1 commit into
mainfrom
fix/autolock-persist-activity

Conversation

@HDauven

@HDauven HDauven commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

  • persist the auto-lock last-activity timestamp so a restarted MV3 background worker does not treat memory reset as infinite inactivity
  • initialize missing activity for an already-unlocked wallet instead of locking on the first alarm after restart
  • refresh persisted activity on unlock, user-controlled extension UI heartbeats, auto-lock setting changes, successful post-approval dApp action methods, and real dApp network switches that actually change node URL
  • do not refresh activity for passive connected dApp polling such as profile reads, public balance reads, chain ID reads, shielded-address reads, or no-op network switches
  • clear persisted activity on manual or automatic lock
  • document the session-storage-backed auto-lock activity behavior

Provider event contract

  • dusk_profiles returns [] when an origin is authorized but the wallet is locked
  • dusk.isAuthorized === true plus profiles.length === 0 is the connected-but-locked state
  • manual lock and auto-lock call the profile broadcaster, and connected dApp ports receive profilesChanged([]) while remaining authorized
  • connected-but-locked dApps can call dusk_requestProfiles to enter the unlock/reconnect approval path

Root cause

lastActivityTimestamp only lived in service worker memory. When the worker slept or restarted, it reset to 0; the next chrome.alarms auto-lock check computed a huge elapsed time and locked immediately. Since the alarm runs about once per minute, this looked like a 1-minute lock even with a 5-minute setting.

Review follow-up

Validated and fixed the P1 finding that connected dApps could keep the wallet unlocked by polling successful no-approval RPCs. The activity refresh allowlist now excludes passive/read/no-op dApp methods, and regression tests cover dusk_profiles, dusk_getPublicBalance, dusk_chainId, and no-op dusk_switchNetwork.

Validation

  • npm ci
  • npm run test:run -- src/background/autoLock.test.js src/background/dappEvents.test.js src/background/rpc.test.js src/integration/providerDiscovery.test.js src/background/lifecycle.conformance.test.js src/background/txLifecycle.flow.test.js
  • npm run test:run
  • npm run build:chrome
  • npm run build:firefox
  • git diff --check

@HDauven
HDauven marked this pull request as ready for review June 23, 2026 10:46
@HDauven
HDauven force-pushed the fix/autolock-persist-activity branch from b2337eb to d1268ef Compare June 23, 2026 10:53
@HDauven
HDauven marked this pull request as draft June 23, 2026 10:54
@HDauven
HDauven force-pushed the fix/autolock-persist-activity branch from d1268ef to a43b0d6 Compare June 23, 2026 11:12
@HDauven
HDauven marked this pull request as ready for review June 23, 2026 11:20
@HDauven
HDauven merged commit 8155b9e into main Jun 23, 2026
2 checks passed
@HDauven
HDauven deleted the fix/autolock-persist-activity branch June 23, 2026 11:22
@HDauven HDauven mentioned this pull request Jun 23, 2026
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.

1 participant