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
Quantity and total in a row of the "Unapproved card" search is wrong #84235
Version Number: v9.3.31-1 Reproducible in staging?: Yes Reproducible in production?: No If this was caught during regression testing, add the test name, ID and link from BrowserStack:#83567 Email or phone of affected tester (no customers):applausetester+ag040326@applause.expensifail.com Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Windows 11/ Chrome, iPhone 13 Mini/ iOS 26.3 App Component: Search
Action Performed:
Precondition: Have a company card feed added, and assign a card to any workspace member.
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
Identify the pull request that introduced this issue and revert it.
Classification: Backend bug Causing PR: #83567 - "Add unreported status to unapproved cards" by @JS00001 (High confidence) Related Issues: #83562 (original issue that PR 83567 was fixing)
Recommendation: REVERT
PR #83567 added UNREPORTED status to the Unapproved Card search query. While the frontend change itself is correct (it allows unreported card transactions to appear in the search), it has exposed a backend bug where the API returns incorrect aggregated count and total values for card groups when unreported transactions are included.
The issue is only reproducible on staging (not production), confirming that PR #83567 introduced or exposed this regression.
Labels: Removing DeployBlockerCash label since this is a backend bug. The DeployBlocker label should remain to block the backend/Web deploy until the API aggregation logic is fixed.
Detailed Analysis
Evidence
The bug reproduction steps involve moving card transactions to a new report and then deleting that report, which puts the transactions into UNREPORTED status
PR #83567 modified src/libs/SearchUIUtils.ts line 762 to add CONST.SEARCH.STATUS.EXPENSE.UNREPORTED to the status filter for the Unapproved Card suggested search.
Root Cause
The issue is in the backend API, not the App code:
SearchCardGroup type (in src/types/onyx/SearchResults.ts) defines count and total fields that come from the backend API
CardListItemHeader component displays these values directly from the API response
However, the backend is incorrectly calculating the aggregated count and total for card groups when unreported transactions are present
The frontend correctly displays what the backend returns - the bug is that the backend API is returning wrong aggregated values for card groups containing unreported transactions.
Why this is a backend bug:
The App PR only changed the search query parameters (which statuses to include)
The aggregation logic that calculates count and total happens on the backend/API
The frontend has no way to fix incorrect aggregated values returned by the API
The fix needs to happen in the backend code that processes Search API requests and calculates group aggregations
Please re-state the problem that we are trying to solve in this issue.
When viewing the "Unapproved card" search (which groups expenses by card), the collapsed card group row shows the wrong count (3 instead of 5) and wrong total ($3,078.50 instead of $4,078.50). However, expanding the row correctly displays all 5 transactions. This started happening after PR #83567 added the UNREPORTED status to the "Unapproved card" search filter.
What is the root cause of that problem?
The root cause is a server-side aggregation mismatch. Here's the evidence chain:
The count and total are computed on the server, not the client. The API returns pre-aggregated count and total fields inside SearchCardGroup objects (keyed with group_ prefix in the response). The client code in getCardSections() (src/libs/SearchUIUtils.ts:2445-2492) simply spreads ...cardGroup directly from the API response — no client-side recalculation.
The expanded view uses a separate API call that works correctly. When a user expands a card group, buildSpecificGroupQuery() (src/libs/SearchUIUtils.ts:2381-2386) builds a new flat query that keeps status=[unreported, drafts, outstanding], removes groupBy, and adds cardID=X. This flat query correctly returns all 5 individual transactions.
The discrepancy is between the server's GROUP BY aggregation and the flat query. The backend's GROUP BY aggregation (which computes count/total for each card group) is not properly including UNREPORTED transactions in its calculation. The flat individual-transaction query does include them. This is why the collapsed header shows 3/$3,078.50 while expanding shows 5/$4,078.50.
PR #83567 changed the client-side search query to include UNREPORTED status (src/libs/SearchUIUtils.ts:765), but the server-side GROUP BY aggregation code path was likely not updated to account for this new status in its totals computation.
What changes do you think we should make in order to solve the problem?
This requires a server-side fix. The backend search handler that processes groupBy=card queries needs to include transactions with UNREPORTED status in its GROUP BY aggregation (count and total computation). The server-side code that generates SearchCardGroup entries should use the same status filter criteria for both:
The GROUP BY aggregation (count/total per card)
The individual transaction listing (when the group is expanded)
The App (client) code is working correctly — it faithfully displays what the server returns and correctly passes the status=[unreported, drafts, outstanding] filter in the search query.
What alternative solutions did you explore? (Optional)
Client-side workaround (not recommended): The client could recalculate count/total from the expanded transactions after they are loaded. However, this would only fix the numbers after expansion, not on initial load, and would create inconsistency between the initial and post-expansion states. The proper fix is to correct the server-side aggregation.
Reverting PR #83567 (temporary mitigation): If an immediate fix is needed for the deploy blocker, reverting the addition of UNREPORTED to the unapproved card search would restore consistent (but incomplete) behavior — the group count/total would match the displayed transactions, but UNREPORTED transactions would be excluded entirely. This was the original behavior before the fix for issue #83562.
Next Steps for Contributor+ team: This is a server-side bug in the Search API's GROUP BY aggregation. The backend team should investigate the search endpoint's aggregation query to ensure it includes UNREPORTED status transactions when computing group-level count and total. Reply with @MelvinBot <your feedback> to refine this analysis.
Activity
melvin-bot commentedon Mar 5, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #83567
melvin-bot commentedon Mar 5, 2026
💬 A slack conversation has been started in #expensify-open-source
melvin-bot commentedon Mar 5, 2026
Triggered auto assignment to @joekaufmanexpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.github-actions commentedon Mar 5, 2026
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
OSBotify commentedon Mar 5, 2026
Investigation Summary
Classification: Backend bug
Causing PR: #83567 - "Add unreported status to unapproved cards" by @JS00001 (High confidence)
Related Issues: #83562 (original issue that PR 83567 was fixing)
Recommendation: REVERT
PR #83567 added
UNREPORTEDstatus to the Unapproved Card search query. While the frontend change itself is correct (it allows unreported card transactions to appear in the search), it has exposed a backend bug where the API returns incorrect aggregatedcountandtotalvalues for card groups when unreported transactions are included.The issue is only reproducible on staging (not production), confirming that PR #83567 introduced or exposed this regression.
Labels: Removing
DeployBlockerCashlabel since this is a backend bug. TheDeployBlockerlabel should remain to block the backend/Web deploy until the API aggregation logic is fixed.Detailed Analysis
Evidence
UNREPORTEDstatusUNREPORTEDstatus to the unapproved card search queryVerification
PR #83567 modified
src/libs/SearchUIUtils.tsline 762 to addCONST.SEARCH.STATUS.EXPENSE.UNREPORTEDto the status filter for the Unapproved Card suggested search.Root Cause
The issue is in the backend API, not the App code:
SearchCardGrouptype (insrc/types/onyx/SearchResults.ts) definescountandtotalfields that come from the backend APICardListItemHeadercomponent displays these values directly from the API responseUNREPORTEDstatus to the query, the backend API began including unreported transactions in the resultsThe frontend correctly displays what the backend returns - the bug is that the backend API is returning wrong aggregated values for card groups containing unreported transactions.
Why this is a backend bug:
MelvinBot commentedon Mar 5, 2026
🔍 Issue Analysis
Please re-state the problem that we are trying to solve in this issue.
When viewing the "Unapproved card" search (which groups expenses by card), the collapsed card group row shows the wrong count (3 instead of 5) and wrong total ($3,078.50 instead of $4,078.50). However, expanding the row correctly displays all 5 transactions. This started happening after PR #83567 added the
UNREPORTEDstatus to the "Unapproved card" search filter.What is the root cause of that problem?
The root cause is a server-side aggregation mismatch. Here's the evidence chain:
The count and total are computed on the server, not the client. The API returns pre-aggregated
countandtotalfields insideSearchCardGroupobjects (keyed withgroup_prefix in the response). The client code ingetCardSections()(src/libs/SearchUIUtils.ts:2445-2492) simply spreads...cardGroupdirectly from the API response — no client-side recalculation.The header renders these server values verbatim.
CardListItemHeader(src/components/SelectionListWithSections/Search/CardListItemHeader.tsx:101-119) rendersString(cardItem.count)andTotalCell({ total: cardItem.total })directly.The expanded view uses a separate API call that works correctly. When a user expands a card group,
buildSpecificGroupQuery()(src/libs/SearchUIUtils.ts:2381-2386) builds a new flat query that keepsstatus=[unreported, drafts, outstanding], removesgroupBy, and addscardID=X. This flat query correctly returns all 5 individual transactions.The discrepancy is between the server's GROUP BY aggregation and the flat query. The backend's GROUP BY aggregation (which computes
count/totalfor each card group) is not properly includingUNREPORTEDtransactions in its calculation. The flat individual-transaction query does include them. This is why the collapsed header shows 3/$3,078.50 while expanding shows 5/$4,078.50.PR #83567 changed the client-side search query to include
UNREPORTEDstatus (src/libs/SearchUIUtils.ts:765), but the server-side GROUP BY aggregation code path was likely not updated to account for this new status in its totals computation.What changes do you think we should make in order to solve the problem?
This requires a server-side fix. The backend search handler that processes
groupBy=cardqueries needs to include transactions withUNREPORTEDstatus in its GROUP BY aggregation (count and total computation). The server-side code that generatesSearchCardGroupentries should use the same status filter criteria for both:The App (client) code is working correctly — it faithfully displays what the server returns and correctly passes the
status=[unreported, drafts, outstanding]filter in the search query.What alternative solutions did you explore? (Optional)
Client-side workaround (not recommended): The client could recalculate count/total from the expanded transactions after they are loaded. However, this would only fix the numbers after expansion, not on initial load, and would create inconsistency between the initial and post-expansion states. The proper fix is to correct the server-side aggregation.
Reverting PR #83567 (temporary mitigation): If an immediate fix is needed for the deploy blocker, reverting the addition of
UNREPORTEDto the unapproved card search would restore consistent (but incomplete) behavior — the group count/total would match the displayed transactions, butUNREPORTEDtransactions would be excluded entirely. This was the original behavior before the fix for issue #83562.Next Steps for Contributor+ team: This is a server-side bug in the Search API's GROUP BY aggregation. The backend team should investigate the search endpoint's aggregation query to ensure it includes
UNREPORTEDstatus transactions when computing group-levelcountandtotal. Reply with@MelvinBot <your feedback>to refine this analysis.JS00001 commentedon Mar 5, 2026
Not a blocker, but PR open to fix
luacmartins commentedon Mar 6, 2026
PR merged and deployed.
luacmartins commentedon Mar 6, 2026
We can close this one