Skip to content

Home-"Recently added" not sorted by when they were added #94339

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.4.17-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #93451
Email or phone of affected tester (no customers): lekima20+615706@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Win 11/Chrome
App Component: Other

Action Performed:

Precondition: Login with new account and create a workspace

  1. Open https://staging.new.expensify.com
  2. Navigate to the workspace chat
  3. Create and submit an expense with date is today
  4. Create and submit an expense with a date in May
  5. Create and submit an expense with a date in April
  6. Create 2 expense with date is today
  7. Click on Home tab
  8. Scroll down to Recently added section and observe the list

Expected Result:

Verify the "Recently added" slot lists up to five expenses sorted by when they were added (an expense added today but dated months ago appears at the top)

Actual Result:

The list isn't sorted by when they were added. The expense with date in April and May aren't displayed at the top.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7188419_1782201941157.Recording__2262.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Murugesan Natarajan
Bug ID: 7188419

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 23, 2026
  2. applause-bot commented on Jun 23, 2026

    @applause-bot
    Author

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

  3. melvin-bot commented on Jun 23, 2026

    @melvin-bot

    @grgia recently merged #93451, but they are OOO right now, so I'll auto-assign someone else.

  4. melvin-bot commented on Jun 23, 2026

    @melvin-bot

    Triggered auto assignment to @Julesssss (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

  5. melvin-bot commented on Jun 23, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  6. github-actions commented on Jun 23, 2026

    @github-actions
    Contributor

    👋 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:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  7. MelvinBot commented on Jun 23, 2026

    @MelvinBot
    Contributor

    Issue Analysis

    Root Cause: The "Recently added" sort relies on each transaction's inserted timestamp, but the data it renders from — the Search snapshot — doesn't carry inserted, and its only fallback source (the local transactions_ collection) doesn't reliably contain these expenses either. So the recency key falls all the way through to the expense date (getCreated), which is why the list is ordered by date instead of by when each expense was added.

    The recency key in useRecentlyAddedData.ts:154-155 is:

    insertedByTransactionID.get(id)  // local transactions_ collection — sparse/on-demand
      ?? transaction.inserted          // snapshot — omits `inserted` by design (see lines 70-71)
      ?? getCreated(transaction)       // expense DATE ('YYYY-MM-DD') — the wrong key, but what we land on
    

    The hook itself documents at :70-71 that the snapshot omits inserted, so ordering "must come from the local transactions_ collection" — but that collection is also flagged as holding "only on-demand data and may be missing most expenses." When both miss, getCreated (date-only) decides the order → exactly the reported symptom.

    Why the PR's tests didn't catch it: the unit tests inject inserted directly onto the snapshot transactions and never populate the local transactions_ collection (useRecentlyAddedDataTest.ts:90-99), so they pass via the ?? transaction.inserted branch — a path that never exists in production. The UI test fully mocks the hook, so it validates no sorting at all.

    ⚠️ The real fix is outside the App repo. Making the sort correct requires the backend Search command (Web-Expensify) to include inserted on the transaction objects it returns in the snapshot (and/or return results pre-sorted by date-added). I don't have access to that repo, so this should be escalated to an internal engineer. There is no reliable App-only source of inserted for arbitrary expenses surfaced via Search.

    Deploy-blocker recommendation: Since this is a brand-new feature (#93451) and the proper fix is a backend change, the fastest path to unblock the deploy is to revert / CP-revert #93451 (or hide the Recently-added section) until the snapshot carries inserted.

    Investigation details & evidence
    • buildOptimisticTransaction does set inserted: DateUtils.getDBTime() (src/libs/TransactionUtils/index.ts:447), so an expense created on-device gets inserted in transactions_ momentarily. But the Home list renders from the Search snapshot (snapshot_<hash>), not from transactions_, and transactions_ is sparse/on-demand — so the snapshot transactions frequently have no matching local entry to borrow inserted from.
    • The App never injects inserted into snapshot data: search() only writes loading/offset metadata optimistically; the transaction payload comes entirely from the backend SEARCH response (src/libs/actions/Search.ts). Whether the snapshot has inserted is a backend decision.
    • getCreated returns modifiedCreated ?? created, a date-only 'YYYY-MM-DD' string — when used as the sort key, all same-day expenses tie and months-ago-dated expenses sink to the bottom regardless of when they were added.
    • Alternative explanations considered & ruled out: (a) sort-direction bug — the comparator at :158-165 correctly orders newest-first; (b) inserted format/precision mismatch — inserted is 'YYYY-MM-DD HH:mm:ss.SSS' and sorts lexicographically fine; the problem is its absence, not its format. The single common cause that explains every symptom is the fallback to getCreated.
    • Test fix needed too: the unit test should seed ONYXKEYS.COLLECTION.TRANSACTION (the local collection) and leave inserted off the snapshot transactions, to actually exercise the production path.

    Next Steps for Contributor+ team:
    To accept the backend escalation: Assign an internal engineer to add inserted to the Search command's transaction payload in Web-Expensify.
    To unblock the deploy now: Revert #93451.
    To refine: @MelvinBot <your feedback>

  8. assigned and unassigned on Jun 23, 2026
  9. added and removed on Jun 29, 2026
  10. grgia commented on Jun 29, 2026

    @grgia
    Contributor

    Closing as dupe

  11. m-natarajan commented on Jul 1, 2026

    @m-natarajan

    @blimpich @grgia Able to reproduce this in the latest staging v9.4.25-0, Should I reopen this issue or is this a dupe of #94162 as per this comment

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

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions