Skip to content

fix: offer existing server accounts on re-approval - #2251

Open
ovitrif wants to merge 6 commits into
masterfrom
fix/reuse-server-account
Open

ovitrif wants to merge 6 commits into
masterfrom
fix/reuse-server-account

Conversation

@ovitrif

@ovitrif ovitrif commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2237
Twin: synonymdev/bitkit-ios#1587
Refs:

Description

  • Adds a Bitcoin Account step to Paykit server approval when the wallet already has active server accounts, so that re-approving a server can share an existing account instead of always creating a new one
  • Preselects the account whose name matches the server's default account name (tracked accounts first, then newest), with "New account" as the other choice
  • Shares the chosen account's xpub again without reserving a new account index; before its claim is sent the account is tracked on the node (even when already stored as tracked) and the approval fails if it is no longer active on this wallet; it stays tracked whatever the outcome
  • Pins a retry to the account the server already holds after a post-delivery authorization failure, while the sheet stays open
  • Resumes an unfinished setup for the same request instead of showing the choice, and drops the choice once a failed attempt leaves one, so a retry never delivers a second xpub for one request or ignores the account shown as selected
  • Cancelling or backing out of a reused account leaves it untouched; only a new account's unfinished setup is cancelled

Out of Scope

Design

N/A — no design available.

Preview

Re-approving a server whose account already exists, same-name account preselected:

Account choice Flow
android-choose-2x.mp4

QA Notes

Setup

  • Dev build (regtest) against the bitkit-docker marketplace profile, as in journeys/pubky-marketplace/README.md
  • A wallet with a Bitkit-created Pubky profile and one active server account from approving ./pubky-marketplace setup-url once
  • Each run of the journey needs a fresh setup-url (a new secret)

Journeys

  • J1: new reapprove-server-account.xml — re-approval offers the existing account preselected, reusing it keeps one account, "New account" adds one

Manual Tests

N/A

Automated Checks

  • updated PubkyAuthApprovalViewModelTest.kt — choice shown with existing accounts, new account beside existing ones, reused account tracked after a post-delivery authorization failure, unfinished setup skips the choice, a failed new-account attempt drops the choice, a reused account is tracked before delivery and stays tracked on failure, a reused account that cannot be tracked is not sent, a post-delivery failure pins the retry
  • updated WatchOnlyAccountRepoTest.kt — reuse shares the chosen account without a new index; an unfinished setup for the request is resumed instead; tracking a reused account adds it to the node, also when stored as tracked, and fails when it is no longer active on this wallet

Evidence

  • 51f95a1 (the choice screen is unchanged in 3b9ed53) on an Android emulator: a second setup URL for a wallet with server accounts shows the Bitcoin Account step with the same-name account preselected and "New account" below; Continue reaches Authorize (Preview)
  • Local verification on 5b2a9b5: just test, just lint

Gaps

  • J1 Back and Cancel steps unrun on device; unit tests cover the state they leave
  • J1 Authorize steps (reuse, then "New account") unrun: they need the live authorization relay from the marketplace profile, which was not running for this run

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: Gemini 4 Neon (reasoning: high)
  • Review rounds: 7

Verified: just test (7034 tests; ElectrumProbeServiceTest unreachable-host case failed under load and passes alone, untouched by this change), just lint, PubkyAuthApprovalViewModelTest and WatchOnlyAccountRepoTest after the last edit
@ovitrif ovitrif added this to the 3.3.0 milestone Dec 3, 2026
@ovitrif ovitrif self-assigned this Dec 3, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 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-12-03T16:55:48.292817Z 51f95a1 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 51f95a17c4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/src/main/res/values/strings.xml Resolved
@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 2/5RetriggerView in Greptile

[Medium impact] The change affects Paykit server approval for wallets with active Bitcoin accounts.

Fix retry consistency and durable tracking before merging.

Findings

  1. P1 Retries can change accounts ▶
  2. P1 The selected account is ignored ▶
  3. P1 Approved accounts can stay untracked ▶
  4. P2 TalkBack cannot read the selection ▶

Summary

Adds a Bitcoin account choice to server approval, with same-name preselection and an option to create a new account.

  • Paykit approval can reuse an existing Bitcoin account.

Acknowledged scope: ovitrif explicitly deferred translated strings to #2250, the service-name difference between apps, and watch-only loading after node start to #2248. No findings are raised for those items.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Receiving-details consent] --> B{Unfinished setup?}
  B -->|Yes| C[Resume the same account]
  B -->|No active accounts| D[Prepare a new account]
  B -->|Active accounts exist| E[Choose an account]
  E -->|Existing| F[Prepare reused account]
  E -->|New| D
  C --> G[Deliver claim and authorize]
  D --> G
  F --> G
  G -->|Success| H[Activate or enable tracking]
  G -->|Failure| I[Return to authorization]
Loading

Reviews (1) · Last reviewed commit: "fix: offer existing server accounts on r..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 5b2a9b5 (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.

1 finding (1 P1). Adds a Bitcoin Account step to Paykit server re-approval, so an existing active account can be shared again instead of reserving a new index. Reviewed 51f95a1, full tier, static.

What I checked, and 4 candidates I ruled out

Read in full: WatchOnlyAccountRepo.kt, the changed paths of PubkyAuthApprovalViewModel.kt (load, approveWatchOnlyConsent, selectAccount, confirmAccountChoice, returnToPreviousStep, authorize, approveSignInRequest, handleApprovalFailure, preselectedAccountId), PubkyAuthApprovalSheet.kt (ChooseAccountContent, approvalBackAction), the new tests in PubkyAuthApprovalViewModelTest.kt and WatchOnlyAccountRepoTest.kt.
Call sites traced: prepareUnsignedClaim, beginAuthorization, cancelAuthorization, setTrackingEnabled, markActive, isPostDeliveryAuthorizationFailure.
Not built: on this repo I review from the code and CI and do not build the branch.
CI: Greptile, build-local and detect-changes green; build-and-test, lint, compose-ui and the local e2e jobs were still pending when I posted.

Ruled out

  • Reused account cancelled on a failed retry: cancelAuthorization returns early for an Active record, and the view model skips cancelIncompleteSetup when isReused, so a reused account's state is never rolled back.
  • Reuse on the signup path: approveSignupAuth requires bitkitClaim == null, so reuseAccountId never reaches a signup.
  • Stale selection after a new auth URL: resetForLoad rebuilds the state from scratch, so existingAccounts and selectedAccountId do not carry over to another request.
  • Tracking a reused account that the user turned off: setTrackingEnabled(enabled = true) runs only after delivery (success or post-delivery failure), and that matches the PR's stated intent.

A second reader from another model family tried to refute the finding; it stood.

Merge confidence: 3/5, one P1 on a retry path.

Reviewer model: claude-opus-5-5, cold refutation pass xiaomi/mimo-v2.6-pro
Reasoning effort: Not exposed (the runtime does not report it for either model)

@ovitrif
ovitrif requested review from a team, ben-kaufman and piotr-iohk and removed request for a team December 3, 2026 18:02
@ovitrif

ovitrif commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

@aldertnl copy for the new Bitcoin Account step on Paykit server re-approval, for your review (screens under Preview; the same on iOS in synonymdev/bitkit-ios#1587):

  • Title: "Bitcoin Account"
  • Description: "Choose the Bitcoin account this server can view. A new account keeps this server apart from your other servers."
  • Last row: "New account"

The step shows only when the wallet already has server accounts. It preselects the account whose name matches this server's default name; with no match it preselects "New account". Sharing one account with several servers lets those servers link the user's payments to one wallet, which the description only hints at. The strings stay English until the copy settles: #2250 and synonymdev/bitkit-ios#1585.

@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 3b9ed537.

No new actionable code findings.

No new actionable code findings. When the wallet already has active server accounts, Paykit re-approval shows a Bitcoin Account step, preselects the same-name account (tracked accounts first, then newest), and shares that account's stored xpub without reserving a new index. A reused account stays unchanged if authorization fails before delivery, and tracking is turned on only after the claim is delivered. "New account" still creates one account. Back and Cancel before authorization do not write a setup.

The review on 51f95a1 that a failed "New account" attempt still offered the chooser, so a later selection was ignored, is marked resolved (Talos, Codex, Greptile). At this head a failed approval that leaves a non-active setup clears the chooser, including when the failure happens before delivery and the record remains PendingDelivery. Back returns to the Earn introduction, and a retry resumes that unfinished account. The same flow is in bitkit-ios#1587 at 850d67bf. That comparison covers this flow only.

Open threads ask for a tracking flag saved before delivery (Codex, Greptile). Tracking is applied after delivery so a failure before delivery leaves a reused account untracked. If enabling tracking then fails, the sheet shows the authorization error and a retry runs it again. Startup loads only accounts already marked tracked, and Server Accounts can turn tracking on. This review does not add that window as a defect. An open thread about a second xpub after a delivered reuse (Greptile) is a later explicit choice, which this head sends as selected.

The three new strings stay English until #2250. Other locales fall back to that English. That thread is marked resolved as out of scope. No design was available for the new step.

Non-blocking consistency suggestions

  • TalkBack cannot tell which account is selected: the checkmark has no content description and the row has no selected state. iOS sets the selected trait on the same row.
  • The iOS suite README notes that the default account name is "{service} account" there and "{service} server" here. The Android README for this journey does not. Preselection compares names on the same platform.

Device testing: not performed in this review. The author reports the choice screen on 51f95a1; J1 Back, Cancel, and Authorize were not run. build-and-test and lint succeeded on this commit. Some local end-to-end jobs were still running and are not evidence for this flow.

Suggested additional test cases

  • Android, regtest, one active server account. Choose "New account" and fail authorization before the server accepts. Back should show the Earn introduction. Authorizing again should keep a single new account for that URL and should not share the original account.
  • Android, several active accounts that share the default name, as in #2237. The checked row should be the newest tracked account and visible on the step. Continue and Authorize should keep that derivation path and xpub, with tracking on, and should not add an account.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@ovitrif

ovitrif commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

TalkBack cannot tell which account is selected

The Android README for this journey does not.

@piotr-iohk both are in: the choice rows set the selected state in e3ffa9e, and the suite README notes the per-app default name in b5c7d56.

One change since 3b9ed53 you reviewed: in e3ffa9e a reused account that was untracked is now tracked before its claim is sent and stays tracked whatever the outcome (the Codex and Greptile threads you mention), and after a post-delivery failure the open sheet pins a retry to the account the server already holds. Keeping that pin once the sheet is closed and reopened is #2253.

@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 3b9ed537, including affected code paths and prior findings, at b5c7d567. Baseline: QA review.

No new actionable code findings.

No new actionable code findings in the follow-up. An untracked reused account is marked tracked before its claim is sent, and that tracking remains if authorization fails. While the sheet stays open, a post-delivery authorization failure pins the retry to that account and hides the account choice. The choice rows now publish a selected state, and the journey README notes that Android's default name is "{service} server" while iOS uses "{service} account". The same tracking and in-sheet pin are in bitkit-ios#1587 at c8fbfbc6; that comparison covers this flow only. Baseline coverage of watch-only claim reuse, unfinished-setup resume, the English account-choice strings, and the changelog fragment is unchanged.

A failed "New account" attempt still clears the chooser, so a later selection is not ignored. That thread is resolved (Talos). Closing the sheet and reopening the same URL can still share a different account after a delivered reuse; that thread is resolved and tracked in #2253. The three new strings stay English until #2250; that thread is resolved.

Device testing: not performed in this review. The author reports the choice screen on 51f95a1; J1 Back, Cancel, and Authorize were not run. build-and-test and lint succeeded on this commit. Local end-to-end jobs were still running and are not evidence for this flow. TalkBack was not run.

Suggested additional test cases

  • Android, regtest, one active server account with tracking off. Open a fresh setup URL, keep that account, and disable the network before Authorize. After the error, Server Accounts should show that same account as tracked, and the open sheet should still offer the account choice.

Reviewer model: grok-4.7
Reasoning effort: xhigh

Verified: just test, just lint
The store can say tracked while the node lost the account, so the node is
always asked to track a reused account before its claim is sent.

Verified: just test, just lint
@ovitrif

ovitrif commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed b8fcf71 and 5b2a9b5: a reused account is now tracked in one step under the account lock before its claim is sent. The approval fails if the account is no longer active on this wallet (a restore or wipe removed it meanwhile), and the node is asked to track it even when the store already says tracked, since the node can lose it. WatchOnlyAccountRepoTest.kt covers both cases.

@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 b5c7d567, including affected code paths and prior findings, at 5b2a9b529. Baseline: QA review.

No new actionable code findings.

No new actionable code findings in the follow-up. Before a reused account's claim is sent, tracking now fails the approval when that account is no longer active on this wallet, and the running node is asked to track the account even when the store already says it is tracked. When the node is not up, the existing deferral remains: the tracked flag stays in the store and startup reconciliation loads the account. A tracking failure still stops the claim. An in-sheet retry after a post-delivery failure stays pinned to that account. A failed new-account attempt still clears the chooser; that thread is resolved (Talos).

Closing the sheet and opening the same URL again can still share a different account after a delivered reuse. That thread is resolved and remains tracked in #2253. The three new account-choice strings stay English until #2250; that thread is resolved.

On bitkit-ios#1587 at c8fbfbc6, a reused account the store already marks tracked is sent without another node tracking call. This Android head asks the running node to track that account and fails the approval when the account is no longer active on this wallet. That comparison covers this tracking path only.

Ready for device testing. The follow-up does not change the account-choice screen. J1 Authorize is the step that now re-tracks an already stored account before the claim is sent.

Device testing: not performed in this review. The author reports just test and just lint on this commit; the choice screen was checked on 51f95a1. J1 Back, Cancel, and Authorize remain unrun. build-and-test and lint succeeded on this commit. Local end-to-end jobs were still running and are not evidence for this flow.

Reviewer model: grok-4.7
Reasoning effort: xhigh

This branch has not been deployed

No deployments
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: each paykit server approval creates a new watch-only account

3 participants