Skip to content

fix(wallet): re-read wallet presence where a setup flow spans user interaction - #1152

Open
romchornyi wants to merge 26 commits into
fix/defer-launch-decision-until-activefrom
fix/wallet-presence-guards-in-setup
Open

romchornyi wants to merge 26 commits into
fix/defer-launch-decision-until-activefrom
fix/wallet-presence-guards-in-setup

Conversation

@romchornyi

@romchornyi romchornyi commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Stacked on #1151 (base branch fix/defer-launch-decision-until-active), which makes the launch decision wait for the first foreground activation. The invariant it states leaves one class of read to the screens: flows spanning user interaction re-read at execute time. Three setup flows did not:

  • the recover screen accepted a phrase against one presence read, and DWSetupViewController executed the deferred DWRecoverWalletCommand after the PIN step without looking again — an import next to a wallet the second read could not see, or setup completed with a PIN and no wallet;
  • DWPreviewSeedPhraseModel.getOrCreateNewWallet turned an unreadable keychain (and an unreadable stored phrase) into an empty phrase that looked like success: Skip could complete setup without a wallet, and the backup preview could open blank; the backup reminder called the generating entry point and could create a wallet from a "view recovery phrase" flow;
  • Create started even when the inventory could not be read.

Split out of #1147 (superseded); the fixes are the ones its review settled on.

Scope

Scope frozen at 71e4903. Stacked on #1151. This PR fixes two defects:

  1. Setup and recover flows now read wallet presence again at the moment an action executes: import only on a definite "absent", Try Again on "unknown", and one attempt at a time.
  2. A failed recover import can be retried. On develop, a retry of the same mnemonic threw WalletAlreadyExists. The host now resumes a partially persisted import: it finds the wallet already stored for that mnemonic and provisions only the missing network.

Deep-link handling findings are pre-existing on develop and tracked in #1158, fixed in #1159.

What was done?

  • DWSetupViewController: executeRecoverCommandIfAllowedThenContinueSetup re-reads presence when the deferred recover command runs. Only a definite absent imports; unknown imports nothing and completes nothing — the command is kept and an alert offers Try Again (re-validate and execute) or Cancel (drop the command, back to the setup screen); present (a wallet landed meanwhile) imports nothing and completes setup into the existing wallet. Create refuses on unknown with the same alert.
  • Recover screen: DWRecoverModel.walletPresence (declared in the Swift extension — the header is in the bridging header) is read once per submitted phrase, and that snapshot drives both the unknown guard and the wipe-versus-recover route; the wipe shortcuts and the support acknowledgement are behind the same guard. New delegate callback recoverContentViewWalletPresenceUnknown: shows the alert.
  • DWPreviewSeedPhraseModel.getOrCreateNewWallet is nullable: nil when the keychain cannot be read, when the stored phrase cannot be read or is empty, and when generation fails. A nil never created anything and no caller reports a step complete on it.
  • BackupInfoViewController: one read — the model's — decides creation at the action (Skip / Show Recovery Phrase); nil stops the step with the alert. The backup reminder reads the stored phrase and binds the model with initWithExistingSeedPhrase:, so it can never generate. The phrase-length picker is offered unless a wallet is definitely present.
  • BackupSeedPhraseViewController: after a screenshot-triggered wipe whose replacement could not be generated, the screen pops back to the backup-info step (the seed view cannot show nothing) and the alert is shown there; the next Show Recovery Phrase / Skip regenerates.
  • One new English string, Your wallet couldn't be read right now. Please try again. (other locales through Transifex).

How Has This Been Tested?

  • App: dashpay scheme, Debug, arm64 simulator, Xcode 27 (local-only -ld64 → -ld_classic) — built successfully.
  • Unit tests on an iOS 26.5 simulator: SwiftDashSDKCoreLifecycleTests + BackgroundRefreshCoordinatorTests: 107 run, 4 failures — the 2 known pre-existing balance-message tests (testDuffDenominatedInsufficientBalanceMessageNamesTheBalance, testShieldedInsufficientBalanceMessageUsesSpendableAmount, each counted twice), untouched by this change. python3 scripts/test_wallet_preparation.py: 44/44.
  • No unit seam exists for these view controllers and the Obj-C model; the flows are covered by the invariant above and were exercised in the simulator on the superseded branch (Create → PIN → backup screens, Recover → PIN, Settings → recovery phrase).

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

…teraction

Follow-up to the launch fix: flows that span user interaction re-read
presence at execute time instead of trusting a read made before the user
typed.

- DWSetupViewController re-validates when the deferred recover command
  runs after the PIN step: only a definite "absent" imports; "unknown"
  keeps the command behind Try Again / Cancel, "present" completes into
  the existing wallet. Create refuses on "unknown".
- The recover screen reads presence once per submitted phrase
  (`DWRecoverModel.walletPresence`) and routes every branch from it.
- `DWPreviewSeedPhraseModel.getOrCreateNewWallet` returns nil when the
  keychain or the stored phrase cannot be read; the backup screens stop
  on nil, the backup reminder previews read-only, and the seed screen
  pops when a post-screenshot replacement cannot be generated.

Split out of #1147.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63436cf6-645c-458b-ab49-90a6202bb69e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit 32d10cd) · triage: critical

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

Preliminary review — Phase 1 blocker gate

Verified the supplied findings against head e9a10f7 and its stacked base. Two blocking recovery defects remain: the unreadable-wallet callback has no implementation, and cancelling the deferred-recovery alert leaves a PIN that causes subsequent recovery to skip command execution. The new error message is also missing from the English localization catalog; the broader existing-wallet security claims do not establish an additional in-scope defect.

Validated blockers were found by the Phase-1 review and confirmed by a fresh verifier. Phase 2 is deferred until a fresh same-head revalidation clears the blocker gate.

🔴 2 blocking | 🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: gemini-3.8-flash-high (agent: phase1-reviewer, role: general); reviewer 2: gemini-3.8-flash-high (agent: phase1-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-gate-verifier, role: verifier)

  • Triage: normal by gpt-6-astra (effort low) — The diff changes wallet creation and recovery guards in DWSetupViewController and DWPreviewSeedPhraseModel, but consists of straightforward presence checks, nullable-result propagation, and retry UI rather than a large or intricate change to key handling.
  • Phase 1 reviewers: gemini-3.8-flash-high — general (completed, effort high); agent phase1-reviewer, gemini-3.8-flash-high — security-auditor (completed, effort high); agent phase1-reviewer
  • Phase 1 model: gemini-3.8-flash-high — antigravity quota: weekly 82% left, 5h 98% left
  • Fresh verifier: gpt-6-astra — verifier; agent astra-gate-verifier
  • Phase 2 reviewers: not run (deferred by blocker gate)
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/RecoverWallet/Views/DWRecoverContentView.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/RecoverWallet/Views/DWRecoverContentView.m:181-185: Implement the unreadable-wallet delegate callback before calling it
  When wallet presence is unknown, this branch sends recoverContentViewWalletPresenceUnknown: to the content view's delegate. DWRecoverViewController assigns itself as that delegate but does not implement the newly declared selector; there is no implementation elsewhere in the source tree. A phrase submission that encounters an unreadable inventory therefore raises an unrecognized-selector exception instead of presenting the promised retryable error. Implement the callback in DWRecoverViewController and display the localized error without proceeding with recovery or wipe. Because this is a required delegate method, adding a respondsToSelector: guard is not a substitute for implementing it.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:169-175: Preserve a working recovery path after cancelling the unreadable-wallet alert
  This alert is reached after DWSetPinViewController successfully persists the new PIN through DWSetPinModel.setPin:. Cancel clears the recovery command and returns to setup but leaves that PIN intact. Once the inventory becomes readable and absent again, submitting another recovery phrase stores a new command and calls continueOrCompleteWalletSetup. DWSetPinModel.shouldSetPin now returns NO, so the PIN callback—the only entry point that executes the deferred command—is skipped. Recovery also sets walletNeedsBackup to NO, so after any biometric step setup can finish without importing the phrase or creating a wallet. Make cancellation roll back the provisional PIN safely, or make the recovery state machine execute and revalidate a pending command even when a PIN already exists. Cover the unknown → Cancel → readable/absent → Recover sequence.
- [SUGGESTION] DashWallet/Sources/UI/Setup/DWSetupViewController.m:105-107: Add the new error message to the English localization catalog
  The new NSLocalizedString key, "Your wallet couldn't be read right now. Please try again.", appears in the setup and backup controllers but is absent from DashWallet/en.lproj/Localizable.strings. The Transifex configuration explicitly uses that file as its source catalog, so pushing the current catalog will not make this message available for translation. Add the English key/value entry in the existing UTF-8 encoding so the stated Transifex follow-up can include it.

jeanpierreroma and others added 2 commits September 25, 2026 12:27
…active' into fix/wallet-presence-guards-in-setup
…h an existing PIN

- `DWRecoverViewController` implements
  `recoverContentViewWalletPresenceUnknown:` (the content view already
  called it) and shows the localized error; nothing proceeds.
- `recoverViewControllerDidRecoverWallet:` executes the recover command
  at once, with the same presence re-read, when a PIN already exists —
  kept through a reinstall, or set by an earlier attempt that stopped at
  the unreadable-wallet alert — because the PIN step, whose callback
  executed the command, is skipped then. Only a launch that still has to
  set a PIN defers to that step.
- The English catalog carries the new string.

The callback and the catalog line were part of the original change and
were lost to a build-residue revert before the commit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

The follow-up correctly adds the unreadable-wallet callback and localization, and it now executes recovery when an existing PIN skips the PIN screen. However, that new path completes setup immediately after starting an asynchronous import whose failures are swallowed, so a failed or delayed import can transition the user into the main app without a wallet.

🔴 1 blocking | 🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The diff intricately changes mnemonic creation, recovery import, and backup handling across deferred PIN and retry flows, notably in DWSetupViewController.executeRecoverCommandIfAllowedThenContinueSetup and DWPreviewSeedPhraseModel.getOrCreateNewWallet, directly affecting key handling.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 35% left, 5h 0% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:180-189: Wait for the asynchronous wallet import before completing setup
  When an existing PIN causes recovery to skip the PIN screen, this branch calls `command.execute`, clears the deferred command, and immediately calls `continueOrCompleteWalletSetup`. `DWRecoverWalletCommand` invokes `DWSwiftDashSDKWalletCreator.importWalletWithMnemonic`, which only queues work on a background queue and returns before the mnemonic is persisted or the runtime is rebuilt. The creator catches import and persistence errors without exposing a completion result. Consequently, a slow or failed import can transition the root controller into the main app with no wallet, while the command has already been discarded and cannot be retried. Make the command or wallet creator provide an awaitable success/failure result, and clear the command and complete setup only after successful import; retain it and show a retryable error on failure.
- [SUGGESTION] DashWallet/Sources/UI/Setup/DWSetupViewController.m:220-230: Add regression coverage for recovery when a PIN already exists
  The existing-PIN conditional is the new behavior that executes the deferred recovery command without presenting the PIN screen, but there is no focused coverage for this exact head. Add a regression test or executable harness covering an existing PIN with a successful import, an `unknown` re-read that retains the command for retry or cancel, and a `present` re-read that avoids importing a second wallet. The test should also verify that setup is not completed until the asynchronous import reports success.

jeanpierreroma and others added 2 commits September 25, 2026 14:57
…active' into fix/wallet-presence-guards-in-setup
`DWSwiftDashSDKWalletCreator.importWalletWithMnemonic:pin:network:` only
queues the import and returns, so the recover flow — the PIN-step path
and the existing-PIN path alike — completed setup before the mnemonic
was persisted, and a slow or failed import opened the main screen over
no wallet with the command already discarded.

The creator gains a completion-bearing import that reports success once
the host has persisted the mnemonic and created the wallet;
`DWRecoverWalletCommand.executeWithCompletion:` uses it. The setup
controller clears the command and continues only on success; a failure
keeps the command behind Try Again (re-run) / Cancel (back to setup).
The fire-and-forget entry point stays for the create flow.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

The current changes resolve four prior findings, including waiting for recovery import completion and restoring recovery when a PIN already exists. Two blocking issues remain: recovery allows overlapping submissions while an import is pending, and the preview still consumes the newly nullable phrase result without checking it. The exact-head preparation harness passed all 48 tests, but it does not exercise these controllers; app compilation and runtime smoke were not independently verified in this pass.

🔴 2 blocking | 🟡 1 suggestion(s)

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: gemini-3.8-flash-high (agent: phase1-reviewer, role: general); reviewer 2: gemini-3.8-flash-high (agent: phase1-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The diff intricately changes mnemonic creation and recovery gating across user interaction and asynchronous import completion in DWSetupViewController, DWPreviewSeedPhraseModel.getOrCreateNewWallet, and SwiftDashSDKWalletCreator, directly affecting key handling and whether setup proceeds with a persisted wallet.
  • Phase 1 reviewers: gemini-3.8-flash-high — general (completed, effort high); agent phase1-reviewer, gemini-3.8-flash-high — security-auditor (completed, effort high); agent phase1-reviewer
  • Phase 1 model: gemini-3.8-flash-high — antigravity quota: weekly 28% left, 5h 63% left
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:167-180: Prevent another recovery submission while the import is pending
  With an existing PIN, the recover screen remains interactive while this completion is pending. Neither its Recover action nor the setup controller has an in-flight guard, so another submission can replace recoverWalletCommand and launch another import. Both submissions can observe absent: SwiftDashSDKHost.createOrImportWallet awaits SDK construction before persisting the mnemonic, and onboarding imports are not lifecycle-serialized. Moreover, this callback unconditionally clears the current command and advances setup, even if it belongs to an older attempt or the user has navigated back. This permits competing wallet/runtime creations and completion against the wrong attempt. Prevent repeat submissions and conflicting navigation until the import settles, and associate completion handling with the attempt that initiated it.
- [SUGGESTION] DashWallet/Sources/UI/Setup/DWSetupViewController.m:241-253: Add regression coverage for recovery when a PIN already exists
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4103994301)
  The existing-PIN route now executes the deferred command directly, but no focused regression test exercises this controller or DWRecoverWalletCommand. The passing preparation harness covers launch/lifecycle behavior, not recovery after setting a PIN and cancelling the unreadable-wallet alert. Add a controller seam or focused UI test for that sequence, asserting exactly one import and no setup completion before delayed success. Also cover an unknown presence re-read retaining the retry/cancel path, a present re-read skipping import, and import failure preserving recovery retry.

In `DashWallet/Sources/UI/Setup/SecureWallet/BackupInfo/BackupInfoViewController.swift`:
- [BLOCKING] DashWallet/Sources/UI/Setup/SecureWallet/BackupInfo/BackupInfoViewController.swift:277-284: Pass the checked recovery phrase through to the preview
  This guard discards the successfully returned phrase. The pushed preview calls getOrCreateNewWallet again in DWPreviewSeedPhraseViewController.setupContentViewModel and assigns the result directly to contentView.model. In a .setup flow with an existing wallet, the model does not cache the stored phrase, so the second call performs another keychain read and can now return nil. The content view accepts nil and still exposes the confirmation checkbox; checking it enables Continue, whose handler force-unwraps contentView.model in BackupSeedPhraseViewController. The reminder path already avoids this second read by binding existingSeedPhrase, but the setup path does not. Pass the checked phrase through to the preview and make the remaining preview consumer reject nil rather than opening a blank, crashable screen.

jeanpierreroma and others added 2 commits September 25, 2026 20:49
… a phrase that could not be read

The recover import with an existing PIN runs off the main queue and
reports back later; meanwhile the recover screen was still accepting a
second submission (a second import), and a completion could not tell
which attempt it belonged to. `RecoverImportAttempts` (small, testable)
numbers the attempts: a submission while one is in flight is ignored, a
progress HUD over the navigation stack blocks input and navigation for
the duration, and a completion for an earlier attempt is inert — it can
neither clear a newer command nor advance setup.

The seed model read the stored phrase on "present" and threw it away, so
the preview screen's own call read the keychain again — a second read
that can fail where the first succeeded — and its nil turned into a blank
preview whose Continue force-unwrapped the missing model. The model now
keeps the phrase it read, the preview leaves the screen with the
"couldn't be read" alert instead of showing nothing, and Continue no
longer force-unwraps.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

At a5f9d56, five prior findings are fixed, but the recovery HUD still leaves keyboard submission and interactive navigation outside the attempt guard. The existing-PIN recovery decision also remains without focused regression coverage. The 50-test wallet-preparation harness, English catalog validation, and diff whitespace checks passed; these checks do not establish full-app build or end-to-end recovery correctness.

🔴 1 blocking | 🟡 1 suggestion(s)

2 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: gemini-3.8-flash-high (agent: phase1-reviewer, role: general); reviewer 2: gemini-3.8-flash-high (agent: phase1-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The diff intricately changes mnemonic creation, import, and retrieval across asynchronous setup and backup flows, notably DWSetupViewController.executeRecoverCommandIfAllowedThenContinueSetup and DWPreviewSeedPhraseModel.getOrCreateNewWallet, directly affecting key handling rather than merely surrounding UI.
  • Phase 1 reviewers: gemini-3.8-flash-high — general (completed, effort high); agent phase1-reviewer, gemini-3.8-flash-high — security-auditor (completed, effort high); agent phase1-reviewer
  • Phase 1 model: gemini-3.8-flash-high — antigravity quota: weekly 16% left, 5h 79% left
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:181-185: Prevent another recovery submission while the import is pending
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4105915981)
  The new delegate guard prevents duplicate imports through recoverViewControllerDidRecoverWallet:, but this HUD does not cover every submission or navigation route. DWRecoverContentView leaves its text view first responder, and its keyboard Done handler calls recoverWalletWithCurrentSeedPhrase directly. After createOrImportWallet persists the current-network mnemonic and suspends while provisioning another network, another Done submission can observe .present and reach recoverContentViewPerformWipe:, bypassing the guarded recovery delegate and offering a wipe during the import. Separately, the HUD is only a subview of the navigation view: it neither disables the navigation controller's interactive-pop recognizer nor invalidates the attempt when recovery is popped. The setup controller remains alive underneath, so finish(attempt) still succeeds and advances setup after the user leaves recovery. End editing and disable submission and conflicting navigation for the import's duration, or use an interaction boundary that covers all these routes; token matching alone does not detect departure from the initiating screen.
- [SUGGESTION] DashWallet/Sources/UI/Setup/DWSetupViewController.m:269-280: Add regression coverage for recovery when a PIN already exists
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4103994301)
  The new RecoverImportAttempts test exercises begin/finish and stale-token handling, not the existing-PIN decision, execute-time presence read, retained recovery command, or setup completion. It would still pass if this branch stopped executing the command or completed setup before the import succeeded. Manual verification therefore does not address the requested regression coverage. Add a focused UIKit fixture or an injectable recovery-decision seam covering existing PIN plus absent/success, unknown followed by Retry or Cancel and resubmission, present without another import, and delayed or failed completion without advancing setup.

jeanpierreroma and others added 4 commits September 26, 2026 00:04
… its submissions through one decision

The progress HUD only covered the navigation stack with a view: the
keyboard's Done key could still submit the phrase (a second import, or —
once the wallet landed mid-import — the recover screen's wipe route), and
the back button or the interactive pop could leave the flow with the
attempt still current, so its completion advanced setup after the user
had gone. While an import runs the keyboard is dismissed, the recover
screen and the navigation bar take no input and the pop gesture is off;
all of it is restored when the import reports. Should the user reach
this screen anyway while an attempt is in flight, the attempt is
invalidated — its completion is stale — and the command dropped.

The recover flow's two decisions move into `RecoverImportRouting`, pure
and unit-tested: at submission an import in flight is ignored, a missing
PIN defers the command to the PIN step and an existing PIN executes now;
at execution only a definite "absent" imports, unreadable retries and
present completes into the wallet that is there.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

At head 6b41ebb, the complete base-to-head diff addresses all seven prior findings, but the new retry path can complete setup after a partially persisted failed recovery. The 50-test preparation harness, two isolated exact-source recovery tests, whitespace and localization checks, and blocking accessibility audit passed. Full app build and runtime smoke remain unverified: package resolution stops because pinned DashUIKit requires Swift tools 6.3 while the installed Xcode 16.4 provides Swift 6.1.

🔴 1 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The diff intricately changes mnemonic creation, retrieval, and import eligibility in DWPreviewSeedPhraseModel.getOrCreateNewWallet and DWSetupViewController’s deferred recovery execution, including asynchronous completion and retry handling across PIN and backup flows, directly affecting key handling.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:223-227: Do not treat a partially persisted failed import as completed recovery
  Try Again can enter this branch because the failed import itself left a mnemonic behind, not because another wallet arrived. `SwiftDashSDKHost.createOrImportWallet` first completes `createAndPersist` for the current network, then provisions the other supported network. If that later provisioning fails, its catch shuts down the unpublished manager without rolling back the already successful current-network creation. The creator consequently returns failure without calling `handleWalletMaterialChanged`. Once the keychain is readable, retry sees `present`, discards the retained command here, and completes setup without finishing provisioning or reopening and binding the persisted wallet. The root controller's setup-completion path does not start the runtime, so without an intervening foreground or connectivity event the main screen opens with recovery unfinished and no running wallet runtime. Track material left by the attempted import separately from a pre-existing wallet, and resume or explicitly reconcile that attempt through the host before advancing. Add a regression that fails other-network provisioning after the current-network commit and then retries.

jeanpierreroma and others added 2 commits September 26, 2026 17:14
… failed instead of completing around it

`createOrImportWallet` persists the current network's wallet, then
provisions the other supported network. When that second step failed,
the current-network wallet stayed (row + mnemonic, no active id, not
published, no runtime kick) and the creator reported a plain failure;
on Try Again the keychain read "present", so the recover flow dropped
the command and completed setup into a wallet nothing had started and
nothing would finish provisioning — nothing retries the other network
later, a switch to it finds no wallet.

The host now reports that case as `provisioningIncomplete`, and the same
import re-run resumes: the persisted wallet is hydrated from the store
(the SDK refuses to create a registered id), only the missing network is
created, the wallet is bound and published as after a first import. The
creator hands the recover flow an outcome instead of a Bool; the setup
controller keeps the command flagged, and its routing sends "present"
back into the import while that flag is set — without it, "present" is
still a wallet that landed meanwhile. Completing setup now also asks the
runtime to open the wallet, so the main screen never opens over a
stopped runtime whichever way setup finished.

Tests: the routing seam with the resume flag, and the creator's mapping
of host errors to outcomes. The host's hydrate-then-provision path needs
SDK managers and is not unit-tested.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Preliminary review — Phase 1 blocker gate

Verified the exact head and all eight prior findings against the current source. Seven are addressed, but partial-import recovery can still complete without finishing provisioning if an intervening retry fails before provisioning begins; the new runtime kick does not repair the missing network wallet. This assessment is based on source inspection, not a new build or runtime smoke test.

Validated blockers were found by the Phase-1 review and confirmed by a fresh verifier. Phase 2 is deferred until a fresh same-head revalidation clears the blocker gate.

🔴 1 blocking

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-gate-verifier, role: verifier)

  • Triage: critical by gpt-6-astra (effort low) — This intricate cross-language change directly alters mnemonic/key handling in SwiftDashSDKHost.importWallet and persistedWalletForImport, including resuming partially persisted multi-network imports, alongside asynchronous recovery and wallet-generation guards across setup flows.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6-astra — verifier; agent astra-gate-verifier
  • Phase 2 reviewers: not run (deferred by blocker gate)
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:220-225: Do not treat a partially persisted failed import as completed recovery
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4111400449)
  The hydrate-then-provision path fixes the first retry, but this assignment forgets the persisted material if a subsequent retry returns `failed`. For example: the initial import persists the current-network wallet and fails other-network provisioning, setting this flag to YES; Try Again then fails during `buildRuntime`, mnemonic retrieval, or `loadFromPersistor`, before reaching the host's `provisioningIncomplete` wrapper. The creator maps that error to `failed`, and this assignment resets the flag to NO even though the earlier wallet remains persisted. The following Try Again sees `present`, discards the command, and completes setup without provisioning the missing network. The runtime kick addresses reopening the current wallet, but does not provision its missing mirror. Preserve the flag across failures of the same retained command, clearing it only on success or explicit abandonment/replacement, and add a regression for partial persistence → ordinary retry failure → retry.

jeanpierreroma and others added 3 commits September 26, 2026 19:51
…membered failure

The resume of a half-provisioned import hung on a flag set by the
previous attempt's outcome, and an ordinary failure on the retry reset
it — the attempt after that completed setup around the persisted wallet
again. The flag is gone. At execution, when the keychain says a wallet
is present, the flow asks whether it is the typed phrase's own —
`SwiftDashSDKHost.persistedWalletId(mnemonic:network:)`, the very check
`createOrImportWallet` resumes on (derive the wallet id, look up its
stored mnemonic) — and runs the import again if so (it resumes, or is a
no-op), completing into the wallet only when it is another one that
landed meanwhile. Nothing is remembered, so nothing in between can
clear it. The import's verdict is a Bool again; the outcome enum, its
host-error mapping and the flag's reset paths are removed.

Test: the routing seam replays the sequence partial persistence → an
ordinary retry failure → retry, and the route is the same on every
attempt for the same inputs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Preliminary review — Phase 1 blocker gate

Verified the exact head 71e4903 against the stacked base and independently revalidated all eight prior findings. Seven are addressed, but partial-import recovery still incorrectly completes setup when the new phrase-specific keychain lookup fails; the reviewer claims that all eight are fixed are therefore not fully supported. Verification was by source inspection, not a fresh build or runtime smoke.

Validated blockers were found by the Phase-1 review and confirmed by a fresh verifier. Phase 2 is deferred until a fresh same-head revalidation clears the blocker gate.

🔴 1 blocking

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-gate-verifier, role: verifier)

  • Triage: critical by gpt-6-astra (effort low) — The intricate cross-layer recovery changes directly alter mnemonic/key handling in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, including resuming partially persisted imports and provisioning missing networks, alongside execution-time guards across setup and seed-backup flows.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6-astra — verifier; agent astra-gate-verifier
  • Phase 2 reviewers: not run (deferred by blocker gate)
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:189-191: Do not treat a partially persisted failed import as completed recovery
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4111400449)
  Deriving resume state from the keychain fixes the remembered-flag problem, but the new lookup still conflates an unreadable result with a different wallet. `SwiftDashSDKWalletCreator.isWalletPersisted` catches every error from `persistedWalletId` and returns false, including mnemonic-read failures. The preceding presence read does not guarantee this lookup succeeds: `persistedSDKWalletPresence` enumerates attributes, and selectable-material classification can use a cached verdict. After an import persists the current-network wallet but fails provisioning the other network, a retry can therefore observe `present` while the phrase-specific mnemonic read fails. These lines route that result to `completeWithExistingWallet`, discard the retained command, and advance setup without retrying provisioning. The runtime kick does not provision the missing network. Preserve an unknown/error result through the creator and command boundary and route it to the retry alert; only a successful lookup establishing that this phrase's wallet is absent should complete around another wallet. Add coverage for present inventory plus a failed phrase-specific lookup.

…wallet cannot be looked up

The lookup that decides whether "a wallet is present" is the typed
phrase's own (resume the import) or another one (complete into it)
turned a refused or failed mnemonic read into "not stored": with the
attribute-only inventory saying present, setup dropped the retained
command and completed around unfinished provisioning.

The lookup is tri-state now, in the host (`persistedWalletLookup`), the
creator and the command: only a definite not-found is `notPersisted`;
any other keychain status, a derivation failure, and a read attempted
while protected data is unavailable are `unknown`. The routing treats
present + unknown like an unreadable presence — the unreadable alert
with Try Again, the command kept, nothing completed — and the host's
own resume path fails the import on `unknown` instead of creating a
twin next to a wallet it could not see.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

Reviewed the complete base-to-head diff at 2b059de: seven prior findings are fixed, but the partial-recovery finding remains because malformed stored mnemonic values can still be classified as absent and cause premature setup completion. An isolated source-extraction harness reproduced that classification for empty and invalid UTF-8 values; 50 wallet-preparation tests, three extracted recovery tests, localization validation, and accessibility blocking checks passed. Full-app compilation and runtime smoke remain unverified because dependency resolution requires Swift tools 6.3 while the installed toolchain provides 6.1.

🔴 1 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: ffi-engineer); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The intricate cross-screen recovery and retry changes directly alter mnemonic/keychain handling and partial wallet-import persistence in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, meeting both the complexity and critical key-handling surface criteria.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — ffi-engineer (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKHost.swift`:
- [BLOCKING] DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKHost.swift:778-779: Do not treat a partially persisted failed import as completed recovery
  The tri-state change correctly preserves access-denied and protected-data failures, but `WalletStorageError.mnemonicNotFound` does not prove that the item is absent. In the referenced SwiftDashSDK source, `retrieveMnemonicUTF8Bytes` also throws it after a successful Keychain query returns empty data, and `retrieveMnemonic` throws it for invalid UTF-8. This catch therefore classifies an existing but unreadable mnemonic as `notPersisted`. If the attributes-only inventory and selectable-material cache report `present`, `RecoverImportRouting.atExecution` chooses `completeWithExistingWallet`; the setup controller clears the retained command and advances without resuming the supplied phrase or finishing missing-network provisioning. An isolated harness using the SDK retrieval methods and this head's lookup/routing code reproduced that outcome for both malformed values. Distinguish malformed values from genuine item-not-found at the SDK boundary, or require a successful inventory read proving the derived wallet ID is absent before returning `notPersisted`. Existing undecodable records must remain `unknown`; add regression cases for empty data and invalid UTF-8 alongside genuine absence and access-denied errors.

…er lookup

`WalletStorageError.mnemonicNotFound` does not prove the item is absent:
the SDK throws it for a query that succeeds with empty data and for a
value that is not UTF-8. The lookup mapped it to `notPersisted`, so a
wallet the attribute inventory lists but whose mnemonic could not be
read let setup complete around it.

The lookup now reads the attribute-only inventory first and answers
`notPersisted` only when that read succeeds and does not list the
derived id. For a listed id, any failed mnemonic read — not-found,
empty, invalid UTF-8, a keychain status — is `unknown`, as is an
unreadable inventory. The verdict is a pure classifier over the two
reads, with regression cases for a genuine absence, empty data and
invalid UTF-8 with the id present, access denied on either read, and
that only a listed id has its value read.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

Reviewed the complete base-to-head diff: eight prior findings are fixed, the asynchronous recovery coverage suggestion remains valid, and two additional non-blocking suggestions are confirmed; no remaining blocking defect was verified. The 50-test wallet-preparation harness, five isolated checks using current production rules, localization validation, diff-whitespace check, and blocking accessibility check passed. Full application and simulator validation remain unverified because the canonical build stops during dependency resolution: pinned DashUIKit requires Swift tools 6.3, while the installed Xcode provides 6.1.

🟡 3 suggestion(s)

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: ffi-engineer); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The diff intricately changes mnemonic/key handling across setup and recovery, notably SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, which now resume partially persisted imports and provision missing networks based on keychain inventory and mnemonic reads.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — ffi-engineer (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [SUGGESTION] DashWallet/Sources/UI/Setup/DWSetupViewController.m:407-412: Avoid a second full runtime rebuild when setup completes
  This refresh is not elided as the comment claims. SwiftDashSDKWalletCreator.performCreate already calls handleWalletMaterialChanged before delivering a successful recovery completion, and RuntimeRefreshPolicy.shouldSkipRebuild always returns false for .walletMaterialChanged, including when Core and Platform are ready. The serial lifecycle queue therefore runs another teardown and rebuild when recovery completes; completing backup can likewise restart an already-running wallet. Each rebuild stops synchronization, clears published wallet state, and reopens the host. Preserve the startup request for branches that discover an existing wallet, but use an idempotent startup path or avoid issuing another material-change refresh when creation/import already requested one. Update the comment to match the actual policy.
- [SUGGESTION] DashWallet/Sources/UI/Setup/DWSetupViewController.m:224-232: Add regression coverage for recovery when a PIN already exists
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4103994301)
  The extracted routing tests cover the existing-PIN decision and presence/lookup matrix, but they do not exercise the asynchronous command lifecycle. testRecoverImportRoutingCoversSubmissionAndExecution checks route values, and RecoverImportAttempts tests token bookkeeping; neither would fail if setup advancement moved before the import callback or if a failed callback cleared the retained command. Add a narrow controller fixture or executable harness with an injected command whose completion can be delayed. Verify that existing-PIN recovery does not advance before completion, failure and unreadable presence retain the command, Cancel drops it, and success advances exactly once.

In `DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKHost.swift`:
- [SUGGESTION] DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKHost.swift:640-646: Exercise the host's hydrate-and-resume import path
  The new tests establish routing and lookup classifications, but none exercises this host transaction. testRetryAfterAPartialImportRerunsTheImportWhateverHappenedInBetween repeats pure routing inputs without persisting a wallet, failing other-network provisioning, or calling loadFromPersistor. It would still pass if the host re-created the registered wallet, failed to hydrate it, or published success before completing missing-network provisioning. Add a focused integration test or injectable transaction seam that fails provisioning after the current-network commit, retries the same phrase, and verifies that the committed wallet is preserved and reused, only the missing network is created, and failure does not publish success. Include the mnemonic-present/SwiftData-row-missing fallback, which takes the creation path instead of reusing a hydrated wallet.

…second rebuild

`completeSetup` requested a material-change refresh on top of the one
the import had just made; that refresh is never elided, so the runtime
the import built was torn down and rebuilt. The start request is
idempotent — a no-op while Core is up, a start when it is not — and
covers the case it was there for: setup completing into a wallet nothing
had started.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

Verified the complete diff at d5191d1: no blocking defect was confirmed, and the reported screenshot-cache bug is unreachable because screenshot replacement is disabled by every production caller. One non-blocking validation gap remains for the SDK-backed hydrate-and-resume transaction. The wallet-preparation harness passed 50 tests, diff and localization checks passed, and the workspace build stopped during package resolution because DashUIKit requires Swift tools 6.3 while the installed toolchain provides 6.1.

🟡 1 suggestion(s)

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: ffi-engineer); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — The large, intricate diff directly changes mnemonic/key handling in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, including resuming partially persisted imports and provisioning missing networks, alongside deferred recovery and seed-generation guards across setup flows.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — ffi-engineer (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKHost.swift`:
- [SUGGESTION] DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKHost.swift:640-646: Exercise the host's hydrate-and-resume import path
  (existing thread: https://github.com/dashpay/dashwallet-ios/pull/1152#discussion_r4113019533)
  The concrete SDK manager and persistence dependencies support your explanation that a fake-manager test would require a broader refactor; that refactor is not necessary here. The remaining gap is transaction-level evidence: the added tests exercise lookup, network planning, and routing, but never hydrate a committed wallet or fail provisioning after that commit. With a compatible toolchain, record a focused fault-injected simulator check at this head: fail other-network provisioning after the current-network wallet is persisted, retry the same phrase, and verify that the committed wallet is reused, only the missing network is created, and setup does not advance before provisioning succeeds. Also exercise the mnemonic-present/SwiftData-row-missing fallback. The reported smoke on the superseded branch does not validate this new transaction; this is a validation suggestion, not a confirmed implementation defect.

…-presence-guards-in-setup

Brings in develop (UIScene life cycle, #1145) through the base PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@romchornyi

Copy link
Copy Markdown
Contributor Author

Merged the base PR (516d9d5), which now carries develop's UIScene life cycle (#1145); no conflicts here, nothing in this PR's setup/recover paths changed. SwiftDashSDKCoreLifecycleTests at this head: the same two existing balance-message failures as before the merge, everything else passes.

@thepastaclaw the gate comment above still reads "⛔ 7 blocking finding(s) (commit d5191d1)", while every thread on this PR is resolved and the 2026-09-27 re-review at d5191d14 cleared the last one. Is that header stale, or is something still open that isn't attached to a thread?

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

Re-review — Final validation — Phase 1 + Phase 2

The complete base-to-head diff preserves unreadable wallet state, waits for recovery import success, and resumes partially persisted imports. One blocking lifecycle race remains: setup completion can start the runtime while fresh-wallet creation is still provisioning another network, allowing competing managers to replace the host's published state. This was a static review of head 516d9d5; the supplied CI snapshot passes accessibility, title validation, and CodeRabbit checks but contains no app-build or runtime validation, and the instrumented recovery smoke predates this head.

🔴 1 blocking

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate cross-screen recovery changes also alter mnemonic persistence and partial-import hydration in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, directly changing key handling.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 15% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:406-415: Avoid starting the runtime while wallet creation is still in flight
  The unconditional startIfReady request also runs when Skip finishes fresh-wallet onboarding, but that creator is not serialized through the runtime lifecycle queue. Show Recovery Phrase starts asynchronous creation; returning to backup-info and tapping Skip reuses the cached generated phrase and can finish setup while createOrImportWallet has committed the current-network wallet but is still awaiting other-network provisioning. Core is not ready and the host has not published the creator's manager, so this request can pass the persisted-presence gate and enter host.start, building another current-network manager. Both operations subsequently publish without an ownership check. In the DASHPAY path, SPV startup captures a manager before awaiting DashPayContactAddressReadiness; the creator can replace host.manager during that wait, after which SPV starts and subscribes to the captured manager while balance reads and performStop resolve the replacement from the host. MainActor isolation and the serial SDK-construction queue do not serialize these operations across their awaits. Restrict the setup startup request to completion into an independently existing wallet, or wait for fresh creation/provisioning to settle before completing setup and starting the runtime. Add regression coverage for finishing setup while other-network provisioning is delayed.

Comment on lines 406 to 415
- (void)completeSetup {
// Setup can complete into a wallet nothing started: one that an earlier
// attempt persisted, or one found present at recover execution. A
// successful create/import already asked for a material-change refresh
// (a full rebuild, never elided); this is the idempotent start request
// instead — a no-op while Core is up, a start when it is not — so the
// main screen never opens over a stopped runtime, and a runtime the
// import just built is not torn down and rebuilt a second time.
[DWSwiftDashSDKWalletRuntime startIfReady];
[self.delegate setupViewControllerDidFinish:self];

@thepastaclaw thepastaclaw Oct 3, 2026 •

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.

✅ Resolved at 0508a0df; see the replies below.

🔴 Blocking: Avoid starting the runtime while wallet creation is still in flight

The unconditional startIfReady request also runs when Skip finishes fresh-wallet onboarding, but that creator is not serialized through the runtime lifecycle queue. Show Recovery Phrase starts asynchronous creation; returning to backup-info and tapping Skip reuses the cached generated phrase and can finish setup while createOrImportWallet has committed the current-network wallet but is still awaiting other-network provisioning. Core is not ready and the host has not published the creator's manager, so this request can pass the persisted-presence gate and enter host.start, building another current-network manager. Both operations subsequently publish without an ownership check. In the DASHPAY path, SPV startup captures a manager before awaiting DashPayContactAddressReadiness; the creator can replace host.manager during that wait, after which SPV starts and subscribes to the captured manager while balance reads and performStop resolve the replacement from the host. MainActor isolation and the serial SDK-construction queue do not serialize these operations across their awaits. Restrict the setup startup request to completion into an independently existing wallet, or wait for fresh creation/provisioning to settle before completing setup and starting the runtime. Add regression coverage for finishing setup while other-network provisioning is delayed.

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0508a0d (the start request is mine, added in d5191d1; develop never started the runtime from setup completion — the creator's own handleWalletMaterialChanged did).

SwiftDashSDKWalletCreator now counts the creations and imports it dispatched, from the call (not from the background block) until they finish; the completion-based import stops counting before its completion runs. completeSetup asks for startIfReady only when no creation is in flight. With Skip during a still-provisioning fresh create, setup completes without a start request (SETUP complete while a wallet creation is still running; … in the log), and the creation brings the runtime up through its own material-change refresh once it lands — the single owner, as on develop. The cases the start request was added for are unchanged: completing into a wallet an earlier attempt persisted, or one found present at recover execution, has no creation in flight, and the recover flow completes from the import's completion, after the count dropped.

Regression (unit): testACreationCountsAsInFlightFromTheCallUntilItFinishes (in flight immediately after createWallet returns, idle once it finished), testAnImportIsNoLongerInFlightWhenItsCompletionRuns, testInFlightCounterIsIdleOnlyWhenEveryBeginHasEnded. Not covered: a test that delays other-network provisioning and finishes setup through the screens — there is no seam for the host's provisioning in the unit target, and I did not drive the Skip path in the app for this commit.

Left as on develop: if that in-flight creation then fails, nothing starts the runtime (setup has already completed). That is the pre-existing fire-and-forget creation, not something this PR changes.

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.

Resolved (re-reviewed at 0508a0df): Your counter begins synchronously before dispatch and remains active through host provisioning and the creator's material-change request; completeSetup now suppresses its competing start during that interval, and completion-bearing imports decrement before calling back. This addresses the reported setup-induced second-manager race, while the delayed-provisioning Skip scenario remains unexercised at this head.

jeanpierreroma and others added 2 commits October 3, 2026 23:07
…-presence-guards-in-setup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Skip finishes fresh-wallet setup while `createWallet` may still be
provisioning the other networks. The creator is not serialized with the
runtime's lifecycle queue, so the start request setup completion made could
pass the presence gate and build a second manager for the same wallet next
to the creator's. The creator now counts the creations and imports it has
dispatched, from the call until they finish (before an import's completion
runs), and setup completion asks for the start only when none is running;
a running creation asks for it itself when it lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

The complete base-to-head diff at 0508a0d addresses the prior production blockers, including the setup-triggered runtime-start race. One nonblocking issue remains: the new creation-counter regression test can fail under a valid background-queue schedule. This verification was static only; the supplied exact-head CI snapshot shows successful accessibility, PR-title, and CodeRabbit checks, but no build, XCTest, or runtime-smoke evidence.

🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The large, intricate diff directly changes mnemonic persistence lookup and partially persisted wallet import recovery in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, meeting the key-handling critical-surface bar.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 15% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
  • Model comparison: every Phase-2 reviewer also ran on gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWalletTests/SwiftDashSDKCoreLifecycleTests.swift`:
- [SUGGESTION] DashWalletTests/SwiftDashSDKCoreLifecycleTests.swift:300-303: Hold the background operation open before asserting it is in flight
  The empty mnemonic makes performCreate return at its first guard on the global queue, without a MainActor hop. That worker can then execute the deferred creations.end() before the assertion at line 303, even though the test is @MainActor. In that valid schedule, isCreationInFlight correctly reports false and the test fails: counting starts before dispatch, but finished work need not remain counted until the caller's next statement. Use a controllable operation or dispatch seam to hold the worker open until the test observes the in-flight state, then release it and verify the transition back to idle. A timing delay would not make this deterministic.

Comment on lines +300 to +303
func testACreationCountsAsInFlightFromTheCallUntilItFinishes() {
XCTAssertFalse(SwiftDashSDKWalletCreator.isCreationInFlight)
SwiftDashSDKWalletCreator.createWallet(mnemonic: "", pin: "", network: .testnet)
XCTAssertTrue(SwiftDashSDKWalletCreator.isCreationInFlight, "in flight as soon as it is dispatched")

@thepastaclaw thepastaclaw Oct 3, 2026 •

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.

✅ Resolved at 926aaa40; see the replies below.

🟡 Suggestion: Hold the background operation open before asserting it is in flight

The empty mnemonic makes performCreate return at its first guard on the global queue, without a MainActor hop. That worker can then execute the deferred creations.end() before the assertion at line 303, even though the test is @mainactor. In that valid schedule, isCreationInFlight correctly reports false and the test fails: counting starts before dispatch, but finished work need not remain counted until the caller's next statement. Use a controllable operation or dispatch seam to hold the worker open until the test observes the in-flight state, then release it and verify the transition back to idle. A timing delay would not make this deterministic.

source: gpt-6-astra (phase2-reviewer: general)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right — fixed in 8a559e6. The counted dispatch is now InFlightCounter.dispatch(on:_:afterEnd:) (all three creator entry points use it; an import's completion is scheduled from afterEnd, so it still runs after the import stopped counting). The racy creator test is replaced by testDispatchedWorkCountsFromTheCallUntilItReturns: the dispatched work blocks on a semaphore, the test asserts the counter is busy right after the call and again once the work has started, releases it, and afterEnd asserts it is idle. No timing assumptions.

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.

Resolved (re-reviewed at 926aaa40): Verified your counted-dispatch replacement: all three creator entry points use InFlightCounter.dispatch, and the regression test holds its worker on a semaphore until both busy-state assertions finish. The afterEnd assertion checks the idle state after decrementing, so the original scheduling-dependent failure is removed.

jeanpierreroma and others added 2 commits October 4, 2026 00:29
The creation test raced: an empty phrase returns at the first guard on the
global queue, which could stop counting before the test's next statement.
`InFlightCounter.dispatch(on:_:afterEnd:)` now owns the counted dispatch
(the creator's three entry points use it; an import's completion still runs
after it stopped counting), and the test holds the dispatched work on a
semaphore, asserts the in-flight state while it certainly runs, releases
it and waits for `afterEnd` to see the counter idle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-presence-guards-in-setup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

Static verification of the complete base-to-head diff at 926aaa4 found no actionable in-scope defects. All 13 prior findings were revalidated: 11 are fixed, and two controller/host integration-coverage suggestions remain intentionally deferred. The supplied exact-head CI reports successful accessibility, PR-title, and CodeRabbit checks, but contains no build, XCTest, or runtime-smoke evidence; no builds or tests were run in this static lane.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The large, cross-flow change directly alters mnemonic persistence and recovery in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, including resuming partially persisted imports across networks.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 15% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@romchornyi

Copy link
Copy Markdown
Contributor Author

Merged the base PR again (a9e3d43), which now carries develop through #1200; no conflicts in this PR's files. SwiftDashSDKCoreLifecycleTests + BackgroundRefreshCoordinatorTests: 128 run, only the two existing balance-message failures.

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

Re-review — Final validation — Phase 1 + Phase 2

Verified the complete base-to-head diff at a9e3d43. The presence guards, phrase handling, and completion-based recovery address the prior behavioral findings, but the newly supported partial-import retry remains unprotected against automatic runtime starts. This was static verification only; no builds or tests were run, and the supplied exact-head CI snapshot has accessibility and title checks queued without build or recovery-flow validation.

🔴 1 blocking

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate, cross-cutting diff changes mnemonic key handling and partially persisted import recovery in SwiftDashSDKHost.createOrImportWallet and persistedWalletForImport, alongside asynchronous setup execution guards.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 14% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/UI/Setup/DWSetupViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/Setup/DWSetupViewController.m:211-214: Serialize resumed imports with automatic runtime starts
  After an import commits the current-network wallet but fails other-network provisioning, Try Again now routes the persisted phrase back through import. This branch reserves only the controller-local attempt token and blocks screen interaction; it does not acquire wallet-lifecycle ownership or wait for operations already running on the runtime queue. SwiftDashSDKWalletCreator.createWalletOnHost calls createOrImportWallet directly, while the connectivity-return path admits startIfReadyWhenLifecycleIdle from the idle phase without consulting isCreationInFlight. The launch hold has already been released before setup is presented.

  Connectivity returning during this retry can therefore run host.start alongside the import across SDK construction, hydration, and mirror-provisioning awaits. Both paths publish their manager without checking ownership. In the DashPay startup path, SPV captures the manager before awaiting DashPayContactAddressReadiness; an import that publishes during that await leaves SPV starting and subscribing to the captured manager while balance reads and teardown resolve the replacement through the host. MainActor isolation and the serial SDK-construction queue do not serialize the complete operations across those awaits. The completeSetup counter check fixes that particular startup request, but not this automatic kick. Execute interactive imports through serialized lifecycle ownership, including waiting for an already-running start, and cover partial-import retry with delayed provisioning and a connectivity-return kick.

Comment on lines +211 to +214
const NSUInteger attempt = [self.recoverAttempts begin];
[self beginRecoverImportBlocking];
__weak typeof(self) weakSelf = self;
[command executeWithCompletion:^(BOOL succeeded) {

@thepastaclaw thepastaclaw Oct 14, 2026 •

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.

✅ Resolved at 32d10cd0; see the replies below.

🔴 Blocking: Serialize resumed imports with automatic runtime starts

After an import commits the current-network wallet but fails other-network provisioning, Try Again now routes the persisted phrase back through import. This branch reserves only the controller-local attempt token and blocks screen interaction; it does not acquire wallet-lifecycle ownership or wait for operations already running on the runtime queue. SwiftDashSDKWalletCreator.createWalletOnHost calls createOrImportWallet directly, while the connectivity-return path admits startIfReadyWhenLifecycleIdle from the idle phase without consulting isCreationInFlight. The launch hold has already been released before setup is presented.

Connectivity returning during this retry can therefore run host.start alongside the import across SDK construction, hydration, and mirror-provisioning awaits. Both paths publish their manager without checking ownership. In the DashPay startup path, SPV captures the manager before awaiting DashPayContactAddressReadiness; an import that publishes during that await leaves SPV starting and subscribing to the captured manager while balance reads and teardown resolve the replacement through the host. MainActor isolation and the serial SDK-construction queue do not serialize the complete operations across those awaits. The completeSetup counter check fixes that particular startup request, but not this automatic kick. Execute interactive imports through serialized lifecycle ownership, including waiting for an already-running start, and cover partial-import retry with delayed provisioning and a connectivity-return kick.

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 32d10cd.

Every recover import now runs as one op of the runtime's serial lifecycle chain (SwiftDashSDKWalletRuntime.performSetupImport, called from SwiftDashSDKWalletCreator for isImported), the same chain performAddWallet uses:

  • an op already on the chain (a launch or connectivity-return start) finishes before the import begins;
  • the runtime that start left up is torn down first (fullReset, shielded recovery suspended as refresh's own teardown does), so no SPV client keeps a manager the import replaces;
  • a kick queued while the import runs (startIfReadyWhenLifecycleIdle included) waits for it; the material-change refresh the creator asks for after success rebuilds the runtime on the imported wallet;
  • a failed import stops the suspended shielded recovery (as a failed refresh does) and logs the host error; it leaves the runtime stopped, as the host's own buildRuntime teardown did before.

Fresh-wallet creation stays off the chain (unchanged; completeSetup still holds its start while a creation is in flight).

Regressions in scripts/test_wallet_preparation.py (real performSetupImport + SerialAsyncLifecycleQueue, faked host): a start already on the chain runs to its end, then teardown, then the import, and a kick enqueued during the import runs after it (fails without the fix: the import interleaves with the start); a throwing import reports its error and the kick queued during it still runs. Harness 121/121; dashpay builds.

🤖 Addressed with Claude Code

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.

Resolved (re-reviewed at 32d10cd0): Your 32d10cd change routes both creator import entry points through performSetupImport, which awaits the shared lifecycle chain and completes BLAST/SPV/host teardown before importing; starts queued during the import cannot interleave with it. The committed harness checks ordering and error release using the production queue and import wrapper, although I did not execute it or independently verify the reported local build.

A retried recover import can find the wallet an earlier attempt persisted
already opened by a start, and a connectivity-return kick could run a start
beside it. Imports now run as one op of the runtime's serial lifecycle
chain (SwiftDashSDKWalletRuntime.performSetupImport): an op already on the
chain finishes first, the runtime it left up is torn down (shielded
recovery suspended, as refresh's own teardown does; stopped if the import
fails), and kicks queued meanwhile run after it. Harness tests cover the
ordering and the failure path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Re-review — Final validation — Phase 1 + Phase 2

Static verification of the complete base-to-head diff at 32d10cd found no remaining in-scope blocking issues or suggestions. Recovery imports now share the runtime lifecycle queue, unreadable wallet lookups fail closed, and setup advances only after a successful current-attempt import callback; controller-level and real-host integration coverage remain deferred. The supplied exact-head CI snapshot reports successful accessibility, PR-title, and CodeRabbit checks, but provides no app-build, XCTest, or end-to-end recovery result; no builds or tests were run in this lane.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The large, intricate diff changes mnemonic key handling and partial-import persistence recovery in SwiftDashSDKHost.persistedWalletForImport and SwiftDashSDKWalletCreator, alongside lifecycle serialization and deferred setup execution.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 14% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
  • Model comparison: every Phase-2 reviewer also ran on gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Serialize fresh-wallet creation with automatic runtime starts — Fresh creation still calls createOrImportWallet outside the lifecycle queue. After current-network persistence, other-network provisioning suspends while the connectivity-return path can independently admit a runtime start; both paths can publish managers, and SPV startup retains its captured manager across the DashPay readiness await. The direct creation path, cross-network provisioning awaits, and automatic-start admission already exist in the PR base, so this is a concrete wallet-runtime ownership follow-up rather than a remaining defect introduced by the recovery-import fix.
    • Follow-up: Track a separate issue or maintainer-requested change to serialize fresh-wallet creation with runtime starts and exercise connectivity return during delayed cross-network provisioning.

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.

3 participants