Skip to content

fix(wallet): show the launch hold's card when the wallet inventory cannot be read - #1153

Closed
romchornyi wants to merge 6 commits into
fix/defer-launch-decision-until-activefrom
fix/unreadable-wallet-inventory-card
Closed

romchornyi wants to merge 6 commits into
fix/defer-launch-decision-until-activefrom
fix/unreadable-wallet-inventory-card

Conversation

@romchornyi

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Stacked on #1151 (base branch fix/defer-launch-decision-until-active). With the launch decided only once the app is active, a "no wallet" answer at launch can still come from a keychain failure that is not the lock (the daemon refusing, an access error). The #1144 launch hold asked hasWallet (a Bool) and, with the migration already done, released into setup on false — Create/Recover over a wallet the read missed. Split out of #1147 (superseded).

What was done?

  • LegacyWalletMigrationLaunchCoordinator: the hasWallet dependency becomes one tri-state walletPresence read (WalletEnvironment.WalletPresence from fix(wallet): decide the launch only once the app is active #1151). Every verdict derives from a single snapshot: .present presents the wallet, only a definite .absent goes on to the legacy-material question and setup, and .unknown is a failure to show — fix(wallet): hold the launch on a failed legacy wallet import instead of offering setup #1144's blocking card with Try Again, WalletPreparationFailure(unreadableWallet:), Kind.keychain, code Keychain:unreadableWalletInventory. Try Again re-reads; the late-success watcher (material-change notification plus the 5 s fallback) completes the launch once a read works.
  • WalletPreparationFailure: the keychain kind and the unreadableWallet initializer (no status in the attachment; the status is in the app log).
  • Production wiring reads WalletEnvironment.walletPresence.

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 (WalletLifecycleTransitionStateTests): 46/46. New: an unreadable inventory shows the card (kind keychain, code Keychain:unreadableWalletInventory) and never setup, and a later successful read completes the launch; successive unknown, unknown, present reads with migration done never release into setup.

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

…nnot be read

Follow-up to the launch fix: with the launch decided only once the app is
active, a "no wallet" answer can still come from a keychain failure that
is not the lock, and the launch hold released it into setup.

The hold takes one tri-state `walletPresence` read instead of a Bool.
Every verdict derives from a single snapshot: present presents the
wallet, only a definite absent goes on to the legacy-material question
and setup, and unknown shows the blocking card
(`Keychain:unreadableWalletInventory`) whose Try Again re-reads and whose
late-success watcher completes the launch once a read works.

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: c8f76877-25f5-48d5-af68-49c71efb43de

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

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.

A build-time rename of the test module slipped into the previous commit.

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

thepastaclaw commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit 98dcf1c) · triage: low

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

Final validation — Phase 1 + Phase 2

The coordinator correctly treats an unreadable wallet inventory as a blocking failure, but the production launch gate does not start it when migration is already complete. In that case, an unknown wallet presence is still converted to the setup screen, so the PR does not fully protect existing wallets from Create/Recover being offered after a failed keychain read.

🔴 1 blocking | 🟡 1 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Unreadable inventory is still routed to setup when migration is complete
DashWallet/Sources/UI/RootNavigation/DWAppRootViewController.m:213-216

The new tri-state coordinator is only started when keyMigrationPending is true. When the migration-done sentinel exists, legacyWalletMaterialPendingMigration() returns false regardless of the SDK wallet inventory result. If WalletEnvironment.walletPresence is .unknown, model.hasAWallet is also false by design, so this condition evaluates to false and the root controller immediately presents setupController without starting the coordinator or showing the blocking keychain failure card. This is the migration-complete scenario described by the PR: a funded wallet can be present while its inventory read fails, and Create/Recover can still be offered over it. The root launch decision must sample wallet presence and hold on .unknown as well as pending legacy material, preferably using one presence snapshot for the gate and coordinator, with an integration regression test covering the migration-complete case.

source: gpt-6-astra (phase2-reviewer: general, security-auditor)

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: normal by gpt-6-astra (effort low) — This is a contained but nontrivial launch-state behavior change spanning coordinator logic, failure modeling, production wiring, and tests, without modifying funds movement, cryptography, key handling, storage migrations, or other critical surfaces.
  • 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 — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); 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/RootNavigation/DWAppRootViewController.m`:
- [BLOCKING] DashWallet/Sources/UI/RootNavigation/DWAppRootViewController.m:213-216: Unreadable inventory is still routed to setup when migration is complete
  The new tri-state coordinator is only started when `keyMigrationPending` is true. When the migration-done sentinel exists, `legacyWalletMaterialPendingMigration()` returns false regardless of the SDK wallet inventory result. If `WalletEnvironment.walletPresence` is `.unknown`, `model.hasAWallet` is also false by design, so this condition evaluates to false and the root controller immediately presents `setupController` without starting the coordinator or showing the blocking keychain failure card. This is the migration-complete scenario described by the PR: a funded wallet can be present while its inventory read fails, and Create/Recover can still be offered over it. The root launch decision must sample wallet presence and hold on `.unknown` as well as pending legacy material, preferably using one presence snapshot for the gate and coordinator, with an integration regression test covering the migration-complete case.

In `DashWallet/Sources/Infrastructure/SwiftDashSDK/WalletPreparationFailure.swift`:
- [SUGGESTION] DashWallet/Sources/Infrastructure/SwiftDashSDK/WalletPreparationFailure.swift:31-35: Add direct coverage for the unreadable-wallet failure initializer
  The new `.keychain` failure kind and `init(unreadableWallet:)` are exercised indirectly by the lifecycle coordinator test through their kind and diagnostic code, but `WalletPreparationFailureTests` does not verify the initializer's presentation copy or diagnostic report. A focused test should construct this failure with a fixed date and assert its kind, `Keychain:unreadableWalletInventory` code, generic recovery title/message, and report category/code so later changes cannot silently regress the new failure presentation.
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.

  • The migration completion callback still re-reads wallet presence before routing — In DWAppRootViewController.m, presentInitialControllerAfterKeyMigration: checks both migratedWalletPresent and a fresh self.model.hasAWallet read. A transient failure on that second read can route a successful coordinator result to setup. This is a concrete fail-open race, but the method predates this PR and should be handled in a separate launch-gating change rather than expanded into this review.
    • Follow-up: Track a separate fix to trust the coordinator's migratedWalletPresent result or pass an explicit tri-state snapshot through the completion path.

Comment on lines +31 to +35
init(unreadableWallet: Void, now: Date = Date()) {
id = UUID()
occurredAt = now
kind = .keychain
codes = ["Keychain:unreadableWalletInventory"]

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.

🟡 Suggestion: Add direct coverage for the unreadable-wallet failure initializer

The new .keychain failure kind and init(unreadableWallet:) are exercised indirectly by the lifecycle coordinator test through their kind and diagnostic code, but WalletPreparationFailureTests does not verify the initializer's presentation copy or diagnostic report. A focused test should construct this failure with a fixed date and assert its kind, Keychain:unreadableWalletInventory code, generic recovery title/message, and report category/code so later changes cannot silently regress the new failure presentation.

source: gemini-3.8-flash-high (phase1-reviewer: general, security-auditor)

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 b662446b): The added WalletPreparationFailureTests coverage directly verifies the unreadable-wallet initializer's keychain category, diagnostic code, generic user-facing copy, and diagnostic report.

jeanpierreroma and others added 2 commits September 25, 2026 12:27
…active' into fix/unreadable-wallet-inventory-card
The hold only began for pending legacy material, so with the migration
already done an inventory that could not be read still reached setup:
`hasAWallet` is false on "unknown" by design, and nothing else looked.
The root controller now reads the tri-state once and hands the launch to
the hold for "unknown" as well, whose card offers Try Again instead of
Create/Recover over a wallet the read missed. The hold's verdict is no
longer re-read before presenting the wallet.

Direct coverage for the unreadable-inventory failure: kind, code, the
generic copy and the diagnostic report.

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 tri-state launch decision correctly prevents setup from being offered when wallet inventory is unreadable, and both prior findings are fixed with direct coverage and single-snapshot routing. One blocking lifecycle gap remains: when inventory recovery later finds an existing wallet, the hold dismisses and presents the wallet without restarting the stopped SDK runtime.

🔴 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); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — This is a cross-cutting behavioral change spanning wallet lifecycle state, launch/root navigation, failure modeling, production wiring, and tests, but it does not alter funds movement, key handling, cryptography, consensus, networking, or storage migrations.
  • 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 verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); 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/WalletLifecycleTransitionState.swift`:
- [BLOCKING] DashWallet/Sources/Infrastructure/SwiftDashSDK/WalletLifecycleTransitionState.swift:495-498: Restart the wallet runtime when inventory recovery releases the hold
  On an already-migrated installation, the initial `SwiftDashSDKWalletRuntime.refresh` can reach its `.unknown` wallet-presence branch and return after teardown, leaving the host and SPV runtime stopped. When the keychain becomes readable, `deliverIfWalletPresent()` calls `deliver(hasWallet: true)`, which clears the launch hold and presents the wallet, but neither that path nor the completion callback requests a runtime start. The polling watcher only rechecks presence, and a Try Again migration run exits at the existing done sentinel without emitting a wallet-material-change notification. The result is a visible wallet UI backed by a stopped runtime until an unrelated restart or sync action occurs. Request an idempotent start through the existing runtime lifecycle boundary when successful inventory recovery delivers the wallet, and add coverage for startup returning `.unknown` followed by both polling recovery and Try Again.

Comment on lines 495 to 498
private func deliverIfWalletPresent() -> Bool {
guard completion != nil, dependencies.hasWallet() else { return false }
guard completion != nil, dependencies.walletPresence() == .present else { return false }
deliver(hasWallet: true)
return true

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.

🔴 Blocking: Restart the wallet runtime when inventory recovery releases the hold

On an already-migrated installation, the initial SwiftDashSDKWalletRuntime.refresh can reach its .unknown wallet-presence branch and return after teardown, leaving the host and SPV runtime stopped. When the keychain becomes readable, deliverIfWalletPresent() calls deliver(hasWallet: true), which clears the launch hold and presents the wallet, but neither that path nor the completion callback requests a runtime start. The polling watcher only rechecks presence, and a Try Again migration run exits at the existing done sentinel without emitting a wallet-material-change notification. The result is a visible wallet UI backed by a stopped runtime until an unrelated restart or sync action occurs. Request an idempotent start through the existing runtime lifecycle boundary when successful inventory recovery delivers the wallet, and add coverage for startup returning .unknown followed by both polling recovery and Try Again.

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

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 98dcf1c2): Your wallet-delivery callback now invokes SwiftDashSDKWalletRuntime.startIfReady() after completing root presentation and releasing the hold-owned phase, using the existing serialized refresh path and readiness-based rebuild suppression. The passing regression tests cover late inventory recovery, Try Again, and excluding setup delivery from runtime-start requests.

romchornyi pushed a commit that referenced this pull request Sep 25, 2026
… link without the wallet gate

Three findings on ab835b9.

- A read that answers "unknown" — a keychain failure while the app is
  active, or an unreadable selectable-material read — no longer reaches
  setup: the root controller reads the tri-state once
  (`DWRootProtocol.walletPresence`) and hands `.unknown` to the launch
  hold, and the hold itself takes one tri-state read — only a definite
  `.absent` goes on to the legacy-material question and setup, `.unknown`
  is the blocking card (`Keychain:unreadableWalletInventory`) whose Try
  Again re-reads and whose late-success watcher completes the launch. The
  hold's verdict is not re-read before presenting the wallet. This is
  #1153's card, carried here so this PR is safe to merge on its own.
- A link kept during a deferred launch is replayed to the initial
  controller directly, not through `application:openURL:options:`, whose
  wallet gate reads presence while the just-enqueued key migration has
  not landed an upgrader's wallet and dropped the link. The root
  controller keeps a Dash URL while no wallet is presented (hold, card,
  setup), as it already kept invitations, and handles it after the
  unlock, after the hold delivers, or after setup finishes.
- The two launch log lines carry only the link's scheme (a universal
  link its host): invitation links carry a bearer key.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
jeanpierreroma and others added 2 commits September 25, 2026 14:57
…active' into fix/unreadable-wallet-inventory-card
… it could not read at launch

A launch whose runtime start saw an unreadable inventory left the
runtime stopped. When the keychain became readable, the hold's
late-success watcher or Try Again delivered the wallet and presented it
— but nothing started the runtime: Try Again's migrator re-run returns
at the done sentinel without a material change, and the watcher only
re-reads presence. The wallet UI sat on a stopped runtime.

The hold's `deliver(hasWallet: true)` now calls a `walletDelivered`
dependency, wired to the idempotent `SwiftDashSDKWalletRuntime.startIfReady()`
(the refresh elides a rebuild when Core is already up, so a wallet the
migrator just delivered is not restarted). Both release paths run under
the card in the foreground, after the launch decision was taken.

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

Independently reviewed the complete base-to-head diff and relevant launch, root-selection, and runtime-start paths at 98dcf1c; all three prior findings are addressed, with no remaining in-scope findings. The focused wallet-preparation harness passed all 49 tests, and the diff whitespace check passed. Full iOS compilation and simulator smoke remain unverified: the pinned DashUIKit revision requires Swift tools 6.3, while the installed Xcode provides Swift 6.1.2.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(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); 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: low by gpt-6-astra (effort low) — The diff adds a small, contained wallet-delivery callback that starts the runtime after launch completion, with focused tests, without changing key handling, migration logic, or funds movement.
  • 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 66% left
  • 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 medium); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort medium); agent phase2-reviewer, gpt-6-astra — general (completed, effort medium); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort medium); 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 pushed a commit that referenced this pull request Sep 25, 2026
… an invitation delivered during it

An inventory that cannot be read at launch leaves the runtime stopped: its
refresh returns on "unknown", and the card that the hold shows offers Try
Again. When the read recovers, the hold delivered the wallet to the UI but
asked nothing to start, so the main screen opened over a runtime that never
came up. The hold now takes a `walletDelivered` dependency, wired to
`SwiftDashSDKWalletRuntime.startIfReady()`, called once the wallet is
delivered — never on the setup outcome. (Brought over from #1153, which
becomes an empty delta against this branch.)

An invitation that reaches the root controller while the launch hold is
still deciding used to go to onboarding's storage, which only a finished
setup reads: with the hold ending in a presented wallet, the invitation was
stranded. The root controller now keeps it with the other deferred links
while the hold is pending, moves an invitation that arrived before its
view loaded out of onboarding's storage when the hold delivers a wallet,
and hands a kept invitation to onboarding only on the hold's definite
"no wallet" verdict. The drain after the unlock is the existing one.

Tests: the coordinator test asserts one runtime-start request per
delivered wallet and none for setup; the python harness adds the
unknown → stopped runtime → readable → start-requested path against the
real funnel.

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

Copy link
Copy Markdown
Contributor Author

Closing as superseded: this PR's changes are now part of #1151. The unreadable-inventory card, the single-read root decision and the failure initializer came in with d8ac3a0, and the runtime start on the hold's delivery (98dcf1c here) with 3be57b4. Merging this branch into #1151's would change nothing.

🤖 Generated with Claude Code

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