App icon indicating copy to clipboard operation
App copied to clipboard

Infinite loading when filter reports which has more than 50 expenses in them

Open applause-bot[bot] opened this issue 3 months ago • 30 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.56-0 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://github.com/Expensify/App/pull/98556 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Windows 11 / Chrome App Component: Search

Action Performed:

Precondition : Create 50+ reports and each report must have 50+ expenses in them and they are in draft state

  1. Open staging.new.expensify
  2. Go to spend > Reports
  3. Click on filter and apply draft status filter

Expected Result:

Page should show draft status filter applied

Actual Result:

Infinite loading when filter reports with draft status

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/04cf503b-df05-4a68-874e-55da2ea2d5be

View all open jobs on GitHub

Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7237253

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Aug 19 '26 13:08 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/202160b7829b099440f6b432ad830f1f86c58e75379223e26d6a0206d3261bf5

applause-bot[bot] avatar Aug 19 '26 13:08 applause-bot[bot]

⚠️ Medium-confidence analysis. The root-cause category (client-side cost of rendering a very large draft-report snapshot) is well-supported by code; the exact dominant mechanism should be confirmed with a perf trace / logs before implementing (see caveat at the bottom).

Proposal

What is the root cause of that problem?

This is a scale/performance problem, not a logic bug — which is why it only reproduces with 50+ reports × 50+ draft expenses.

A draft report search is the worst possible case for payload size: draft reports carry all of their unsubmitted transactions, so the snapshot returned for this query contains ~2,500 transactions plus their report actions and violations. The client then does a large amount of synchronous work over that entire snapshot on the main thread:

  1. The Reports view (EXPENSE_REPORT data type) is assembled by getReportSections, which loops over every transaction key in the snapshot and runs heavy per-item work (report lookup, violations, actions, formatting) for all ~2,500 transactions — regardless of the status filter.
  2. That assembly runs inside a useMemo that re-fires on every Onyx change while the large snapshot is still streaming/merging in, so the multi-hundred-ms pass runs repeatedly.
  3. Merging the ~2,500-transaction response into Onyx is itself expensive, and the terminal "loaded" flag that clears the skeleton is written after that merge.

The net effect is the JS thread stays pegged and the skeleton never visibly clears → "infinite loading." The loading flag itself is not structurally stuck (it has a valid path to false), which is why this presents as a spinner that never resolves rather than an error.

Code references (App @ 0f5a2b3)

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

Reduce the client-side cost of the draft-reports render so the main thread frees up and the skeleton clears:

  1. Skip work for filtered-out items. In getReportSections, apply the status/eligibility check before the expensive per-transaction formatting so transactions belonging to reports that won't be shown aren't fully processed.
  2. Stop re-running the full projection while data streams in. Stabilize / debounce the getReportSections useMemo so it doesn't recompute over thousands of transactions on every intermediate Onyx write, or memoize per-transaction results so only changed rows are reprocessed.
  3. Confirm pagination is bounded. Verify the reports+draft snapshot is paginated server-side rather than returning all transactions at once — an unbounded page multiplies both the Onyx merge cost and the per-render loop.

What alternative solutions did you explore? (Optional)

The other candidate is a backend Search request that never settles for large draft sets: isLoading is cleared only by finallyData/failureData, and there's no client-side timeout for the SEARCH command, so a promise that never resolves would leave the spinner stuck. I consider this less likely because (a) a normal timeout/5xx would settle and surface an error rather than spin forever, and (b) the bug is deterministically reproducible in both staging and production, which points to a client-side scaling limit rather than an intermittent backend hang. This can't be fully ruled out from code alone.

Confidence caveat — recommended confirmation

I could not pull production logs in this run (VictoriaLogs was unavailable to the log agent). Before implementing, confirm the mechanism with one of:

  • A web perf trace of the repro: if the JS main thread is pegged inside getReportSections/Onyx merge while the network request has already returned 200, that confirms the client-side hypothesis above.
  • Logs for the Search READ command on this query (tester account [email protected]): if the request returns quickly with 200, backend hang is ruled out; if it shows very high latency / no completion / 555/460, the backend path deserves attention instead.

I did not run the app tester because the precondition (50+ reports × 50+ draft expenses each) can't be provisioned in a fresh test session.


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

MelvinBot avatar Aug 19 '26 13:08 MelvinBot

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

melvin-bot[bot] avatar Aug 19 '26 13:08 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022090069739728752715

melvin-bot[bot] avatar Aug 19 '26 13:08 melvin-bot[bot]

Quick thing I wanted to check while reading through Melvin's proposal, Wouldn't the actual cost be coming from the transaction branch rather than the report branch?

The report-level shouldShow check already runs before the expensive formatting, so filtered-out reports skip that cost fine. But for transactions, it looks like every single one gets fully processed (violations, formatted amounts, actions lookup, all of it) and only afterwards does the code check whether its report made it into the results. So a transaction belonging to a filtered-out report still pays the full cost, it just gets thrown away at the end instead of never being processed in the first place. With 2500+ transactions and most reports not matching "draft," that seems like it'd account for most of the slowdown.

If that's right, moving that check earlier should be safe, report keys are always processed before transaction keys in this function, so the check would give the same answer sooner.

Wanted to flag this just in case.

Sidsmartz avatar Aug 19 '26 20:08 Sidsmartz

@rojiphil Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Aug 24 '26 21:08 melvin-bot[bot]

@rojiphil Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Aug 26 '26 21:08 melvin-bot[bot]

@jponikarchuk Can you please share again the test video for this issue along with the inspect ->Network tab as demonstrated below? I am curious if you are referring to the same delay that I am observing.

https://github.com/user-attachments/assets/ba57a445-7c5d-4df6-9232-9b77e3ac306a

rojiphil avatar Aug 27 '26 13:08 rojiphil

@rojiphil Here is the issue retest

https://github.com/user-attachments/assets/7eb7253d-1fea-432b-b98f-8dd562f28d18

jponikarchuk avatar Aug 27 '26 18:08 jponikarchuk

@rojiphil Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Sep 01 '26 21:09 melvin-bot[bot]

@rojiphil this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] avatar Sep 02 '26 21:09 melvin-bot[bot]

@rojiphil 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Sep 03 '26 23:09 melvin-bot[bot]

@rojiphil Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Sep 04 '26 01:09 melvin-bot[bot]

@rojiphil Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Sep 04 '26 02:09 melvin-bot[bot]

@MelvinBot The issue can be reproduced if we duplicate draft reports (50 reports × 50 expenses, freshly created — means roughly 2,500 sequential round-trips ahead of the search) and immediately apply a search filter for draft reports. This will display the loading skeleton until all of the duplicate reports are created. Please analyse and propose a solution for this.

rojiphil avatar Sep 06 '26 15:09 rojiphil

rojiphil — your repro changes the root cause. It isn't render cost, it's request ordering: the search is never sent while the duplicates are still uploading.

Proposal

What is the root cause of that problem?

search() parks on the write queue before it dispatches anything. It calls waitForWrites(READ_COMMANDS.SEARCH), which is SequentialQueue.waitForIdle() — it resolves only when every persisted write has responded.

Duplicating 50 reports × 50 expenses enqueues one persisted write per expense (~2,500), and the sequential queue sends them one at a time. So the SEARCH read leaves the client only after the last duplicate responds — minutes later.

While it waits there is no snapshot for the new hash, so isDataLoaded is false and the skeleton stays up. Nothing is stuck and nothing errors: no request has been sent yet, so there is nothing to time out. That matches the symptom exactly — the skeleton clears the moment duplication finishes.

Code references (App @ 0283d2b)

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

Make the wait bounded instead of unbounded, in search():

  1. Cap the queue wait. Race waitForWrites() against a short timeout (or a getPersistedRequestsLength() threshold) and dispatch the SEARCH read when it expires. Normal queues keep today's ordering guarantee; a 2,500-write queue no longer holds the UI hostage.
  2. Re-fire once the queue drains. Chain a second search() off waitForIdle() for the same hash so the list picks up the server-created duplicates. The existing in-flight dedupe keeps this to one extra request.
  3. Make the wait legible. While the search is parked, show a syncing state rather than a bare skeleton, so the user can tell progress from a hang.

Safety of firing early is already documented at Search.ts:1146-1152 — a search response writes only snapshot_<hash> keys, so it can't clobber a pending write's optimistic data. The one thing to verify while implementing: optimistic rows that IOU actions fan into the snapshot must survive the response merge (they should, since the response is an Onyx.merge).

The durable fix is a single backend command that duplicates a selection, which the code comment above already anticipates — that removes 2,500 round-trips instead of racing them. That's outside the App repo, so it needs an internal engineer.

What alternative solutions did you explore? (Optional)

Options considered and why they lose
  • Always pass skipWaitForWrites on the Search page. Simplest, but drops the ordering guarantee for every search, not just pathological ones. The bounded wait gets the same result with a smaller blast radius.
  • Client-side timeout/abort for SEARCH. Surfaces an error instead of a spinner, but still returns no data — the request was never sent.
  • Batch or parallelize the write queue. Would help every blocked read, but conflict resolution and retry ordering make it a much larger change.
  • My earlier render-cost analysis (and Sidsmartz's point about the transaction branch in getReportSections). That cost is real and worth fixing separately, but it can't explain a skeleton whose duration tracks the duplication run exactly. Treat it as a follow-up, not this bug.
Verification note

I did not run the app tester: reproducing this needs ~2,500 queued writes, which can't be provisioned in a fresh test session. The mechanism is read directly from the code path above. To confirm in production, check the SearchData.queue span — it measures exactly this wait.


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

MelvinBot avatar Sep 06 '26 15:09 MelvinBot

@rojiphil Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Sep 09 '26 21:09 melvin-bot[bot]

@rojiphil Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Sep 11 '26 21:09 melvin-bot[bot]

@rojiphil 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

melvin-bot[bot] avatar Sep 15 '26 21:09 melvin-bot[bot]

@rojiphil this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

melvin-bot[bot] avatar Sep 16 '26 21:09 melvin-bot[bot]