Repository navigation
Description
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
- On a workspace with a multi-level approval chain (submitter → approver 1 → approver 2), submit a report with an expense.
- As approver 1, approve the report so it is forwarded to approver 2.
- As the submitter, open the expense on the forwarded report.
- Observe the Delete option is available. Delete the expense.
- 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): requiresgetSubmitToAccountID(policy, report) === report.managerIDand noFORWARDEDaction in the locally loaded report actions (hasReportBeenForwardedSinceLastSubmit). - Back end (
Report::isAwaitingFirstLevelApproval, AuthReport.cpp): compares the current manager to thesubmittedTorecorded in the SUBMITTED/CREATED report action message, falling back to checking for aFORWARDEDaction since the last submit in the DB.
Likely front-end failure modes:
- The
FORWARDEDreport action is not present in the client's loaded report actions (pagination / partial Onyx data), sohasReportBeenForwardedSinceLastSubmitreturns false. - Stale or mismatched
managerID/ policysubmitsTodata 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 atReport.cpp:8633inDeleteMoneyRequest - 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 Owner
Current Issue Owner: @NicolasBonetUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022090208466723580720
- Upwork Job ID: 2090208466723580720
- Last Price Increase: 2026-08-19
Activity
NicolasBonet commentedon Aug 19, 2026
@MelvinBot let's propose a solution for this
MelvinBot commentedon Aug 19, 2026
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 gatescanAddOrDeleteTransactionsand the submitter Delete affordance atReportUtils.ts:3300:For a report that was moved past its first approver this must return
false, but both guards fail together:FORWARDEDaction on the client — it writes anAPPROVEDaction and advancesmanagerIDto the next approver while the report stays in theSUBMITTED/processing state. ButhasReportBeenForwardedSinceLastSubmitonly matchesFORWARDEDactions, so it returnsfalseeven though the report has clearly moved on. This is the core bug.submitsToAccountID === managerIDis a fragile fallback.getSubmitToAccountIDis 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 forwardedmanagerID, making the guard wrongly report "still at first level." This is the exact fragility flagged in‑code by theExpensify/Expensify#507850comment.With guard #2 wrongly true and guard #1 wrongly reporting "not forwarded,"
isAwaitingFirstLevelApprovalreturnstrue, 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 === managerIDcomparison. In a processing report, anAPPROVEDaction created after the lastSUBMITTEDaction uniquely means the report is past first‑level approval (single‑level approval flips the report out of processing, soisProcessingReportalready excludes it — no false positives).Update the shared helper
hasReportBeenForwardedSinceLastSubmitto treat the report as moved‑on when either aFORWARDEDor anAPPROVEDaction exists after the lastSUBMITTEDaction (using the already‑exportedisApprovedActionalongsideisForwardedAction). Because this helper feeds bothisAwaitingFirstLevelApprovaland the duplicated forwarding check incanEditMoneyRequest, 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)
APPROVED, notFORWARDED:buildOptimisticApprovedReportActionhard‑codesactionName: APPROVED; the approve flow keeps the report inSUBMITTEDstate and advances the manager to the next approver (ReportWorkflow.ts:515-518). There is no optimisticFORWARDEDbuilder in App —FORWARDEDactions are only produced server‑side.getSubmitToAccountIDresolves the first‑level approver statically from policy config and never consultsreport.managerID, so it can't track the report down the chain — that's why the secondary forwarded check exists in the first place.APPROVED(and typically noFORWARDED) action since the lastSUBMITTED. That verifies theAPPROVEDdetection fully covers the reported case.What alternative solutions did you explore? (Optional)
submittedTocomparison).OriginalMessageCreated.submittedToexists in the client types but currently has zero readers, so this is closer to the broaderExpensify/Expensify#507850rework and is heavier than needed here.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
melvin-bot commentedon Aug 19, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @suneox (
External)melvin-bot commentedon Aug 19, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022090208466723580720
NicolasBonet commentedon Aug 19, 2026
@MelvinBot implement this
MelvinBot commentedon Aug 19, 2026
🤖 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
isAwaitingFirstLevelApprovalrelied onhasReportBeenForwardedSinceLastSubmit, which only matchedFORWARDEDactions — but an intermediate multi-level Approve records anAPPROVEDaction while keeping the report in the processing state, so the check missed it. The fix treats anAPPROVEDaction created since the last submit as "moved past first level" too, which also fixes the same symptom incanEditMoneyRequestand resolves the duplicateExpensify/App#93999.Verification (local AI tests, all passing):
npm run typecheck-tsgo✅npm run lint-changed✅ReportUtilsTest.ts(hasReportBeenForwardedSinceLastSubmit) — 11 passed, incl. 3 new cases covering theAPPROVED-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/QAsections are left for the human co-author to fill with that manual flow before marking the PR ready for review.view run
NicolasBonet commentedon Aug 20, 2026
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):
CreateMoneyRequest); report actions: CREATED + IOU onlySubmitReport; approval chain built as a single level, SUBMITTED action stored withsubmittedTo= the managerDeleteMoneyRequestrejected atAuth Report.cpp:8633RetractReportsucceededNo
FORWARDEDorAPPROVEDaction was ever created, andApproveMoneyRequestnever ran against the report.The real trigger: the workspace's approval mode is
DYNAMIC_EXTERNAL(Dynamic External Workflow). The backend'sReport::isAwaitingFirstLevelApprovalreturnsfalseunconditionally 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 sawsubmitsTo === managerID(true — the report was still with its first-line manager) and no FORWARDED action in the report actions (true — none exists), so it returnedtrueand showed Delete.Correct fix
isAwaitingFirstLevelApprovalshould returnfalsewhen the report's policyapprovalModeisCONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL, mirroring the backend. That hides Delete (and the related affordances gated on this helper) on submitted DEW reports.The longer-term hardening from the earlier discussion still applies: a server-derived
isWaitingOnFirstLevelApprovalfield on the report Onyx object would remove this whole class of client-side reconstruction bugs (pagination, stale policy data, DEW and future approval modes).NicolasBonet commentedon Aug 20, 2026
The fix PR for this issue, #99009, has been closed as superseded: #98704 merged to
mainon 2026-08-20 (12:54 UTC) with the same fix —isAwaitingFirstLevelApprovalnow returnsfalsefor 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.
NicolasBonet commentedon Aug 24, 2026
Waiting on re-test by QA
IuliiaHerets commentedon Aug 24, 2026
Not repro
Windows 11/ Chrome
v9.4.59-4
99008.mp4
NicolasBonet commentedon Aug 24, 2026
Closing now as the other PR fixed this!