fix: recover interrupted paykit sessions - #1339
ben-kaufman wants to merge 5 commits into
Conversation
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
|
| } | ||
| is InitResult.RestorationFailed -> { | ||
| clearAuthenticatedState() | ||
| clearAuthenticatedState(clearCachedProfile = false) |
There was a problem hiding this comment.
Cached identity data crosses accounts If identity A’s saved session fails to restore and the user then authorizes identity B through Ring, this branch keeps A’s cached data. The cache is not separated by identity, and B’s authentication does not clear it. As a result, A’s saved contact overrides can change how B’s contacts appear, and A’s name or image can appear while B’s profile is unavailable. Keep the cache for a retry with the same identity, but clear or separate it when the identity changes.
Knowledge Base Used: Pubky identity and profile
There was a problem hiding this comment.
Fixed in 9890462. Activation now clears the cached profile and contact overrides when the saved SDK owner changes. Same-identity recovery keeps them. A missing SDK owner also preserves restored legacy backup overrides.
Ring completion clears stale in-memory profile/contacts and resets the contact-load marker before loading the new identity. Regression coverage includes same/different owners, normalized keys, legacy backups, and cache-reset failure. All 2,903 Android tests passed.
Applied the matching cache fix and corrected the profile recovery route on iOS #796 too.
A failed Paykit session restore after connection loss or a device clock change could make an existing profile appear missing and discard contacts. This PR preserves saved identity data, retries recovery when connectivity returns or the app resumes, and corrects retry and billing-reminder timing.
Fixes #1344.
Counterpart: iOS PR.
Related: #1334 also changes the persisted-identity lookup as part of backup protection; that overlapping hunk needs reconciling when both PRs merge.
Description
Out of Scope
Design
N/A — no UI changes.
Preview
Android offline-start/reconnect recordings were captured locally: the original build lost the profile name and did not recover; the fixed build retained the name and contact and restored the same identity about 1.7 seconds after reconnecting. Live clock-change recording remains pending.
QA Notes
Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
Live grant-session clock-change E2E has not been rerun. Android offline cold-start/reconnect and contact preservation were verified on a disposable regtest emulator. The full procedure is in paykit-clock-changes.md.
Automated Checks
PaykitSdkServiceTest.kt— identity lookup failures stop activation without deleting saved state or credentials; activation tests cover same/different owners, normalized keys, legacy backup caches, and cache-reset failure.PubkyAuthHandlerRegistrarTest.ktandAppViewModelSendFlowTest.kt— saved/unreadable identities do not advertise signup; reconnect and foreground trigger recovery.PubkyRepoTest.kt— automatic retry after failure, unreadable credentials, queued wipe, active Ring authorization, and cancelled completion racing retry; restoration preserves profile data for retry; failed Ring auth cleans up only a session installed by that attempt, including unreadable ownership and cancellation coverage; identity switches discard stale in-memory profile/contact data and reset the contact-load marker.PubkyIdentityRepublishTest.kt— clock rollback retries publication and then resumes throttling.PaykitSubscriptionNotificationSchedulerTest.kt— a worker running before the billing boundary defers its reminder.PaykitSubscriptionTest.kt— timezone and DST changes preserve UTC billing boundaries.