You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-06-09] [Due for payment 2026-06-08] [$250] Android - App crashes reopening while the GPS trip is in progress after discard tracking twice #88700
Version Number: v9.3.62-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:https://test-management.browserstack.com/projects/2219752/folder/39523254/test-cases/86239624 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Android 13 / Xiaomi Poco F5 App Component: Money Requests
Action Performed:
Login to the ND app
Navigate to WS Chat
Click + > Track Distance > GPS
Start the GPS tracking, kill and reopen the app
Stop the GPS tracking, then discard the distance tracking
Repeat steps 4-5
Start the GPS tracking
While the trip is in progress kill the app or force close
Reopen the app
Expected Result:
App should not crash when reopening while the GPS trip is in progress
Actual Result:
App crashes reopening while the GPS trip is in progress after discard the distance tracking twice
Note:
The app will crash several time on the next reopening, then it can be launched normally again
When the app is killed during GPS tracking, GpsTripService.onTaskRemoved() cancels the Android notification but does not end the Airship LiveUpdate. The LiveUpdate persists in Airship's internal storage across app kills.
On app restart, Airship SDK re-initializes and restores the pending LiveUpdate, which calls GpsLiveUpdateHandler.onUpdate(). For non-END events, this calls context.startService(GpsTripService) at line 32without a try-catch. On Android 12+ (API 31+), if this fires before the Activity is fully in the foreground during early Airship initialization, it throws an uncaught IllegalStateException / ForegroundServiceStartNotAllowedException, crashing the app.
This is worsened by a race condition in GPSTripStateChecker where checkAndCleanGpsNotification() is called twice — once inside handleGpsTripInProgressOnAppRestart() (async) and once immediately after. Both race to listAll() and end() the same LiveUpdate concurrently, which can corrupt Airship's internal state. After multiple start/kill/discard cycles, the accumulated stale LiveUpdate state makes the crash reliably reproducible.
The crash eventually self-resolves because each crash-restart cycle gives checkAndCleanGpsNotification another opportunity to clean up the stale LiveUpdate before the handler fires.
Android-only because iOS Live Activities are managed by the OS and cleaned up on app termination, while Android's Airship LiveUpdate persists across kills.
What changes do you think we should make in order to solve the problem?
End the Airship LiveUpdate in GpsTripService.onTaskRemoved() — call Airship.android.liveUpdateManager.end() (or equivalent native API) alongside the notification cancellation so stale LiveUpdates don't persist after app kill.
Wrap context.startService() in a try-catch in GpsLiveUpdateHandler.onUpdate() to prevent the crash from IllegalStateException on Android 12+ when the app isn't fully foregrounded.
Remove the duplicate checkAndCleanGpsNotification() call on line 46 of GPSTripStateChecker — it's already called inside handleGpsTripInProgressOnAppRestart() on line 35, and the duplicate creates the race condition.
Supporting evidence
GpsTripService.onTaskRemoved() only calls cancelGpsNotifications() (dismisses the Android notification) and stopSelf() — no LiveUpdate cleanup
GpsLiveUpdateHandler.onUpdate() unconditionally calls context.startService() for all non-END events with no exception handling
checkAndCleanGpsNotification() in index.android.ts calls stopGpsTripNotification() → end() for each matching LiveUpdate, but if called concurrently (as the race condition causes), both instances may try to end the same update
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
changed the title [-]Android - App crashes reopening while the GPS trip is in progress after discard tracking twice[/-][+][$250] Android - App crashes reopening while the GPS trip is in progress after discard tracking twice[/+]on Apr 24, 2026
Please re-state the problem that we are trying to solve in this issue.
On Android, the app crashes when reopened while a GPS trip was in progress and the user had discarded tracking twice.
What is the root cause of that problem?
The background location task in backgroundLocationTrackingTask calls addGpsPoints(gpsDraftDetails, newGpsPoints) without checking if gpsDraftDetails is null. On Android, the headless JS background task can fire after stopLocationUpdatesAsync due to timing races — especially after discarding twice quickly. When it fires post-discard, gpsDraftDetails is null, so addGpsPoints() in GPSDraftDetails writes a partial object to Onyx containing only gpsPoints and distanceInMeters — missing startAddress, endAddress, and other fields.
On app reopen, useUpdateGpsTripOnReconnect destructures startAddress from this corrupt partial draft and accesses startAddress.type — a TypeError on undefined, crashing the app. A similar unsafe access exists in GPSDraftDetailsUtils with gpsDraftDetails?.startAddress.value. Android-only because expo-task-manager background tasks run in a separate headless JS context that survives app kill, unlike iOS.
What changes do you think we should make in order to solve the problem?
In backgroundLocationTrackingTask, add an early return if gpsDraftDetails is null or isTracking is falsy — this prevents corrupt partial data from ever being written:
if(!gpsDraftDetails?.isTracking){return;}
In useUpdateGpsTripOnReconnect, add optional chaining as defense-in-depth: startAddress?.type and endAddress?.type.
In GPSDraftDetailsUtils, fix the unsafe access: gpsDraftDetails?.startAddress?.value and gpsDraftDetails?.endAddress?.value.
What alternative solutions did you explore? (Optional)
MelvinBot's proposal targets the native Android Airship LiveUpdate layer (Kotlin GpsTripService/GpsLiveUpdateHandler) — wrapping startService() in try-catch and ending LiveUpdates in onTaskRemoved(). That addresses a different crash vector (native IllegalStateException from foreground service restrictions). This proposal targets the actual JS-layer TypeError from corrupt Onyx data, which is the crash path triggered by the specific "discard tracking twice" repro. The two are complementary but mine addresses the data corruption that causes the reproducible crash described in the issue. MelvinBot's duplicate checkAndCleanGpsNotification fix is unrelated to this crash path.
The app crashes on Android when reopening during an active GPS trip after discarding tracking twice.
Root Cause
The issue appears after multiple discard cycles, indicating a state desynchronization between persisted tracking data (Onyx) and the Android location tracking service. After repeated discard actions, the trip data is partially cleared while the background service or related metadata is not fully reset. On relaunch, the app attempts to resume an invalid session, leading to a crash.
Solution
Make discard handling idempotent to prevent duplicate state mutations
Ensure complete cleanup of all tracking-related data (distance request, waypoints, tracking state)
Add validation during app initialization to prevent resuming invalid or corrupted trips
Stop the Android foreground service when no valid trip exists
📣 @hanif-2000! 📣
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:
Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
[Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to the comment on the PR:
Link to the comment on the Issue:
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Test:
Crashes # 1:
Start a GPS live tracking session
Go back to Home
Background the app
Leave the phone for 1 - 2 minutes (Can lock the phone)
Open the phone
Tap on the Live tracking notification
Repeat 4-7 for 2 - 3 times
Verify the app doesn't crash
Crashes # 2:
Navigate to WS Chat
Click + > Track Distance > GPS
Start the GPS tracking, kill and reopen the app
Stop the GPS tracking, then discard the distance tracking
Repeat steps 4-5
Start the GPS tracking
While the trip is in progress kill the app or force close
Reopen the app
Verify that the app doesn't crash
Starting GPS trip and backgrounding the app:
Start GPS trip
Verify that it shows a notification banner at the top of the screen
Verify that there is a notification on the lock screen and in the notifications panel
Navigate to a different screen and background the app
Tap on the GPS notification
Verify that it opens the app and navigates to the GPS screen with ongoing GPS trip
Background the app again
Tap on the GPS notification
Verify that it opens the app on the GPS screen (there should be no unnecessary navigation animation or anything like that)
Logging out:
Start GPS trip
Verify that the GPS notification appears
Log out
Verify that the GPS notification disappeared
App termination:
Start GPS trip
Verify that the GPS notification appears
Terminate the app
Verify that the GPS notification disappeared
Open the app again, it should show the Continue GPS trip recording? modal
Activity
MelvinBot commentedon Apr 24, 2026
Proposal
What is the root cause of that problem?
When the app is killed during GPS tracking,
GpsTripService.onTaskRemoved()cancels the Android notification but does not end the Airship LiveUpdate. The LiveUpdate persists in Airship's internal storage across app kills.On app restart, Airship SDK re-initializes and restores the pending LiveUpdate, which calls
GpsLiveUpdateHandler.onUpdate(). For non-END events, this callscontext.startService(GpsTripService)at line 32 without a try-catch. On Android 12+ (API 31+), if this fires before the Activity is fully in the foreground during early Airship initialization, it throws an uncaughtIllegalStateException/ForegroundServiceStartNotAllowedException, crashing the app.This is worsened by a race condition in
GPSTripStateCheckerwherecheckAndCleanGpsNotification()is called twice — once insidehandleGpsTripInProgressOnAppRestart()(async) and once immediately after. Both race tolistAll()andend()the same LiveUpdate concurrently, which can corrupt Airship's internal state. After multiple start/kill/discard cycles, the accumulated stale LiveUpdate state makes the crash reliably reproducible.The crash eventually self-resolves because each crash-restart cycle gives
checkAndCleanGpsNotificationanother opportunity to clean up the stale LiveUpdate before the handler fires.Android-only because iOS Live Activities are managed by the OS and cleaned up on app termination, while Android's Airship LiveUpdate persists across kills.
What changes do you think we should make in order to solve the problem?
End the Airship LiveUpdate in
GpsTripService.onTaskRemoved()— callAirship.android.liveUpdateManager.end()(or equivalent native API) alongside the notification cancellation so stale LiveUpdates don't persist after app kill.Wrap
context.startService()in a try-catch inGpsLiveUpdateHandler.onUpdate()to prevent the crash fromIllegalStateExceptionon Android 12+ when the app isn't fully foregrounded.Remove the duplicate
checkAndCleanGpsNotification()call on line 46 ofGPSTripStateChecker— it's already called insidehandleGpsTripInProgressOnAppRestart()on line 35, and the duplicate creates the race condition.Supporting evidence
GpsTripService.onTaskRemoved()only callscancelGpsNotifications()(dismisses the Android notification) andstopSelf()— no LiveUpdate cleanupGpsLiveUpdateHandler.onUpdate()unconditionally callscontext.startService()for all non-END events with no exception handlingcheckAndCleanGpsNotification()inindex.android.tscallsstopGpsTripNotification()→end()for each matching LiveUpdate, but if called concurrently (as the race condition causes), both instances may try to end the same updateNext Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 24, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @truph01 (
External)[-]Android - App crashes reopening while the GPS trip is in progress after discard tracking twice[/-][+][$250] Android - App crashes reopening while the GPS trip is in progress after discard tracking twice[/+]melvin-bot commentedon Apr 24, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022047732395455734421
twilight2294 commentedon Apr 24, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Android, the app crashes when reopened while a GPS trip was in progress and the user had discarded tracking twice.
What is the root cause of that problem?
The background location task in
backgroundLocationTrackingTaskcallsaddGpsPoints(gpsDraftDetails, newGpsPoints)without checking ifgpsDraftDetailsis null. On Android, the headless JS background task can fire afterstopLocationUpdatesAsyncdue to timing races — especially after discarding twice quickly. When it fires post-discard,gpsDraftDetailsis null, soaddGpsPoints()inGPSDraftDetailswrites a partial object to Onyx containing onlygpsPointsanddistanceInMeters— missingstartAddress,endAddress, and other fields.On app reopen,
useUpdateGpsTripOnReconnectdestructuresstartAddressfrom this corrupt partial draft and accessesstartAddress.type— a TypeError onundefined, crashing the app. A similar unsafe access exists inGPSDraftDetailsUtilswithgpsDraftDetails?.startAddress.value. Android-only becauseexpo-task-managerbackground tasks run in a separate headless JS context that survives app kill, unlike iOS.What changes do you think we should make in order to solve the problem?
backgroundLocationTrackingTask, add an early return ifgpsDraftDetailsis null orisTrackingis falsy — this prevents corrupt partial data from ever being written:In
useUpdateGpsTripOnReconnect, add optional chaining as defense-in-depth:startAddress?.typeandendAddress?.type.In
GPSDraftDetailsUtils, fix the unsafe access:gpsDraftDetails?.startAddress?.valueandgpsDraftDetails?.endAddress?.value.What alternative solutions did you explore? (Optional)
MelvinBot's proposal targets the native Android Airship LiveUpdate layer (Kotlin
GpsTripService/GpsLiveUpdateHandler) — wrappingstartService()in try-catch and ending LiveUpdates inonTaskRemoved(). That addresses a different crash vector (nativeIllegalStateExceptionfrom foreground service restrictions). This proposal targets the actual JS-layer TypeError from corrupt Onyx data, which is the crash path triggered by the specific "discard tracking twice" repro. The two are complementary but mine addresses the data corruption that causes the reproducible crash described in the issue. MelvinBot's duplicatecheckAndCleanGpsNotificationfix is unrelated to this crash path.hanif-2000 commentedon Apr 24, 2026
Proposal
Problem
The app crashes on Android when reopening during an active GPS trip after discarding tracking twice.
Root Cause
The issue appears after multiple discard cycles, indicating a state desynchronization between persisted tracking data (Onyx) and the Android location tracking service. After repeated discard actions, the trip data is partially cleared while the background service or related metadata is not fully reset. On relaunch, the app attempts to resume an invalid session, leading to a crash.
Solution
Testing
I’m happy to implement this fix once the proposal is approved.
melvin-bot commentedon Apr 24, 2026
📣 @hanif-2000! 📣
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:
74 remaining items
melvin-bot commentedon Jun 8, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon Jun 8, 2026
@truph01 👀 plz. Are you the only one due payment? If so, how much? I see a regression it looks like it was expected. Thx
truph01 commentedon Jun 9, 2026
@mallenexpensify Yes, I should be eligible for the $250 payment.
This issue needs two PRs. The regression occurred because the two PRs were not merged and deployed together.
mallenexpensify commentedon Jun 9, 2026
Payment Summary
Contributor+: @truph01 due $250 via NewDot
@truph01 do we need a checklist here? If no, why not? Thx
melvin-bot commentedon Jun 12, 2026
@mallenexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!
melvin-bot commentedon Jun 15, 2026
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
mallenexpensify commentedon Jun 15, 2026
@truph01 do we need a checklist here? If no, why not? Thx
truph01 commentedon Jun 16, 2026
BugZero Checklist:
[Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to the comment on the PR:
Link to the comment on the Issue:
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Test:
Crashes # 1:
Crashes # 2:
Starting GPS trip and backgrounding the app:
Logging out:
App termination:
Continue GPS trip recording?modalContinue tripDo we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-5a9f-ab94-8f4a-5be5704eb424garrettmknight commentedon Aug 10, 2026
$250 approved for @truph01