Skip to content

[Due for payment 2026-05-12] [$250] App update clears Onyx data not synced with server / PERSISTED_REQUESTS must be preserved during Onyx.clear() #86710

Closed

Description

@MelvinBot

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

  1. Add ONYXKEYS.PERSISTED_REQUESTS and ONYXKEYS.PERSISTED_ONGOING_REQUESTS to the KEYS_TO_PRESERVE list in App.ts:122-146, OR modify the RESET_REQUIRED listener to snapshot/restore the queue the same way clearOnyxAndResetApp() already does.

  2. Set persistWhenOngoing: true for expense creation commands (REQUEST_MONEY, TRACK_EXPENSE, SPLIT_BILL_AND_OPEN_REPORT, etc.) so in-flight requests survive app kills.

Relevant Code

Implementation Notes

  • Adding PERSISTED_REQUESTS to KEYS_TO_PRESERVE is the simplest fix for the RESET_REQUIRED path, but care must be taken to ensure the queue is processed correctly after openApp() refreshes the Onyx state (since the optimistic data keys the queue references will have been cleared)
  • The persistWhenOngoing flag already exists in the infrastructure — expense creation commands just need to opt into it
Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022039242963579817769
  • Upwork Job ID: 2039242963579817769
  • Last Price Increase: 2026-04-08

Activity

  1. changed the title [-]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()[/+] on Mar 31, 2026
  2. self-assigned this
    on Mar 31, 2026
  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Apr 1, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Apr 1, 2026
  5. melvin-bot commented on Apr 1, 2026

    @melvin-bot

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

  6. changed the title [-]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()[/+] on Apr 1, 2026
  7. melvin-bot commented on Apr 1, 2026

    @melvin-bot
  8. trasnake87 commented on Apr 1, 2026

    @trasnake87
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When Onyx.clear() is called via the RESET_REQUIRED listener, the PERSISTED_REQUESTS queue (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_REQUIRED listener at App.ts:154-168 calls Onyx.clear(KEYS_TO_PRESERVE) without first snapshotting the sequential queue. ONYXKEYS.PERSISTED_REQUESTS and ONYXKEYS.PERSISTED_ONGOING_REQUESTS are not in the KEYS_TO_PRESERVE list, so the queue is destroyed. The correct pattern already exists in clearOnyxAndResetApp() at App.ts:827-876, which snapshots and restores the queue — but the RESET_REQUIRED listener doesn't use it.

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

    We should modify the RESET_REQUIRED listener to snapshot and restore the sequential queue, matching the existing pattern in clearOnyxAndResetApp():

    // App.ts, RESET_REQUIRED listener (~line 154)
    Onyx.connectWithoutView({
        key: ONYXKEYS.RESET_REQUIRED,
        callback: (isResetRequired) => {
            if (!isResetRequired) {
                return;
            }
    
            const sequentialQueue = getAll();
            rollbackOngoingRequest();
    
            Onyx.clear(KEYS_TO_PRESERVE).then(() => {
                Onyx.set(ONYXKEYS.RESET_REQUIRED, false);
                openApp().then(() => {
                    for (const request of sequentialQueue) {
                        save(request);
                    }
                });
            });
        },
    });

    The getAll, rollbackOngoingRequest, and save imports are already present in App.ts (used by clearOnyxAndResetApp). This ensures offline requests survive the reset, and by restoring them after openApp() resolves, we maintain data consistency — the fresh Onyx state from openApp is established first, then the pending queue is re-enqueued for processing.

  9. trasnake87 commented on Apr 1, 2026

    @trasnake87
    Contributor

    Contributor details
    Your Expensify account email: trasnake87@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~010f770315ab181656

  10. melvin-bot commented on Apr 1, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  11. 40 remaining items

  12. melvin-bot commented on May 12, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • (if NewFeature) I have created a PR for any necessary HelpDot updates, or I confirmed no updates are necessary.
    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2039242963579817769/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  13. melvin-bot commented on May 14, 2026

    @melvin-bot

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

  14. ShridharGoel commented on May 17, 2026

    @ShridharGoel
    Contributor

    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:

    • User is signed in.
    • User has access to a workspace chat.
    • The app can use Troubleshoot options like Force offline and Reset and refresh / Clear cache and restart.

    Test:

    1. Open the app and go to a workspace chat.
    2. Go to Settings > Troubleshoot.
    3. Turn on Force offline.
    4. Create a manual expense in the workspace chat.
    5. Verify the expense appears locally.
    6. Trigger a local reset using Reset and refresh / Clear cache and restart.
    7. Wait for the app to reload.
    8. Turn Force offline off.
    9. Return to the workspace chat.
    10. Verify the expense is still visible.
    11. Wait for sync to finish.
    12. Verify the expense is still visible after sync.

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-353c-a304-2dd1-bafcf3a6dd34
  15. mallenexpensify commented on May 19, 2026

    @mallenexpensify
    Contributor

    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

  16. marufsharifi commented on May 20, 2026

    @marufsharifi

    @mallenexpensify, I've accepted the offer. thanks.

  17. mallenexpensify commented on May 20, 2026

    @mallenexpensify
    Contributor

    @marufsharifi paid, summary updated above. Thx.

  18. garrettmknight commented on May 21, 2026

    @garrettmknight
    Contributor

    $250 approved for @ShridharGoel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributorImprovementItem broken or needs improvement.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions