Skip to content

[Due for payment 2026-04-01] [Due for payment 2026-03-31] [RCA #83896] Expense - Error when duplicating report from deleted workspace #86095

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: 9.3.42-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #83896
Email or phone of affected tester (no customers): sdsodsoijnosjdio@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create two expenses.
  4. Delete the workspace.
  5. Create a new workspace.
  6. Open the expense report from the deleted workspace.
  7. Click More > Duplicate report.
  8. Open the new workspace chat.
  9. Open the reports with RBR in LHN.

Expected Result:

Expense report will be duplicated in new workspace without issue.

Actual Result:

Expense report is not duplicated. These expenses show up with RBR in LHN.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 23, 2026
  2. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83896

  3. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 23, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 23, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #83896 - "Implement core "Duplicate report" action logic." by @Krishna2323 (High confidence)
    Related Issues: #82153

    Recommendation: ROLL FORWARD

    The issue can be fixed with a small targeted change to the workspace/chat selection logic. Reverting would remove the entire "Duplicate report" feature, which is a significant new capability.

    Labels: This is a Frontend bug (App PR caused the issue). Keeping DeployBlockerCash label as appropriate.

    Detailed Analysis

    Evidence

    PR #83896 introduced the "Duplicate report" feature, which is the exact feature that is failing according to the reproduction steps. The bug only occurs when duplicating a report from a deleted workspace, which is a specific edge case not covered in the original test plan.

    Verification

    The bug is in src/components/MoneyReportHeader.tsx lines 1927-1928:

    const targetPolicyForDuplicate = policy ?? defaultExpensePolicy;
    const targetChatForDuplicate = policy ? chatReport : activePolicyExpenseChat;

    When the source workspace is deleted but the policy object still exists, the code incorrectly uses the deleted workspace's policy and chat as the target. This causes the duplicated expenses to show up with RBR (red brick road) errors because they are being created in a deleted/invalid workspace context.

    Root Cause

    The code needs to check if the user is still a member of the source policy before using it as the target:

    Current logic:

    • If policy exists (even if deleted) → use it

    Correct logic:

    • If policy exists AND user is a member → use it
    • Otherwise → use default workspace

    The fix requires:

    1. Import isPolicyMember from @libs/PolicyUtils in MoneyReportHeader.tsx
    2. Update lines 1927-1928 to check policy membership:
    const isSourcePolicyValid = policy && isPolicyMember(policy, currentUserLogin);
    const targetPolicyForDuplicate = isSourcePolicyValid ? policy : defaultExpensePolicy;
    const targetChatForDuplicate = isSourcePolicyValid ? chatReport : activePolicyExpenseChat;

    This is a simple 3-line fix that handles the deleted workspace edge case properly.

    Why Roll Forward Instead of Revert

    1. The fix is small and straightforward
    2. Reverting would remove an entire feature that works correctly in most cases
    3. The bug only affects the specific edge case of duplicating from a deleted workspace
    4. Test case 9 in PR Implement core "Duplicate report" action logic. #83896 mentions cross-workspace duplication, but the test was for "leave workspace" not "delete workspace" - slightly different scenarios
  6. Krishna2323 commented on Mar 23, 2026

    @Krishna2323
    Contributor

    Working on the PR...

  7. MelvinBot commented on Mar 23, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a user creates expenses in a workspace, deletes that workspace, then tries to "Duplicate report" on the expense report from the deleted workspace, the duplication fails and the expenses show RBR (Red Brick Road) errors in the LHN.

    What is the root cause of that problem?

    When a workspace is deleted, only chat rooms, policy expense chats, and task reports are archived — but IOU/expense reports are NOT archived and retain their original policyID pointing to the deleted workspace (useTransactionViolationOfWorkspace.tsx:12-14).

    The "Duplicate Report" action has no guard against deleted policies. isDuplicateReportAction (ReportSecondaryActionUtils.ts:801-811) only checks if the user is the submitter and the report is an expense report — it never validates that the report's policy still exists.

    In MoneyReportHeader.tsx, the duplicate logic resolves the target policy like this (lines 1927-1928):

    const targetPolicyForDuplicate = policy ?? defaultExpensePolicy;
    const targetChatForDuplicate = policy ? chatReport : activePolicyExpenseChat;

    There are two failure modes depending on timing:

    • If the policy was removed from Onyx by the server: policy is undefined, so it falls back to defaultExpensePolicy (a different workspace). However, the expenses from the original workspace may have categories/tags/settings that don't exist on the new workspace, causing server-side validation failures.
    • If the policy still exists in Onyx with pendingAction: DELETE (optimistic phase): policy is truthy, so the deleted policy is used directly as the target. The server rejects the request since the policy no longer exists.

    In both cases, the API returns errors, which set pendingAction: ADD + error states on the created report actions. These are detected by getAllReportErrors / getViolatingReportIDForRBRInLHN, causing RBR to appear in the LHN.

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

    The fix should be in MoneyReportHeader.tsx at lines 1927-1928. When determining targetPolicyForDuplicate, we should treat a policy with pendingAction: DELETE the same as a missing policy — i.e., fall back to defaultExpensePolicy:

    const isDeletedPolicy = policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
    const targetPolicyForDuplicate = (policy && !isDeletedPolicy) ? policy : defaultExpensePolicy;
    const targetChatForDuplicate = (policy && !isDeletedPolicy) ? chatReport : activePolicyExpenseChat;
    

    This ensures that when duplicating a report from a deleted workspace, the duplicate always targets the user's default active workspace instead of trying to use the deleted one.

    Additionally, isDuplicateReportAction in ReportSecondaryActionUtils.ts could be hardened to hide the "Duplicate Report" option entirely when the report's policy is deleted and no fallback workspace exists — but the MoneyReportHeader fix is the critical one since shouldShow: !!defaultExpensePolicy already partially handles the "no workspace" case.

    What alternative solutions did you explore? (Optional)

    1. Hide the action entirely for deleted-workspace reports: Modify isDuplicateReportAction to check the policy's existence. This was rejected because it's valid to duplicate a report from a deleted workspace into an active workspace — the feature should work, just with the correct target.

    2. Archive expense reports when deleting workspace: Modify useTransactionViolationOfWorkspace to also include IOU/expense reports in reportsToArchive. This would be a larger change with broader implications and doesn't directly fix the duplicate action.


    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.

  8. Krishna2323 commented on Mar 23, 2026

    @Krishna2323
    Contributor

    PR ready for review: #86098

    cc: @hungvu193

  9. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  10. 6 remaining items

  11. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Mar 24, 2026
  12. changed the title [-][RCA #83896] Expense - Error when duplicating report from deleted workspace[/-] [+][Due for payment 2026-03-31] [RCA #83896] Expense - Error when duplicating report from deleted workspace[/+] on Mar 24, 2026
  13. melvin-bot commented on Mar 24, 2026

    @melvin-bot

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

  14. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.42-3 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-31. 🎊

  15. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    @Valforte 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. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  17. changed the title [-][Due for payment 2026-03-31] [RCA #83896] Expense - Error when duplicating report from deleted workspace[/-] [+][Due for payment 2026-04-01] [Due for payment 2026-03-31] [RCA #83896] Expense - Error when duplicating report from deleted workspace[/+] on Mar 25, 2026
  18. melvin-bot commented on Mar 25, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.43-3 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-04-01. 🎊

  19. melvin-bot commented on Mar 25, 2026

    @melvin-bot

    @Valforte @mallenexpensify 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]

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.EngineeringWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions