Skip to content

Email Notifications Display Messages in Reverse Order #89790

Closed

Description

@m-natarajan

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: 9.3.67-11
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @shawnborton
Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Trigger an email notification with multiple messages (e.g., chat thread or report activity)
  2. Open the email
  3. Observe the order of messages

Expected Result:

Messages should be displayed in chronological order with the latest message at the bottom

Actual Result:

Messages are displayed in reverse order

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

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

MelvinBot investigation:

I investigated the email notification comment ordering code. Here's what I found:

The array_reverse() on email comments has been in the code since at least Oct 2024​ (and likely since Jan 2023 when getCommentBlock() was first created). This means email notifications have shown newest-on-top for a long time — this is not a recent regression.

The data flow is:

1.  Auth returns comments in ASC order (oldest first) via getHistory() with ACTION_ORDER_ASC
2.  Comment.php:686 calls array_reverse() → flips to newest-first
3.  The for loop renders them top-to-bottom → newest comment appears at top of email

Recent changes reviewed:

•   ​App PR #85114​ (FlashList migration) — purely frontend, zero impact on email notifications
•   ​Commit 47b5d98640​ (Apr 21, 2026) — added usort() + system message filtering in ReportUtils.php:3190. The usort sorts by created ASC which is the same order the data was already in, so this shouldn't have changed display order.

Bottom line:​ I could not find a recent commit that changed the ordering. The newest-on-top behavior appears to be long-standing. If the ordering truly needs to be oldest-on-top (newest-on-bottom), the fix would be to remove the array_reverse() call on line 686 of Comment.php. But I'd recommend first confirming with the reporter whether this is actually a recent change vs. something that was always this way and is only now being noticed.

Screenshots/Videos

Image Image

View all open jobs on GitHub

Activity

  1. added
    InternalRequires API changes or must be handled by Expensify staff
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 6, 2026
  2. m-natarajan commented on May 6, 2026

    @m-natarajan
    Author

    @MelvinBot Don't replace Internal label

  3. MelvinBot commented on May 6, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    Email notifications show messages newest-first (reverse chronological) because Comment.php:686 calls array_reverse() on comments that Auth already returns in ASC order (oldest first). The rendering loop then iterates top-to-bottom, placing the newest message at the top of the email.

    This is not a recent regression — the array_reverse() has been present since getCommentBlock() was first created (~Jan 2023). The recent usort() change in ReportUtils.php:3190 (commit 47b5d98640, Apr 2026) sorts by created ASC which matches the pre-existing order and had no effect on display order.

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

    Remove the array_reverse() call on Comment.php:686. Without the reversal, comments will remain in their original ASC order (oldest first) and render chronologically in the email — newest message at the bottom, matching the expected behavior.

    Before applying the fix, confirm via git blame whether the array_reverse() was intentional (e.g., a deliberate design choice for email digest format) and verify no other callers of getCommentBlock() depend on the reversed order.

    What alternative solutions did you explore? (Optional)

    Instead of removing array_reverse(), the rendering loop could be modified to iterate in reverse. However, this adds unnecessary complexity — removing the reversal is the simplest and most direct fix.

    Data flow summary
    1. Auth/getHistory() returns comments in ACTION_ORDER_ASC (oldest first)
    2. Comment.php:686 calls array_reverse() → flips to newest-first
    3. The for loop in getCommentBlock() renders top-to-bottom → newest appears at email top

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  4. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 6, 2026
  5. added
    Hot PickReady for an engineer to pick up and run with
    on May 6, 2026
  6. self-assigned this
    on May 6, 2026
  7. removed
    Hot PickReady for an engineer to pick up and run with
    on May 6, 2026
  8. Beamanator commented on May 6, 2026

    @Beamanator
    Contributor

    I do believe https://github.com/Expensify/Web-Expensify/pull/52233 may have caused this, as it looks like the order flipped the day that PR went to prod 😅

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2InternalRequires API changes or must be handled by Expensify staffReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions