Skip to content

[$250] “Page not found” error when submitting manual distance entry offline #74640

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.2.47-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #74511
Email or phone of affected tester (no customers): applausetester+dp31fsdjfgj@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Mac / Safari
App Component: Other

Action Performed:

  1. Create a workspace
  2. Go offline
  3. Delete the workspace
  4. Click FAB → Track distance → Manual
  5. Enter any value and submit

Expected Result:

“Choose recipient” page should be displayed after submitting.

Actual Result:

Error message appears: “Hmm… it’s not here” “Oops, this page cannot be found”
The page is partially visible and appears semi-transparent (opaque).

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021988131288441773354
  • Upwork Job ID: 1988131288441773354
  • Last Price Increase: 2025-11-11
Issue OwnerCurrent Issue Owner: @RachCHopkins

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 8, 2025
  2. melvin-bot commented on Nov 8, 2025

    @melvin-bot

    Triggered auto assignment to @RachCHopkins (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.

  3. daledah commented on Nov 8, 2025

    @daledah
    Contributor

    Proposal

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

    Error message appears: “Hmm… it’s not here” “Oops, this page cannot be found”
    The page is partially visible and appears semi-transparent (opaque).

    What is the root cause of that problem?

    Even though the workspace has been deleted, we still allow navigation to the confirmation page here.

    setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
    Navigation.navigate(
    ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
    CONST.IOU.ACTION.CREATE,
    iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
    transactionID,
    activePolicyExpenseChat?.reportID,
    ),
    );

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

    We should not allow navigate to confirmation page if defaultExpensePolicy has pending action is delete (or we can use utils function isPolicyAccessible). It will navigate the user to Choose recipient steps

                if (
                    iouType === CONST.IOU.TYPE.CREATE &&
                    isPaidGroupPolicy(defaultExpensePolicy) &&
                    defaultExpensePolicy?.isPolicyExpenseChatEnabled &&
                    defaultExpensePolicy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
                    !shouldRestrictUserBillableActions(defaultExpensePolicy.id)
                ) {
    

    if (
    iouType === CONST.IOU.TYPE.CREATE &&
    isPaidGroupPolicy(defaultExpensePolicy) &&
    defaultExpensePolicy?.isPolicyExpenseChatEnabled &&
    !shouldRestrictUserBillableActions(defaultExpensePolicy.id)
    ) {

    What alternative solutions did you explore? (Optional)

    We should filter out the expense policy if it has pending action is delete

        if (isPaidGroupPolicy(activePolicy) && activePolicy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
            return activePolicy;
        }
    
        // If there is exactly one group policy, use that as the default expense policy
        const groupPolicies = Object.values(allPolicies ?? {}).filter((policy) => isPaidGroupPolicy(policy) && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
        if (groupPolicies.length === 1) {
            return groupPolicies.at(0);
        }
    

    if (isPaidGroupPolicy(activePolicy)) {
    return activePolicy;
    }
    // If there is exactly one group policy, use that as the default expense policy
    const groupPolicies = Object.values(allPolicies ?? {}).filter(isPaidGroupPolicy);
    if (groupPolicies.length === 1) {
    return groupPolicies.at(0);
    }

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. ShridharGoel commented on Nov 8, 2025

    @ShridharGoel
    Contributor

    Proposal

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

    When a user deletes a workspace while offline and then chooses “Track distance → Manual”, the flow should continue to the “Choose recipient” step. Instead, the form redirects to a semi-transparent “Hmm… it’s not here” not-found view.

    What is the root cause of that problem?

    The helper that decides which workspace should be used for new expenses (useDefaultExpensePolicy) never checks whether the workspace is in the middle of being deleted. After deleting a workspace while offline, Onyx still contains the workspace record with pendingAction: DELETE. Because the hook keeps returning that record, every new distance expense tries to load a workspace the server will soon remove, and AccessOrNotFoundWrapper sends the user to the error page.

    export default function useDefaultExpensePolicy() {
    const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
    const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true});
    const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
    if (isPaidGroupPolicy(activePolicy)) {
    return activePolicy;
    }
    // If there is exactly one group policy, use that as the default expense policy
    const groupPolicies = Object.values(allPolicies ?? {}).filter(isPaidGroupPolicy);
    if (groupPolicies.length === 1) {
    return groupPolicies.at(0);
    }

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

    Add a guard inside useDefaultExpensePolicy that filters out any policy whose pendingAction is DELETE. If the active policy fails the guard, fall back to the first non-deleted paid policy. This keeps the tracker pointed at a valid workspace and lets the flow reach the participant selector again.

    const isValidPolicy = (policy: Parameters<typeof isPaidGroupPolicy>[0]) => isPaidGroupPolicy(policy) && !isPendingDeletePolicy(policy);
    
    if (isValidPolicy(activePolicy)) {
        return activePolicy;
    }
    
    const groupPolicies = Object.values(allPolicies ?? {}).filter(isValidPolicy);
    if (groupPolicies.length === 1) {
        return groupPolicies.at(0);
    }
  5. Krishna2323 commented on Nov 8, 2025

    @Krishna2323
    Contributor

    Proposal

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

    “Page not found” error when submitting manual distance entry offline when the default workspace is also deleted offline.

    What is the root cause of that problem?

    • In the useDefaultExpensePolicy hook, we do not check if the policy is accessible or not. When that policy is pending deletion or no longer accessible (leave), the flow navigates into screens that require a writable/accessible report/policy, which shows NotFound.
      if (isPaidGroupPolicy(activePolicy)) {
      return activePolicy;
      }
      // If there is exactly one group policy, use that as the default expense policy
      const groupPolicies = Object.values(allPolicies ?? {}).filter(isPaidGroupPolicy);
      if (groupPolicies.length === 1) {
      return groupPolicies.at(0);
      }
      return null;
    • Directly checking only pendingAction !== DELETE misses several cases: empty policy, missing id, user not a member, policy errors. This leads to the flow still showing the unaccessible policy on the participants page.
    • If we only check for pendingAction !== DELETE, the participants step still shows the policy that the user has left , enabling track submissions against inaccessible workspaces.
    • Leaving a workspace did not optimistically archive its reports on the frontend, so they remained visible in offline mode.
      function leaveWorkspace(policyID?: string) {
      if (!policyID) {
      return;
      }

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

    • We should use isPolicyAccessible instead of only checking pendingAction because directly checking for pending actions misses some cases like when user leaves the policy.

      App/src/libs/PolicyUtils.ts

      Lines 1409 to 1417 in 2087489

      function isPolicyAccessible(policy: OnyxEntry<Policy>, currentUserLogin: string): boolean {
      return (
      !isEmptyObject(policy) &&
      (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) &&
      !!policy?.id &&
      policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
      !!getPolicyRole(policy, currentUserLogin)
      );
      }
    • We should also align leave workspace action with delete workspace:
      • Optimistically archive the related reports and add a CLOSED action (reason: REMOVED_FROM_POLICY) so they no longer appear accessible on the frontend after leaving workspace in offline mode. This aligns with the delete behavior and avoids picking them during Participant selection.
    Pseudocode
        const pendingChatMembers = ReportUtils.getPendingChatMembers([sessionAccountID], [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
        const currentTime = DateUtils.getDBTime();
        const finallyData: OnyxUpdate[] = [];
    
        workspaceChats.forEach((report) => {
            const parentReport = ReportUtils.getRootParentReport({report});
            const reportToCheckOwner = isEmptyObject(parentReport) ? report : parentReport;
    
            if (ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isReportOwner(reportToCheckOwner)) {
                return;
            }
    
            optimisticData.push(
                {
                    onyxMethod: Onyx.METHOD.MERGE,
                    key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`,
                    value: {
                        statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
                        stateNum: CONST.REPORT.STATE_NUM.APPROVED,
                        oldPolicyName: policy?.name ?? '',
                        isPinned: false,
                    },
                },
                {
                    onyxMethod: Onyx.METHOD.MERGE,
                    key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`,
                    value: {
                        pendingChatMembers,
                    },
                },
                {
                    onyxMethod: Onyx.METHOD.MERGE,
                    key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`,
                    value: {
                        private_isArchived: currentTime,
                    },
                },
            );
            // Add an optimistic closed action to mirror the server behavior and immediately hide the report from active views
            const emailClosingReport = (report?.ownerAccountID && report.ownerAccountID !== CONST.POLICY.OWNER_ACCOUNT_ID_FAKE)
                ? (allPersonalDetails?.[report.ownerAccountID]?.login ?? '')
                : CONST.POLICY.OWNER_EMAIL_FAKE;
            const optimisticClosedReportAction = ReportUtils.buildOptimisticClosedReportAction(
                emailClosingReport,
                policy?.name ?? '',
                CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY,
            );
            optimisticData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`,
                value: {
                    [optimisticClosedReportAction.reportActionID]: optimisticClosedReportAction as ReportAction,
                },
            });
            // Remove the optimistic closed action after server response to avoid duplication
            finallyData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`,
                value: {
                    [optimisticClosedReportAction.reportActionID]: null,
                },
            });
            successData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`,
                value: {
                    pendingChatMembers: null,
                },
            });
            failureData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`,
                value: {
                    pendingChatMembers: null,
                },
            });
        });
    
        const params: LeavePolicyParams = {
            policyID,
            email: sessionEmail,
        };
        API.write(WRITE_COMMANDS.LEAVE_POLICY, params, {optimisticData, successData, failureData, finallyData});

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    N/A

    What alternative solutions did you explore? (Optional)

    Result

  6. RachCHopkins commented on Nov 11, 2025

    @RachCHopkins
    Contributor

    Easy repro

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 11, 2025
  8. 18 remaining items

  9. brunovjk commented on Nov 18, 2025

    @brunovjk
    Contributor

    Great, reviewing ASAP

  10. brunovjk commented on Dec 2, 2025

    @brunovjk
    Contributor

    Update: PR went into production yesterday, December 1st, according to this deployment checklist.

  11. brunovjk commented on Dec 8, 2025

    @brunovjk
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: No PR appears to have introduced this bug directly.

    • [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.

    Regression Test Proposal

    Test 1

    Precondition: Account should not have any workspaces

    1. Create a workspace
    2. Go offline
    3. Delete the workspace
    4. Click FAB → Track distance → Manual
    5. Enter any value and submit
    6. Verify “Choose recipient” page is displayed after submitting.

    Test 2

    Precondition: Account should not have any workspaces

    1. [USER A] - Create a workspace Invite User B
    2. [USER B] - Go offline after workspace appears on workspace list page
    3. [USER B] - Leave the workspace
    4. [USER B] - Click FAB → Track distance → Manual
    5. [USER B] - Enter any value and submit
    6. [USER B] - Verify “Choose recipient” page is displayed after submitting.

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-eb52-a01c-3185-6d21256fa954
  12. brunovjk commented on Dec 8, 2025

    @brunovjk
    Contributor

    @RachCHopkins when do you have some time to help with payment here? Thanks.

  13. melvin-bot commented on Dec 12, 2025

    @melvin-bot

    This issue has not been updated in over 15 days. @lakchote, @RachCHopkins, @Krishna2323, @brunovjk eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  14. RachCHopkins commented on Dec 15, 2025

    @RachCHopkins
    Contributor

    Payment Summary:

    • Contributor: @Krishna2323 to be paid $250 via NewDot Manual Request
    • Contributor+: @brunovjk to be paid $250 via NewDot Manual Request

    Upwork job here - now closed, and no contracts to end.

    🟢 to request payment via NewDot.

  15. brunovjk commented on Dec 15, 2025

    @brunovjk
    Contributor

    Requested in ND.

  16. JmillsExpensify commented on Dec 15, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @brunovjk

  17. Krishna2323 commented on Dec 29, 2025

    @Krishna2323
    Contributor

    Requested in ND.

  18. twisterdotcom commented on Dec 30, 2025

    @twisterdotcom
    Contributor

    @Krishna2323 has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Zapier Logs Run ID: 00040eee-1cd0-af97-b56f-46b38445c164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in review

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions