[$250] Admin can't delete $0 report through Copilot access
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.4.32-3 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @marianaabussamra Slack conversation (hyperlinked to channel name): #Expensify Bugs
Action Performed:
- Copilot's into the user account
- Go to the Spend page
- Select both $0 reports
- Click the selection
- Click Delete
- Refresh the page
- Reports are still there
Expected Result:
They should be able to delete the reports through the Copilot access
Actual Result:
They refresh the page, and the report is still there; they can only delete it through Expensify Classic
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [x] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/5a9356aa-ad4a-4522-8631-ce433e0cd1fd
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022075316849266381044
- Upwork Job ID: 2075316849266381044
- Last Price Increase: 2026-07-09
Issue Analysis
Root Cause (medium confidence): Two things combine here:
-
The delete is rejected by the backend for Copilot/delegate sessions. When a Copilot bulk-deletes reports from the Spend page, the App fires the
DeleteAppReportAPI command optimistically (report disappears), but the backend rejects the write for the delegate auth token, so on refresh the report reappears. This backend restriction is the reason it only works via Expensify Classic — confirming and fixing this part requires a separate internal/backend investigation (the command allow-list for delegate tokens is not in the App repo). -
The App surfaces no error on that rejection for $0 / empty reports, which is why it looks like a silent no-op.
deleteAppReportonly attaches a failure error message to a transaction row or the parent report-action preview. An empty $0 report has neither, so itsfailureDatajust reverts the pending state with no red-brick-road error — exactly matching "refresh → report still there, no error."
Notably, the bulk-delete handler has no delegate-access guard, unlike the Approve and Pay bulk actions in the same file which early-return a "no access" modal when acting as a restricted delegate.
Recommended Fix:
- Backend (primary): Escalate to an internal engineer to determine whether
DeleteAppReportshould be allowed for Copilot/delegate sessions (Classic allows it) and, if so, permit it server-side. This is the change that actually makes delete work. - App-side (defensive): Regardless of the backend decision, the delete path should not fail silently — either show a "no access" modal up front for restricted delegates, or surface the generic delete-failure error for empty reports so the user gets feedback instead of a silent revert.
Investigation details
App checked out at commit 98130124dd6e9330a0f955cb41beaf08470248e5.
- Bulk-delete handler (no delegate guard, unlike Approve/Pay in the same file):
src/hooks/useSearchBulkActions.ts:934-1017. Empty $0 reports (selection key == reportID,VIEWaction) are routed as whole-report deletions todeleteAppReport. deleteAppReportfires theDeleteAppReportwrite command:src/libs/actions/Report/index.ts:6700-6707.- Failure error message is only attached inside the transaction / parent-preview branch, so an empty report's
failureDatajust revertspendingActionwith no visible error:src/libs/actions/Report/index.ts:6645-6698.
Alternative explanations considered: A pure client-side no-op (delete never dispatched) — ruled out, the handler unconditionally dispatches deleteAppReport for a Copilot. A restricted-delegate client guard blocking it — ruled out, a full-access Copilot has isDelegateAccessRestricted = false, so no client guard fires; enforcement must be server-side.
Confidence: Medium. The App-side silent-failure mechanism is confirmed in code (high confidence). The backend rejection is the most consistent explanation for the delete failing at all but is not yet confirmed by production logs — a log check of the DeleteAppReport command for the affected Copilot's requestID (reportIDs are in the linked Slack/video) would confirm the server rejection and pin down whether it's intended.
Possibly related: Expensify/App#93760 (error when deleting an Agent) and Expensify/App#91978 (Copilot access issues) touch delegate/Copilot behavior but are not the same bug.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/95759) to create a draft PR for the App-side defensive fix (visible error / no-access guard). The backend delete-permission decision must be handled separately by an internal engineer.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Please re-state the problem that we are trying to solve in this issue.
When a user acts as Copilot for another account, selects $0 reports on the Spend page, and clicks Delete, the reports are not actually deleted — after a refresh they reappear. Expected: the Copilot should be able to delete the reports on behalf of the delegator (same as Expensify Classic).
What is the root cause of that problem?
The permission predicate canDeleteMoneyRequestReport in src/libs/ReportUtils.ts:3187 compares the report's actor/submitter against deprecatedCurrentUserAccountID — the Copilot's own accountID, not the delegator's. Specifically, isOwner at line 3190 (actorAccountID === deprecatedCurrentUserAccountID) and the isExpenseReport branch at line 3219 (isCurrentUserSubmitter(report)) both fail because the report was submitted by the delegator, so the predicate returns false. shouldShowDeleteOption in src/libs/SearchUIUtils.ts:6361 consumes this via every(...), so the bulk-delete short-circuits / no-ops for delegator-owned reports. The Copilot has no legitimate delete path in NewDot even though the API already accepts the delegate parameter appended by enhanceParameters.ts:82.
The key identity mismatch: account.delegatedAccess.delegate holds the Copilot's own email (the email of the user who is acting as a delegate), not the delegator's identity. The active delegator — the account being accessed — is found in account.delegatedAccess.delegators[], where each entry carries an email field. The delegator's accountID must be resolved by looking up that email in personalDetails (via getPersonalDetailByEmail or equivalent). All ownership comparisons in canDeleteMoneyRequestReport use deprecatedCurrentUserAccountID (the Copilot's own ID) instead of the delegator's resolved accountID, which is why every branch returns false.
What changes do you think we should make in order to solve the problem?
-
Resolve the delegator's accountID before the ownership checks. In
src/libs/ReportUtils.tsaround lines 3187–3223, detect whether a Copilot session is active by checking thataccount?.delegatedAccess?.delegateis non-empty (this field being set is whatisActingAsDelegateSelectortests). When active, identify the delegator's email by finding the matching entry inaccount.delegatedAccess.delegators[]— specifically the entry whoseemailmatches the stashed session email (the original user's email before the Copilot switch). Resolve that email to anaccountIDviagetPersonalDetailByEmail. Use this resolveddelegatorAccountIDas the comparand in every ownership check insidecanDeleteMoneyRequestReport. When no Copilot session is active, fall back todeprecatedCurrentUserAccountIDas today. -
Apply the resolved accountID to all ownership branches. The three branches that need updating are:
isOwner(line 3190): compareactorAccountIDagainstdelegatorAccountID ?? deprecatedCurrentUserAccountIDisInvoiceReportbranch (line 3205): comparereport?.ownerAccountIDagainstdelegatorAccountID ?? deprecatedCurrentUserAccountIDisIOUReportbranch (line 3208): sameisOwnercheck already flows through; verify it uses the updated comparandisExpenseReportbranch (line 3215):isCurrentUserSubmitter(report)internally usesdeprecatedCurrentUserAccountID; either passdelegatorAccountIDas an optional override (the function already accepts an optionalaccountIDparameter per src/libs/ReportUtils.ts:2835) or inline the check asreport?.ownerAccountID === delegatorAccountID ?? deprecatedCurrentUserAccountID
-
In
src/hooks/useSearchBulkActions.tsaround line 951, ensure the delete-report path is not blocked by a delegate-access modal (it currently is not — but confirm no upstreamisDelegateAccessRestrictedguard is added that would incorrectly block Copilot delete). Delete on Spend is a supported Copilot action. -
Verify the API side:
DELETE_APP_REPORTrequest built at src/libs/actions/Report/index.ts:6700 already benefits from the automaticdelegateparam added in src/libs/Network/enhanceParameters.ts:82, so no additional param is required — the backend already attributes the delete to the delegator via that param. -
Add a unit test for
canDeleteMoneyRequestReportcovering the delegate-active case:account.delegatedAccess.delegateset to the Copilot's email (non-empty → Copilot session active)account.delegatedAccess.delegatorscontaining an entry with the delegator's emailpersonalDetailsentry for that delegator email resolving to the delegator'saccountID- An
isExpenseReportreport withownerAccountIDequal to the delegator'saccountID - Assert
canDeleteMoneyRequestReportreturnstrue(currently returnsfalse)
What alternative solutions did you explore? (Optional)
🚨 Edited by proposal-police: This proposal was edited at 2026-07-09 20:34:55 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user acts through Copilot access (a delegate) and bulk-selects reports on the Spend page and taps Delete, nothing happens — after a refresh the reports are still there. The action gives no feedback: it neither deletes the reports nor tells the user why.
What is the root cause of that problem?
Copilot access maps to a delegate. A delegate whose access level is Submitter is restricted from write actions in NewDot. That restriction is computed here and exposed to every bulk action on Search:
isDelegateAccessRestricted — https://github.com/Expensify/App/blob/89bfa7e40388cee8788a8b33a7618f940fe0f314/src/components/DelegateNoAccessModalProvider/index.tsx#L34-L35
isDelegateOnlySubmitter — https://github.com/Expensify/App/blob/89bfa7e40388cee8788a8b33a7618f940fe0f314/src/libs/AccountUtils.ts#L9-L14
Every other bulk write action in useSearchBulkActions guards on this flag before firing and, when restricted, shows the "not allowed" modal instead. For example, Approve:
https://github.com/Expensify/App/blob/89bfa7e40388cee8788a8b33a7618f940fe0f314/src/hooks/useSearchBulkActions.ts#L797-L810
The same guard exists for Reject, Pay and Bulk Pay. Delete is the only bulk action that omits it. handleDeleteSelectedTransactions goes straight from the confirm modal to deleteAppReport/deleteTransactions with no delegate check:
https://github.com/Expensify/App/blob/89bfa7e40388cee8788a8b33a7618f940fe0f314/src/hooks/useSearchBulkActions.ts#L921-L935
So a Submitter-role Copilot still sees the Delete button, taps it, and the client dispatches DeleteAppReport. The server refuses the write for a restricted delegate, the optimistic update rolls back, and because there is no frontend guard the user gets no modal and no error — the report simply reappears on refresh. That is the silent no-op being reported. (For an empty $0 report this runs through the whole-report branch → deleteAppReport → API.write(WRITE_COMMANDS.DELETE_APP_REPORT, ...).)
What changes do you think we should make in order to solve the problem?
Add the same isDelegateAccessRestricted guard that every other bulk action already uses to the delete handler. In handleDeleteSelectedTransactions, right after the confirm check returns:
if (result.action !== ModalActions.CONFIRM) {
return;
}
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
return;
}
isDelegateAccessRestricted and showDelegateNoAccessModal are already pulled into this hook (they back the Approve/Reject/Pay guards), so no new wiring is needed.
The split-aware delete entry point that calls deleteTransactions directly from the dropdown option needs the same guard so it can't bypass the check:
https://github.com/Expensify/App/blob/89bfa7e40388cee8788a8b33a7618f940fe0f314/src/hooks/useSearchBulkActions.ts#L2116-L2130
onSelected:
shouldShowEditSplitOnDelete && firstTransaction?.transactionID
? () => {
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
return;
}
deleteTransactionsFromHook([firstTransaction.transactionID], duplicateTransactions, duplicateTransactionViolations, hash);
}
: handleDeleteSelectedTransactions,
This makes Delete behave exactly like Pay/Approve/Reject for a restricted Copilot: the restricted delegate gets the clear "not allowed" modal instead of a silent failure, and a full-access Copilot (where isDelegateAccessRestricted is false) continues to delete normally.
What specific scenarios should we cover in automated tests to prevent this bug from reoccurring in the future?
- Acting as a Submitter-role delegate (
isDelegateAccessRestricted === true): selecting reports and choosing Delete callsshowDelegateNoAccessModaland does not calldeleteAppReport/DeleteAppReport. Cover both the whole-report path and the split-delete dropdown path. - Not a restricted delegate (
isDelegateAccessRestricted === false): choosing Delete proceeds and dispatches the delete as before.
What alternative solutions did you explore? (Optional)
Hide/disable the Delete option entirely for restricted delegates by extending the canShowDeleteAction condition where the option is pushed. I favored the guard-in-handler approach because it mirrors the established pattern for every other bulk action (the option stays visible and the tap surfaces the same explanatory "not allowed" modal), keeping Delete consistent with Pay/Approve/Reject rather than making it a silent-disabled special case.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abzokhattab (External)
Proposal
What is the root cause of that problem?
When someone Copilots (delegates) into another user's account, selects both $0 reports on the Spend page, and clicks Delete, the rows disappear briefly but reappear after a page refresh. This is the classic signature of an optimistic Onyx update that gets reverted because the backend rejected the write command.
Bulk delete from the Search / Spend view does not go through the report chat delete flow. It is dispatched from the Search actions layer, which applies optimistic Onyx data to remove the report and its transactions, then sends a delete command to the server. For a normal (non-delegate) session this command is authorized and the report is removed permanently. For a delegate/Copilot session the same command is rejected server-side because deleting an expense report is not one of the write actions permitted while acting as a delegate. Since the client already applied the optimistic removal, the report looks deleted until the next full data sync (page refresh), at which point Onyx re-hydrates the still-existing report from the server and it reappears.
In other words, the client lets the delegate trigger the delete and shows a success state, but the delete command carries the delegate context and the backend refuses it, so nothing is actually removed. This is why the same delete works in Expensify Classic (where delegate deletion is handled) but not in New Expensify.
The delete is triggered from the Search selection footer handler and the Search actions deleteMoneyRequestOnSearch path, which does not run the delegate access check that other write actions use before dispatching.
What changes do you think we should make in order to solve the problem?
The correct behavior needs alignment between client and backend for delegate deletes:
-
If deleting reports as a delegate is meant to be supported, the delete command dispatched from the Search actions bulk-delete handler (
deleteMoneyRequestOnSearchinSearch.ts) must be sent with the delegate/Copilot authentication context so the backend authorizes it, matching how Classic handles it. This removes the silent server rejection that causes the report to reappear on refresh. -
If deleting reports as a delegate is intentionally restricted, the client should not present an apparent success. The bulk Delete action in the Search selection flow should run the existing delegate access guard (the
isDelegateAccessRestricted/ delegate no-access modal pattern used elsewhere for restricted write actions inDelegate.ts) before applying the optimistic Onyx removal, so the user gets the standard "not available in this account" message instead of a fake deletion.
Given the Expected Result in the issue is that delegates should be able to delete, option 1 is the intended fix: route the Spend-page bulk delete through the same delegate-aware command handling used by Classic so the server accepts the delete and the optimistic Onyx update is not reverted.
I will confirm the exact command name and delegate-context wiring in Search.ts and Delegate.ts and add the missing delegate authentication to the delete command dispatched from the Spend page.
What alternative solutions did you explore? (Optional)
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.
Job added to Upwork: https://www.upwork.com/jobs/~022075316849266381044
Proposal
Please re-state the problem that we are trying to solve in this issue.
While Copiloting into a user's account, an Admin selects two $0 reports on the Spend (Search) page and clicks Delete. The confirmation flow completes with no error, but after refreshing the page the reports are still there — the delete never actually happened.
What is the root cause of that problem?
On the Search page's general "Spend" view (as opposed to the dedicated "Expense Reports" tab), a $0 report with no transactions is rendered as an empty report-group row. When such a row is selected, mapEmptyReportToSelectedEntry stores its selection entry with action: item.action, which is the report's live primary action (e.g. submit, since the report is still Open/unsubmitted and owned by the acting user) — it only falls back to VIEW when item.action is unset. So a $0, not-yet-submitted report's selection entry ends up with action: 'submit', not 'view'.
https://github.com/Expensify/App/blob/fd39bffc1666cfa46b5b9d6a7b6fab77192c1bdb/src/components/Search/selectionBuilders.ts#L110-L133
When the bulk Delete handler runs, it partitions the selection into "whole report" deletions vs. individual transaction deletions. Per its own comment, a whole-report row is identified purely by its selection key equaling its reportID — but the code additionally requires selectedItem.action === CONST.SEARCH.ACTION_TYPES.VIEW. Because our $0 report's action is 'submit' (not 'view'), it fails this check on both loops: it's never added to wholeReportIDs, and it isn't skipped in the second loop, so it falls into the !wholeReportIDs.includes(...) branch and gets pushed into transactionIDsToDelete — even though its key is actually a reportID, not a transactionID.
https://github.com/Expensify/App/blob/fd39bffc1666cfa46b5b9d6a7b6fab77192c1bdb/src/hooks/useSearchBulkActions.ts#L972-L997
That reportID is then handed to deleteTransactionsFromHook, which looks it up as a transaction ID. Since no transaction with that ID exists, it silently deletes nothing, deleteAppReport (the API call that actually deletes the report) is never invoked, and the modal closes with no visible error — so the report reappears unchanged after a refresh.
What changes do you think we should make in order to solve the problem?
Drop the action === VIEW requirement when identifying whole-report rows — a row's selection key equaling its reportID is already the sufficient and correct signal (as the existing comment states), regardless of what primary action (view, submit, approve, etc.) that report currently shows.
https://github.com/Expensify/App/blob/fd39bffc1666cfa46b5b9d6a7b6fab77192c1bdb/src/hooks/useSearchBulkActions.ts#L976-L986
for (const key of Object.keys(selectedTransactions)) {
const selectedItem = selectedTransactions[key];
if (key === selectedItem.reportID) {
wholeReportIDs.push(selectedItem.reportID);
}
}
for (const key of Object.keys(selectedTransactions)) {
const selectedItem = selectedTransactions[key];
if (key === selectedItem.reportID) {
continue;
}
With this change, a selected $0 report — no matter whether its computed primary action is view, submit, approve, etc. — is correctly recognized as a whole-report row, added to wholeReportIDs, excluded from transactionIDsToDelete, and routed to the existing deleteAppReport call further down in the same function, which performs the real deletion via the DELETE_APP_REPORT API command.
⚠️ @samranahm Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When an admin copilots into a member's account and bulk-deletes their $0 (empty) expense reports from the Search/Spend page, the delete appears to go through but nothing actually happens — after a refresh the reports are still there, and the only working path is Expensify Classic.
What is the root cause of that problem?
The structural cause: the delete option's visibility gate and the delete handler read the report from two different stores. The gate reads the search snapshot; the handler reads only the live ONYXKEYS.COLLECTION.REPORT collection. When a report exists only in the snapshot, the option shows but the delete silently no-ops.
The chain:
- The Delete option is offered based on the search snapshot:
shouldShowDeleteOptionresolves the report fromcurrentSearchResultsand passes it tocanDeleteMoneyRequestReport— https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/SearchUIUtils.ts#L6353-L6382. For a $0 open expense report owned by the copiloted user this returns true (submitter + open report), so the option shows — https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/ReportUtils.ts#L3187-L3225. - But when the user confirms, the handler resolves the report from the live collection only, with no snapshot fallback:
const report = allReports?.[${ONYXKEYS.COLLECTION.REPORT}${reportID}]— https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L950-L955. deleteAppReportthen silently returns when the report is undefined — only aLog.warn, no optimistic data, no error, and crucially no API call: https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6286-L6289. The backend never receivesDeleteAppReport, which is why the reports are intact after refresh.- Why Copilot triggers it: connecting as a copilot re-runs
openApp()on a fresh session for the target account (https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Delegate.ts#L143 → https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Delegate.ts#L228), so local Onyx holds only what OpenApp returns. The member's stale $0 reports were never opened in that session — they exist only in the search snapshot, so step 2 returnsundefined. - Why only $0 reports: empty reports are exactly the rows that route through the whole-report
deleteAppReportpath. Rows with expenses are deleted by transaction ID taken from the snapshot itself (deleteTransactionsFromHook), which is why normal expense deletion works in the same copilot session.
All affected paths (both hit the identical broken lookup):
- Reports (expense-report type) branch: https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L950-L955
- Spend (expense type) whole-report branch — the repro's path: https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L1000-L1015
- The
reportActionsargument at both call sites has the same live-store-only gap (L955, L1004), which for non-empty reports makes the optimistic move-to-selfDM and thetransactionIDToReportActionAndThreadDataAPI param silently empty.
The other two deleteAppReport callers are NOT affected and must not change: useExpenseActions.ts (L589) and PopoverReportActionContextMenu.tsx (L404) pass an in-memory report object from an open screen, so they can never hit the early return.
What changes do you think we should make in order to solve the problem?
Use the snapshot-first helper this hook already imports and uses for bulk pay/approve — getReportFromSearchSnapshot (https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Search.ts#L128-L136, imported at https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L25) — at both delete call sites, and give reportActions the same snapshot fallback:
const report = getReportFromSearchSnapshot(reportID, currentSearchResults?.data, allReports);
deleteAppReport({
report,
reportActions:
allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ??
currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`],
...
Regression safety in one sentence: snapshot-first resolution is the established pattern for every other bulk action in this same hook (L829, L1075, L1148, L1163, L1495), and when the report is loaded locally the helper's ?? allReports fallback keeps today's behavior unchanged.
Why the obvious spot-fix does not work: patching only the L952 lookup (or adding a one-off ?? currentSearchResults... there) leaves the Spend-tab whole-report branch at L1001 — the exact path in the QA repro — still silently no-oping; and fixing the report lookup while leaving reportActions live-only means a non-empty report deleted from search on a fresh session sends an empty transactionIDToReportActionAndThreadData, so its expenses aren't moved to the self-DM. The fix must cover both call sites and both arguments.
I'd also add a defensive Log.warn→error surface is not needed once the lookup is fixed, and I'll cover the corrected path with a unit test in tests/actions/ for deleteAppReport invoked with a snapshot-resolved report.
What alternative solutions did you explore? (Optional)
- Tighten
shouldShowDeleteOptionto require the report inallReports— hides the Delete option instead of fixing it; the user still has no way to delete these reports in New Expensify (the reported bug remains, just quieter). Fix the missing data source, not the gate. - Call
OpenReportto load the report before deleting — adds a network round-trip that races the delete and is unnecessary: the snapshot already contains the report object, and bulk pay already trusts it. - Blame the
delegateparam the API layer appends (enhanceParameters.tsL82-L83) and treat it as a backend permission bug — ruled out: a backend rejection would firefailureData(row restored + error shown), but QA saw no error, and it cannot explain why only $0 reports fail while expense deletes work in the same copilot session. The request is never sent at all.
🚨 Edited by proposal-police: This proposal was edited at 2026-07-09 21:06:27 UTC.
Proposal
What is the root cause of that problem?
The bulk-delete flow decides that selected report rows can be deleted from the search snapshot, but then executes the delete using only the global report collection. shouldShowDeleteOption() receives currentSearchResults?.data, so a report that exists in the search snapshot can show the Delete option.
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/SearchUIUtils.ts#L6353-L6396
However, both whole-report delete branches in useSearchBulkActions() resolve the report with allReports?.[...] only and pass that value into deleteAppReport().
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L950-L966
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L999-L1014
When a Copilot session opens Spend/Search, these empty $0 reports can be present in the search snapshot without being hydrated in ONYXKEYS.COLLECTION.REPORT. In that case report is undefined, and deleteAppReport() returns before applying optimistic data or sending the DeleteAppReport API write, even though the selected reportID is already known.
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6286-L6289
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6700-L6707
That makes the Delete confirmation a silent no-op for snapshot-only empty report rows, so refreshing the page shows the same reports again.
What changes do you think we should make in order to solve the problem?
Resolve the report from the same source that made the row deletable. In both whole-report delete branches of useSearchBulkActions(), replace the direct allReports lookup with the existing getReportFromSearchSnapshot(reportID, searchResults?.data, allReports) helper, and include the search data in the callback dependencies.
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Search.ts#L129-L137
With that change, selected $0 report rows that are only present in the active search snapshot still pass a real report into deleteAppReport(), so the existing DeleteAppReport request is dispatched. Reports already hydrated in the global collection keep the same behavior because the helper falls back to allReports.
Test coverage:
- Add a
useSearchBulkActionsbulk-delete unit test where the selected report row exists only incurrentSearchResults.data,allReportsdoes not contain it, and the selected key equalsreportID; after confirming Delete, assertdeleteAppReport()receives the snapshot report. - Keep an existing hydrated-report case to verify direct
allReportsdeletes still work. - If
deleteAppReport()is made more defensive later, add a focused action test proving a valid selectedreportIDcannot silently skip the API write just because the global report object is missing.
What alternative solutions did you explore? (Optional)
I considered adding a new delegate parameter to DeleteAppReport, but that does not fix this no-op path because the request is never sent when report is undefined. Also, authenticated requests already get the active Copilot delegate email from enhanceParameters().
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/Network/enhanceParameters.ts#L28-L35
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/Network/enhanceParameters.ts#L82-L83
Proposal Updated
I reworked my proposal with what I think is the real root cause. On Search, every bulk write action (Pay, Approve, Reject, Bulk Pay) guards on isDelegateAccessRestricted and shows the "not allowed" modal for a restricted copilot — Delete is the only one that skips that check, so the copilot taps Delete, the client fires DeleteAppReport, and it silently no-ops. Fix is to add the same guard the other actions already use.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When I copilot into another account and delete a report from the Search/Reports (Spend) page, the report disappears from the list but comes back after I refresh — the deletion is never persisted. Today this happens silently, with no feedback that the delete didn't go through.
What is the root cause of that problem?
Delete is the only write action on Search that doesn't check delegate (copilot) access. When you act as a limited/Submitter copilot, isDelegateAccessRestricted is true, and every write action routes you to the "no access" modal instead of hitting the backend — except delete, which skips the check, optimistically removes the report, fires DeleteAppReport, gets rejected by the backend (a Submitter copilot isn't authorized to delete), and then reverts. So the report reappears on refresh.
isDelegateAccessRestricted is exactly "acting as a delegate and the delegate role is Submitter":
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/components/DelegateNoAccessModalProvider/index.tsx#L34-L35
Every sibling action guards on it and shows the modal — Pay and Approve in Search…
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/libs/actions/Search.ts#L281-L285
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/libs/actions/Search.ts#L316-L320
…Hold/Unhold on the selected-transactions menu…
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/hooks/useSelectedTransactionsActions.ts#L328-L332
…and five more places inside the bulk-actions hook itself (e.g. L807, L1051, L1775, L1958, L1990):
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/hooks/useSearchBulkActions.ts#L807-L808
But the bulk-delete handler has no such guard — it calls deleteAppReport straight away:
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/hooks/useSearchBulkActions.ts#L934-L967
…and the same is true for the selected-transactions delete option:
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/hooks/useSelectedTransactionsActions.ts#L557-L568
deleteAppReport then dispatches DeleteAppReport, and enhanceParameters already attaches delegate=<copilotEmail> to the request — so the backend knows a delegate is acting and enforces the role:
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/libs/actions/Report/index.ts#L6676-L6683
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/libs/Network/enhanceParameters.ts#L82-L83
When the backend rejects it, failureData resets the report's pendingAction back to null, restoring it in Onyx:
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/libs/actions/Report/index.ts#L6663-L6674
Timeline (limited copilot deletes a report):
- Copilot taps Delete →
handleDeleteSelectedTransactionsruns, no delegate check. - Optimistic update marks the report
pendingAction: DELETE→ it vanishes from the list. DeleteAppReportis sent;enhanceParametersaddsdelegate=<copilotEmail>.- Backend sees a Submitter-role delegate deleting → rejects.
failureDatarevertspendingActiontonull→ the report is restored in Onyx.- Refresh re-fetches the still-existing report from the server → "Reports are still there."
The $0 amount is incidental — the trigger is the copilot context, not the amount. The Delete option itself is correctly offered, because canDeleteMoneyRequestReport passes for the delegator-owned open report; the gap is purely the missing delegate guard behind it:
- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/libs/ReportUtils.ts#L3187-L3220
What changes do you think we should make in order to solve the problem?
Add the same delegate guard the sibling actions already use to the two delete entry points. Both hooks already pull isDelegateAccessRestricted and showDelegateNoAccessModal into scope (useSearchBulkActions.ts L358-L359, useSelectedTransactionsActions.ts L87-L88), so this is a small, in-pattern change with no new state:
-
At the top of
handleDeleteSelectedTransactions(the bulk delete from the Reports view — the exact repro path), right where the!hashearly-return is:- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/hooks/useSearchBulkActions.ts#L934-L937
if (isDelegateAccessRestricted) { showDelegateNoAccessModal(); return; } -
At the start of the selected-transactions delete
onSelected(same bug class from the report/row selection menu):- https://github.com/Expensify/App/blob/89a5c2d4d28d414e51c969fc701b90a496e58f98/src/hooks/useSelectedTransactionsActions.ts#L557-L568
This is intentionally minimal — it reuses the exact if (isDelegateAccessRestricted) { showDelegateNoAccessModal(); return; } block already shipped for Pay/Approve/Hold, rather than inventing a new fallback, so a restricted copilot gets a clear "no access" modal instead of a silent revert.
Note (full-access copilots): the guard fires only for limited/Submitter copilots (isActingAsDelegate && isDelegateOnlySubmitter). A full-access copilot has isDelegateAccessRestricted === false, so the delete flows through unchanged — this change never blocks someone who is allowed to delete. If deletion also fails for a full copilot, that's a separate backend issue: DeleteAppReport would need to honor the delegate param for full delegates the same way ApproveMoneyRequest/pay already do. Since we can't see the tester's copilot role from the report, I'd confirm it first; the frontend guard above is correct and safe either way.
What alternative solutions did you explore? (Optional)
-
(Recommended) Add the delegate guard to both delete entry points — matches the existing Pay/Approve/Hold pattern, needs no backend change, and gives one consistent behavior for restricted copilots. It's safe because it only affects limited copilots, who already can't Pay/Approve/Hold.
-
Allow limited copilots to delete (backend authorization change) — rejected: it contradicts the delegate-role model. Submitter copilots are intentionally restricted from write actions, and delete is a write action; the frontend already blocks the siblings, so delete should match them, not become an exception.
-
Guard all delegates (not just Submitters) on delete — rejected: this would wrongly block full-access copilots who are supposed to be able to delete. Gating on
isDelegateAccessRestricted(Submitter-only) is the correct, narrow condition.
Plausible-but-wrong root cause I ruled out: "the Delete option shouldn't be shown for these reports." It should — canDeleteMoneyRequestReport correctly returns true for the delegator's open report, so the button is right; the defect is the missing delegate guard behind the button, not the button's visibility.
Proposal
What is the root cause of that problem?
deleteAppReport aborts the entire operation — including the backend DeleteAppReport write — the moment it isn't handed a fully-hydrated in-memory report object, even though the only thing it actually needs to delete an empty report is the reportID:
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6286-L6289
The entire rest of the function is already written to tolerate a missing report: it derives everything from reportID and uses report?. optional chaining / reportActions ?? {} throughout, and for a $0 report the money-request loop never runs (no reportActions), so transactionIDToReportActionAndThreadData is simply {}. The API params are built purely from reportID:
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6700-L6707
So the guard on line 6286 is the sole thing stopping the delete. It only requires the report object because the signature forces callers to pass one:
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6260-L6271
Why Copilot surfaces it: a delegate connects on a fresh session, so local Onyx holds only what OpenApp returned. A member's stale $0 reports were never opened, so allReports has no entry and the hook passes report: undefined into deleteAppReport, which then hits the early return and silently no-ops — no optimistic update, no error, no API call — so the reports are still there after refresh. This is why only empty reports fail: rows with expenses are deleted by transaction ID (deleteTransactionsFromHook), never through this whole-report path.
Both whole-report call sites pass the report object that may be undefined:
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L950-L967
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useSearchBulkActions.ts#L999-L1015
What changes do you think we should make in order to solve the problem?
Make deleteAppReport accept an explicit reportID and stop requiring the hydrated report object. The reportID is always known — it is the loop variable at both call sites — so the delete for an empty report can proceed from it alone.
- Add
reportID: stringtoDeleteAppReportPropsand gate on that instead ofreport:
type DeleteAppReportProps = {
reportID: string;
report: OnyxEntry<Report>;
// ...unchanged
};
function deleteAppReport({reportID, report, /* ... */}: DeleteAppReportProps) {
if (!reportID) {
Log.warn('[Report] deleteAppReport called with no reportID');
return;
}
// ...rest unchanged; it already uses `reportID` and `report?.` everywhere
The optimistic snapshot merge already spreads {...report, pendingAction: DELETE} — with report undefined this becomes {pendingAction: DELETE}, which still greys out the row; and on failure the ${SNAPSHOT}${hash} block already resets the row's pendingAction to null, so the search row is correctly restored even without a local report object:
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/libs/actions/Report/index.ts#L6687-L6698
- Pass
reportIDat both whole-report call sites inuseSearchBulkActions(the loop already binds it):
for (const reportID of selectedReportIDs) {
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
deleteAppReport({reportID, report, /* ...unchanged */});
}
- The two unaffected callers already hold a hydrated report, so they just forward its ID and keep today's behavior exactly:
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/hooks/useExpenseActions.ts#L589-L600
https://github.com/Expensify/App/blob/98130124dd6e9330a0f955cb41beaf08470248e5/src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx#L403-L415
Regression safety: when the report is loaded locally, every downstream line still reads the same reportID and report?. fields it does today, so behavior is byte-for-byte identical; the change only lets the delete proceed in the one case it currently drops on the floor. Test coverage: a unit test invoking deleteAppReport with report: undefined but a valid reportID, asserting DELETE_APP_REPORT is dispatched with that reportID and an empty transactionIDToReportActionAndThreadData.
What alternative solutions did you explore? (Optional)
- Resolve the report object from the search snapshot before calling (
getReportFromSearchSnapshot(reportID, searchData, allReports)at both call sites, plus a snapshot fallback forreportActions). This works, but it plumbs snapshot data into a function that doesn't need the full object to delete an empty report; fixing the guard removes the requirement at its source, so the delete can't silently no-op regardless of which store happens to hold the report. For non-empty reports deleted on a fresh session,reportActionscan still be given the same snapshot fallback on top of this change if we want the un-report-to-selfDM optimism to populate. - Guard the handler on
isDelegateAccessRestrictedand show the no-access modal — wrong for this bug: a full-access Copilot (admin) is supposed to delete, and QA saw no permission error, so the write never being sent is the failure, not a rejected write. - Thread
delegateAccountIDintoDeleteAppReportParams— the API layer already appends delegate context viaenhanceParameters; the request is never sent at all, so adding a param to a command that never fires cannot fix it. - Mount
SearchBulkActionsButtoninsideSearchScopeProvidersouseOnyxredirects theallReports/allReportActionscollection reads to the snapshot — rejected: that redirect would also swapselfDMReportand other individual report reads in the hook to snapshot-only values, changing optimistic self-DM behavior for non-empty deletes. Too broad a blast radius for this bug.
⚠️ @lorretheboy Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Proposal
Updated the proposal above to tighten 1 edge case (additional guards and broader coverage).
Proposal
Please re-state the problem that we are trying to solve in this issue.
A Copilot (delegate) acting on another user's account selects $0 reports on the Spend/Search page and taps Delete. The rows leave the list, but after a refresh the reports are still there — the deletion is never persisted. The same reports delete fine in Expensify Classic.
What is the root cause of that problem?
Every other report-resolution call site in useSearchBulkActions routes through one shared helper — getReportFromSearchSnapshot(reportID, searchData, allReports) (src/libs/actions/Search.ts:129), which resolves snapshot-first, collection-second ("Prefer the search snapshot…", :135). It is already imported (src/hooks/useSearchBulkActions.ts:25) and called at six sibling sites — :349, :829, :1075, :1148, :1163, :1495.
The delete handler is the sole exception. Both whole-report branches resolve the report with a bare collection lookup and no snapshot fallback:
src/hooks/useSearchBulkActions.ts:952(expense-report branch)src/hooks/useSearchBulkActions.ts:1001(other-reports branch)
both: const report = allReports?.[\${ONYXKEYS.COLLECTION.REPORT}${reportID}`];`
When the report lives only in the snapshot, report is undefined and deleteAppReport short-circuits before any network call:
// src/libs/actions/Report/index.ts:6286
if (!report?.reportID) {
Log.warn('[Report] deleteAppReport called with no reportID');
return;
}
No DeleteAppReport is ever sent, so nothing is removed server-side. The Delete button still shows because shouldShowDeleteOption reads the report from currentSearchResults — the snapshot — where it does exist (src/libs/SearchUIUtils.ts:6363). Visibility reads the snapshot; delete reads the collection, and delete is the one path that never adopted the shared helper.
This reliably hits Copilots because connecting as a delegate atomically clears Onyx except for KEYS_TO_PRESERVE_DELEGATE_ACCESS (src/libs/actions/Delegate.ts:35-54) — reports are not preserved — via clearOnyxForDelegateTransition → clearOnyxAndSeedFullReconnect (Delegate.ts:64-67); the subsequent openApp reloads only a subset, so $0 reports browsed on Spend but never opened are snapshot-only. Classic has no snapshot/collection split, hence the contrast.
What changes do you think we should make in order to solve the problem?
Make delete consistent with its six siblings by routing both call sites through the already-imported helper:
// src/hooks/useSearchBulkActions.ts:952 and :1001
const report = getReportFromSearchSnapshot(reportID, searchResults?.data, allReports);
getReportFromSearchSnapshot is already imported (:25); searchResults is already in hook closure scope (:400, the last-non-empty result, so it survives transient empties); allReports is already passed. Add searchResults to the handleDeleteSelectedTransactions dependency array (:1018-1039); the helper itself is a stable module import. With a defined report, deleteAppReport issues DeleteAppReport and the report is genuinely removed. Reports already in allReports are unaffected — the snapshot is consulted only as a fallback — so currently-working deletes are unchanged.
Proposal
What is the root cause of that problem?
The bulk delete flow for empty report rows is not using the same source of truth throughout the action lifecycle.
The Search UI decides that Delete is available using the active search snapshot. That snapshot can contain the $0 report row, its report object, and sometimes its report actions even when the global Onyx report collection is not hydrated yet, especially after a Copilot/delegate transition.
But after the user confirms Delete, useSearchBulkActions resolves whole-report deletes from allReports only. If the selected empty report exists only in the snapshot, deleteAppReport receives report: undefined, hits its early return, and never sends DeleteAppReport. The result is a silent no-op: the modal closes, selection clears, but nothing was deleted server-side.
There is a second routing bug in the Spend/grouped path: whole-report rows are identified using both key === reportID and action === VIEW. Empty report rows can carry another primary action such as submit, so a report ID can be misclassified as a transaction ID and sent to the transaction delete path, which also deletes nothing.
What changes do you think we should make in order to solve the problem?
Use a single delete target resolution path for Search bulk deletes before calling either deleteAppReport or deleteTransactionsFromHook.
In useSearchBulkActions, build a small local “delete targets” resolver that consumes:
selectedTransactionsselectedReportssearchResults?.dataallReportsallReportActionsallTransactionsallTransactionViolations
The resolver should classify selected items as:
- whole-report deletes when the selected key equals
selectedItem.reportID, regardless ofselectedItem.action - transaction deletes when the selected key is a transaction ID and is not covered by a selected whole report
For each whole-report delete, resolve the report snapshot-first with the existing getReportFromSearchSnapshot(reportID, searchResults?.data, allReports) helper. Resolve related report actions the same way: prefer allReportActions, then fall back to searchResults?.data[REPORT_ACTIONS + reportID]. Resolve parentReportAction from either live Onyx or snapshot data using the resolved report’s parentReportID and parentReportActionID.
If a whole-report target cannot be resolved from either snapshot or allReports, do not clear selection as if the delete succeeded. Log a warning with the report ID and leave that item unmodified, or surface the existing generic delete failure path. The important part is that the UI must not silently treat an unresolved destructive action as completed.
Then call deleteAppReport only with a resolved report object. Keep deleteAppReport’s current contract intact instead of making it accept a bare reportID; that action depends on report metadata for optimistic snapshot updates, parent preview cleanup, self-DM movement, failure rollback, and offline-safe state restoration.
For transaction deletes, pass only real transaction IDs to deleteTransactionsFromHook. This prevents empty report IDs from being misrouted into the transaction delete path.
The delete handler should continue to support offline-first behavior by relying on the existing deleteAppReport optimistic/failure/success data. Once the snapshot report is passed correctly, deleteAppReport already marks the snapshot row pending delete, updates report/reportActions state, and rolls back through failure data if the API fails.
I would also add targeted regression coverage:
- snapshot-only empty
$0report selected from Spend: sendsDeleteAppReport - empty report with
action: submitor non-view: still routes as whole-report delete - hydrated report in
allReports: unchanged behavior - mixed selection of empty reports and transactions: report IDs are not sent as transaction IDs
- missing report in both snapshot and
allReports: no silent success - report actions only available in snapshot: passed into
deleteAppReport - full-access Copilot: delete proceeds with existing delegate request enhancement
This keeps delegate permissions out of the primary fix. If product separately wants restricted submitter delegates blocked from Delete, add the existing isDelegateAccessRestricted modal guard as a separate behavior change. It should not be used to “fix” this bug because the expected result is successful deletion for an admin/full-access Copilot.
What alternative solutions did you explore? (Optional)
⚠️ @x-dev90 Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Updated my proposal.
What changed: Updated the proposal to focus on resolving selected reports from the active search snapshot before deleting.
Why: The delete flow can skip the API request when a selected report is not hydrated in the global report collection.
⚠️ @wildan-m Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.