Skip to content

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

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

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

Conversation

@ovitrif

@ovitrif ovitrif commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Twin: synonymdev/bitkit-android#2251
Source: qa, synonymdev/bitkit-android#2237
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 in one locked step (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

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
ios-choose-2x.mp4

QA Notes

Setup

  • Debug 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
  • iOS opens the setup URL as bitkit://pubky-auth/setup?<query of the pubkyauth URL>; 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 PubkyAuthApprovalSheetTests.swift — choice offered when accounts exist, same-name preselection, reuse shares the chosen account and tracks it, inactive accounts rejected, reused account tracked before delivery and kept tracked after either failure, unfinished setup resumed instead of a chosen account, an already tracked account is tracked on the node again
  • updated WatchOnlyAccountServiceTests.swift — tracking a reused account needs it active on this wallet
  • ran PubkyAuthApprovalSheetTests and WatchOnlyAccountServiceTests on 6017e8e

Evidence

  • 7afd2c593 (before the review fixes; the screen is unchanged since) on an iPhone simulator: 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 (Preview)

Gaps

  • J1 Back, Cancel and Authorize steps unrun on device; Authorize needs the live authorization relay from the marketplace profile, which was not running for this run; unit tests cover the state each step leaves

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: 6

Verified: xcodebuild test unit selection from unit-tests.yml on an iPhone 17 simulator before the review fixes (4721 tests, 0 failures), PubkyAuthApprovalSheetTests after them (48 tests, 0 failures), swiftformat --lint on changed files, node scripts/validate-translations.js
@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-03T18:03:53.115231Z 5109478 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.

Verified: none (changelog text only)
@ovitrif
ovitrif requested review from a team, ben-kaufman and jvsena42 and removed request for a team December 3, 2026 18:03

@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: 510947876a

ℹ️ 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 Bitkit/Services/PubkyService.swift Resolved
@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 3/5RetriggerView in Greptile

[High impact] The change reaches the Paykit server approval flow and can share an existing account with a server.

Save the reused account's request ownership and tracking intent before merging.

Findings

  1. P1 Retry can share another account ▶
  2. P1 Delivered accounts can stay untracked ▶

Summary

Adds a Bitcoin Account choice when approving a server request with existing active accounts.

  • Server approval lets people choose an existing Bitcoin account.
  • Re-approval can share an active account without creating another.

Acknowledged scope from ovitrif: translations are deferred until copy is final; account-name differences between platforms remain intentional; account loading after node start is deferred to #1584.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Approve receiving details] --> B{Unfinished setup?}
    B -->|Yes| C[Resume saved account]
    B -->|No active accounts| D[Create new account]
    B -->|Active accounts exist| E[Choose account]
    E -->|New account| D
    E -->|Existing account| F[Deliver chosen xpub]
    F --> G[Enable tracking]
    C --> H[Authorize]
    D --> H
    G --> I{Authorization finished?}
    I -->|Yes| J[Success]
    I -->|No| K[Retry can choose another account]
Loading

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

Comment thread Bitkit/Services/PubkyService.swift Resolved
Comment thread Bitkit/Services/PubkyService.swift Resolved

@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 new findings. Adds a Bitcoin Account step to server re-approval so an existing active server account can be shared again instead of reserving a new index. Reviewed 850d67bfd, full tier, static: iOS does not build on Linux, so this review is reasoned from the code and from CI.

What I checked, and 6 candidates I ruled out

Read in full: PubkyService.approveAuthRequest, WatchOnlyAccountManager (claim preparation, authorization attempt, setTrackingEnabled, requestFingerprint), PubkyAuthApprovalSheet state machine, onBack and performAuthorization, the new tests and reapprove-server-account.xml
Call sites traced: hasIncompleteSetup, reusableAccount, offersAccountChoice, didDeliverCompanionClaim
CI: SwiftFormat and validate green; Run Tests, Run Integration Tests and build-local still pending at the time of review

Ruled out

  • Reused path skips acquireSetupAuthorizationAttempt: it writes no setup state, and two concurrent reuses only call the idempotent setTrackingEnabled under the lifecycle lock, so the lock has nothing to protect there.
  • Stale choice after a failed new-account attempt: cancelIncompleteAuthorization leaves the record in .pendingDelivery, so hasIncompleteSetup is true and the sheet clears existingAccounts; the retry resumes that record.
  • Account from another wallet: the sheet filters by currentWalletIndex and reusableAccount re-checks wallet and .active under the lock.
  • USDT combined claims: unsignedPayload(account:usdtEndpoint:) takes the reused record the same way as a new one; requiresUsdtAddress is false whenever Bitcoin is shared, so the USDT toggle cannot strand the sheet in .chooseAccount.
  • Back navigation: .authorize returns to .chooseAccount only while the choice is offered; after a failure clears it, Back goes to consent as before.
  • Already raised, not repeated: tracking not persisted before delivering a reused account, and a retry after a post-delivery failure sharing a different account (Greptile and Codex threads on PubkyService.swift:240), still unaddressed at this head; localization is out of scope via #1585; the changelog fragment landed in 850d67bfd.

Merge confidence: 3/5, the open P1 on keeping a delivered reused account tracked across a crash is real by trace (nothing persists tracking before companionApproval) and unaddressed at this head, and unit tests had not finished.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (runtime setting only, no per-review record)

Verified: PubkyAuthApprovalSheetTests on an iPhone 17 simulator (48 tests, 0 failures), swiftformat --lint on changed files
@ovitrif

ovitrif commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

c8fbfbc also has the reuse path take the same single authorization attempt as a new account, so two approval sheets can no longer send claims at the same time.

A reused account is checked and tracked in one step under the lifecycle lock,
failing when it is no longer active on this wallet. The node is asked to track
it even when the store already says tracked, since the node can lose it.

Verified: xcodebuild test -only-testing:BitkitTests/PubkyAuthApprovalSheetTests -only-testing:BitkitTests/WatchOnlyAccountServiceTests, swiftformat --lint
A wallet switch while waiting for the lock could match a reused account
against the previous wallet, so the wallet is read inside the lock.

Verified: xcodebuild test -only-testing:BitkitTests/PubkyAuthApprovalSheetTests -only-testing:BitkitTests/WatchOnlyAccountServiceTests, swiftformat --lint
@ovitrif

ovitrif commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 12b0c53 and 6017e8e: a reused account is now tracked in one step under the account lock before its claim is sent, with the current wallet read inside the lock. The approval fails if the account is no longer active on this wallet (a restore, wipe or wallet switch meanwhile), and the node is asked to track it even when the store already says tracked, since the node can lose it. WatchOnlyAccountServiceTests.swift and PubkyAuthApprovalSheetTests.swift cover both cases.

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.

2 participants