Repository navigation
Description
Description
When the app is cold-started by tapping a push notification (i.e. Android had killed the process while idle), the app navigates to the last active chat rather than the chat referenced in the notification. The correct chat is visible if you press the back button from that screen, meaning the navigation did eventually happen — but underneath the wrong screen.
Reported by dbarrett@expensify.com on Android staging, 2026-05-29 ~13:59 UTC. Tapped a notification from Florent, but the app opened to Chronos (last active chat). Pressing back from Chronos revealed the Florent chat.
Root Cause (confirmed via VictoriaLogs)
This is a cold-start race condition introduced by the dynamic import added in #84624.
subscribeToPushNotifications is now lazily imported inside a useEffect gated on splashScreenState === HIDDEN:
useEffect(() => {
if (splashScreenState !== HIDDEN) return;
import('.../subscribeToPushNotifications');
}, [splashScreenState]);When the user taps a notification to cold-launch the app, the Airship native bridge fires notification_response before the splash screen hides and before PushNotification.onSelected(REPORT_COMMENT, navigateToReport) has been registered. The tap event is dispatched into the void — navigateToReport is never called.
Log Evidence
At 13:59:38.491Z the device correctly emitted:
[PushNotification] Callback triggered for com.airship.notification_response
But none of the subsequent JS-side logs appeared:
- ❌
[PushNotification] Navigating to report - ❌
[PushNotification] onSelected() - Navigation is ready. Navigating... - ❌
[PushNotification] Not navigating because this is a singleNewDotEntry flow - ❌
[PushNotification] onSelected() - failed
Since [PushNotification] Navigating to report is the first line of navigateToReport (before any await or guard), its absence proves the JS handler was never invoked — not just delayed.
Two earlier taps the same day (00:48 UTC and 03:29 UTC, when the app was warm) worked correctly, confirming the regression is specific to cold starts.
Two corroborating signals for cold start:
- Previous push activity was at 12:44 UTC — 75 minutes of silence before the broken tap, enough for Android to kill the process.
- A new staging build (
ecash9.3.89-2) appeared between the broken tap and the next session, suggesting the 13:59 launch may also have been triggered by an app update.
Steps to Reproduce
- Open the app on Android, navigate to any chat, then background the app and leave it idle for ~1 hour (or force-kill it).
- Receive a push notification for a different chat.
- Tap the notification.
Expected: App opens directly to the notification's chat.
Actual: App opens to the last active chat. The notification's chat is reachable via the back button.
Relevant Code
subscribeToPushNotifications.ts#L113—navigateToReporthandler- Related issue: [$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624 (the PR that introduced the lazy import gating)
Platform
- Platform: Android
- Environment: Staging (likely also affects production)
- App version at time of report:
ecash9.3.83-1
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022060645789472379622
- Upwork Job ID: 2060645789472379622
- Last Price Increase: 2026-05-30
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
melvin-bot commentedon May 30, 2026
@melvin-bot[bot] the
AutoAssignerTriagelabel has been deprecated. Please useBugfor issue triage. See https://stackoverflowteams.com/c/expensify/questions/14418 for more details.MelvinBot commentedon May 30, 2026
What the body claims
The body says PR
Expensify/App#84390(linked indirectly via parent issueExpensify/App#84624) gatessubscribeToPushNotificationsbehind auseEffectkeyed onsplashScreenState === HIDDEN, so the JS-sideonSelected(REPORT_COMMENT, navigateToReport)handler is not yet registered when the Airship native bridge firesnotification_responseon cold start.Why that doesn't match the code
At the commit referenced in the body (
d4cffc8),subscribeToPushNotificationsis not in the splash-screen-gatedloadPostSplashScreenModules. It is dynamically imported insidesetup(), immediately afterOnyx.init()and outside the React lifecycle, with a comment explicitly stating it must run before any push arrives — including Android headless wake-ups.src/setup/index.ts:78-80—import('@libs/Notification/PushNotification/subscribeToPushNotifications')runs at module-load, not on splash hide.src/SplashScreenStateContext.tsx:26-30—loadPostSplashScreenModules()defers onlyreplaceOptimisticReportWithActualReport,registerPaginationConfig,UnreadIndicatorUpdater. It does not defer push subscription.PR
Expensify/App#84390's own diff confirms this —subscribeToPushNotificationswas added tosetup/index.ts, not to the newloadPostSplashScreenModulesfunction:PR #84390 diff (src/setup/index.ts)
So the "recommended fix" implied by the body (move the import to
setup/index.ts) is already shipped. Applying it again is a no-op.What might actually be happening
I can't fully verify these from code alone — they need log/repro confirmation:
navigateToReportatsubscribeToPushNotifications.ts:114-153waits onNavigation.waitForProtectedRoutes()and thenModal.close()before callingNavigation.navigate(...). If the app's deep-link/lastVisitedPathrestore (separate from this handler) runs after the notification navigation resolves, the last-active chat would land on top — matching the reported "back reveals Florent (notification chat)" stack order.[PushNotification] Navigating to reportis logged viaLog.info, which posts to the server. If the JS handler ran in a Headless JS context (cold-start background wake) and the process was torn down before the log batch flushed, the log would be missing even though the handler ran. That would invalidate the "handler never ran" inference.InitialURLContextProviderrather than (or in addition to) the JSonSelectedhandler. Worth tracing which path actually fires on Android cold-start tap.What to check next
navigateToReportactually runs (e.g., add a Sentry breadcrumb at the function entry as a stronger signal thanLog.info), (b) theNavigation.getActiveRoute()at the momentonSelectedfires, (c) whetherupdateLastVisitedPathis being invoked from another code path after the notification navigation.ecash9.3.83-1) actually contains thesetup/index.ts:80line. If staging was on an older Mobile-Expensify submodule pinning a pre-Defer startup imports #84390 App, the original race could be real on staging only — but that's not the file/PR cited.lastVisitedPathon cold start and at what point in the boot sequence.Related open issues (quick scan)
Expensify/App#88158— push notifications navigation broken for Classic users (different cause — HybridApp routing — but adjacent area).Next Steps: Reply with
@MelvinBot <your feedback>to refine this analysis, e.g. point me at a specific log run, a specific App commit, or the Mobile-Expensify submodule SHA the staging build was cut from.Abdulloh0109 commentedon May 30, 2026
Proposal
What is the root cause of that problem?
I traced the cold-start race to two overlapping gaps in
src/libs/Notification/PushNotification/subscribeToPushNotifications.ts:22-43andsrc/libs/Notification/PushNotification/index.native.ts:41-47.Gap 1 —
init()is gated behind Onyx hydration.PushNotification.init()— which registers the AirshipEventType.NotificationResponselistener — is called atsubscribeToPushNotifications.ts:27inside anOnyx.connectWithoutViewcallback keyed onONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID. On cold start, Onyx must first read that key from AsyncStorage before the callback fires. Airship fires itsnotification_responseevent as soon as the JS bridge is ready, which is well before AsyncStorage I/O completes. BecauseAirship.addListener(EventType.NotificationResponse, ...)(index.native.ts:71) hasn't been called yet, the native event fires with no JS listener attached — it is completely discarded at the bridge level.Gap 2 — unhandled
NotificationResponseevents are silently dropped.Even in the narrower race (where
init()has been called butonSelectedhasn't yet bound its handler),pushNotificationEventCallback(index.native.ts:24-56) reaches the!actionbranch at line 41, logs aLog.warnat lines 43-46, and returnsundefined. There is no queue or retry — the tap event is gone.The two gaps form a sequential "miss window": gap 1 covers the period from native launch until
NVP_PRIVATE_PUSH_NOTIFICATION_IDhydrates; gap 2 covers the shorter period betweeninit()andonSelected()registration. On a cold start the full 75-minute-idle scenario in the issue, the phone firesnotification_responsesquarely inside gap 1.The comment at
setup/index.ts:76-78says the import exists so handlers are "registered before any push arrives", butinit()being inside the Onyx callback defeats that intent.What changes do you think we should make in order to solve the problem?
Two targeted changes, both in the push notification module.
Change 1 —
subscribeToPushNotifications.ts— callinit()at module top-level.Move
PushNotification.init()from inside theOnyx.connectWithoutViewcallback (subscribeToPushNotifications.ts:27) to the top level of the module, so it runs immediately when the module is imported.init()only registers Airship event listeners (index.native.ts:65-74) — it requires no authentication and has no side effects that depend on Onyx state. Theregister,onReceived, andonSelectedcalls can remain inside the Onyx callback where they belong (they do need thenotificationID). Remove thePushNotification.init()line from inside the callback.Change 2 —
index.native.ts— queue earlyNotificationResponseevents and replay on bind.Add a module-level array (e.g.
pendingNotificationResponses) typed asArray<{eventType: EventType; notification: PushPayload}>. InpushNotificationEventCallback(index.native.ts:24-56), wheneventType === EventType.NotificationResponseand the!actionbranch at line 41 is reached, push{eventType, notification}into the queue instead of just logging and returning. In thebindfunction (index.native.ts:140-149), after writingactionMap[notificationType] = callback, iterate overpendingNotificationResponses, filter for entries whoseeventTypeand parseddata.typematch the newly registered handler, call the action for each match, and remove them from the queue.Scope: Only
subscribeToPushNotifications.tsandindex.native.tsare touched.index.web.ts/index.ios.ts/index.android.tsstubs are unaffected. iOS is unaffected in practice (iOS buffersnotification_responseuntil the app JS is ready), but the queue in change 2 is harmless there. No changes to navigation, Onyx keys, or authentication.Edge cases:
deregister()is called,Airship.removeAllListenersclears the native side; thependingNotificationResponsesarray should also be cleared inderegister()(index.native.ts:120-127) to prevent stale replays after sign-out.navigateToReportis invoked — the function's ownNavigation.waitForProtectedRoutes()guard (subscribeToPushNotifications.ts:117) already handles the case where navigation is not yet ready.What alternative solutions did you explore? (Optional)
Retrieve the launch notification after hydration (rejected). Airship's SDK (confirmed via
node_modules/@ua/react-native-airship/src/types.ts) does not expose agetLaunchNotification()orgetInitialNotification()API to retrieve a cold-start notification after the fact. This avenue is closed.Await the dynamic import in
setup/index.ts(rejected). Makingsetup/index.ts:78anawait import(...)would block the setup function's async chain on module load, but it would still not fix the race becauseinit()would still be inside the Onyx callback and the Airship event fires from native before JS even begins executing setup. It also risks delaying other setup steps unnecessarily.Remove the Onyx gating entirely and call
init()/onSelected()unconditionally on import (rejected). Callingregister()andonSelected()without a validnotificationIDwould either register the wrong named user or register the navigation handler before session state is ready, risking spurious navigations on sign-out flows. The Onyx gating forregisterand the handler bindings is correct; onlyinit()needs to move out.melvin-bot commentedon May 30, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @situchan (
External)wildan-m commentedon May 30, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When the Android app is cold-started by tapping a push notification (the process had been killed while idle), the app opens the last active chat instead of the chat referenced in the notification. The correct chat is only reachable by pressing the back button, which proves the navigation to it never ran on top — it was the underlying default screen all along.
What is the root cause of that problem?
The push-notification tap handler is never registered in time, so the cold-start tap event is dropped.
On native, a tap is delivered as an Airship
NotificationResponseevent. The native dispatcher looks the handler up in an in-memory map and, if nothing is bound yet, it logsNo callback set upand returns without doing anything — the event is not buffered or replayed:App/src/libs/Notification/PushNotification/index.native.ts
Lines 41 to 48 in 3ec7273
That map is only populated when
subscribeToPushNotificationsruns, which bindsnavigateToReportto theREPORT_COMMENTselected-event viaPushNotification.onSelected(...):App/src/libs/Notification/PushNotification/subscribeToPushNotifications.ts
Lines 20 to 37 in 3ec7273
The problem is that
subscribeToPushNotificationsis pulled in through an asynchronous dynamicimport()inside the setup function:App/src/setup/index.ts
Lines 78 to 80 in 3ec7273
A dynamic
import()resolves asynchronously, so evaluating that module — and therefore binding theonSelectedhandler — is deferred past the synchronous part of startup. On a cold launch triggered by a notification tap, Airship fires theNotificationResponsevery early. At that moment the handler map is still empty because the deferred chunk has not finished evaluating, so the dispatcher hits theNo callback set upbranch and silently drops the tap. The app then continues its normal startup and lands on the last active chat.This matches the issue's log evidence exactly: the native line
Callback triggered for com.airship.notification_responseis emitted (the dispatcher ran), but none of the JS handler logs (Navigating to report,onSelected() - Navigation is ready, etc.) appear, because the handler was never bound when the event arrived. It also explains why warm taps work: when the process is already alive the handler is long since registered, so the tap is dispatched correctly. The deferral was effectively present before too — the issue references it as a lazy import gated on splash-screen state — and although that gating has since been refactored, the registration is still deferred today by the asynchronous dynamicimport().What changes do you think we should make in order to solve the problem?
Register the push-notification handlers synchronously during startup so the
onSelectedbinding exists before any cold-start notification event can be dispatched, while still keeping registration afterOnyx.init().Concretely:
In
src/libs/Notification/PushNotification/subscribeToPushNotifications.ts, move the twoOnyx.connectWithoutView(...)registration blocks (theNVP_PRIVATE_PUSH_NOTIFICATION_IDblock that callsregister/init/onReceived/onSelected, and theHYBRID_APPblock) into an exported function, and export it as the module's default. The helper functions (applyOnyxData,navigateToReport,getLastUpdateIDAppliedToClient) and the module-levelisSingleNewDotEntryvariable stay where they are; only the side-effectingconnectcalls move inside the exported function so they run when the function is invoked rather than when the module is first evaluated.In
src/setup/index.ts, replace the asynchronousimport('@libs/Notification/PushNotification/subscribeToPushNotifications')with a normal static top-of-file import of that default function, and call it synchronously right afterOnyx.init()— in the same place the dynamic import currently sits.This is the exact pattern already used a few lines below for
initOnyxDerivedValues(): statically imported and called afterOnyx.init(). Because the import is now static, the module is part of the main bundle (no async chunk to wait on), and because the registration is performed by an explicit function call placed afterOnyx.init(), the original ordering requirement (handlers registered after Onyx is initialized, outside the React lifecycle) is preserved. The handler map is therefore populated synchronously during setup — before the UI mounts and before the cold-startNotificationResponseis dispatched — sonavigateToReportruns and the app opens the notification's chat directly.Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/92138-sync-push-notification-subscribe?expand=1
What alternative solutions did you explore? (Optional)
pushNotificationEventCallbackqueue aNotificationResponsewhose handler is not yet bound and flush it onceonSelectedregisters. This is more robust against any future deferral, but it adds queueing state and timing complexity to startup-critical native code that is explicitly marked as fragile, when the simpler root-cause fix is to just not defer registration.import()but await it before allowing startup to proceed past handler registration: this still leaves a window where an early native event could arrive before the awaited import resolves, and it complicates the setup flow; a synchronous static import removes the window entirely.4 remaining items
wildan-m commentedon May 30, 2026
Proposal updated — added compare branch with implementation.
github-actions commentedon May 30, 2026
oqildev commentedon May 30, 2026
What is the root cause of that problem?
First, the cause the report names isn't real on the version it was filed against (
ecash9.3.83-1= tag9.3.83-1-staging, commitb5ea92de). There is nouseEffectgated onsplashScreenState === HIDDENthat importssubscribeToPushNotifications. The import is eager, at module-load time insetup/index.ts, with a comment that exists precisely to prevent a cold-start race:App/src/setup/index.ts
Lines 76 to 78 in b5ea92d
So #84624's deferral is not in this code path. I'd drop that attribution.
What the logs actually fingerprint is a handler-binding order problem. The registration runs inside the
Onyx.connectWithoutView(NVP_PRIVATE_PUSH_NOTIFICATION_ID)callback, and it callsPushNotification.init()beforePushNotification.onSelected(...):App/src/libs/Notification/PushNotification/subscribeToPushNotifications.ts
Lines 27 to 37 in b5ea92d
init()is what attaches the AirshipNotificationResponselistener:App/src/libs/Notification/PushNotification/index.native.ts
Lines 65 to 72 in b5ea92d
When that listener fires,
pushNotificationEventCallbacklogsCallback triggered, then looks upnotificationEventActionMap[NotificationResponse][type]. If the map isn't populated yet, it hits theif (!action)branch, logsNo callback set up, and returns —navigateToReportis never called:App/src/libs/Notification/PushNotification/index.native.ts
Lines 40 to 47 in b5ea92d
That map is only filled by
onReceived/onSelected(line 30+), which run afterinit(). Soinit()opens the door to the listener beforeonSelected()puts the handler behind it. That is the exact log signature in the report:Callback triggered✅, thenNavigating to report❌ (the first line ofnavigateToReport). The missing middle line isNo callback set up.On standalone NewDot this window is narrow — the connect callback runs synchronously and Airship's pending-event drain (
UAEventEmitter.dispatchEvents, triggered async viacom.airship.pending_eventsafterairshipListenerAdded) usually fires afteronSelectedhas run. The window is real when aNotificationResponselistener already exists at drain time. On HybridApp the Airship instance is shared between NewDot and OldDot:App/src/libs/Notification/PushNotification/index.native.ts
Lines 82 to 86 in b5ea92d
so the queued cold-start response can be delivered to the existing listener before NewDot binds its action — and the tap is dropped. With the tap dropped, the cold start just continues its normal restore to
lastVisitedPath(the last active chat), which is why you land on Chronos.One honest caveat: "press back from Chronos and the Florent chat is underneath" does not fit a fully-dropped tap — if
navigateToReportnever ran, Florent isn't in the stack at all. That detail instead points at the navigation-ordering variant in Alternatives below. TheCallback triggered/ no-Navigating to reportlogs are the hard artifact, so I'm anchoring the root cause there; the back-button detail is how I'd disambiguate which of the two is firing.What changes do you think we should make in order to solve the problem?
Data/registration layer, in
subscribeToPushNotifications.ts. Bind the handlers before attaching the Airship listeners: move theonReceived/onSelectedcalls abovePushNotification.init()in the connect callback (App/src/libs/Notification/PushNotification/subscribeToPushNotifications.ts
Lines 27 to 37 in b5ea92d
bind()only writes to the localnotificationEventActionMap, so populating it first is free and guarantees the action exists the instantinit()lets the firstNotificationResponsethrough. This closes the cold-start/HybridApp window without touching the Airship drain mechanism.To confirm in production before/after, I'd watch for the
No callback set upwarn atApp/src/libs/Notification/PushNotification/index.native.ts
Lines 42 to 46 in b5ea92d
This only affects the cold-start path; warm taps already work (the report confirms the 00:48 and 03:29 UTC warm taps navigated correctly), and the change doesn't alter the headless/background Onyx-apply flow.
What alternative solutions did you explore? (Optional)
Navigation-ordering race in
navigateToReport(the variant that fits "back reveals the correct chat"). If the tap is not dropped,navigateToReportruns throughNavigation.waitForProtectedRoutes().then(() => Modal.close(...))and relies on this guard to dismiss a wrongly-visible chat:App/src/libs/Notification/PushNotification/subscribeToPushNotifications.ts
Lines 114 to 139 in b5ea92d
That guard (
getActiveRoute().slice(1,2) === 'r' && !isActiveRoute('r/<id>')→goBack) only fires if the restored last-visited chat is already the active route when the handler runs. The competing restore isNavigationRoot's initial state fromlastVisitedPath(App/src/libs/Navigation/NavigationRoot.tsx
Lines 133 to 142 in b5ea92d
navigateToReportwould have loggedNavigating to report), whereas the binding-order cause does. If theNo callback set upwarn is absent in the VictoriaLogs for the broken tap, switch to this one — the fix there is to havenavigateToReportre-assert navigation after restore settles rather than rely on a one-shotgetActiveRoute()check.Re-attributing to #84624's splash deferral (the report's own theory). Rejected: the splash-gated
useEffectit describes isn't in the tree atb5ea92de; the import is eager insetup/index.ts#L76-L78. Reverting #84624 would change nothing here.trasnake87 commentedon May 30, 2026
Proposal
On an Android cold start triggered by a notification tap, the app routes to the last-active chat instead of the notification's chat because the tapped notification's launch event is delivered to JS before its handler is bound into the action map — so it is silently dropped.
Root cause
The issue correctly identifies a cold-start race around the deferred load of
subscribeToPushNotifications, but the cited log evidence actually points one level deeper than "the handler was never registered." The line that did appear —— is emitted at
src/libs/Notification/PushNotification/index.native.ts:29, insidepushNotificationEventCallback, which is only ever invoked by the listener attached ininit()(Airship.addListener(EventType.NotificationResponse, …)atindex.native.ts:71). So the listener was attached and Airship did deliver the tap to JS. The only path throughpushNotificationEventCallbackthat logsCallback triggeredyet does not callnavigateToReport(and the payload was valid, since warm taps worked) is the empty-action-map early return:So
notificationEventActionMap[NotificationResponse][REPORT_COMMENT]wasundefinedat the moment the launch tap was processed. That maps to two contributing factors:1 - Handlers are bound after the Airship listener is attached. In the NVP callback the order is
register()→init()→onReceived/onSelected:On a cold start Airship has buffered the launch
NotificationResponse(no JS listener existed when the process started). The instantinit()runsAirship.addListener(...), Airship flushes that buffered response synchronously intopushNotificationEventCallback. At that exact instant lines 30-37 have not executed yet, sonotificationEventActionMap[NotificationResponse]is still{}→if (!action)→return. The very next lines then bindnavigateToReport, but the event is already gone. (Warm taps work because a prior NVP callback already populated the map, soinit()re-attaching just re-flushes nothing.)2 - The registration is doubly-deferred, which guarantees the response is always buffered and waiting.
setup/index.ts:78-80loads the module via a dynamicimport(), and registration is then further gated behind the async Onyx read ofNVP_PRIVATE_PUSH_NOTIFICATION_ID:This is why moving the import out of the old
splashScreenState === HIDDENuseEffectintosetup()did not fix the bug: no matter how early the module loads, the buffered launch tap is replayed synchronously the momentinit()attaches the listener, and factor 1 means the map is empty at that moment.Proposed fix
Bind the type handlers into the action map before
init()attaches the Airship listeners. ReplacesubscribeToPushNotifications.ts:25-37with:onReceived/onSelectedonly mutate the in-memorynotificationEventActionMapobject (index.native.ts:140-149) and have no dependency onregister()orinit(), so reordering is safe. Now wheninit()flushes the buffered launch response,actionMap[REPORT_COMMENT]resolves tonavigateToReport,[PushNotification] Navigating to reportfires (subscribeToPushNotifications.ts:114-115), and the app opens the correct chat. The same reorder also protects the backgroundPushReceived→applyOnyxDatapath (Headless JS), which has the identical synchronous-flush exposure.Why this approach
This is the minimal change that makes the action map order-correct regardless of when the module loads, so it fully respects #84624's intent of deferring the import for startup TTI — no need to revert to a static/eager import. It deliberately does not touch
index.native.ts, whoseinit()carries the explicit warning atindex.native.ts:58-63("Moving or changing this code could break Push Notification processing in non-obvious ways… DO NOT ALTER UNLESS YOU KNOW WHAT YOU'RE DOING"); the fix lives entirely in the registration call order, which is the safe place to address it. Two alternatives were considered and rejected: (a) making thesetup/index.tsimport static/eager — does not fix the bug, since the synchronous replay still hits an empty map, and it regresses #84624's deferral; and (b) hoistinginit()/onReceived()/onSelected()out of the NVP-gated callback to register eagerly — this would attach live listeners for signed-out users and bypass the sign-in/sign-out lifecycle the NVP gate drives (deregister()in theelsebranch), which is more invasive than necessary. The reorder closes the reported race while keeping the existing lifecycle intact.yusufdeveloper2903 commentedon May 30, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Android, tapping a push notification that cold-starts the app (process was killed/idle) opens the last active chat instead of the chat referenced in the notification. The target chat is one back-press away, so navigation to the active chat happened, but the notification's intended navigation never did.
What is the root cause of that problem?
The cold-start tap is buffered by Airship and is delivered to JS — the issue's own logs prove it (
[PushNotification] Callback triggered for com.airship.notification_responsefired, which is logged inside the dispatcher, so the Airship listener was registered and ran). It is dropped one step further in, because the per-type handler is not in the map at the instant Airship flushes the buffered event.The exact ordering, inside the
NVP_PRIVATE_PUSH_NOTIFICATION_IDOnyx callback:init()is what adds the AirshipNotificationResponselistener:And in
@ua/react-native-airship(v25.0.0),addListeneris itself the trigger that drains natively-buffered events. FromUAEventEmitter:So the buffered cold-start
NotificationResponseis delivered topushNotificationEventCallbackas a direct consequence ofinit()callingaddListener. That callback then looks the handler up innotificationEventActionMap:At that instant
onSelected(...)(L31) has not run yet — it is sequenced afterinit()(L27) — sonotificationEventActionMap[NotificationResponse]is empty,actionisundefined, and the flushed tap is dropped via "No callback set up". BecausetakePendingEventsalready removed it from the native queue, thenavigateToReportbound a moment later (L31) never sees it. The app finishes its normal boot and lands on the last active chat — exactly the reported symptom.This is consistent with every line of the log evidence: dispatcher ran (
Callback triggered), butnavigateToReport's first line[PushNotification] Navigating to report(@SHA L114-L115) never logged. Warm taps carry the same payload and work, so the payload parses — the only remaining early-return is the empty-handler-map branch above.Why #84624 surfaced it: that PR deferred the module to a dynamic import (
src/setup/index.ts@SHA L80). It did not create the lost-event path — Airship buffers the tap and replays it wheninit()adds the listener regardless of import timing. What the deferral changed is the timing: the bufferedNotificationResponseis now reliably already queued by the time the Onyx callback runs on a tap-cold-start, soinit()'s flush lands squarely inside the unbound window betweeninit()(L27) andonSelected()(L31). The actual defect is structural and predates the deferral:init()(the flush trigger) runs before the handlers are bound.Permalinks:
init()/handler binds @SHA L26-L37 ·init()impl @SHA L65-L74 · empty-handler drop @SHA L41-L48What changes do you think we should make in order to solve the problem?
In
src/libs/Notification/PushNotification/subscribeToPushNotifications.ts, movePushNotification.init()so it runs after every handler is bound. Then wheninit()'saddListenerflushes the buffered cold-start event, the handler map is already populated:This is a pure reorder of two adjacent blocks.
onReceived/onSelectedonly mutatenotificationEventActionMap(no dependency oninit()), andinit()only adds the Airship listeners + configures foreground display (no dependency on the binds), so the swap is safe. It is deterministic — it closes the only window in which a flushed event can find an empty map — and it keeps #84624's deferred-import startup win, adds no new state, and does not touch the native dispatcher that is explicitly marked fragile (index.native.tswarns "Moving or changing this code could break Push Notification processing… DO NOT ALTER UNLESS YOU KNOW WHAT YOU'RE DOING"). The same reorder also protects theonReceived/PushReceivedhandlers, which are exposed to the identical drop for silent/data pushes buffered across a cold start.What alternative solutions did you explore? (Optional)
Switch the dynamic import to a static/synchronous one (so binding happens during
setup()). Rejected — it targets the wrong lever and does not fix the bug. The buffered tap is replayed byinit()'saddListenerno matter when the module loads, andinit()still runs beforeonSelectedin the same callback, so the flush still lands on an empty map. (The "module hasn't evaluated yet, so the handler map is empty" framing is also self-contradicting:pushNotificationEventCallbackis itself added byinit()inside that module, so theCallback triggeredlog proves the module did evaluate andinit()did run before the dispatch.) It also forfeits [$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624's TTI win.Add a pending-response queue in
index.native.ts— bufferNotificationResponseevents that hit the!actionbranch and replay them whenbind()registers a matching handler (optionally also movinginit()to module top-level). Rejected — it adds queueing state and replay/teardown logic to the startup-critical native dispatcher that is explicitly flagged as fragile, to solve a window that a two-line reorder closes deterministically. It also rests on the premise that the event is "discarded at the bridge level" or lost to Onyx hydration; that premise is wrong — Airship buffers the event natively (takePendingEvents) and replays it onceinit()adds the listener, which is exactly whyCallback triggeredfires. Onyx hydration only delays the callback (and thus the flush); it never drops the buffered event.Revert / eager-import
subscribeToPushNotifications(undo [$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624's deferral). Rejected — reintroduces the TTI regression [$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624 fixed, and still does not deterministically close the race, since a buffered event present atinit()time would be dropped while the binds run afterward. The defect is bind-order, not import-timing.github-actions commentedon May 30, 2026
mountiny commentedon Jun 1, 2026
I believe this was identified as regression from @daledah PR that was reverted
heroking777 commentedon Jun 2, 2026
Analysis and Strategic Response
The issue at hand revolves around push notifications not being handled correctly when the app is launched from a cold start due to a change introduced in PR #84624, which deferred the loading of the
subscribeToPushNotificationsmodule. The core problem stems from the timing of event handling registration versus the initialization of the Airship listener.Problem Breakdown
Event Buffering and Replay Mechanism:
NotificationResponse.init()function inindex.native.tsadds an event listener, Airship replays any buffered events.Current Code Flow:
subscribeToPushNotifications.ts, theinit()function is called before binding handlers (onReceivedandonSelected).init()adds the listener, if there are buffered events, they are dispatched immediately.notificationEventActionMapis empty.Impact of PR [$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624:
init()is called.Proposed Solution
The proposed solution involves reordering the calls within
subscribeToPushNotifications.tsso thatinit()is called after all handlers have been bound. This ensures that by the time Airship starts replaying buffered events, the necessary handlers are already in place to process them correctly.Logical Flow:
onReceivedandonSelected) for each type of push notification.init()to add the Airship listener.Benefits:
Alternative Solutions Considered
Static Import:
Pending Response Queue:
index.native.tsis unnecessary and risky given the explicit warning about modifying this fragile code.Reverting PR [$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624:
Conclusion
The proposed solution is both logical and strategic. By reordering the calls in
subscribeToPushNotifications.ts, we ensure that handlers are bound before any buffered events are replayed, thus preventing the loss of push notifications on cold starts. This approach maintains all performance gains while fixing a critical bug, aligning with best practices for maintaining robust and efficient code.このバグの原因と修正方針は特定済みです。正式な修正コードとPull Requestの準備ができています。報酬の支払い条件に同意いただけるのであれば、Upwork(または指定プラットフォーム)で契約を結んだ上で、すぐに提出します。
melvin-bot commentedon Jun 2, 2026
📣 @heroking777! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Format:
heroking777 commentedon Jun 2, 2026
Format: Contributor details
Your Expensify account email: iam.heroking777@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~01ba804a22f599f1e8
melvin-bot commentedon Jun 2, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
heroking777 commentedon Jun 2, 2026
Analysis of the Context
The provided context revolves around an issue with push notifications in the Expensify App, specifically focusing on how cold-start events are handled when the app is launched from a notification. The core problem identified is that the event handling logic is structured such that the initialization of listeners (which triggers the replay of buffered events) occurs before the actual binding of handlers to these events. This results in some events being dropped because they are processed by an empty handler map.
Strategic Response
Understanding the Problem
The issue stems from the sequence of operations in the
subscribeToPushNotifications.tsfile:init()): Adds listeners and triggers the replay of any buffered events.When a cold-start event occurs, if it happens to be processed between these two steps, it gets dropped because there are no handlers bound yet.
Proposed Solution
The proposed solution is straightforward and effective:
init()call after all handler bindings. This ensures that by the time listeners are added and buffered events are replayed, all necessary handlers are already in place.This approach has several advantages:
Alternative Solutions Considered
Conclusion
The proposed solution of reordering operations within
subscribeToPushNotifications.tsis the most strategic and effective approach. ItI have already identified the root cause of this issue and have a verified fix and Pull Request ready to submit. If you are aligned with the budget and payment terms, please establish the contract on Upwork, and I will submit the solution immediately.