fix: metro session runtime stability [WPB-26140] [WPB-26134]#4953
Conversation
Ups 🫰🟨This PR is too big. Please try to break it up into smaller PRs. |
2d9f4bd to
956fbfa
Compare
50eaf8d to
94ac585
Compare
956fbfa to
df22494
Compare
| fun NavController.startDestination() = currentBackStack.value.firstOrNull { it.route() is DestinationSpec } | ||
| fun NavController.startDestination() = currentBackStack.value.firstOrNull { it.safeRoute() is DestinationSpec } | ||
|
|
||
| internal fun NavBackStackEntry.safeRoute(): Route? = runCatching { route() }.getOrNull() |
There was a problem hiding this comment.
hmmm why do we need this saferoute i would rather crash to know if there is an issue with a route rather than silently fail.
There was a problem hiding this comment.
Agree in principle. This is not meant as a final route-validation strategy or to hide broken destinations.
This was added as a transitional guard because during logout/session graph transitions currentBackStack can contain entries before DestinationsNavHost can resolve route(), and that was crashing while we were only trying to scan for the first app destination.
I’ll add a TODO / follow-up to remove this once the session graph/navigation transition is cleaned up. If you prefer, I can also narrow the helper name/comment so it’s clear this is only for transition-time back stack scanning, not general navigation.
94ac585 to
d54b2cf
Compare
df22494 to
4d78a38
Compare
d54b2cf to
d5a24bc
Compare
4d78a38 to
94b4fed
Compare
| var resolvedUserId = currentSessionUserId() | ||
| repeat(retries) { attempt -> | ||
| if (resolvedUserId != null) return@repeat | ||
| delay(CURRENT_SESSION_RESOLUTION_RETRY_DELAY_MS) | ||
| resolvedUserId = currentSessionUserId() | ||
| if (resolvedUserId != null) { | ||
| appLogger.i("Resolved current session after retry ${attempt + 1}") | ||
| } | ||
| } | ||
| resolvedUserId |
There was a problem hiding this comment.
I know that it works with repeat, but withTimeoutOrNull would look better 😄
Something like:
withTimeoutOrNull(CURRENT_SESSION_RESOLUTION_TIMEOUT_MS) {
coreLogic.value.getGlobalScope().session.currentSessionFlow()
.filterIsInstance(CurrentSessionResult.Success::class)
.filter { it.accountInfo.isValid() }
.firstOrNull()
}
7d720f0 to
d496d44
Compare
|
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (35.89%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #4953 +/- ##
===========================================
- Coverage 49.09% 48.97% -0.12%
===========================================
Files 643 643
Lines 23014 23120 +106
Branches 3518 3536 +18
===========================================
+ Hits 11298 11324 +26
- Misses 10669 10746 +77
- Partials 1047 1050 +3
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|



https://wearezeta.atlassian.net/browse/WPB-26140
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764The PR Description
What's new in this PR?
This PR fixes runtime regressions introduced while moving ViewModel creation to Metro-backed graphs.
The main issue was that some session-backed UI could keep using stale or missing session graph state during account transitions, logout, removed-client events, and authentication edge cases. That caused blank screens, wrong session reuse, or crashes when the current account disappeared while UI was still composing session-scoped ViewModels.
What changed
WireActivitysession graph resolution into smaller helpers.Why
Metro does not magically mirror Hilt’s activity/session scoping unless the graph lifecycle is modeled explicitly. This PR tightens that lifecycle so session-scoped ViewModels are recreated or dropped consistently when the active account changes.
Side Note
This is a stabilization step for the transitional Hilt-to-Metro phase. The long-term target is to simplify this further once all session-scoped ViewModels are owned by an explicit SessionGraph(userId) and the remaining legacy current-session assumptions are removed.
Manual QA focus