Skip to content

Delete option shown to submitter on expense report forwarded past first approval; delete fails with "You cannot delete expenses from a forwarded report" #99008

Closed

Description

@NicolasBonet

Problem

When an expense report in a multi-level approval workflow has been approved by the first approver and forwarded to the next approver, the submitter still sees the Delete option on expenses in that report. Tapping Delete optimistically removes the expense from the UI, but the API rejects it and the expense reappears:

{
    "code": 666,
    "jsonCode": 404,
    "type": "Expensify\\Error\\Transaction\\CantReportTransactions",
    "message": "You cannot delete expenses from a forwarded report.",
    "title": "Cannot Remove Expenses"
}

The backend rejection is intentional (submitters must retract the report to make it editable again — retract → delete → resubmit works fine). The bug is that the front end shows a Delete option it already intends to hide in this state, producing a confusing optimistic-delete-then-revert experience with no actionable error guidance.

Reproduction

  1. On a workspace with a multi-level approval chain (submitter → approver 1 → approver 2), submit a report with an expense.
  2. As approver 1, approve the report so it is forwarded to approver 2.
  3. As the submitter, open the expense on the forwarded report.
  4. Observe the Delete option is available. Delete the expense.
  5. Expense disappears, then reappears once the API responds with the error above.

Expected result

Delete should be hidden for the submitter once the report is no longer awaiting first-level approval — canAddOrDeleteTransactions in src/libs/ReportUtils.ts already gates processing expense reports on isAwaitingFirstLevelApproval(report).

Actual result

Delete is shown, the optimistic update fires, and the server rejects it.

Analysis

The front-end and back-end definitions of "awaiting first-level approval" diverge:

  • Front end (isAwaitingFirstLevelApproval, src/libs/ReportUtils.ts): requires getSubmitToAccountID(policy, report) === report.managerID and no FORWARDED action in the locally loaded report actions (hasReportBeenForwardedSinceLastSubmit).
  • Back end (Report::isAwaitingFirstLevelApproval, Auth Report.cpp): compares the current manager to the submittedTo recorded in the SUBMITTED/CREATED report action message, falling back to checking for a FORWARDED action since the last submit in the DB.

Likely front-end failure modes:

  • The FORWARDED report action is not present in the client's loaded report actions (pagination / partial Onyx data), so hasReportBeenForwardedSinceLastSubmit returns false.
  • Stale or mismatched managerID / policy submitsTo data on the client.

Related known limitation referenced in the code: https://github.com/Expensify/Expensify/issues/507850

Evidence (production)

  • Report ID: 2942262138851419, transaction ID: 2101509572720817241
  • Failing request ID: a2dc8f5e1d041bc9-SJC (2026-08-19T22:22:58Z), Auth throw at Report.cpp:8633 in DeleteMoneyRequest
  • Platform: web (new.expensify.com), app version 9.4.55-4
  • Retracting the report and then deleting the expense worked, confirming backend behavior is as designed.
Issue OwnerCurrent Issue Owner: @NicolasBonet
Upwork Automation - Do Not Edit

Activity

  1. self-assigned this
    on Aug 19, 2026
  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed on Aug 19, 2026
  3. NicolasBonet commented on Aug 19, 2026

    @NicolasBonet
    ContributorAuthor

    @MelvinBot let's propose a solution for this

  4. MelvinBot commented on Aug 19, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The front-end decides whether an expense on a processing report can be deleted with isAwaitingFirstLevelApproval, which gates canAddOrDeleteTransactions and the submitter Delete affordance at ReportUtils.ts:3300:

    isProcessingReport(report) && submitsToAccountID === report.managerID && !hasReportBeenForwardedSinceLastSubmit(report)
    

    For a report that was moved past its first approver this must return false, but both guards fail together:

    1. The "forwarded" check looks for the wrong action type. A normal multi‑level Approve does not write a FORWARDED action on the client — it writes an APPROVED action and advances managerID to the next approver while the report stays in the SUBMITTED/processing state. But hasReportBeenForwardedSinceLastSubmit only matches FORWARDED actions, so it returns false even though the report has clearly moved on. This is the core bug.
    2. submitsToAccountID === managerID is a fragile fallback. getSubmitToAccountID is a static policy lookup of the first‑level approver — it never reads the report's live position. When owner login/policy data is stale or falls back to the default approver, it can coincidentally equal the forwarded managerID, making the guard wrongly report "still at first level." This is the exact fragility flagged in‑code by the Expensify/Expensify#507850 comment.

    With guard #2 wrongly true and guard #1 wrongly reporting "not forwarded," isAwaitingFirstLevelApproval returns true, Delete is shown, the optimistic delete fires, and the backend rejects it (Report.cpp:8633).

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

    Make the "has this report moved past its first approver" signal reliable instead of depending on the fragile submitsToAccountID === managerID comparison. In a processing report, an APPROVED action created after the last SUBMITTED action uniquely means the report is past first‑level approval (single‑level approval flips the report out of processing, so isProcessingReport already excludes it — no false positives).

    Update the shared helper hasReportBeenForwardedSinceLastSubmit to treat the report as moved‑on when either a FORWARDED or an APPROVED action exists after the last SUBMITTED action (using the already‑exported isApprovedAction alongside isForwardedAction). Because this helper feeds both isAwaitingFirstLevelApproval and the duplicated forwarding check in canEditMoneyRequest, the one change fixes the Delete affordance and the related edit/unreport affordances at once. Consider renaming it (e.g. hasReportMovedPastFirstApprovalSinceLastSubmit) since it no longer keys only on forwarding.

    Why this is the robust fix (evidence)
    • Intermediate approve writes APPROVED, not FORWARDED: buildOptimisticApprovedReportAction hard‑codes actionName: APPROVED; the approve flow keeps the report in SUBMITTED state and advances the manager to the next approver (ReportWorkflow.ts:515-518). There is no optimistic FORWARDED builder in App — FORWARDED actions are only produced server‑side.
    • getSubmitToAccountID resolves the first‑level approver statically from policy config and never consults report.managerID, so it can't track the report down the chain — that's why the secondary forwarded check exists in the first place.
    • One production check would raise confidence to High: confirm that on a real forwarded report the submitter's loaded actions contain an APPROVED (and typically no FORWARDED) action since the last SUBMITTED. That verifies the APPROVED detection fully covers the reported case.

    What alternative solutions did you explore? (Optional)

    • Read the original submit target from the report action (mirror the backend's submittedTo comparison). OriginalMessageCreated.submittedTo exists in the client types but currently has zero readers, so this is closer to the broader Expensify/Expensify#507850 rework and is heavier than needed here.
    • Better error UX only (keep showing Delete, but surface the "retract to edit" guidance on rejection). This treats the symptom, not the cause, and still leaves the confusing optimistic‑delete‑then‑revert.

    Related issue

    Expensify/App#93999 ("Delete/unreport affordance is shown on transactions belonging to forwarded reports", open) is the same root cause with production impact data (~112 rejected attempts/day). This proposal's single-helper fix resolves both. Recommend deduping.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/99008) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 19, 2026
  6. melvin-bot commented on Aug 19, 2026

    @melvin-bot

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

  7. melvin-bot commented on Aug 19, 2026

    @melvin-bot
  8. removed
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 19, 2026
  9. NicolasBonet commented on Aug 19, 2026

    @NicolasBonet
    ContributorAuthor

    @MelvinBot implement this

  10. MelvinBot commented on Aug 19, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #99009
    Please mark it as "Ready for review" when it is ready for review.

    What it does: Hides the Delete affordance for the submitter once a report has moved past its first level of approval. The gate isAwaitingFirstLevelApproval relied on hasReportBeenForwardedSinceLastSubmit, which only matched FORWARDED actions — but an intermediate multi-level Approve records an APPROVED action while keeping the report in the processing state, so the check missed it. The fix treats an APPROVED action created since the last submit as "moved past first level" too, which also fixes the same symptom in canEditMoneyRequest and resolves the duplicate Expensify/App#93999.

    Verification (local AI tests, all passing):

    • npm run typecheck-tsgo ✅
    • npm run lint-changed ✅
    • Jest ReportUtilsTest.ts (hasReportBeenForwardedSinceLastSubmit) — 11 passed, incl. 3 new cases covering the APPROVED-since-last-submit behavior ✅

    I did not run a live end-to-end app repro: reproducing this requires a coordinated multi-level approval workflow across three accounts (submitter, approver 1, approver 2) with an intermediate approval, which isn't feasible in the automated test session. The Tests/QA sections are left for the human co-author to fill with that manual flow before marking the PR ready for review.


    view run

  11. NicolasBonet commented on Aug 20, 2026

    @NicolasBonet
    ContributorAuthor

    Root cause found — updates the analysis above

    Production log investigation showed the report was never forwarded at all. Timeline for the affected report (all 2026-08-19 UTC):

    • 20:43–20:44 — expense created (CreateMoneyRequest); report actions: CREATED + IOU only
    • 20:45:53 — SubmitReport; approval chain built as a single level, SUBMITTED action stored with submittedTo = the manager
    • 22:22:58 — DeleteMoneyRequest rejected at Auth Report.cpp:8633
    • 22:28:41 — RetractReport succeeded

    No FORWARDED or APPROVED action was ever created, and ApproveMoneyRequest never ran against the report.

    The real trigger: the workspace's approval mode is DYNAMIC_EXTERNAL (Dynamic External Workflow). The backend's Report::isAwaitingFirstLevelApproval returns false unconditionally for DEW policies — submitted reports on DEW workspaces are never submitter-editable, because the first approver is configured externally. The delete path then reuses the generic "forwarded report" error even though nothing was forwarded.

    The front end's isAwaitingFirstLevelApproval (src/libs/ReportUtils.ts) has no DEW-mode handling: it saw submitsTo === managerID (true — the report was still with its first-line manager) and no FORWARDED action in the report actions (true — none exists), so it returned true and showed Delete.

    Correct fix

    1. App: isAwaitingFirstLevelApproval should return false when the report's policy approvalMode is CONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL, mirroring the backend. That hides Delete (and the related affordances gated on this helper) on submitted DEW reports.
    2. Backend (separate, internal): the DEW rejection should use its own error message (e.g. "Expenses on this workspace can't be deleted after submission — retract the report first") instead of the misleading "forwarded report" wording.

    The longer-term hardening from the earlier discussion still applies: a server-derived isWaitingOnFirstLevelApproval field on the report Onyx object would remove this whole class of client-side reconstruction bugs (pagination, stale policy data, DEW and future approval modes).

  12. NicolasBonet commented on Aug 20, 2026

    @NicolasBonet
    ContributorAuthor

    The fix PR for this issue, #99009, has been closed as superseded: #98704 merged to main on 2026-08-20 (12:54 UTC) with the same fix — isAwaitingFirstLevelApproval now returns false for expense reports on Dynamic External Workflow policies, so the Delete option is hidden on submitted DEW reports.

    Deploy status: the fix is not yet in production (latest production release 9.4.56-3 predates it). It will reach staging with the next deploy and production after that. This issue can be closed once the fix is verified on staging/production.

  13. NicolasBonet commented on Aug 24, 2026

    @NicolasBonet
    ContributorAuthor

    Waiting on re-test by QA

  14. IuliiaHerets commented on Aug 24, 2026

    @IuliiaHerets

    Not repro
    Windows 11/ Chrome
    v9.4.59-4

    99008.mp4
  15. NicolasBonet commented on Aug 24, 2026

    @NicolasBonet
    ContributorAuthor

    Closing now as the other PR fixed this!

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

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions