Skip to content

[CP Staging] preserve distance when submitting from IOU to WS#90679

Merged
youssef-lr merged 5 commits into
Expensify:mainfrom
mukhrr:fix/90561
May 15, 2026
Merged

[CP Staging] preserve distance when submitting from IOU to WS#90679
youssef-lr merged 5 commits into
Expensify:mainfrom
mukhrr:fix/90561

Conversation

@mukhrr
Copy link
Copy Markdown
Contributor

@mukhrr mukhrr commented May 14, 2026

Explanation of Change

Fixed Issues

$ #90561
PROPOSAL:

Tests

  1. Go to self DM.
  2. Create a distance expense.
  3. Open the expense.
  4. Click Distance.
  5. Go to Manual tab.
  6. Edit the distance and save it.
  7. Click on the header > Submit it to someone.
  8. Select workspace chat.
  9. Click Create expense.
  10. Open the created expense in workspace chat.
  11. Click Distance.
  • Verify distance will not revert to the original distance after editing it and submitting the expense from self DM.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

The 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
  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@mukhrr mukhrr requested review from a team as code owners May 14, 2026 14:16
@melvin-bot melvin-bot Bot requested review from aimane-chnaif and joekaufmanexpensify and removed request for a team May 14, 2026 14:16
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 14, 2026

@aimane-chnaif 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]

Copy link
Copy Markdown

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

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: 605e21d958

ℹ️ 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/actions/IOU/TrackExpense.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

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/libs/actions/IOU/UpdateMoneyRequest.ts 79.72% <ø> (+12.00%) ⬆️
.../pages/iou/request/step/IOURequestStepDistance.tsx 76.49% <ø> (-0.11%) ⬇️
src/libs/actions/IOU/TrackExpense.ts 80.86% <92.30%> (+0.22%) ⬆️
... and 377 files with indirect coverage changes

Copy link
Copy Markdown
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

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

Fixing DBs

@aimane-chnaif
Copy link
Copy Markdown
Contributor

Tests failing

@MelvinBot
Copy link
Copy Markdown
Contributor

Code Review

Overall: The approach is sound. hasManualDistanceOverride correctly compares the transaction's own customUnit.quantity (converted to meters) against routes.route0.distance to distinguish manual edits from GPS-tracked distances. The distance param is only used as a gate, not in the comparison, so the roundToTwoDecimalPlaces in useExpenseSubmission doesn't affect the detection logic.

The getUpdateTrackExpenseParams fix correctly mirrors the existing pattern in getUpdateMoneyRequestParams.

A few items to consider:

  1. The Codex bot review comment is a false alarm — it says "any numeric distance is treated as a manual override," but hasManualDistanceOverride does NOT do that. It checks whether the transaction's stored quantity diverges from its route0.distance, which correctly returns false for GPS-tracked expenses where the two values match.

  2. Minor: the distance param in hasManualDistanceOverride is only used as a type guard (typeof distance !== 'number'return false). Consider whether this guard is necessary — if the caller always passes a number for distance expenses and undefined for non-distance expenses, the function's name + the quantity/distanceUnit/routeDistanceMeters checks already handle non-distance cases. The extra param adds a slight indirection to readability.

  3. Test coverage looks good — edge cases for missing fields, tolerance, and pure-manual expenses are all covered.

Copy link
Copy Markdown

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

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: 0b88a391b4

ℹ️ 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/actions/IOU/TrackExpense.ts Outdated
Comment on lines +1433 to +1435
const quantityInMeters = DistanceRequestUtils.convertToDistanceInMeters(quantity, distanceUnit);
// 1m tolerance swallows float-precision noise between the two representations.
return Math.abs(quantityInMeters - routeDistanceMeters) > 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Detect overrides using unrounded distance source

hasManualDistanceOverride() compares customUnit.quantity (converted to meters) against routes.route0.distance, but customUnit.quantity is often stored rounded to 2 decimals when routes are updated (see src/libs/TransactionUtils/index.ts:771). That rounding alone can exceed the 1m tolerance (e.g., 0.01 mi granularity is ~16m), so non-overridden GPS/map expenses can be misclassified as “manual override”. When that happens, convertTrackedExpenseToRequest() drops waypoints, which removes route context needed to preserve/regenerate the map receipt on submit.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

🚧 @trjExpensify has triggered a test Expensify/App build. You can view the workflow run here.

@youssef-lr
Copy link
Copy Markdown
Contributor

Failure is unrelated, I'll re-run it

@github-actions

This comment has been minimized.

@youssef-lr
Copy link
Copy Markdown
Contributor

@aimane-chnaif checks passing!

@trjExpensify
Copy link
Copy Markdown
Contributor

Don't think this is fixed:

2026-05-15_00-18-05.mp4
image image

From testing, I observed that when I edit the unreported expense manually, it uses the wrong rate. It should be using the rate of the default workspace.

  • When you have a default group workspace and create an unreported expense, it uses the rate of your workspace.
  • When you edit it, it should still use that rate.

See how if I edit the map via waypoints it uses my default workspace rate. When I move it to a workspace, the rate remains the same and it doesn't revert.

2026-05-15_00-35-09.mp4

Now look at when I edit manually. It applies the wrong rate (the user's personal rate), thus throws the error on upload > I fix that > move it to the workspace > distance reverts.

2026-05-15_00-37-48.mp4

@mukhrr
Copy link
Copy Markdown
Contributor Author

mukhrr commented May 15, 2026

I see PR is cloned. So is this PR is still valid and I should continue fixing?! @trjExpensify @youssef-lr @aimane-chnaif

@trjExpensify
Copy link
Copy Markdown
Contributor

@youssef-lr is on it. We're testing BE as well.

@aimane-chnaif
Copy link
Copy Markdown
Contributor

We can continue here as it looks like PR is not yet in mergeable state. Please check Tom's feedback above

@mukhrr
Copy link
Copy Markdown
Contributor Author

mukhrr commented May 15, 2026

Let's know if @youssef-lr is working on it right now. Asked in Slack

@youssef-lr
Copy link
Copy Markdown
Contributor

I'm working on it, the condition here

const routeDistanceMeters = transaction?.routes?.route0?.distance;
is not working because the meters are found in transaction?.comment?.customUnit?.routeDistanceMeters;. I'm relying on this to send a param to the backend which predates this feature and is only used from Classic: hasDistanceBeenManuallyUpdated which fixes the issue Tom found. @mukhrr if you'd like to continue pushing this forward feel free to merge my branch into your PR. I'm gonna push this fix in a bit.

@youssef-lr
Copy link
Copy Markdown
Contributor

youssef-lr commented May 15, 2026

Though we also need a backend fix for that. AddTrackedExpenseToPolicy does not yet accept hasDistanceBeenManuallyUpdated .

Copy link
Copy Markdown

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

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: f1ca924a39

ℹ️ 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/actions/IOU/TrackExpense.ts Outdated
@mukhrr
Copy link
Copy Markdown
Contributor Author

mukhrr commented May 15, 2026

I see bugs are fixed. Answering to comments now

@youssef-lr
Copy link
Copy Markdown
Contributor

The bug is fixed without sending hasDistanceBeenManuallyUpdated by the way.

@mukhrr
Copy link
Copy Markdown
Contributor Author

mukhrr commented May 15, 2026

@aimane-chnaif @Beamanator comments are adressed

@MelvinBot
Copy link
Copy Markdown
Contributor

Regression Analysis

I reviewed the diff for three potential regression areas. Overall this PR is low-risk, but there are two items worth verifying.

1. False-positive risk in hasManualDistanceOverride (low-medium risk)

The 0.01 tolerance in display units (~10m for km, ~16m for miles) should be safe for most cases. However, if routeDistanceMeters and quantity were ever derived from slightly different computations (e.g., client-side route vs backend route), floating-point differences could exceed 0.01 and incorrectly strip waypoints from a GPS-tracked expense, causing the map receipt to not be regenerated on the converted expense.

Worth verifying: are there real-world GPS-tracked transactions where quantity and convertDistanceUnit(routeDistanceMeters, distanceUnit) differ by more than 0.01?

2. Backend handling of distance expenses without waypoints (unknown risk)

When waypoints are stripped, the backend still receives distance, amount, and isDistance — but no waypoints. Two open questions:

  • Does the backend create a valid distance expense without waypoints, or does it require waypoints to set up distance-specific fields?
  • What happens to the map receipt image? The original receipt exists on the transaction, but if the backend tries to regenerate it during conversion and finds no waypoints, it could produce a broken/missing receipt.

This is a backend question that cannot be answered from frontend code alone. Manual testing of the full flow (edit distance → submit to workspace → verify receipt in workspace) would confirm this works end-to-end.

3. distanceOriginalPolicy dependency array fix (no risk)

This is a correctness fix — distanceOriginalPolicy was already used inside the submitWaypoints and submitManualDistance callbacks (IOURequestStepDistance.tsx:473) but was missing from the dependency arrays (stale closure bug). Adding it is strictly a fix, not a regression risk.

4. Bulk convert path

convertBulkTrackedExpensesToIOU also calls convertTrackedExpenseToRequest, so the waypoint-stripping logic applies to bulk conversions too. If a GPS-tracked expense hits a false positive (item #1), it would also be affected in bulk flows. Same risk profile as #1.


Bottom line: The main thing to verify is that the backend handles the waypoints: undefined case gracefully for distance expenses (creates valid expense, preserves receipt). Everything else looks solid.

Copy link
Copy Markdown
Contributor

@trjExpensify trjExpensify left a comment

Choose a reason for hiding this comment

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

re-approving.

@Beamanator Beamanator changed the title preserve distance when submitting from IOU to WS [CP Staging] preserve distance when submitting from IOU to WS May 15, 2026
@youssef-lr youssef-lr merged commit 0eea15d into Expensify:main May 15, 2026
47 of 49 checks passed
@melvin-bot melvin-bot Bot added the Emergency label May 15, 2026
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 15, 2026

@youssef-lr looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@github-actions
Copy link
Copy Markdown
Contributor

🚧 @youssef-lr has triggered a test Expensify/App build. You can view the workflow run here.

OSBotify pushed a commit that referenced this pull request May 15, 2026
[CP Staging] preserve distance when submitting from IOU to WS

(cherry picked from commit 0eea15d)

(cherry-picked to staging by Beamanator)
@OSBotify OSBotify added the CP Staging marks PRs that have been CP'd to staging label May 15, 2026
@OSBotify
Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Copy Markdown
Contributor

🚀 Cherry-picked to staging by https://github.com/Beamanator in version: 9.3.74-6 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@MelvinBot
Copy link
Copy Markdown
Contributor

No help site changes required.

This PR is a bug fix that preserves manually-edited distance values when submitting expenses from self DM to a workspace. The changes are internal code logic only (TrackExpense.ts, UpdateMoneyRequest.ts, IOURequestStepDistance.tsx) — no user-facing workflows, UI labels, or features were added or changed.

The existing Distance Expenses help article already covers creating, editing, and submitting distance expenses accurately.

@trjExpensify
Copy link
Copy Markdown
Contributor

Staging ✅

2026-05-15_17-16-26.mp4

@OSBotify
Copy link
Copy Markdown
Contributor

🚀 Cherry-picked to staging by https://github.com/Beamanator in version: 9.3.74-7 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@MelvinBot
Copy link
Copy Markdown
Contributor

👋 Thanks for the review request, mukhrr.

No help site changes are required for this PR.

This PR fixes an internal bug where manually edited distance values revert when submitting a tracked expense from self DM to a workspace. The changes are limited to:

  • Data flow logic in TrackExpense.ts and UpdateMoneyRequest.ts
  • A minor prop pass-through in IOURequestStepDistance.tsx
  • Unit tests

No user-facing features, workflows, terminology, or UI were added or changed — this is a bug fix to preserve existing behavior (manually edited distances). The help site already documents distance expenses at a feature level, and nothing in that documentation needs updating.

@OSBotify
Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 9.3.74-7 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@Beamanator
Copy link
Copy Markdown
Contributor

Beamanator commented May 15, 2026

Working well in iOS 9.3.74-6 still 👍

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

Labels

CP Staging marks PRs that have been CP'd to staging Emergency

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants