Skip to content

fix: ask for an update when paykit data is newer - #1416

Merged
ovitrif merged 7 commits into
masterfrom
fix/paykit-update-msg
Nov 25, 2026
Merged

ovitrif merged 7 commits into
masterfrom
fix/paykit-update-msg

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1414
Twin: synonymdev/bitkit-android#2023

Description

  • Fixes the raw Paykit storage error shown when creating, restoring or connecting a profile whose Paykit shared state was saved by a newer Paykit, because the views passed error.localizedDescription straight to the toast
  • Adds isPaykitStateFromNewerVersion(), which matches the typed PaykitError.Storage (code storage_error, context SDK state blob contains trailing bytes or unsupported SDK state blob version N), also inside AppError, and profileErrorDescription, which swaps in the new profile__update_required string on the Create Profile and Pubky choice toasts
  • Fixes the "session expired" toast on launch when restoring a saved session hits the same error, because resolveSessionInitialization mapped it to .restorationFailed; it now returns .restorationNeedsUpdate, keeps the saved session, skips the re-sign-in that cannot read the state either, and shows the update message, automatic recovery and Retry included, once per saved identity so foreground polling stays silent; the background retry loop stops after that result; the toast waits until Bitkit is active and unlocked, and Profile keeps the update message above Try Again after the toast is gone; a later toast such as Back online waits until the warning hides, and clearing the profile drops a pending warning
  • Adds the string to every locale

Paykit keeps each identity's state on its homeserver, shared by every app and device on it. Paykit 0.1.1-rc5 and older fail on the current format with the trailing-bytes error, and this app's Paykit 0.1.1-rc9 will fail with the unsupported-version error once pubky/paykit-rs#267 moves the format to version 6. Both now read "This profile needs a newer version of Bitkit. Update the app to use it." under the existing error title.

Out of Scope

  • Views/Sheets/PubkyAuthApproval: the auth approval sheet keeps its current error text
  • Paykit shared state: the app does not clear or rewrite the newer state; it is shared across apps and devices and holds contacts, receipts and allowances

Design

N/A — no design available.

Preview

N/A — the message only shows with Paykit state written by a newer Paykit; see Manual Tests.

QA Notes

Setup

Journeys

N/A — not drivable; see Manual Tests.

Manual Tests

  • 1. Connect or restore the profile whose Paykit state a newer Paykit saved → the error toast says Bitkit needs an update, with no storage_error text — the journey environment cannot write a newer Paykit state format
  • 2. With the profile connected, write newer state from the other build, then relaunch this build → the toast says Bitkit needs an update instead of "session expired" — same capability
  • 3. With the profile connected, write newer state from the other build, start this build offline, go online → the toast says Bitkit needs an update; on Profile the same message shows above Try Again, and tapping it keeps the message — same capability
  • 4. With the update warning from case 1 on screen, disconnect and reconnect while it is visible or fading → the warning stays until it hides, Back online appears after it, and a connection warning that was waiting does not return — same capability

Automated Checks

  • added PaykitNewerStateTests.swift — newer-state storage errors ask for an update, older-version corruption keeps its text, and a saved session hitting newer state needs an update
  • updated PubkyProfileManagerTests.swift — automatic recovery asks for the update once and the retry loop stops

Evidence

Local verification: BitkitTests (unit selection from unit-tests.yml) on an iPhone 17 Pro simulator, iOS 26.4; swiftformat --lint on the changed files; node scripts/validate-translations.js.

Gaps

  • 1, 2, 3. not run: no build with a newer Paykit state format was available.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: Claude Sonnet 5.5 (reasoning: high)

Verified: BitkitTests unit selection on iOS 26.4 simulator, swiftformat --lint, validate-translations
@ovitrif ovitrif self-assigned this Nov 24, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T21:25:57.461367Z 910d0d5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif
ovitrif requested review from a team, ben-kaufman and piotr-iohk and removed request for a team November 24, 2026 21:24

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Replaces the raw Paykit storage error on the Create Profile and Pubky choice toasts with an update prompt when the shared state was written by a newer Paykit. Reviewed 910d0d5, full tier, static: iOS does not build on this reviewer's Linux host, so this is reasoned from the code and CI.

What I checked, and 5 candidates I ruled out

Read in full: PaykitError+NewerState.swift, the new test, the changed catch blocks in CreateProfileView.swift and PubkyChoiceView.swift, AppError in Errors.swift; paykit-rs state_blob.rs and errors.rs at v0.1.1-rc9 (the pinned revision 0b9c63d) and at pubky/paykit-rs#267.
CI: SwiftFormat and validate green; Run Tests, Run Integration Tests and build-local still running at review time.

Ruled out

  • Context strings drift from Paykit: both match the pinned 0.1.1-rc9 (paykit-sdk/src/storage/state_blob.rs:195 and :203) and are unchanged on the head of pubky/paykit-rs#267 (:333, :341); the FFI keeps the context and sets code storage_error for PaykitSdkError::Storage (paykit-ffi/src/errors.rs:124-128).
  • Current-version corruption shown as "update required": the plain trailing-bytes context is only raised past an AEAD-authenticated decrypt, so it takes a writer that encoded more than this format, which is the newer-Paykit case. The per-version SDK state blob version N contains trailing bytes contexts are correctly left out, and the test pins that.
  • rc6+ reading rc5 data: rc9 still decodes v1 (state_blob.rs:140), so the older direction never hits these errors.
  • Typed error hidden by a wrapper: AppError(error:) keeps the original as underlyingError, which the matcher unwraps; the profile manager paths rethrow the original error (PubkyProfileManager.swift, the adopt and create flows), and no service on them rethrows a string.
  • A toast still showing the raw text: every catch-all in both views now goes through profileErrorDescription; the one remaining localizedDescription is PubkyAppProfileError.changedElsewhere, an app error. The key is in every .lproj.

Merge confidence: 4/5, no findings and the matcher is covered by PaykitNewerStateTests.swift, but the unit test job had not finished when I reviewed.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not carry it)

Verified: BitkitTests unit selection on iOS 26.4 simulator, swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 24, 2026 22:26
Verified: BitkitTests unit selection on iOS 26.4 simulator, swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 24, 2026 23:12
Verified: BitkitTests unit selection on iOS 26.4 simulator, swiftformat --lint
@ovitrif

ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

9cc6119: the update message now shows once per saved identity while the error lasts, matching the Android twin (raised in synonymdev/bitkit-android#2023 (comment)). Foreground polling of the same identity stays silent; a successful restore resets it, and a new sign-in asks again.

The update toast waits until Bitkit is active and unlocked, and Profile shows the update message above Try Again while a restore needs an update.

Verified: xcodebuild test (unit-tests.yml skips), swiftformat --lint
@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

a824e9c also makes the update toast wait until Bitkit is active and unlocked, like the expiry toast, so a restore that finds newer Paykit state in the background no longer loses its one-time prompt. It matches synonymdev/bitkit-android#2023.

@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 00:19
Comment thread Bitkit/AppScene.swift Resolved
…ofile

Verified: xcodebuild test (unit-tests.yml skips), swiftformat --lint
@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

7075244 also keeps the update warning on screen until it hides: a later toast such as Back online waits for it, and only the newest waiting toast shows next. It matches synonymdev/bitkit-android#2023.

@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 01:31
Verified: xcodebuild test (unit-tests.yml skips), swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 02:25

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: full PR diff against its merge base, at 229faff.

No new actionable code findings.

No actionable code findings. A saved session that hits either Paykit storage context from #1414 resolves to an update prompt, skips re-sign-in, stops the restore retry, and keeps the update reason on Profile above Try Again. The prompt is shown once per session revision, after the app is active and unlocked, and clearing the profile drops a prompt that has not been shown yet. A current-version blob with extra trailing bytes uses the same unversioned context that #1414 asks to treat as an update; versioned trailing-byte errors stay on the raw path.

The same flow on the twin bitkit-android#2023 at aa2d1a2 uses the same two contexts, a once-per-identity prompt, a non-interruptible toast, and the profile hint. That comparison is limited to this flow. The five existing review threads are resolved, and this head still contains the fixes they describe.

Device testing was not performed in this review. Manual cases 1–3 still need a Bitkit build that writes a newer Paykit state format; the author reports that build was not available. PaykitNewerStateTests and the recovery case in PubkyProfileManagerTests were inspected and not executed.

Suggested additional test cases:

  • iOS, newer-state profile from case 1, update warning on screen: disconnect, then reconnect while the warning is visible or fading. The warning stays until it hides, Back online appears after it, and a connection warning that was waiting does not return.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device QA and approval

Approved at 229faff501af9eea5e55b06ce426dcaaaa636e20. Tested the Debug regtest build on an iPhone 17 simulator (iOS 27.2) and a separately signed build on an iPhone 13 (iOS 27.0.1). A newer Paykit SDK wrote version 6 state for the test profiles. The tested build expected version 4.

All four manual cases passed. Across manual cases, controls, and exploration, 7 passed, 1 failed, and none remained blocked.

Case Result Device observation
1. Interactive profile connection PASS Submitting a profile with newer state showed the localized update guidance.
2. Cold launch with a saved profile PASS The same profile was readable before the version-6 write. On relaunch it showed the update warning.
3. Offline start and retry PASS Cold-launched the iPhone with Airplane Mode on and Wi-Fi off. Reconnecting produced the warning. The update hint stayed above Try Again after a retry.
4. Disconnect and reconnect during the warning PASS On the physical iPhone, the green “Back online” message followed the update warning. The previous connection warning stayed dismissed.

Additional checks. A compatible profile remained accessible after relaunch. Recovery from an isolated homeserver outage preserved the update guidance after retry. Backgrounding and reopening the app produced no duplicate warning during the observation period.

Exploratory failure. Confirming Disconnect on the incompatible profile twice exposed a raw SDK storage error and left the profile in place. The sign-out error display and cleanup ordering also exist on the base revision. The recording, restore log, UI trace, and reproduction steps are tracked separately in #1427.

@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Merging at 229faff: approved on this head, CI green, no open threads. The Disconnect error from the exploratory run predates this PR and gets its own fix for #1427.

@ovitrif
ovitrif merged commit 325b409 into master Nov 25, 2026
21 checks passed
@ovitrif
ovitrif deleted the fix/paykit-update-msg branch November 25, 2026 11:33
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.

bug: profile connect shows a raw error when paykit data is newer

4 participants