Skip to content

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

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

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

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2022
Twin: synonymdev/bitkit-ios#1416

Description

  • Fixes the raw code=storage_error, context=… text shown when creating, restoring or connecting a profile whose Paykit shared state was saved by a newer Paykit, because the app passed the SDK message straight to the toast
  • Adds isPaykitStateFromNewerVersion(), which matches the typed PaykitException.Storage (code storage_error, context SDK state blob contains trailing bytes or unsupported SDK state blob version N) through the cause chain, 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 PubkyRepo mapped it to a failed restore; it now keeps the saved session, skips the re-sign-in that cannot read the state either, and shows the update message, also when a retry after an offline start finds it; it asks once per saved identity, so the minute-by-minute restore polling stays silent; a prompt found while Bitkit is in the background waits and shows when it returns to the foreground; Profile keeps the update message above Try Again after the toast is gone; the warning shows only on the wallet screen, and a later toast such as Back online waits until it hides; toasts waiting behind it keep their place, except the address-type progress toast, which its result replaces
  • 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

  • ui/utils/PubkyAuthErrorMessage.kt: other Paykit errors on these toasts keep their current 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, then go online → after the retry on reconnect, the toast says Bitkit needs an update, and Profile shows the same message above Try Again after it disappears — same capability
  • 4. With a restored wallet that still has an in-flight Pubky swap claim and the profile from case 1, open Bitkit while the update warning shows, let the claim finish, then go offline and back online → after the warning hides, "Payment returned to Savings" shows and stays until dismissed, then Back online shows — same capability
  • 5. With the update warning from case 1 on screen, change the address type and let it finish → after the warning hides, the address-type result shows and "Applying changes" does not stay; a toast already waiting, such as "Payment returned to Savings", stays until dismissed — same capability

Automated Checks

  • added PaykitExceptionExtTest.kt — newer-state storage errors match, older-version corruption and plain text do not
  • updated PubkyRepoTest.kt — a saved session hitting newer state flags an update, not a failed restore, and keeps the session; the deferred retry flags it too, and later restores of the same identity do not repeat it

Evidence

Local verification: just compile, just test, just lint on the final tree.

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: just compile, just test, just lint
@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:24:43.162349Z 55f005d 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
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 17b0f3c (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@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 55f005d, full tier, static: per the repo's agent rules an auto review does not build the branch here, so this is reasoned from the code and CI.

What I checked, and 5 candidates I ruled out

Read in full: PaykitExceptionExt.kt, PubkyAuthErrorMessage.kt, CreateProfileViewModel.kt, PubkyChoiceViewModel.kt, the new test; paykit-rs state_blob.rs and errors.rs at v0.1.1-rc9 and at pubky/paykit-rs#267.
CI: build-and-test, lint, detekt green. compose-ui / ui-tests failed before any test ran: sdkmanager --install emulator hit Error reading Zip content from a SeekableByteChannel and the emulator never started; build is the gate that requires it. A runner fault, not this diff; a re-run should clear it.

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: isPaykitStateFromNewerVersion walks the cause chain, and no repository or service on these paths rethrows with the message only.
  • A toast still showing the raw text: the one remaining it.message in CreateProfileViewModel is the deriveKeys() failure, which is local key derivation with no Paykit storage read (PubkyRepo.kt:996-1003). The string is in all 18 values* directories.

Merge confidence: 3/5, CI is red for a reason outside the change (emulator install on the runner); with that job green it is 5/5, the matcher is covered by PaykitExceptionExtTest.kt.

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

Verified: just compile, just test, just lint
@ovitrif

ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

2bb6fb7: restoring a saved session on launch now shows the update message too, instead of "session expired". PubkyRepo maps the newer-state storage error to its own restore outcome, keeps the saved session and skips the re-sign-in, which cannot read that state either. Raised on the iOS twin in synonymdev/bitkit-ios#1416 (comment); Android had the same gap.

The earlier compose-ui / ui-tests failure was the runner's emulator download (corrupt SDK zip, no emulator on port 5554), not this change; this push reruns it.

@ovitrif
ovitrif requested a review from ben-kaufman November 24, 2026 22:26
@ovitrif
ovitrif requested a review from ben-kaufman November 24, 2026 23:12
Verified: just compile, just test, just lint
Verified: just compile, just test, just lint
@ovitrif
ovitrif requested a review from ben-kaufman November 24, 2026 23:48
Verified: just compile, just test, just lint
@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

ad80852 shows the update message on Profile above Try Again while a restore needs an update, so the reason stays visible after the one-time toast. It matches the iOS change for synonymdev/bitkit-ios#1416 (synonymdev/bitkit-ios#1416 (comment)).

Verified: just compile, just test, just lint
@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 00:16
Verified: just compile, just test, just lint
@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 00:52
Verified: just compile, just test, just lint
@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 01:31
Verified: just compile, just test, just lint (ToastQueueManagerTest rerun after the lint wrap)
@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 01:56

@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 aa2d1a2.

1 actionable finding — resolve or provide an evidence-backed rebuttal.

A saved session whose Paykit state is newer stays in place, skips re-sign-in, and asks for an update once per saved identity, including the deferred retry after an offline start. Profile keeps that reason above Try Again. Earlier review threads on this PR match that behavior at this head. The queue change that lets the update warning finish, and that lets an address-type result replace its progress toast, also deletes a queued sticky explanation before it is shown.

Compared with bitkit-ios#1416 at 229faff, session handling matches. iOS waits until the app is active and unlocked before showing the one-shot warning; Android shows it when MainActivity resumes, including over the PIN screen, and then clears it. That iOS patch was the comparison source; this is not a review of the iOS PR.

Device testing: not performed in this review. The author reports manual cases 1–3 were not run because no newer Paykit state format was available. No unit suite was run for this review.

Suggested additional test cases

Android. Use a restored wallet that still has an in-flight Pubky swap claim, and a profile whose Paykit state was saved by a newer Paykit. Open Bitkit so the update warning is showing, let the claim finish, then let a later toast enqueue (for example go offline and back online so “Bitkit successfully reconnected” appears). Expected: after the update warning hides, “Payment returned to Savings” is shown and stays until it is dismissed.

Non-blocking consistency suggestions

iOS holds the update warning until the PIN is verified. Android shows the same one-shot toast as soon as the wallet activity resumes, so the three seconds can elapse while the PIN is on screen.

Findings

  • [MEDIUM] Keep the returned-payment toast until the user dismisses it — inline at app/src/main/java/to/bitkit/ui/shared/toast/ToastQueueManager.kt:50.

Reviewer model: grok-4.7
Reasoning effort: xhigh

Only the address-type progress toast is replaced by a later toast while it waits; the returned-payment toast keeps its place behind the update warning.

Verified: just compile, just test, just lint
@ovitrif
ovitrif requested a review from piotr-iohk November 25, 2026 06:40
AppViewModel rebuilt toasts from ToastEventBus and dropped replacedByNext, so a queued address-type progress toast could hide its result.

Verified: just compile, just test, just lint
@ovitrif
ovitrif requested a review from ben-kaufman November 25, 2026 07:19

@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: changes since 2739903, including the affected toast-forwarding path, at 17b0f3c. Baseline: fe3c7316-9c0b-4a6c-8ffe-003fe5c2ae18. Unchanged Paykit matching, session restore, the resume prompt, profile retry, create-profile copy, and update strings stay covered by that baseline.

No new actionable code findings.

AppViewModel.toast(Toast) enqueues the original toast, so an address-type progress toast keeps replacedByNext and leaves the queue when a later toast arrives while the update warning is showing. Compared bitkit-ios#1416 at 229faff: iOS keeps the newest toast waiting behind a non-interruptible warning, and Android keeps non-progress toasts in order, which is what manual test 4 describes.

Device testing: not performed in this review. This pass is source analysis. The new AppViewModelSendFlowTest case and ToastQueueManagerTest were inspected and were not run. Author cases 1–4 still need a build that writes a newer Paykit state.

Suggested additional test cases

  • Android, with the update warning visible from manual test 1: change address type and let it finish. After the warning hides, the address-type result shows, and “Applying changes” does not remain until dismissed. A toast already waiting, such as “Payment returned to Savings”, stays until the user dismisses it.

Earlier findings reconciled at this revision: 1 verified fixed.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving at 17b0f3c8f: no findings from the code scan, and the device gate passes.

Fixture: newer Paykit state was written by the same app code built against Paykit v0.1.1-rc9 with pubky/paykit-rs#267 merged (state format 6), installed over the PR build on one emulator, staging homeserver, fresh identity. The PR build then logs unsupported SDK state blob version 6, expected 4.

  • Case 1, restore the profile: "Failed to create profile / This profile needs a newer version of Bitkit. Update the app to use it.", no storage_error text.
  • Case 2, relaunch: the update toast shows once, no "session expired".
  • Case 3, offline start then online: "Internet Connection Restored", then the update toast; Profile keeps the update reason above Try Again.
  • Case 5, address type change during the warning: the warning stays, then "Applying changes…" and "Address Type Changed", nothing left on screen.
  • Regression: a normal launch restores with no toast; Disconnect from the unrestored profile returns to Home and clears the owner.
  • ⚠️ Case 4 not run: it needs a swaps-enabled build, a regtest swap provider and an interrupted claim that survives a restore. Also not run: case 1 through Pubky Ring, and the case 5 variant where the result arrives while the warning is still showing.

On skipping the re-sign-in: at v0.1.1-rc9 neither sign_in nor import_session reads the shared state; both go through activateBootstrapResult, which does. A re-sign-in would fail the same way after creating a new grant, so skipping it loses nothing. On device, sign-up and sign-in both failed with the version-6 error.

Note on case 3: the offline cold start logs identity_error for both the restore and the re-sign-in attempt, not a deferred restore, and the update toast came from the reconnect retry. The user sees the same result; the description's "deferred retry after an offline start" is not the path taken here.

Device gate: cases 1, 2, 3, 5 and both regression checks pass; ⚠️ case 4 not run. perf: ⚠️ not measured; not performance-relevant (an error classification and one toast).

Reviewer model: claude-fable-5-2 (primary, device runbook), claude-opus-5-5 (coordinator)
Reasoning effort: Not exposed

@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Merging at 17b0f3c: approved on this head, CI green, no open threads. Case 4 stays unrun; it needs a swaps-enabled build with an interrupted claim that survives a restore. The description now says an offline start gets its update toast from the retry on reconnect, as the device run showed.

@ovitrif
ovitrif merged commit 791d51b into master Nov 25, 2026
23 checks passed
@ovitrif
ovitrif deleted the fix/paykit-update-msg branch November 25, 2026 10:05
@piotr-iohk

Copy link
Copy Markdown
Collaborator

Device QA results

Tested 17b0f3c8fa6ccb63a86329fa4c1a6ee7c6bd63db on a Pixel 6 emulator (API 33) and Galaxy S22 (Android 16), using regtest. A newer Paykit SDK wrote and read back version 6 state on the test homeserver. The tested build expected version 4.

Four of five manual cases passed. Across manual cases, controls, and exploration, 11 passed, 2 failed, and none remained blocked.

Case Result Device observation
1. Interactive connection PASS Connecting the incompatible profile showed the translated update guidance.
2. Saved profile on cold launch PASS The wallet showed the update warning and retained the saved session.
3. Offline start and recovery PASS Reconnecting triggered the warning. Profile retained the update hint above Try Again.
4. Restored swap and reconnect FAIL A real 20,000-sat swap settled. “Payment returned to Savings” appeared for 1.243 seconds before a connection warning displaced it without dismissal. “Back online” followed.
5. Address change with a payment return queued PASS During the real update warning, a test emitter queued the production payment-return event. The Taproot result replaced “Applying changes” in the queue. The payment message stayed visible for 63 seconds until its close button was tapped. The green Taproot confirmation appeared next.

Additional checks. Compatible-profile relaunch, ordinary address change and persistence, a completed address change behind the warning, background/foreground without a duplicate warning, and disconnecting the incompatible profile passed. S22 controls verified both the warning and the standalone payment notification. The second failure was a timing variant of case 4: starting an address change when the payment message was already visible displaced it before dismissal.

The restored-swap recording, provider settlement log, queue timestamps, and reproduction steps are in #2030.

@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

4. Restored swap and reconnect | FAIL

@piotr-iohk Thanks, taking it in #2030. A shown toast is still replaced by the next one, as on master. The fix makes "Payment returned to Savings" hold later toasts behind it until it is closed, which covers both the reconnect and the address-change timing.

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

5 participants