Skip to content

Conversation

@piotr-iohk
Copy link
Collaborator

@piotr-iohk piotr-iohk commented Jan 20, 2026

Fixes: #553
Fixes: #691
OBS: #657 (comment)

Description

This PR fixes a crash that occurs when VssBackupClient.setup() is called before the mnemonic is available in the keychain. This race condition can happen during wallet restoration when BackupRepo.startObservingBackups() is triggered (on NodeLifecycleState.Running) before the mnemonic has been saved.

Root cause:

FATAL EXCEPTION: DefaultDispatcher-worker-6
to.bitkit.utils.ServiceError$MnemonicNotFound: Mnemonic not found
    at to.bitkit.data.backup.VssStoreIdProvider.getVssStoreId(VssStoreIdProvider.kt:23)
    at to.bitkit.data.backup.VssBackupClient$setup$2$1$1.invokeSuspend(VssBackupClient.kt:38)

Changes:

  • VssBackupClient.setup() now returns Boolean (true = success, false = mnemonic not available yet)
  • Added early mnemonic availability check before attempting VSS initialization
  • Added idempotency check to return immediately if already set up
  • BackupRepo now retries setup() with linear backoff (1s, 2s, 3s... up to 10 attempts) when mnemonic is not yet available

Preview

N/A - crash fix, no UI changes

QA Notes

  1. To reproduce the original crash: note: it is intermittent.

  2. Unit tests added:

    • setup returns false when mnemonic is not available
    • setup does not call vssStoreIdProvider when mnemonic is not available
    • setup checks mnemonic before proceeding with vss initialization
    • setup can be called multiple times when mnemonic not available

    Run with: ./gradlew testDevDebugUnitTest --tests "to.bitkit.data.backup.VssBackupClientTest"

@piotr-iohk piotr-iohk self-assigned this Jan 20, 2026
@jvsena42 jvsena42 changed the title Fix/mnemonic not found crash fix: mnemonic not found crash Jan 20, 2026
ovitrif
ovitrif previously approved these changes Jan 20, 2026
Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

utAck

PS. Still need to resolve the nit review comments to be able to merge AFAIU, so I let myself choose Approve even though I want the remarks addressed 🙏🏻

@claude

This comment has been minimized.

@ovitrif
Copy link
Collaborator

ovitrif commented Jan 20, 2026

@piotr-iohk to streamline this I am claude is making a PR targeting the branch of this PR, where I address my own review comments 👍🏻

- Remove unused assertTrue import from VssBackupClientTest
- Remove doc comments and inline comments from VssBackupClient
- Refactor setup() to return Result<Boolean>
- Add DSL-style setupWithRetry() with SetupRetryLogger builder
- Move retry logic from BackupRepo to VssBackupClient
- Update tests for Result<Boolean> return type

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…view

fix: address PR review comments for mnemonic crash fix
@ovitrif

This comment was marked as resolved.

@ovitrif ovitrif enabled auto-merge January 20, 2026 21:11
jvsena42
jvsena42 previously approved these changes Jan 21, 2026
Copy link
Member

@jvsena42 jvsena42 left a comment

Choose a reason for hiding this comment

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

Just left two suggestion that can be solved here or in other PR

@ovitrif
Copy link
Collaborator

ovitrif commented Jan 21, 2026

Just left two suggestion that can be solved here or in other PR

Addressing here 🙏🏻

ovitrif and others added 4 commits January 21, 2026 11:25
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jvsena42

This comment was marked as resolved.

Copy link
Member

@jvsena42 jvsena42 left a comment

Choose a reason for hiding this comment

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

Tested:

  • Lightning channels
  • Install over RN
  • recover from RN
  • Reset and restore

@ovitrif ovitrif merged commit 0f97a88 into master Jan 21, 2026
33 of 40 checks passed
@ovitrif ovitrif deleted the fix/MnemonicNotFound-crash branch January 21, 2026 13:10
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.

Add a check to prevent concurrent Vss.setup() calls crash with MnemonicNotFound exception after reseting app

4 participants