Skip to content

fix: prevent crash during wallet backup#1092

Merged
jvsena42 merged 6 commits into
masterfrom
fix/backup-repo-crash
Jul 22, 2026
Merged

fix: prevent crash during wallet backup#1092
jvsena42 merged 6 commits into
masterfrom
fix/backup-repo-crash

Conversation

@jvsena42

@jvsena42 jvsena42 commented Jul 17, 2026

Copy link
Copy Markdown
Member

This PR fixes a crash that could put the app into a restart loop shortly after launch.

Description

The wallet backup payload was assembled outside of any error handling, so a failure while reading Paykit state escaped the backup coroutine and brought the whole app down. The automatic backup runs shortly after every launch, so an affected wallet crash-looped on startup with no way for the user to recover.

The payload is now built inside the existing failure handling. A failed read marks the backup as failed and retries later, the same way an upload failure already did. This also covers the retry action on the Backup settings screen, which previously crashed when tapped for a failed wallet backup.

The trigger seen in the wild was a stored Paykit session missing capabilities the SDK now requires, which is only reachable if Paykit was turned on from dev settings. The backup path itself is not gated, so any Paykit initialisation failure could take down the app the same way for any user.

Relationship to #1094

This branch was cut before #1094 merged, which is why the crash above was reachable at all: the backup scope had no exception handler, so the throw reached the system default handler and killed the process. #1094 has since been merged into this branch and now contains that throw.

The two fixes are complementary rather than overlapping. #1094 stops the process dying, but on its own it leaves the failure only logged, and the backup then retries every five seconds indefinitely because the category is never marked as failed. This PR is the concrete instance of the follow-up #1094 called out: guarding the specific background body so the failure is handled meaningfully instead of only logged.

The retry action on the Backup settings screen runs on the screen's view-model scope, which #1094 does not cover, so that path was fatal before #1094 and stays fatal without this PR.

Recovering a stale session and broader coroutine error handling are follow-ups (#1093). That includes the Paykit dependencies resolved when backup observation starts, which also run on a view-model scope and are still unguarded. This PR only stops the crash, so an affected wallet will report a failed wallet backup instead of crashing.

Preview

N/A — no user-facing UI changes.

QA Notes

Manual Tests

  • 1. regression: Fresh launch with wallet activity → wait for automatic backup: Settings → Backup shows wallet backup synced, no crash.
  • 2. regression: Settings → Backup → tap retry on a failed wallet backup: retries without crashing.
  • 3. Dev settings → Paykit enabled with a stale session → launch and wait for automatic backup: app stays up, wallet backup reports a failure once, and does not retry in a loop. With fix: guard coroutine scopes against crashes #1094 merged in, an unfixed build no longer crashes here, so check the session log for a backup attempt repeating every five seconds rather than for a process death.

Automated Checks

  • Unit tests added: cover the wallet backup marking a failure instead of crashing when the Paykit snapshot fails, in BackupRepoTest.kt. Verified failing before the fix and passing after.
  • CI: standard compile, unit test, and detekt checks run by the PR bot.

@jvsena42

Copy link
Copy Markdown
Member Author

Waiting for upstream branch merge

Comment thread app/src/main/java/to/bitkit/repositories/BackupRepo.kt Outdated
Comment thread app/src/test/java/to/bitkit/repositories/BackupRepoTest.kt
@jvsena42

Copy link
Copy Markdown
Member Author

Tested from https://github.com/synonymdev/bitkit-android/actions/runs/29591563331 . My app stopped crashing

Base automatically changed from release-2.4.0 to master July 20, 2026 11:33
@jvsena42 jvsena42 added this to the 2.5.0 milestone Jul 22, 2026
@jvsena42
jvsena42 marked this pull request as ready for review July 22, 2026 10:28
@jvsena42
jvsena42 enabled auto-merge July 22, 2026 10:28
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR prevents Paykit state-read failures from escaping the wallet backup coroutine. The main changes are:

  • Builds backup payloads inside cancellation-aware error handling.
  • Reuses backup failure cleanup for payload and upload errors.
  • Returns the upload result explicitly from triggerBackup.
  • Adds a test for failed Paykit snapshots during automatic backup.
  • Documents the crash fix in the changelog.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Payload failures now follow the established failure-state cleanup.
  • Coroutine cancellation still propagates to the existing job cleanup path.
  • Current callers can safely discard the newly explicit result.

Important Files Changed

Filename Overview
app/src/main/java/to/bitkit/repositories/BackupRepo.kt Handles payload construction failures through the existing backup failure state path while preserving coroutine cancellation.
app/src/test/java/to/bitkit/repositories/BackupRepoTest.kt Tests that a failed Paykit snapshot skips upload and clears the running backup state.
changelog.d/next/1092.fixed.md Documents the automatic wallet backup crash fix.

Reviews (1): Last reviewed commit: "fix: keep backup result type on snapshot..." | Re-trigger Greptile

@jvsena42
jvsena42 disabled auto-merge July 22, 2026 10:40
Comment thread app/src/main/java/to/bitkit/repositories/BackupRepo.kt
@jvsena42
jvsena42 merged commit 796f97b into master Jul 22, 2026
44 of 48 checks passed
@jvsena42
jvsena42 deleted the fix/backup-repo-crash branch July 22, 2026 16:02
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