Skip to content

[Due for payment 2026-03-04] [$250] Expense - Distance expense created in offline is not shown in expense report #80591

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: V9.3.9-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: #80003
Email or phone of affected tester (no customers): dreamnitethedragon+yydyd373@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redminote 10S Android 13
App Component: Workspace Settings

Action Performed:

  1. Launch app (use expensifail account)
  2. Open expense report
  3. Go offline
  4. Tap add expense
  5. Create a map distance expense offline
  6. Note expense created is not in expense report
  7. Navigate back to workspace chat
  8. Note expense created in step 5 is created as new report

Expected Result:

Distance expense created in offline must be shown in expense report.

Actual Result:

Distance expense created in offline is not shown in expense report. Expense is shown in workspace chat as seperate new report.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022018801594579053430
  • Upwork Job ID: 2018801594579053430
  • Last Price Increase: 2026-02-03
Issue OwnerCurrent Issue Owner: @greg-schroeder

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 27, 2026
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 27, 2026
  3. melvin-bot commented on Jan 27, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @suneox (External)

  4. melvin-bot commented on Jan 27, 2026

    @melvin-bot

    Triggered auto assignment to @greg-schroeder (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. MobileMage commented on Jan 27, 2026

    @MobileMage
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user is inside an existing expense report and creates a distance expense while offline, the expense is incorrectly created as a new separate report in the workspace chat instead of being added to the current expense report. This breaks the expected offline behavior where expenses should be added to the report the user is currently viewing.

    What is the root cause of that problem?

    The root cause is an inconsistency between how the scan/manual expense flow and the distance expense flow determine whether the user started the expense from within an existing report.

    In src/libs/actions/IOU/MoneyRequest.ts, the scan flow at line 304 uses:

    if (!initialTransaction?.isFromGlobalCreate && !isArchivedExpenseReport && iouType !== CONST.IOU.TYPE.CREATE) {

    However, the distance flow at line 512 uses:

    if (report?.reportID && !isArchivedExpenseReport && iouType !== CONST.IOU.TYPE.CREATE) {

    The difference is:

    • Scan flow: Uses !initialTransaction?.isFromGlobalCreate - this flag is set in the transaction draft when initialized via initMoneyRequest and is always reliably available
    • Distance flow: Uses report?.reportID - this depends on the report object being loaded from Onyx

    When offline, the report object from Onyx might not be available or fully loaded (the HOC withWritableReportOrNotFound loads it from ONYXKEYS.COLLECTION.REPORT based on route params). When report?.reportID is undefined, the condition fails and the code falls through to line 626-627 which calls navigateToParticipantPage, effectively treating the expense as if it was started from the global create menu.

    The transaction draft, however, correctly has isFromGlobalCreate: false (or undefined) and reportID set to the expense report's ID when initialized from within a report. This data is reliable and available offline.

    What changes do you think we should make in order to solve the problem?

    Update the condition in handleMoneyRequestStepDistanceNavigation in src/libs/actions/IOU/MoneyRequest.ts at line 512 to use !transaction?.isFromGlobalCreate instead of report?.reportID, making it consistent with the scan flow:

    Before (line 512):

    if (report?.reportID && !isArchivedExpenseReport && iouType !== CONST.IOU.TYPE.CREATE) {

    After:

    if (!transaction?.isFromGlobalCreate && !isArchivedExpenseReport && iouType !== CONST.IOU.TYPE.CREATE) {

    This change ensures that the distance expense flow correctly identifies when the user started the expense from within an existing report (where isFromGlobalCreate is false/undefined) versus from the global create menu (where isFromGlobalCreate is true), regardless of whether the full report object is available in Onyx.

    What alternative solutions did you explore? (Optional)

  6. daledah commented on Jan 27, 2026

    @daledah
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user is offline and creates a distance expense from an existing expense report (via "Add expense" → "Track distance"), the expense is not added to the existing expense report. Instead, it creates a new separate report in the workspace chat.

    What is the root cause of that problem?

    The root cause is in the createDistanceRequest function in src/libs/actions/IOU/index.ts. When the user adds a distance expense to an existing expense report, the function extracts the moneyRequestReportID from the passed report object and passes it to getMoneyRequestInformation.

    // If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
    const isMoneyRequestReport = isMoneyRequestReportReportUtils(report);
    const currentChatReport = isMoneyRequestReport ? getReportOrDraftReport(report?.chatReportID) : report;
    const moneyRequestReportID = isMoneyRequestReport ? report?.reportID : '';

    Inside getMoneyRequestInformation, the moneyRequestReportID is used to look up the expense report from allReports:

    } else if (moneyRequestReportID) {
    iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;

    When offline, allReports may not have the expense report loaded/synced, so iouReport becomes null. Then at line 3117-3123, shouldCreateNewMoneyRequestReport returns true because !existingIOUReport is true, and a new report is created instead of using the existing one.

    What changes do you think we should make in order to solve the problem?

    Instead of only passing moneyRequestReportID (which requires a lookup in allReports), we should pass the expense report object directly as existingIOUReport when it's available. This way, getMoneyRequestInformation can use the report object directly without needing to look it up from allReports.

    In src/libs/actions/IOU/index.ts, in the createDistanceRequest function:

     const isMoneyRequestReport = isMoneyRequestReportReportUtils(report);
     const currentChatReport = isMoneyRequestReport ? getReportOrDraftReport(report?.chatReportID) : report;
     const moneyRequestReportID = isMoneyRequestReport ? report?.reportID : '';
    +const existingIOUReport = isMoneyRequestReport ? report : undefined;
    
     // ... later in the function ...
    
     const {
         iouReport,
         chatReport,
         // ...
     } = getMoneyRequestInformation({
         parentChatReport: currentChatReport,
         existingTransaction,
    +    existingIOUReport,
         moneyRequestReportID,
         // ...
     });

    This ensures that when the user is adding a distance expense to an existing expense report, the report object is passed directly and used without needing to look it up from allReports, making the offline flow work correctly.

    What alternative solutions did you explore? (Optional)

  7. yatin-italy commented on Jan 27, 2026

    @yatin-italy

    Proposal

    Restate the problem this issue is trying to solve.

    When a distance expense is created while offline from an opened expense report, the expense is added to a new report instead of the opened report. This happens on Android when the report exists locally but is not synced.

    What is the root cause of that problem?

    The earliest wrong assumption is in getMoneyRequestInformation() in src/libs/actions/IOU/index.ts. The code assumes the IOU report will always exist in allReports. This is wrong when offline because the report may exist only in allReportsDraft. The direct lookup returns null, and the function then creates a new report.

    What changes do you think we should make in order to solve the problem?

    • Replace direct allReports access with getReportOrDraftReport() so drafts are checked.
    • Update both the primary and fallback IOU report lookups.
    • Keep logic the same. Change only the lookup method.

    File: src/libs/actions/IOU/index.ts

    // In getMoneyRequestInformation() function, around line 2980-2989
    
    // STEP 2: Get the Expense/IOU report.
    // If the existingIOUReport or moneyRequestReportID has been provided, we want to add the transaction to this specific report.
    // If no such reportID has been provided, let's use the chatReport.iouReportID property.
    // In case that is not present, build a new optimistic Expense/IOU report.
    
    let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
    
    if (existingIOUReport) {
        iouReport = existingIOUReport;
    } else if (moneyRequestReportID) {
        iouReport = getReportOrDraftReport(moneyRequestReportID);
    } else if (!getReportOrDraftReport(chatReport.iouReportID)?.errorFields?.createChat) {
        iouReport = getReportOrDraftReport(chatReport.iouReportID);
    }

    What alternative solutions did you explore? (Optional)

    • Sync drafts into allReports when offline. Not chosen because it changes data flow and is larger than needed.
    • Add special offline checks. Not chosen because it adds new logic instead of using the existing pattern.
  8. truph01 commented on Jan 27, 2026

    @truph01
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    • A distance expense created while offline does not appear in the existing expense report. Instead, it shows up in the workspace chat as a separate new report.

    What is the root cause of that problem?

    • In the logic used to determine whether shouldCreateNewMoneyRequestReport is true, we incorrectly evaluate isScanRequest as true:

    • This happens because the isScanRequestTransactionUtils function expects a full transaction object containing fields like iouRequestType, source, amount, etc.—but we currently only pass {amount, receipt}.

    What changes do you think we should make in order to solve the problem?

    • We should correct how we determine the isScanRequest value. This can be done by either:

      • Passing iouRequestType: existingTransaction.iouRequestType in the current object, or
      • Passing the entire existingTransaction instead of just {amount, receipt} at the following location:
        const isScanRequest = isScanRequestTransactionUtils({amount, receipt});
    • We should also check and update other call sites as needed to ensure consistency.

    What alternative solutions did you explore? (Optional)

    • We considered updating the call as follows:
    const isDistanceRequest = existingTransaction && isDistanceRequestTransactionUtils(existingTransaction);
    const isScanRequest = isScanRequestTransactionUtils({
        amount,
        receipt,
        iouRequestType: existingTransaction?.iouRequestType,
    }) && !isDistanceRequest;
  9. HiepPP commented on Jan 27, 2026

    @HiepPP
    Contributor

    Proposal for Issue #80591: Distance Expense Created Offline Not Shown in Expense Report

    Problem

    When a user creates a distance expense while offline from within an expense report, the expense does not appear in that report. Instead, it is created as a separate new report in the workspace chat.

    Root Cause

    The issue occurs in the distance expense creation flow in src/libs/actions/IOU/index.ts:

    Critical Code Section 1: Report Type Determination

    In createDistanceRequest at lines 7508-7511:

    // If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
    const isMoneyRequestReport = isMoneyRequestReportReportUtils(report);
    const currentChatReport = isMoneyRequestReport ? getReportOrDraftReport(report?.chatReportID) : report;
    const moneyRequestReportID = isMoneyRequestReport ? report?.reportID : '';

    const isMoneyRequestReport = isMoneyRequestReportReportUtils(report);
    const currentChatReport = isMoneyRequestReport ? getReportOrDraftReport(report?.chatReportID) : report;
    const moneyRequestReportID = isMoneyRequestReport ? report?.reportID : '';

    When creating a distance expense from within an expense report:

    1. report is the expense report object
    2. isMoneyRequestReport evaluates to true (expense reports are money request reports)
    3. moneyRequestReportID is set to the expense report's ID
    4. currentChatReport is set to the expense report's linked chat report

    Critical Code Section 2: Report Lookup Logic

    In getMoneyRequestInformation at lines 3131-3140:

    // STEP 2: Get the Expense/IOU report. If the existingIOUReport or moneyRequestReportID has been provided, we want to add the transaction to this specific report.
    // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report.
    let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
    if (existingIOUReport) {
    iouReport = existingIOUReport;
    } else if (moneyRequestReportID) {
    iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;
    } else if (!allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]?.errorFields?.createChat) {
    iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null;
    }

    // STEP 2: Get the Expense/IOU report. If the existingIOUReport or moneyRequestReportID has been provided, we want to add the transaction to this specific report.
    // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report.
    let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
    if (existingIOUReport) {
        iouReport = existingIOUReport;
    } else if (moneyRequestReportID) {
        iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;
    } else if (!allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]?.errorFields?.createChat) {
        iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null;
    }

    When offline, if the expense report isn't in the allReports cache:

    • The lookup at line 3137 fails (returns null)
    • A NEW optimistic IOU report is created instead of using the intended expense report

    Why This Happens Offline

    When offline, the expense report object may not be in the Onyx cache (allReports). The code at line 3137 attempts to look up the report by ID from the cache, which fails. The code then falls through to create a new optimistic report rather than using the expense report that was passed in.

    Solution

    Approach

    Pass the expense report object directly to getMoneyRequestInformation when creating a distance expense from within an expense report, rather than relying on looking it up in the cache. This ensures the report is used even when offline.

    Implementation Plan

    Change 1: Add expenseReport parameter to type definition

    File: src/libs/actions/IOU/index.ts
    Location: Line 544-572 (MoneyRequestInformationParams type)

    Add expenseReport parameter after moneyRequestReportID:

    type MoneyRequestInformationParams = {
        parentChatReport: OnyxEntry<OnyxTypes.Report>;
        existingIOUReport?: OnyxEntry<OnyxTypes.Report>;
        transactionParams: RequestMoneyTransactionParams;
        participantParams: RequestMoneyParticipantParams;
        policyParams?: BasePolicyParams;
        moneyRequestReportID?: string;
        expenseReport?: OnyxEntry<OnyxTypes.Report>; // NEW PARAMETER
        // ... rest of params

    Change 2: Update report lookup logic in getMoneyRequestInformation

    File: src/libs/actions/IOU/index.ts
    Location: Lines 3131-3140

    Update the IOU report lookup to check for expenseReport before checking cache:

    // STEP 2: Get the Expense/IOU report. If the existingIOUReport, moneyRequestReportID, or expenseReport has been provided, we want to add the transaction to this specific report.
    // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report.
    let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
    if (existingIOUReport) {
        iouReport = existingIOUReport;
    } else if (expenseReport) {
        // Use the expense report directly when provided (e.g., when creating distance expense from within an expense report)
        iouReport = expenseReport;
    } else if (moneyRequestReportID) {
        iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;
    } else if (!allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]?.errorFields?.createChat) {
        iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null;
    }

    Change 3: Pass expenseReport from createDistanceRequest

    File: src/libs/actions/IOU/index.ts
    Location: Lines 7598-7636 (getMoneyRequestInformation call)

    Add expenseReport parameter when calling getMoneyRequestInformation:

    } = getMoneyRequestInformation({
        parentChatReport: currentChatReport,
        existingTransaction,
        moneyRequestReportID,
        expenseReport: isMoneyRequestReport ? report : undefined, // NEW: Pass expense report when applicable
        participantParams: {
            participant,
            payeeAccountID: userAccountID,
            payeeEmail: currentUserEmail,
        },
        // ... rest of params

    Why This Works

    1. When isMoneyRequestReport is true, we have the expense report object in the report parameter
    2. By passing this object directly as expenseReport, we bypass the cache lookup
    3. The getMoneyRequestInformation function uses the provided report directly, avoiding the need for cache lookup
    4. This works offline because we're using the report object we already have, not looking it up

    Edge Cases Handled

    1. Chat-based distance expenses: isMoneyRequestReport is false, so expenseReport remains undefined and the existing logic is used
    2. Online scenarios: Works the same as offline - uses the provided report object
    3. Different report types: Only passes expenseReport when the report is a money request report (IOU or expense report)

    Files Modified

    1. src/libs/actions/IOU/index.ts
      • Add expenseReport to MoneyRequestInformationParams type (line ~551)
      • Update report lookup logic in getMoneyRequestInformation function (lines 3131-3140)
      • Pass expenseReport parameter in createDistanceRequest (line ~7601)

    Testing Approach

    1. Offline distance expense from expense report

      • Go offline
      • Open an expense report
      • Create a distance expense
      • Verify the expense appears in the report (not as a new report)
    2. Online distance expense from expense report

      • Ensure online behavior is unchanged
      • Distance expense should appear in the expense report
    3. Chat-based distance expense

      • Create a distance expense from a chat
      • Verify it still works correctly
    4. Track expense flow

      • Ensure track expense flow is not affected
    5. Different report types

      • Test with IOU reports
      • Test with expense reports
      • Test with policy expense chats

    Alternative Approaches Considered

    Alternative 1: Cache the expense report before creating the distance expense

    Rejected because:

    • Would require significant changes to report caching logic
    • Could introduce timing issues
    • More invasive than the proposed solution

    Alternative 2: Use draft reports collection

    Rejected because:

    • Expense reports aren't stored in the draft collection, only transactions are
    • Would require architectural changes

    Alternative 3: Modify getReportOrDraftReport to accept the report directly

    Rejected because:

    • This is a utility function used throughout the codebase
    • Changing its signature would require updates in many places
    • More invasive than the proposed solution

    Potential Risks and Mitigations

    1. Risk: Breaking chat-based distance expenses

      • Mitigation: Only pass expenseReport when isMoneyRequestReport is true. Chat-based flows continue using existing logic.
    2. Risk: Creating invalid report references

      • Mitigation: The expense report is already validated before being passed to createDistanceRequest. We're ensuring it's used rather than looked up.
    3. Risk: Issues with report totals

      • Mitigation: The existing logic for updating report totals remains unchanged. We're only changing how the report is initially selected.

    References

  10. suneox commented on Jan 30, 2026

    @suneox
    Contributor

    Thanks for all proposals. I'll take a look at this one today

  11. 27 remaining items

  12. changed the title [-][$250] Expense - Distance expense created in offline is not shown in expense report[/-] [+][Due for payment 2026-03-04] [$250] Expense - Distance expense created in offline is not shown in expense report[/+] on Feb 25, 2026
  13. melvin-bot commented on Feb 25, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  14. melvin-bot commented on Feb 25, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.25-13 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-03-04. 🎊

    For reference, here are some details about the assignees on this issue:

    • @suneox requires payment through NewDot Manual Requests
    • @truph01 requires payment through NewDot Manual Requests
  15. melvin-bot commented on Feb 25, 2026

    @melvin-bot

    @suneox / @truph01 @greg-schroeder The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  16. greg-schroeder commented on Mar 6, 2026

    @greg-schroeder
    Contributor

    Payment summary:

    Author: @truph01 - $250 - ND manual request
    Reviewer: @suneox - $250 - ND manual request

    Approved for payments as outlined above ☝️

  17. trjExpensify commented on Mar 6, 2026

    @trjExpensify
    Contributor

    approved $250 for @suneox

  18. JmillsExpensify commented on Mar 18, 2026

    @JmillsExpensify
    Contributor

    $250 approved for @truph01

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions