Repository navigation
Description
Split from https://github.com/Expensify/Expensify/issues/618149
Problem
When Onyx.clear() is called (e.g., via the RESET_REQUIRED listener), the PERSISTED_REQUESTS queue — which holds all offline API requests waiting to sync — is wiped because it is not in the KEYS_TO_PRESERVE list. This causes permanent loss of offline-created expenses that were never synced to the server.
Customers are reporting missing expenses after app updates. Investigation confirms these expenses were created offline and existed only in the Onyx cache / SequentialQueue.
Root Cause
There are three data loss vectors:
1. RESET_REQUIRED listener wipes offline queue
The listener at App.ts:154-168 calls Onyx.clear(KEYS_TO_PRESERVE) then openApp() without saving/restoring the SequentialQueue.
Contrast with clearOnyxAndResetApp() at App.ts:827-876 which correctly snapshots the queue first:
function clearOnyxAndResetApp() {
const sequentialQueue = getAll(); // ← Saves queue first
rollbackOngoingRequest();
Onyx.clear(KEYS_TO_PRESERVE).then(() => {
openApp().then(() => {
for (const request of sequentialQueue) { save(request); } // ← Restores queue
});
});
}2. Full reconnect replaces local state
When the server returns previousUpdateID=0 (triggered when clientUpdateID is stale or -1), a Pusher ReconnectApp event causes a full state replacement from the server — which knows nothing about expenses that were never synced.
3. Processing window vulnerability
In PersistedRequests.ts:255-284, when a request starts processing, it's removed from PERSISTED_REQUESTS and held only in memory. Expense creation commands do not set persistWhenOngoing, so if the app is killed during this window, the request is lost.
Recommended Fix
-
Add
ONYXKEYS.PERSISTED_REQUESTSandONYXKEYS.PERSISTED_ONGOING_REQUESTSto theKEYS_TO_PRESERVElist inApp.ts:122-146, OR modify theRESET_REQUIREDlistener to snapshot/restore the queue the same wayclearOnyxAndResetApp()already does. -
Set
persistWhenOngoing: truefor expense creation commands (REQUEST_MONEY,TRACK_EXPENSE,SPLIT_BILL_AND_OPEN_REPORT, etc.) so in-flight requests survive app kills.
Relevant Code
App.ts:122-168—KEYS_TO_PRESERVElist +RESET_REQUIREDlistenerApp.ts:827-876—clearOnyxAndResetApp(correct pattern for queue preservation)PersistedRequests.ts:107-147,255-284— Request persistence + processing windowNetwork/enhanceParameters.ts:11—clientUpdateIDdefaults to -1SignInRedirect.ts:47-105— AnotherOnyx.clear()path that doesn't preserve the queue
Implementation Notes
- Adding
PERSISTED_REQUESTStoKEYS_TO_PRESERVEis the simplest fix for theRESET_REQUIREDpath, but care must be taken to ensure the queue is processed correctly afteropenApp()refreshes the Onyx state (since the optimistic data keys the queue references will have been cleared) - The
persistWhenOngoingflag already exists in the infrastructure — expense creation commands just need to opt into it
Issue Owner
Current Issue Owner: @mallenexpensifyUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022039242963579817769
- Upwork Job ID: 2039242963579817769
- Last Price Increase: 2026-04-08
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]PERSISTED_REQUESTS must be preserved during Onyx.clear()[/-][+]App update clears Onyx data not synced with server / PERSISTED_REQUESTS must be preserved during Onyx.clear()[/+]melvin-bot commentedon Apr 1, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ShridharGoel (
External)[-]App update clears Onyx data not synced with server / PERSISTED_REQUESTS must be preserved during Onyx.clear()[/-][+][$250] App update clears Onyx data not synced with server / PERSISTED_REQUESTS must be preserved during Onyx.clear()[/+]melvin-bot commentedon Apr 1, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022039242963579817769
trasnake87 commentedon Apr 1, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When
Onyx.clear()is called via theRESET_REQUIREDlistener, thePERSISTED_REQUESTSqueue (holding offline API requests) is wiped because it's not preserved, causing permanent loss of unsynced expenses.What is the root cause of that problem?
The
RESET_REQUIREDlistener at App.ts:154-168 callsOnyx.clear(KEYS_TO_PRESERVE)without first snapshotting the sequential queue.ONYXKEYS.PERSISTED_REQUESTSandONYXKEYS.PERSISTED_ONGOING_REQUESTSare not in theKEYS_TO_PRESERVElist, so the queue is destroyed. The correct pattern already exists inclearOnyxAndResetApp()at App.ts:827-876, which snapshots and restores the queue — but theRESET_REQUIREDlistener doesn't use it.What changes do you think we should make in order to solve the problem?
We should modify the
RESET_REQUIREDlistener to snapshot and restore the sequential queue, matching the existing pattern inclearOnyxAndResetApp():The
getAll,rollbackOngoingRequest, andsaveimports are already present inApp.ts(used byclearOnyxAndResetApp). This ensures offline requests survive the reset, and by restoring them afteropenApp()resolves, we maintain data consistency — the fresh Onyx state fromopenAppis established first, then the pending queue is re-enqueued for processing.trasnake87 commentedon Apr 1, 2026
Contributor details
Your Expensify account email: trasnake87@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~010f770315ab181656
melvin-bot commentedon Apr 1, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
40 remaining items
melvin-bot commentedon May 12, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
melvin-bot commentedon May 14, 2026
@mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
ShridharGoel commentedon May 17, 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: N/A
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: N/A
[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: N/A - regression coverage was added directly in PR Fix: Prevent Onyx.clear() from removing unsynced PERSISTED_REQUESTS data #87874.
Regression Test Proposal
Precondition:
Test:
Do we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-353c-a304-2dd1-bafcf3a6dd34mallenexpensify commentedon May 19, 2026
Payment Summary
Contributor: @marufsharifi paid $250 via Upwork
Contributor+: @ShridharGoel due $250 via NewDot
@marufsharifi can you please accept the job below? Please reply here and tag me once you have.
https://www.upwork.com/jobs/~022056762025568895726
^ Test case created
marufsharifi commentedon May 20, 2026
@mallenexpensify, I've accepted the offer. thanks.
mallenexpensify commentedon May 20, 2026
@marufsharifi paid, summary updated above. Thx.
garrettmknight commentedon May 21, 2026
$250 approved for @ShridharGoel