fix(wdk): prevent resetting cron job lastRun timestamps to 0 in storage#1016
fix(wdk): prevent resetting cron job lastRun timestamps to 0 in storage#1016Ysh204 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32f7180fa3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| '@0xsequence/dapp-client': patch | |||
There was a problem hiding this comment.
Add wallet-wdk to the changeset
This commit changes packages/wallet/wdk/src/sequence/cron.ts in the public @0xsequence/wallet-wdk package, but the changeset only lists @0xsequence/dapp-client. With the repo's Changesets release flow, only packages named in the frontmatter are versioned/changelogged, so the cron persistence fix will not be published to consumers unless @0xsequence/wallet-wdk is included here as a patch release.
Useful? React with 👍 / 👎.
Description
This PR resolves a critical bug in the WDK
Cronscheduler utility (packages/wallet/wdk/src/sequence/cron.ts) that caused persisted cron joblastRuntimestamps to be overwritten with0inlocalStoragewhen WDK reloaded or initialized.The Bug
lastRun = 0.runJobs()loads the persisted last run timestamps fromlocalStorageasynchronously.lastRunis less than the job's interval, the job's handler is not executed.job.lastRunremained at0.runJobs(),syncWithStorage()serialized the in-memorythis.jobs(where the job'slastRunwas0) and wrote it back tolocalStorage, erasing the actual last run timestamp.lastRun: 0and triggered the job prematurely.In practice, this meant every background cron job (such as checking queued recovery payloads) would run on every single app restart/tab refresh plus exactly 1 tick later, completely ignoring the configured execution interval.
The Fix
Update
runJobs()incron.tsto sync the in-memoryjob.lastRunstate with the loadedlastRunvalue from storage before evaluating the elapsed time. This ensures that non-triggered jobs preserve their actual persisted timestamps when writing back to storage.Testing & Verification
packages/wallet/wdk/test/cron.test.tsto verify last run persistence, check skip behavior, and ensure correct interval triggers.