fix: guard coroutine scopes against crashes#1094
Draft
jvsena42 wants to merge 2 commits into
Draft
Conversation
ovitrif
approved these changes
Jul 18, 2026
ovitrif
left a comment
Collaborator
There was a problem hiding this comment.
did an early untested review. LGTM 🫡
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to #1093 , #986
This PR:
Description
A recent crash came from an uncaught error escaping a background coroutine. None of the app's long-lived scopes had an exception handler, so any unhandled throw in a background task reached the system's default handler and killed the process — often in a restart loop.
This introduces a single helper used across the repositories, services, and background workers so that every long-lived scope shares the same behavior: an uncaught error is logged with its owning tag and the scope stays alive, rather than taking the app down. The same handler is applied to the shared base scope used by the Lightning service and the keychain.
Background queue work now preserves coroutine cancellation instead of wrapping it into a generic error, so structured cancellation keeps working as intended.
Finally, a global uncaught-exception logger is installed at startup that records anything still slipping through before delegating to the platform's default handler, so normal crash behavior is preserved while we gain a log trail.
This is the safety net for the broader hardening tracked in #1093. Guarding the specific background bodies so a failure is handled meaningfully instead of only logged remains a follow-up.
Preview
N/A — no UI changes.
QA Notes
Manual Tests
regression:Cold start with an existing wallet → let startup finish: node starts, balances and widgets load, app does not crash.regression:Background the app during sync, then foreground: sync resumes, no crash.Automated Checks
CoroutineScopesTest.ktasserts a scope keeps running after an uncaught child exception (verified failing without the handler, passing with it).ServiceQueueTest.ktasserts background work rethrows cancellation unchanged and wraps other failures in AppError.