Repository navigation
fix(app): navigate from FCM background/terminated notification taps (#5126) - #11144
Conversation
…asedHardware#5126) Register onMessageOpenedApp and getInitialMessage so push taps honor navigate_to instead of leaving the user on the last screen. Resurrects closed BasedHardware#5127 with a shared String-safe navigate_to parser. Co-authored-by: Cursor <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…dware#5126) getInitialMessage can resolve before runApp attaches globalNavigatorKey, so pushReplacement previously no-op'd on terminated taps. Poll until the navigator is ready (same race class as app_links BasedHardware#4763). Co-authored-by: Cursor <[email protected]>
|
Follow-up @cf6340f7: wait for |
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Confidence score: 3/5
- In
app/lib/services/notifications/notification_service_fcm.dart, a terminated-launch path can race becausegetInitialMessage()may resolve while_init()is still running beforerunApp()inmain.dart, so the first notification/deep-link intent can be missed or handled inconsistently on cold start; make initialization order deterministic (or buffer initial-message handling until init completes) to de-risk startup behavior.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/services/notifications/notification_service_fcm.dart">
<violation number="1" location="app/lib/services/notifications/notification_service_fcm.dart:278">
P2: In a terminated-state launch, `getInitialMessage()` resolves while `_init()` is still awaiting work before `runApp()` (see main.dart: `await NotificationService.instance.initialize()` runs well before `runApp(const MyApp())`). The `.then(handleNotificationTap)` callback therefore runs before the widget tree is built, so `_handleAppLinkOrDeepLink`'s `globalNavigatorKey.currentState?.pushReplacement(...)` sees `currentState == null` and silently does nothing — dropping the very tap this change is meant to navigate. This makes the #5126 fix timing-dependent (works only if `getInitialMessage` happens to resolve after the navigator attaches). Consider deferring the navigation until the navigator is available (e.g. wait for the first frame / a navigator-ready signal) or re-checking once the app is fully up before navigating.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| FirebaseMessaging.onMessageOpenedApp.listen(handleNotificationTap); | ||
|
|
||
| // Terminated: app was killed and opened via notification tap (#5126). | ||
| FirebaseMessaging.instance.getInitialMessage().then(handleNotificationTap); |
There was a problem hiding this comment.
P2: In a terminated-state launch, getInitialMessage() resolves while _init() is still awaiting work before runApp() (see main.dart: await NotificationService.instance.initialize() runs well before runApp(const MyApp())). The .then(handleNotificationTap) callback therefore runs before the widget tree is built, so _handleAppLinkOrDeepLink's globalNavigatorKey.currentState?.pushReplacement(...) sees currentState == null and silently does nothing — dropping the very tap this change is meant to navigate. This makes the #5126 fix timing-dependent (works only if getInitialMessage happens to resolve after the navigator attaches). Consider deferring the navigation until the navigator is available (e.g. wait for the first frame / a navigator-ready signal) or re-checking once the app is fully up before navigating.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/services/notifications/notification_service_fcm.dart, line 278:
<comment>In a terminated-state launch, `getInitialMessage()` resolves while `_init()` is still awaiting work before `runApp()` (see main.dart: `await NotificationService.instance.initialize()` runs well before `runApp(const MyApp())`). The `.then(handleNotificationTap)` callback therefore runs before the widget tree is built, so `_handleAppLinkOrDeepLink`'s `globalNavigatorKey.currentState?.pushReplacement(...)` sees `currentState == null` and silently does nothing — dropping the very tap this change is meant to navigate. This makes the #5126 fix timing-dependent (works only if `getInitialMessage` happens to resolve after the navigator attaches). Consider deferring the navigation until the navigator is available (e.g. wait for the first frame / a navigator-ready signal) or re-checking once the app is fully up before navigating.</comment>
<file context>
@@ -261,6 +262,20 @@ class _FCMNotificationService implements NotificationInterface {
+ FirebaseMessaging.onMessageOpenedApp.listen(handleNotificationTap);
+
+ // Terminated: app was killed and opened via notification tap (#5126).
+ FirebaseMessaging.instance.getInitialMessage().then(handleNotificationTap);
}
</file context>
There was a problem hiding this comment.
Already addressed in cf6340f7 (before this review comment landed).
_handleAppLinkOrDeepLink now waits for the navigator before pushing:
final navigator = await waitUntilNonNull(() => globalNavigatorKey.currentState);
if (navigator == null) {
Logger.debug('Navigator unavailable; dropping navigate_to=$navigateTo');
return;
}
navigator.pushReplacement(...);So terminated cold starts where getInitialMessage resolves before runApp no longer no-op via currentState?.pushReplacement. Follow-up 730adc8c only clears the analyzer ratchet (const test maps).
…Hardware#5126) Non-const map literals tripped prefer_const_literals (baseline 0). Drop the redundant foundation import that also added an unnecessary_import. Co-authored-by: Cursor <[email protected]>
|
CI: cubic P2: already covered by |
…re#5126) Detect Hermetic Backend Scope hit the 2m job timeout (cancelled); Merge Gate fail-closed on SCOPE_RESULT=cancelled. App-only PR — no backend scope change. Co-authored-by: Cursor <[email protected]>
|
CI note: Backend Hermetic Merge Gate red is not from this PR’s app changes.
Cubic P2 remains covered by |
|
Thanks @aryanorastar — solid fix for #5126. I reviewed the full diff against What I verified
Minor follow-up (non-blocking)
Marking as a positive signal — leaving for a human maintainer to merge. Appreciate you resurrecting #5127 with the type-safety feedback applied. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@Git-on-my-level Thanks for the positive signal and for verifying the cold-start race against Agreed the Completer/ No further author code changes pending; leaving APPROVE/merge to a human maintainer. |
|
@Git-on-my-level need human response Head Merge still blocked solely on write-access APPROVE. Could a human maintainer APPROVE/merge when you have a moment? No further author work pending. |
kodjima33
left a comment
There was a problem hiding this comment.
Registers onMessageOpenedApp/getInitialMessage and waits for the navigator on cold start so notification taps route correctly.
What changed and why
Tapping an Omi/plugin chat push from background or terminated state opened the last screen because
listenForMessages()only handled foregroundonMessage. Backend already sendsnavigate_to(e.g./chat/omi). RegisteronMessageOpenedApp+getInitialMessage, and exposeNotificationUtil.handleNavigateTo. Fixes #5126.Terminated cold-start harden:
getInitialMessagecan resolve beforerunAppattachesglobalNavigatorKey, so a barecurrentState?.pushReplacementsilently no-ops._handleAppLinkOrDeepLinknow polls viawaitUntilNonNulluntil the navigator is ready (same race class as app_links inapp_shell/ #4763), then pushes.Resurrects closed unmerged #5127 with Gemini’s type-safe helper feedback applied.
Product invariants affected
none
How it was verified
Could not exercise a live FCM tap from background/terminated on a device in this environment; wiring matches FlutterFire’s documented handlers and the prior #5127 approach. Navigator-wait helper is unit-tested for immediate / delayed / timeout cases.
Tests
app/test/unit/notification_fcm_navigate_to_test.dart—navigateToFromFcmDataaccepts non-empty String routes and rejects missing/empty/non-String values;waitUntilNonNullcovers cold-start readiness polling.Failure class (fixes)
Failure-Class: none
Scoped cleanups (optional)
n/a