You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-06-03] [$250] Expense - Duplicate report with rejected expenses #88236
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Version Number: v9.3.60-14 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:https://test-management.browserstack.com/projects/2219752/folder/27754595/test-cases/65943370 Email or phone of affected tester (no customers):agexptest+wt170426@gmail.com Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Windows 11/ Chrome, Samsung S23FE/ Android 16, iPhone 13 Mini/ iOS 26.3 App Component: Money Requests
Action Performed:
Preconditions:
Have a workspace with Delayed Submissions and Approvals enabled.
Have an expense report with 3 expenses from a submitter user.
Open the Expensify app
Log in as the workspace admin
Go to the submitter's workspace chat
Go to the expense report
Reject 2 of those 3 expenses
Go back to the submitter's workspace chat
Expected Result:
Only one report with rejected expenses is created.
Actual Result:
Two identical reports with rejected expenses are created.
When rejecting 2 of 3 expenses from a report with delayed submission enabled, rejectMoneyRequestsOnSearch (Search.ts:1244-1249) generates a single sharedRejectedToReportID and calls rejectMoneyRequest in a synchronous for-loop — one call per expense.
Each call runs prepareRejectMoneyRequestData, which looks up allReports for an existingOpenReport to reuse. However, API.write() applies Onyx optimistic data asynchronously, so the second call still reads stale allReports and doesn't see the optimistic report created by the first call. Both calls fall into the "create new report" branch.
While sharedRejectedToReportID ensures both calls target the same report ID, each call independently creates its own REPORTPREVIEW action and MERGEs it into the workspace chat's report actions. Two REPORTPREVIEW actions in the same workspace chat render as two separate report entries in the UI — the duplicate reports.
Additionally, the second Onyx.METHOD.SET on the same report key overwrites the first, so the report's parentReportActionID only points to the second REPORTPREVIEW.
What changes do you think we should make in order to solve the problem?
In prepareRejectMoneyRequestData, when sharedRejectedToReportID is provided and no existingOpenReport is found, only the first call (the one that creates the report) should generate the REPORTPREVIEW action and the Onyx.METHOD.SET for the new report. Subsequent calls using the same sharedRejectedToReportID should skip report creation and REPORTPREVIEW generation, and instead only add their transaction to the already-created destination report (similar to the existingOpenReport branch at line 358).
Concretely: track whether the report for sharedRejectedToReportID has already been optimistically created (e.g., via a shared mutable flag or by building the optimistic report once in rejectMoneyRequestsOnSearch and passing it down). When the flag is set, the second call should take the existingOpenReport path — reuse the report and skip REPORTPREVIEW + SET creation.
What alternative solutions did you explore? (Optional)
An alternative is to batch all transactions into a single API.write call (similar to rejectMoneyRequestInBulk), consolidating optimistic data so only one REPORTPREVIEW is ever created. This is cleaner but is a larger change — the current per-transaction loop exists because rejectMoneyRequestInBulk only handles the "all expenses selected" case with different server-side semantics.
Investigation details
Key code path:
rejectMoneyRequestsOnSearch — generates sharedRejectedToReportID, loops calling rejectMoneyRequest per transaction
Why sharedRejectedToReportID doesn't fully prevent duplication: It ensures both calls use the same destination reportID, but each call still independently generates its own buildOptimisticReportPreview action (line 466) and SETs the report data (line 481). The sharedRejectedToReportID mechanism was designed to share the ID but not to coordinate which call "owns" the report creation.
Confidence: High — the async Onyx update timing and duplicate REPORTPREVIEW generation are clearly visible in the code path.
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.
changed the title [-]Expense - Duplicate report with rejected expenses[/-][+][$250] Expense - Duplicate report with rejected expenses[/+]on Apr 17, 2026
⚠️@aswin-s Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).
When the admin selects 2 of 3 expenses and bulk-rejects from the expense report view (via SelectionToolbar), the app navigates to SearchRejectReasonPage.tsx, which calls rejectMoneyRequestsOnSearch in src/libs/actions/Search.ts. Because fewer than all expenses are selected, the code at lines 1244–1249 runs a synchronous for loop, calling rejectMoneyRequest() once per selected transaction with a shared sharedRejectedToReportID.
The problem is that both iterations of the loop run in the same JavaScript execution frame. The allReports module-level variable in src/libs/actions/IOU/index.ts is updated via an Onyx.connect() callback, which fires asynchronously — after the current call stack completes. So when the second rejectMoneyRequest() call reads getAllReports() and checks for existingOpenReport (lines 349–356 of RejectMoneyRequest.ts), the optimistically created report from the first call is not yet reflected in allReports. Both calls fall through to the else branch at line 433 and both enter the "create new report" path with the same rejectedToReportID.
Each call issues its own API.write(REJECT_MONEY_REQUEST, ...) with a unique reportPreviewReportActionID (line 860) and unique createdIOUReportActionID/expenseCreatedReportActionID. The server interprets each as a separate "create expense report + add preview to workspace chat" operation, resulting in two distinct reports. Additionally, the second call's Onyx.METHOD.SET (line 481) destructively overwrites the first call's optimistic report data, so local state only reflects the second transaction.
What changes do you think we should make in order to solve the problem?
src/libs/actions/Search.ts — in the for loop (lines 1247–1249), track iteration index and pass a new isFirstInBatch: boolean flag to each rejectMoneyRequest call: true only for the first iteration, false for all subsequent ones.
src/libs/actions/IOU/RejectMoneyRequest.ts — add isFirstInBatch?: boolean to the options type on the prepareRejectMoneyRequestData and rejectMoneyRequest signatures (lines 109 and 878).
src/libs/actions/IOU/RejectMoneyRequest.ts — in the else branch at line 433, when sharedRejectedToReportID is provided and isFirstInBatch === false, skip buildOptimisticExpenseReport, skip creating a new reportPreviewAction (line 466), use Onyx.METHOD.MERGE instead of SET for the report key (line 481), and omit reportPreviewReportActionID/expenseCreatedReportActionID from the API parameters. The second and later calls should only carry their own transactionID, iouAction, and childReportID update — effectively the same "add to existing report" path as lines 376–432 but targeting the shared destination reportID.
This ensures only the first API call creates the report and the preview in the workspace chat; subsequent calls in the same batch simply add their transaction to it.
What alternative solutions did you explore? (Optional)
An alternative is to introduce a new server endpoint that accepts an array of transaction IDs and rejects them atomically, eliminating the loop entirely. This is more robust but requires a backend change and is a larger scope. The chosen approach is a targeted client-side fix that works within the existing REJECT_MONEY_REQUEST endpoint by ensuring only one "create report" payload is sent per batch.
Edge cases the fix must handle:
Offline state: API.write() queues requests; the fix must ensure the merged optimistic data for the shared report is consistent so rollback on failure reverts both transactions correctly.
Single-transaction rejection (no sharedRejectedToReportID supplied, e.g., from RejectReasonPage.tsx): the new isFirstInBatch flag defaults to true/undefined, leaving that path unchanged.
⚠️@Yatin-Bhatti 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.
Please re-state the problem that we are trying to solve in this issue.
Expense - Duplicate report with rejected expenses
What is the root cause of that problem?
In the search rejection flow, we generate one shared rejectedToReportID, but we still call rejectMoneyRequest() once per selected transaction inside a synchronous loop:
If no open report is found, the code falls into the "create new report" branch, where it creates a new optimistic expense report, a new REPORTPREVIEW action, and the related optimistic data for the destination report:
The issue is that both rejections run in the same JS turn, while the optimistic Onyx update from the first rejection is not yet available through allReports when the second rejection executes. As a result, the second call does not see the optimistic destination report created by the first call, falls into the same "create new report" branch, and creates a second REPORTPREVIEW entry for the same shared destination.
So the bug is not that sharedRejectedToReportID is missing. The bug is that the second iteration has no synchronous access to the optimistic rejected report object created by the first iteration.
What changes do you think we should make in order to solve the problem?
We should keep the fix local to the existing sequential reject flow and pass the optimistic rejected report forward in memory during the loop, instead of waiting for allReports to catch up.
1. Reuse one shared options object across the whole rejection loop
This keeps one mutable object alive for the whole batch. The first rejection can store the optimistic rejected report on it, and later rejections can reuse that exact object immediately.
2. Teach rejectMoneyRequest() to prefer the in-memory optimistic rejected report before reading allReports
If the first iteration already created an optimistic rejected report, the second iteration should use that object directly instead of relying on allReports, which is still stale at that moment.
3. Store the optimistic rejected report into the shared options object as soon as it is known
Apply this change in both branches that determine the destination rejected report:
The first rejection writes the optimistic destination report into the shared options object immediately. The second rejection then reuses it and takes the existing-report path, which prevents another REPORTPREVIEW from being created.
Why this approach is the best fit
This is a small, low-risk fix because it:
keeps the current API contract and reject flow intact
only changes the delayed-submission multi-reject path
solves the stale-state race at the point where it happens
follows an existing codebase pattern where optimistic report objects are passed forward locally during sequential operations
What alternative solutions did you explore? (Optional)
@mananjadhav 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]
@nabi-ebrahimi can you please accept the job below? Please reply here and tag me once you have.
If you're not sent an offer in Upwork when you're assigned to an issue, please tag me. If an Upwork job exists, please submit a proposal. https://www.upwork.com/jobs/~022062321553178426298
@mananjadhav plz complete the BZ checklist and tag me in a post once you have. Thx
[Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
[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: NA
[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.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
MelvinBot commentedon Apr 17, 2026
Proposal
What is the root cause of that problem?
When rejecting 2 of 3 expenses from a report with delayed submission enabled,
rejectMoneyRequestsOnSearch(Search.ts:1244-1249) generates a singlesharedRejectedToReportIDand callsrejectMoneyRequestin a synchronous for-loop — one call per expense.Each call runs
prepareRejectMoneyRequestData, which looks upallReportsfor anexistingOpenReportto reuse. However,API.write()applies Onyx optimistic data asynchronously, so the second call still reads staleallReportsand doesn't see the optimistic report created by the first call. Both calls fall into the "create new report" branch.While
sharedRejectedToReportIDensures both calls target the same report ID, each call independently creates its ownREPORTPREVIEWaction and MERGEs it into the workspace chat's report actions. TwoREPORTPREVIEWactions in the same workspace chat render as two separate report entries in the UI — the duplicate reports.Additionally, the second
Onyx.METHOD.SETon the same report key overwrites the first, so the report'sparentReportActionIDonly points to the secondREPORTPREVIEW.What changes do you think we should make in order to solve the problem?
In
prepareRejectMoneyRequestData, whensharedRejectedToReportIDis provided and noexistingOpenReportis found, only the first call (the one that creates the report) should generate theREPORTPREVIEWaction and theOnyx.METHOD.SETfor the new report. Subsequent calls using the samesharedRejectedToReportIDshould skip report creation andREPORTPREVIEWgeneration, and instead only add their transaction to the already-created destination report (similar to theexistingOpenReportbranch at line 358).Concretely: track whether the report for
sharedRejectedToReportIDhas already been optimistically created (e.g., via a shared mutable flag or by building the optimistic report once inrejectMoneyRequestsOnSearchand passing it down). When the flag is set, the second call should take theexistingOpenReportpath — reuse the report and skipREPORTPREVIEW+SETcreation.What alternative solutions did you explore? (Optional)
An alternative is to batch all transactions into a single
API.writecall (similar torejectMoneyRequestInBulk), consolidating optimistic data so only oneREPORTPREVIEWis ever created. This is cleaner but is a larger change — the current per-transaction loop exists becauserejectMoneyRequestInBulkonly handles the "all expenses selected" case with different server-side semantics.Investigation details
Key code path:
rejectMoneyRequestsOnSearch— generatessharedRejectedToReportID, loops callingrejectMoneyRequestper transactionprepareRejectMoneyRequestData— readsallReports(stale on second iteration)existingOpenReportlookup — fails to find optimistic report from first callWhy
sharedRejectedToReportIDdoesn't fully prevent duplication: It ensures both calls use the same destination reportID, but each call still independently generates its ownbuildOptimisticReportPreviewaction (line 466) and SETs the report data (line 481). ThesharedRejectedToReportIDmechanism was designed to share the ID but not to coordinate which call "owns" the report creation.Confidence: High — the async Onyx update timing and duplicate REPORTPREVIEW generation are clearly visible in the code path.
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 17, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @mananjadhav (
External)[-]Expense - Duplicate report with rejected expenses[/-][+][$250] Expense - Duplicate report with rejected expenses[/+]melvin-bot commentedon Apr 17, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022045238445165917906
github-actions commentedon Apr 17, 2026
aswin-s commentedon Apr 17, 2026
Proposal
What is the root cause of that problem?
When the admin selects 2 of 3 expenses and bulk-rejects from the expense report view (via
SelectionToolbar), the app navigates toSearchRejectReasonPage.tsx, which callsrejectMoneyRequestsOnSearchinsrc/libs/actions/Search.ts. Because fewer than all expenses are selected, the code at lines 1244–1249 runs a synchronousforloop, callingrejectMoneyRequest()once per selected transaction with a sharedsharedRejectedToReportID.The problem is that both iterations of the loop run in the same JavaScript execution frame. The
allReportsmodule-level variable insrc/libs/actions/IOU/index.tsis updated via anOnyx.connect()callback, which fires asynchronously — after the current call stack completes. So when the secondrejectMoneyRequest()call readsgetAllReports()and checks forexistingOpenReport(lines 349–356 ofRejectMoneyRequest.ts), the optimistically created report from the first call is not yet reflected inallReports. Both calls fall through to theelsebranch at line 433 and both enter the "create new report" path with the samerejectedToReportID.Each call issues its own
API.write(REJECT_MONEY_REQUEST, ...)with a uniquereportPreviewReportActionID(line 860) and uniquecreatedIOUReportActionID/expenseCreatedReportActionID. The server interprets each as a separate "create expense report + add preview to workspace chat" operation, resulting in two distinct reports. Additionally, the second call'sOnyx.METHOD.SET(line 481) destructively overwrites the first call's optimistic report data, so local state only reflects the second transaction.App/src/libs/actions/Search.ts
Lines 1244 to 1249 in c05060c
What changes do you think we should make in order to solve the problem?
src/libs/actions/Search.ts— in theforloop (lines 1247–1249), track iteration index and pass a newisFirstInBatch: booleanflag to eachrejectMoneyRequestcall:trueonly for the first iteration,falsefor all subsequent ones.src/libs/actions/IOU/RejectMoneyRequest.ts— addisFirstInBatch?: booleanto theoptionstype on theprepareRejectMoneyRequestDataandrejectMoneyRequestsignatures (lines 109 and 878).src/libs/actions/IOU/RejectMoneyRequest.ts— in theelsebranch at line 433, whensharedRejectedToReportIDis provided andisFirstInBatch === false, skipbuildOptimisticExpenseReport, skip creating a newreportPreviewAction(line 466), useOnyx.METHOD.MERGEinstead ofSETfor the report key (line 481), and omitreportPreviewReportActionID/expenseCreatedReportActionIDfrom the API parameters. The second and later calls should only carry their owntransactionID,iouAction, andchildReportIDupdate — effectively the same "add to existing report" path as lines 376–432 but targeting the shared destination reportID.This ensures only the first API call creates the report and the preview in the workspace chat; subsequent calls in the same batch simply add their transaction to it.
What alternative solutions did you explore? (Optional)
An alternative is to introduce a new server endpoint that accepts an array of transaction IDs and rejects them atomically, eliminating the loop entirely. This is more robust but requires a backend change and is a larger scope. The chosen approach is a targeted client-side fix that works within the existing
REJECT_MONEY_REQUESTendpoint by ensuring only one "create report" payload is sent per batch.Edge cases the fix must handle:
API.write()queues requests; the fix must ensure the merged optimistic data for the shared report is consistent so rollback on failure reverts both transactions correctly.sharedRejectedToReportIDsupplied, e.g., fromRejectReasonPage.tsx): the newisFirstInBatchflag defaults totrue/undefined, leaving that path unchanged.Yatin-Bhatti commentedon Apr 18, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
github-actions commentedon Apr 18, 2026
nabi-ebrahimi commentedon Apr 18, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
Expense - Duplicate report with rejected expenses
What is the root cause of that problem?
In the search rejection flow, we generate one shared
rejectedToReportID, but we still callrejectMoneyRequest()once per selected transaction inside a synchronous loop:App/src/libs/actions/Search.ts
Lines 1242 to 1248 in 03023c1
Then, inside
prepareRejectMoneyRequestData(), each call looks for an already-open destination report by readingallReports:App/src/libs/actions/IOU/RejectMoneyRequest.ts
Lines 349 to 356 in 03023c1
If no open report is found, the code falls into the "create new report" branch, where it creates a new optimistic expense report, a new
REPORTPREVIEWaction, and the related optimistic data for the destination report:App/src/libs/actions/IOU/RejectMoneyRequest.ts
Lines 433 to 513 in 03023c1
The issue is that both rejections run in the same JS turn, while the optimistic Onyx update from the first rejection is not yet available through
allReportswhen the second rejection executes. As a result, the second call does not see the optimistic destination report created by the first call, falls into the same "create new report" branch, and creates a secondREPORTPREVIEWentry for the same shared destination.So the bug is not that
sharedRejectedToReportIDis missing. The bug is that the second iteration has no synchronous access to the optimistic rejected report object created by the first iteration.What changes do you think we should make in order to solve the problem?
We should keep the fix local to the existing sequential reject flow and pass the optimistic rejected report forward in memory during the loop, instead of waiting for
allReportsto catch up.1. Reuse one shared options object across the whole rejection loop
Apply this change at:
Search.ts#L1245-L1248
2. Teach
rejectMoneyRequest()to prefer the in-memory optimistic rejected report before readingallReportsApply this change around:
RejectMoneyRequest.ts#L349-L356
allReports, which is still stale at that moment.3. Store the optimistic rejected report into the shared options object as soon as it is known
Apply this change in both branches that determine the destination rejected report:
RejectMoneyRequest.ts#L358-L398
RejectMoneyRequest.ts#L442-L513
movedToReport = { ...existingOpenReport, total: (existingOpenReport?.total ?? 0) - transactionAmount, }; + if (options) { + options.existingRejectedReport = movedToReport; + }const newExpenseReport = buildOptimisticExpenseReport({...}); newExpenseReport.parentReportActionID = reportPreviewAction.reportActionID; + if (options) { + options.existingRejectedReport = newExpenseReport; + }REPORTPREVIEWfrom being created.Why this approach is the best fit
This is a small, low-risk fix because it:
What alternative solutions did you explore? (Optional)
Demo
88236.mov
30 remaining items
melvin-bot commentedon May 27, 2026
@mananjadhav 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]
melvin-bot commentedon Jun 1, 2026
@mananjadhav Huh... This is 4 days overdue. Who can take care of this?
melvin-bot commentedon Jun 2, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Jun 2, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon Jun 3, 2026
Payment Summary
Contributor: @nabi-ebrahimi paid $250 via Upwork
Contributor+: @mananjadhav due $250 via NewDot
@nabi-ebrahimi can you please accept the job below? Please reply here and tag me once you have.
If you're not sent an offer in Upwork when you're assigned to an issue, please tag me. If an Upwork job exists, please submit a proposal.
https://www.upwork.com/jobs/~022062321553178426298
@mananjadhav plz complete the BZ checklist and tag me in a post once you have. Thx
nabi-ebrahimi commentedon Jun 4, 2026
@mallenexpensify, the offer accepted. thanks.
mallenexpensify commentedon Jun 4, 2026
@nabi-ebrahimi paid, summary updated above. Thx.
@mananjadhav plz complete the BZ checklist and tag me in a post once you have. Thx
mananjadhav commentedon Jun 5, 2026
BugZero Checklist:
[Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to the comment on the PR: https://github.com/Expensify/App/pull/62787/changes#r3361367666
Link to the comment on the Issue:
[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: NA
[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.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue: https://github.com/Expensify/Expensify/issues/645971
Regression Test Proposal
Precondition:
Test:
Do we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-32b8-a8ac-0254-fe801fb373e4mananjadhav commentedon Jun 5, 2026
@mallenexpensify Checklist completed.
garrettmknight commentedon Jun 10, 2026
$250 approved for @mananjadhav