Skip to content

[$250] Inbox - Marking all as read does not clear unread chats and unread markers #101684

Open

Description

@applause-bot

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.90-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #100693
Email or phone of affected tester (no customers): applausetester+bm2244a@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: android
App Component: Left Hand Navigation (LHN)

Action Performed:

Preconditions:
Log in to an account that has unread messages

  1. Go to staging.new.expensify.com
  2. Go to Inbox page, switch to Unread tab
  3. Long-press on Unread tab, select "Mark all as read"

Expected Result:

App should clear all unread chats and unread markers

Actual Result:

Unread chats and unread markers are not cleared

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7263667_1789776019296.1.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Rizky Gunawan
Bug ID: 7263667

Issue OwnerCurrent Issue Owner: @stacklancer
Upwork Automation - Do Not Edit

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 21, 2026
  2. applause-bot commented on Sep 21, 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/c329b51fb7afe7ab201e84c73e9afdd567d11ca1817f62d37f25bb746871e11f

  3. MelvinBot commented on Sep 21, 2026

    @MelvinBot
    Contributor

    Proposal

    This is two separate defects that together produce the reported symptom. "Unread chats not cleared" is a regression from [Phase 4] - Remove module-level reportAttributesDerivedValue in isEmptyReport(). "Unread markers not cleared" is a pre-existing gap that PR QA surfaced for the first time.

    What is the root cause of that problem?

    A. Unread chats aren't cleared — regression from PR #100693

    That PR rewrote isEmptyReport() to take the emptiness flag as a parameter, and in doing so changed what an absent value means:

    • Before (ReportUtils.ts:9695-9707) — read the derived attributes live; if the entry existed, use its isEmpty, even when false.
    • After (ReportUtils.ts:9689-9694) — derivedIsEmptyReport ?? generateIsEmptyReport(...). If the caller's value is undefined, recompute.

    The fallback is not equivalent. generateIsEmptyReport() returns true for any report with no lastMessageText whose actions aren't in memory — the normal state on a freshly launched mobile app. The derived flag is persisted to disk, so it can hold false where a fresh recompute says true.

    The same PR also changed where markAllMessagesAsRead gets that data. It used to come from ReportUtils' own live Onyx.connect, independent of React. Now it's a render snapshot captured in InboxTabSelector.tsx:47 and passed down at :101.

    When that snapshot is missing or unhydrated, every report fails the isUnread() filter, reportIDList stays empty, and the action returns before API.write — no optimistic write, no network call, no error. Silently nothing happens, which is exactly what the tester saw.

    Note the same PR kept the live read in UnreadIndicatorUpdater/index.ts:68-75. So the badge and the action can now disagree about what's unread.

    B. Unread markers can't be cleared by this action at all — pre-existing

    Even with a successful write, markAllMessagesAsRead cannot remove the in-chat "New" line, for two independent reasons:

    1. unreadMarkerTime is seeded once at mount (useUnreadMarker.ts:82) and only advanced by the unreadAction_* / readNewestAction_* DeviceEventEmitter events. markAllMessagesAsRead emits neither — it only merges lastReadTime.
    2. shouldDisplayNewMarkerOnReportAction.ts:65-66 hard-pins the marker whenever manuallyMarkedUnreadReportActionID is set, ignoring lastReadTime entirely. Only openReport ever clears it; markAllMessagesAsRead never does.

    This matters for this exact repro: if the tester created the unread state with "Mark as unread" (the usual way to satisfy the "account with unread messages" precondition), the marker survives even a fully successful mark-all-as-read.

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

    1. Make markAllMessagesAsRead read REPORT_ATTRIBUTES live via Onyx.connectWithoutView, matching what UnreadIndicatorUpdater already does, instead of accepting a render snapshot. This restores pre-PR behavior and lets the reportAttributesDerived plumbing come back out of InboxTabSelector and MarkAllMessagesAsReadHandler.
    2. Restore the old contract in isEmptyReport so "no derived entry" is distinguishable from "entry says false". An absent caller value must never silently trigger a recompute that can disagree with the cached flag.
    3. Clear the manual-unread state in markAllMessagesAsRead: include manuallyMarkedUnreadReportActionID: null in the optimistic merge and emit readNewestAction_<reportID> for each marked report, so mounted chats drop the "New" line.
    4. Close the test gap. The only coverage is tests/actions/ReportTest.ts:3592, which calls markAllMessagesAsRead(undefined, undefined, undefined) — it never exercises the derived-isEmpty path. Add a test with REPORT_ATTRIBUTES populated, and one asserting the Unread tab's membership and what the action marks stay in agreement.

    What alternative solutions did you explore?

    • Backend rejection + failureData rollback. There's no successData, and failureData restores the previous lastReadTime for every report, so a rejected MarkAllMessagesAsRead would look identical to "nothing cleared". I could not rule this out — VictoriaLogs was unavailable in this run, so there is no production confirmation of whether the request was sent. One log query settles it: if no MarkAllMessagesAsRead request exists for the tester's session, the client bailed and the diagnosis above is confirmed; if one exists and failed, it's the backend instead.
    • Frozen LHN snapshot. Ruled out — updateReportsToDisplayInLHN correctly rewrites the entry when unread flags clear (SidebarUtils.ts:404-421), so the optimistic merge is sufficient to clear LHN bolding and the tab badge.
    • Wrong or misordered arguments in the PR. Ruled out — every changed isUnread() / isEmptyReport() call site was audited and threads the correct value in the correct position.
    • A different staging-only PR. Ruled out at blob level, see below.
    Supporting evidence

    Release-window fit is exact. Comparing production 9.4.89-0 against staging 9.4.90-0:

    Also verified and ruled out: shape mismatch in useReportAttributes() (it correctly returns .reports); a different archived input in the derived isEmpty computation; partial derived entries missing isEmpty; stale closures in PopoverMenu (byte-identical prod↔staging).

    Separate pre-existing asymmetry, worth noting but not the cause here: the Unread tab calls isUnread(report, undefined, ...) while the action passes the one-transaction thread report. Since isUnread takes max(report.lastReadTime, thread.lastReadTime), a one-transaction expense report whose thread was already read looks unread to the tab but read to the action. That's present verbatim in production, and would cause a partial failure, not a total one.

    Confidence: high that PR #100693 is the cause (blob-level proof); medium on the precise runtime trigger, which needs the log query above or a device log of reportIDList.length at the call site.

    Reproduction note: I attempted to verify on web, but agent-device in this environment supports neither right-click nor long-press, and right-click is the only entry point to this menu on desktop web. The repro was not reproduced first-hand.

    Related issues

    💡 Suggested AI code review rule

    The refactor that caused this is being applied repeatedly (this PR is "Phase 4", citing Phase 2's pattern, under refactor issue #66412), so the same hazard can recur in each phase. Proposed for Expensify/App:

    • Rule: CONSISTENCY-18 — Threading a cached Onyx value into a parameter must not make undefined mean "recompute"
    • Condition: Flag when a refactor replaces a module-level derived-Onyx read with a caller-passed parameter and the absent case falls back to a recompute (return derivedX ?? computeX(...)). The recompute is rarely equivalent to the persisted cached value. Make the parameter required, or keep the entry-exists check so an absent caller value can't silently flip the result. Separately, flag imperative one-shot actions in src/libs/actions/ that receive derived Onyx data as a React render snapshot instead of reading it live via Onyx.connectWithoutView.
    • Why: A wrong emptiness answer made isUnread() false for every report, so markAllMessagesAsRead early-returned with no API call and no optimistic write — a completely silent no-op.
    • Search pattern: return\s+\w*[Dd]erived\w*\s*\?\?\s*(generate|compute|get)\w+\( across src/libs/, plus Derived(Value)?\b appearing in a parameter list under src/libs/actions/.
    • Offending code (❌): src/libs/ReportUtils.ts:9689-9694
    • Fix (✅): src/libs/ReportUtils.ts:9695-9707 as it was before the PR

    The full rule file, with the ❌/✅ code inline in the app-coding-standards format, would go in App/.claude/skills/app-coding-standards/rules/. If it's worth adding, a maintainer can open it there as a draft PR.


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


    view run · no recording available

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Sep 21, 2026
  5. melvin-bot commented on Sep 21, 2026

    @melvin-bot

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

  6. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  7. melvin-bot commented on Sep 24, 2026

    @melvin-bot

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

  8. M00rish commented on Sep 25, 2026

    @M00rish
    Contributor

    Reproduced on web. The cause is not a missing isEmpty snapshot. In my run the derived value was present and correct, and a normal unread chat was marked read as expected.

    What gets stuck is a one-expense report whose expense (thread) was already read. The Unread tab checks it without the thread, so it's listed as unread:

    isUnread(report, undefined, isReportArchived, derivedIsEmptyReport) &&

    The action checks it with the thread, so it's treated as read and skipped:

    if (!isUnread(report, oneTransactionThreadReport, isReportArchived, reportAttributesDerived?.[report.reportID]?.isEmpty)) {

    Values logged inside the action for a report the Unread tab was showing:

    6133559146143422 {"derived":{"isEmpty":false,"oneTransactionThreadReportID":"2055341732240261"},"unread":false}
    reportIDList []
    

    No API call and no optimistic update. The report stays in the Unread tab until it's opened.

    Fix: pass the one-transaction thread to getIsUnreadReportForInboxTab, so the tab, the LHN bold state and the action use the same check. In both getReportsToDisplayInLHN and updateReportsToDisplayInLHN:

    const oneTransactionThreadReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAttributes?.[report?.reportID]?.oneTransactionThreadReportID}`];
    const isUnreadReport = getIsUnreadReportForInboxTab(report, oneTransactionThreadReport, isReportArchived, reportAttributes?.[report?.reportID]?.isEmpty);

    and pass it through to isUnread in getIsUnreadReportForInboxTab. I tested this locally: with the same state, the Unread tab shows "No unread chats".

  9. ashusatyarthi-wq commented on Sep 27, 2026

    @ashusatyarthi-wq

    Proposal

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

    When using the "Mark all as read" action on the Inbox > Unread tab, certain one-expense reports remain stuck in the Unread tab with bold unread markers and do not clear until manually opened.


    What is the root cause of that problem?

    There is a discrepancy in how unread state is calculated between the Inbox tab filter and the MarkAllMessageAsRead action:

    1. In src/libs/SidebarUtils.ts:987-995, getIsUnreadReportForInboxTab checks whether a report should appear in the "Unread" tab by calling isUnread with undefined for oneTransactionThreadReport:
    function getIsUnreadReportForInboxTab(report: Report, isReportArchived: boolean, derivedIsEmptyReport: boolean | undefined): boolean {
        return (
            isUnread(report, undefined, isReportArchived, derivedIsEmptyReport) &&
            !!report.lastActorAccountID &&
            getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE
        );
    }

    Because oneTransactionThreadReport is undefined, for a one-expense report whose expense thread was already read, isUnread falls back to evaluating the parent report in isolation and returns true. Consequently, isUnreadReport is set to true, and the report is displayed in the "Unread" tab.

    1. In src/libs/actions/Report/MarkAllMessageAsRead.tsx:67, markAllMessagesAsRead checks whether the report needs to be marked read with the thread report:
    isUnread(report, oneTransactionThreadReport)

    Because the one-transaction thread is already read, isUnread evaluates to false.

    1. As a result, MarkAllMessageAsRead determines that the report is already read and excludes it from the reportIDList payload. No optimistic update and no API call are made. The report remains permanently trapped in the Unread tab until opened.

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

    Pass the oneTransactionThreadReport to getIsUnreadReportForInboxTab so that the Unread tab, the LHN bold indicator, and MarkAllMessageAsRead all use the identical, unified unread check.

    1. In src/libs/SidebarUtils.ts:

    Update getIsUnreadReportForInboxTab to accept oneTransactionThreadReport:

    -function getIsUnreadReportForInboxTab(report: Report, isReportArchived: boolean, derivedIsEmptyReport: boolean | undefined): boolean {
    +function getIsUnreadReportForInboxTab(
    +    report: Report,
    +    oneTransactionThreadReport: OnyxEntry<Report>,
    +    isReportArchived: boolean,
    +    derivedIsEmptyReport: boolean | undefined,
    +): boolean {
         return (
    -        isUnread(report, undefined, isReportArchived, derivedIsEmptyReport) &&
    +        isUnread(report, oneTransactionThreadReport, isReportArchived, derivedIsEmptyReport) &&
             !!report.lastActorAccountID &&
             getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE
         );
     }

    2. Pass oneTransactionThreadReport at call sites in SidebarUtils.ts:

    In both getReportsToDisplayInLHN (line 316) and updateReportsToDisplayInLHN (line 405):

    +const oneTransactionThreadReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAttributes?.[report?.reportID]?.oneTransactionThreadReportID}`];
     const isUnreadReport = getIsUnreadReportForInboxTab(
         report,
    +    oneTransactionThreadReport,
         isReportArchived,
         reportAttributes?.[report?.reportID]?.isEmpty,
     );

    What specific scenarios should be covered in tests?

    Add unit tests in tests/unit/SidebarUtilsTest.ts:

    1. One-transaction expense report where thread is read:
      • Given a one-transaction expense report with an associated oneTransactionThreadReport whose lastReadTime >= lastVisibleActionCreated.
      • Assert getIsUnreadReportForInboxTab returns false.
      • Assert the report does not appear in CONST.INBOX_TAB.UNREAD.
    2. One-transaction expense report where thread is unread:
      • Given a one-transaction expense report with an unread oneTransactionThreadReport.
      • Assert getIsUnreadReportForInboxTab returns true.
      • Execute markAllMessagesAsRead and assert report is included and unread state clears.

    What alternative solutions did you explore? (Optional)

    1. Removing oneTransactionThreadReport from MarkAllMessageAsRead:
      • Rejected because MarkAllMessageAsRead's check is the correct business logic (an expense report whose single transaction thread has been read should not be treated as unread). Aligning SidebarUtils ensures consistent UI behavior across the entire app.
  10. melvin-bot commented on Sep 28, 2026

    @melvin-bot

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

  11. melvin-bot commented on Sep 30, 2026

    @melvin-bot

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

  12. 110 remaining items

  13. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    Triggered auto assignment to @justinpersaud, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  14. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 26, 2026
  15. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    📣 @stacklancer You have been assigned to this job!
    Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
    Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
    Keep in mind: Code of Conduct | Contributing 📖

  16. stacklancer commented on Oct 27, 2026

    @stacklancer

    Thanks @eVoloshchak! I've applied on Upwork. I'll update the branch to latest main and open the PR within 24 hours.

  17. stacklancer commented on Oct 27, 2026

    @stacklancer

    @eVoloshchak the PR is up: #105176

    I tested it on web (Chrome on Windows), in a phone-width Chrome window, and offline. Screenshots are in the PR. I couldn't run the iOS/Android native builds on my machine, so those aren't covered yet. Happy to fix anything you find.

  18. stacklancer commented on Oct 28, 2026

    @stacklancer

    Update: PR #105176 is ready for review. I addressed the Codex review (fixed the To-do tab case and the Shift+Esc shortcut, with tests). @eVoloshchak whenever you get a chance.

  19. jeffrey-graham commented on Nov 7, 2026

    @jeffrey-graham
  20. melvin-bot commented on Nov 7, 2026

    @melvin-bot
  21. expensify-chore-bot commented on Nov 18, 2026

    @expensify-chore-bot

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

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.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions