Skip to content

fix: Keep the sole GPS segment when a trip is stopped after one recorded point - #101027

Open
TaduJR wants to merge 3 commits into
Expensify:mainfrom
TaduJR:fix-Android-GPS-Save-and-Resume-buttons-not-present-after-tapping-Stop-without-moving
Open

fix: Keep the sole GPS segment when a trip is stopped after one recorded point#101027
TaduJR wants to merge 3 commits into
Expensify:mainfrom
TaduJR:fix-Android-GPS-Save-and-Resume-buttons-not-present-after-tapping-Stop-without-moving

Conversation

@TaduJR

@TaduJR TaduJR commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Standing still while tracking records only one location, because the app records a new location only after you move 100 m. When you tapped Stop, the app removed the last section of the trip if it had one location or none. That's right for a section added by Resume that recorded nothing useful, but it also happened when that section was the whole trip. The app treats a trip with no locations as one that never started, so the trip disappeared: no Resume or Save, no distance or addresses, and the button went back to Start.

Stop now only removes a short section when there's an earlier section to fall back on. So stopping without moving keeps the trip with Resume and Save, and tapping Save shows the existing "Can't create expense" message. The same applies when a trip is stopped from "View trip" after reopening the app, or by switching to Expensify Classic.

Keeping that one location makes a few new situations possible, and this PR handles them:

  • The map pins assumed every section has a start and an end, so a section with one location made the last pin show as a normal waypoint instead of the stop. Pins are now picked by where they sit in their section, on both the trip screen and the Edit stop screen.
  • A trip too short to trim, like one that never moved, no longer shows the Edit button.
  • A trip can now be discarded right after its first location, while its start address is still being looked up. When that lookup finished, it saved the address and the discarded trip came back. It now saves nothing if the trip is gone.
  • For a trip with a single location, the map now centers on it at the zoom used for a single pin, instead of trying to fit its view around a route that has no size.

This is a regression from #88609. The check that kept a trip's only section was lost when the logic was split into a helper before that PR merged.

Fixed Issues

$ #100938
PROPOSAL:

Tests

  1. Tap FAB, then Track distance, then the GPS tab.
  2. Tap Start and allow any location prompts.
  3. Wait until Distance shows 0.00, your address appears under Start, and Tracking distance... appears under Stop.
  4. Without moving, tap Stop.
  5. Verify the trip stays on screen: Distance 0.00, your address under both Start and Stop, a trash icon next to the distance, no pencil icon, and Resume and Save buttons.
  6. Verify the map is centered on your location at a normal zoom where nearby streets are visible, not zoomed in all the way.
  7. Drag the map away, then tap the crosshair button at the top right of the map. Verify the map returns to your location at the same normal zoom.
  8. Tap Save. Verify a "Can't create expense" message says "You can't create an expense with the same start and stop location."
  9. Tap Got it. Verify the trip is still on screen and no expense was created.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-09-12.at.7.51.01.PM.mov
Android: mWeb Chrome
iOS: Native
Screen.Recording.2026-09-12.at.7.58.04.PM.mov
iOS: mWeb Safari
MacOS: Chrome / Safari

@TaduJR
TaduJR requested review from a team as code owners September 12, 2026 16:52
@melvin-bot
melvin-bot Bot requested review from garrettmknight and mkhutornyi and removed request for a team September 12, 2026 16:52
@melvin-bot

melvin-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

@mkhutornyi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@TaduJR

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c80098738

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/GPSDraftDetailsUtils.ts
@MelvinBot

This comment has been minimized.

@TaduJR

This comment was marked as resolved.

@MelvinBot

This comment has been minimized.

@TaduJR

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5c7fcff1f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/GPSDraftDetailsUtils.ts Outdated
@MelvinBot

This comment has been minimized.

@TaduJR

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 72026b82e9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@MelvinBot

This comment has been minimized.

@TaduJR

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f5852e0a3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/GPSDraftDetailsUtils.ts Outdated
@MelvinBot

This comment has been minimized.

@TaduJR

This comment was marked as resolved.

@MelvinBot

MelvinBot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🤖 Done — all five of my comments on this PR are now hidden as resolved:

Comment Pass
5647386443 Initial review at 2c80098
5647713052 Withdrew the refactor, raised the .value finding
5647815991 Re-review at a5c7fcf
5648186152 Re-review at 72026b8
5648667453 Re-review at 8f5852e

Correcting my last reply: I said there was nothing to resolve because these were top-level comments rather than inline review threads. That was wrong — GitHub's Hide comment → Resolved works on top-level comments too, and that's what I've applied.

Head is still 8f5852e, the commit my last pass cleared, so nothing has changed since. The two inline review threads from chatgpt-codex-connector were already resolved and I left them alone.


Next Steps: Reply with @MelvinBot <your feedback> if you want any of these unhidden.


view run · no recording available

@TaduJR
TaduJR force-pushed the fix-Android-GPS-Save-and-Resume-buttons-not-present-after-tapping-Stop-without-moving branch from 8f5852e to 77648b2 Compare September 13, 2026 14:10
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/MapView/utils.ts 92.10% <100.00%> (+2.91%) ⬆️
src/libs/GPSDraftDetailsUtils.ts 87.50% <100.00%> (+28.09%) ⬆️
src/libs/actions/GPSDraftDetails.ts 57.47% <100.00%> (+55.19%) ⬆️
...OURequestStepDistanceGPS/useGPSWaypointMarkers.tsx 100.00% <100.00%> (+100.00%) ⬆️
...tup/backgroundLocationTrackingTask/index.native.ts 82.05% <100.00%> (+79.34%) ⬆️
...estStepDistanceGPS/Waypoints/EditGPSTripButton.tsx 0.00% <0.00%> (ø)
src/components/MapView/GPSMapView.tsx 2.46% <0.00%> (-0.17%) ⬇️
... and 16 files with indirect coverage changes

@TaduJR

TaduJR commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d854560b4e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@MelvinBot

MelvinBot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

🤖 Re-reviewed at d854560. The branch was rewritten since my last pass (8f5852e is no longer an ancestor — the three commits here are new), so this is a fresh read rather than a delta. CI is fully green. Two findings.

Test step 3 now contradicts the code

Step 3 still says to verify "trash and pencil icons next to the distance". Commit 77648b2 deliberately hides the pencil for exactly that trip: EditGPSTripButton now gates on canGpsTripBeTrimmed, and a stopped trip with one point has distanceInMeters === 0, so it returns null. QA will fail that step on correct behavior.

While you're in there — the steps only exercise the first commit. Nothing covers the map centering on a single point, the stop marker on a segment that holds one point, or the Edit button disappearing. QA Steps say "Same as tests", so both sections inherit the gap.

The rewrite dropped the addressFromGpsPoint fix

The previous revision changed GPSPointUtils.ts:21 to return address || null. That file is not in this PR any more, and main still has the bare return address.

It matters here specifically. Line 19 builds the address as formattedAddress ?? [name, city, region].filter(Boolean).join(', ') — a geocode result with a location object whose fields are all null yields '', not null. updateStartAddress gates on address !== null, so {value: '', type: 'address'} gets written. Then Waypoints/index.tsx:49-50 reads !address?.value, '' is falsy, and both rows render the '...' spinner with nothing to ever resolve them.

That's a latent bug on main, not one you introduced. But before this PR a one-point trip was deleted on Stop, so the stuck rows were never on screen. Keeping the trip is what makes it reachable — which is presumably why the earlier revision fixed it. Worth pulling back.

Nits

  • The caller-side if is now redundant. GPSDraftDetailsUtils.ts:143-147 guards on gpsPoints.length > 1, and removeLastSegment:68 now returns early on length <= 1 itself. Both branches of the outer if fall to the same return, so dropping it leaves behavior identical. Your earlier reason for keeping it — the sole segment continuing into the address logic — no longer applies to this code.
  • getSinglePointCoordinate([], undefined) returns undefined by accident. getBounds on empty input gives southWest: [Infinity, Infinity] and northEast: [-Infinity, -Infinity], so the equality check happens to fail. The test asserting this passes for a reason a reader would not guess. An explicit empty check would say it.
  • getBounds runs twice per render. GPSMapView.tsx:48 walks every coordinate, then getWaypointBounds walks them again on the same inputs — a third time in the focus effect. Computing the bounds once and deriving singlePointCoordinate from them would collapse all three.
  • The discard guard doesn't cover a restart. index.native.ts:82 catches the discard, but if a new trip is started during the lookup, updatedGpsDraftDetails is truthy and the stale tripSegmentIndex from line 72 writes the old trip's address onto the new one. Nearly always harmless since both points sit in the same place, but it's the same race the commit is about.
What I checked and found correct

canGpsTripBeTrimmed's threshold is exact, not approximate. > GPS_DISTANCE_INTERVAL_METERS matches Slider.tsx:33, where minRatio = GPS_DISTANCE_INTERVAL_METERS / totalDistanceMeters. At exactly one interval minRatio is 1, so the slider's min equals its max and there is genuinely nothing to trim. I went looking for an off-by-one here and there isn't one.

The .catch(() => undefined) on the draft read is unreachable, which makes the new guard unambiguous. getGpsDraftDetails wraps Onyx.connectWithoutView in a promise with no reject path, so !updatedGpsDraftDetails can only mean "no draft". Good — the branch can't silently swallow a read failure.

removeLastSegment owning the invariant is the change I asked for two passes ago, and the tests now assert real Onyx state instead of mock call counts, including the [[]] and resumed-segment cases.

useGPSWaypointMarkersisLastWaypointSegmentStart uses findLast((segment) => segment.length > 0), which matches the segment.length < 1 skip inside getGPSWaypoints, so the index arithmetic stays aligned. The two trimmed cases I flagged as untested last round are now covered, including segmentIndex: 1.

Onyx array semantics. Onyx.merge replaces arrays rather than merging them, so stopGpsTrip writing its stale gpsPoints parameter can still clobber a point that lands during the awaits. Unchanged from main and not something this PR makes worse, so I'm not reopening it — noting it only because the backgroundLocationTrackingTask commit fixes the same class of race one file over.

CI. All 8 test jobs pass, along with typecheck, ESLint check, React Compiler Compliance, Oxfmt check, spellcheck, Storybook tests and both perf jobs. The only red checks are Check independent approval and checklist, neither of which reflects the code.

I did not run the app — this flow is native-only and isn't reproducible on web, so I reviewed statically against green CI.


Next Steps: Reply with @MelvinBot <your feedback> to refine this review.


view run · no recording available

@TaduJR

TaduJR commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot The bug is already on main branch. I can make a follow-up. Addressing here will bloat up the PR. For now make the comment your wrote as resolved including all the others.

@MelvinBot

MelvinBot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

🤖 Nothing left to resolve — and my main point is already fixed on your branch.

All three inline review threads are already resolved, and no review is in a blocking state. My review was posted as a top-level PR comment, which GitHub gives no resolve control for. Treat it as closed out — I'm not holding anything open.

You already applied the cleanup I asked for. At src/libs/actions/GPSDraftDetails.ts:66-70, removeLastSegment now early-returns on gpsPoints.length <= 1. The clear-to-[[]] branch that was the actual bug is gone, so the invariant lives in one place. That was the only thing I flagged as "should fix."

Agreed on the follow-up for the rest — the remaining ... endpoint edge cases predate this PR, and widening the diff to chase them here is the wrong trade.

One optional leftover whenever you touch this next: the if (gpsPoints.length > 1) guard at src/libs/GPSDraftDetailsUtils.ts:144 is now redundant with the one inside removeLastSegment. Harmless as defense in depth — just not worth a push on its own.


view run · no recording available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants