You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-10-27] [$250] the conversation that requested the money is marked as read instead of unread #102117
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
On a wide (desktop) layout the Inbox always mounts a report in the central pane, and merely mounting a report marks it as read — even though the user never opened it. So the chat with account A is auto-read within a second of B landing on the Inbox.
The chain:
The split navigator guarantees a central-pane REPORT screen whenever only the sidebar is present — SplitRouter.ts:111-126. This is wide-layout only, which matches the report being macOS/Chrome-only.
Which report it shows comes from findLastAccessedReport. For a brand-new account there is no visit history, so it falls back to "the report with the newest lastReadTime" — ReportUtils.ts:2560-2567.
ReportsSplitNavigator snapshots that ID in a useState initializer on the first render, with no "reports finished loading" guard — ReportsSplitNavigator.tsx:45-68. ReportRouteParamHandler does have that guard and its comment names this exact hazard: picking from a partially loaded collection "can pin a report that isn't really the last accessed one… Neither can be corrected later" — ReportRouteParamHandler.tsx:50-60.
Mounting that screen fires openReport with shouldMarkAsRead defaulting to true (ReportFetchHandler.tsx:235-253), and the one-shot initial mark-as-read in useMarkAsRead.ts:171-194 calls readNewestAction. That effect has no screen-focus and no visibility check — unlike the other two mark-as-read effects in the same hook, which require isVisible && Visibility.hasFocus().
readNewestAction writes lastReadTime = now and persists it to the server (Report/index.ts:3184-3216), so the chat is read permanently, not just visually.
This also explains the odd precondition "do not switch to another tab or use another window": signing in in the same tab means no page reload, so the navigator mounts while B's reports are still streaming in from OpenApp — and at that instant the chat with A may be the only report present.
What changes do you think we should make in order to solve the problem?
Primary fix — a report the user did not explicitly open should not be marked as read. In useMarkAsRead.ts:171-194, gate the one-shot initial mark-as-read on the same conditions the other two effects already use (screen focused and window visible/focused). Today a report auto-mounted in the central pane — even one sitting behind an onboarding modal — is marked read.
Secondary fix — stop the navigator from pinning a report chosen from a half-loaded collection. In ReportsSplitNavigator.tsx:45-68, apply the same isLoadingOnyxValue guard that ReportRouteParamHandler uses before locking in initialReportID.
What alternative solutions did you explore?
Alternatives considered and evidence
Stale state left over from account A's session. Ruled out: KEYS_TO_PRESERVE_ON_SIGN_OUT (SignInRedirect.ts:55-67) preserves no report, route, or read-state key, and the navigation state is reset on sign-out (getStateToResetAfterLogout.ts:27-35). A's optimistic lastReadTime cannot survive into B's session.
The sender's lastReadTime being sent to the server. Ruled out on the client: no IOU/money-request API parameter carries a read time — only ReadNewestActionParams, MarkAsUnreadParams, MarkAllMessagesAsReadParams, and OpenReportParams.clientLastReadTime do.
Not fully ruled out (would need backend access): the server may already return a non-null lastReadTime for B's copy of the chat when it materialises the report for the newly created account. If so the fix is in Auth/Web-Expensify, not App, and needs an internal engineer. The decisive check is whether a ReadNewestAction request is sent for that report within seconds of B signing in (→ App bug, as proposed above) or whether lastReadTime is already set in the OpenApp response (→ backend bug).
A second, independent way the row can render non-bold: the LHN requires a truthy lastActorAccountID — SidebarUtils.ts:839. If B's copy of the chat comes back without it, the row is not bold regardless of lastReadTime. Worth checking in Onyx during a repro.
Verification status: I could not confirm this at runtime — the test session was handed over with the web app stuck on a blank page, so the repro was not executed. The conclusion rests on code reading only, hence medium confidence.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/102117) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
🚨 Edited by proposal-police: This proposal was edited at 2026-09-25 17:50:13 UTC.
Proposal
Updated: my first version blamed useMarkAsRead. That was wrong. Nothing ever marks this chat as read, so I have replaced the root cause and the fix below.
Please re-state the problem that we are trying to solve in this issue.
A brand-new account B receives a money request from A, signs in and opens the Inbox. The chat with A is shown as read in the LHN (not bold, missing from the Unread tab) even though B never opened it.
What is the root cause of that problem?
The chat really is unread. Only the UI hides it.
B's copy of the chat comes back from OpenApp with:
+ lastReadTime: undefined // B has read nothing+ lastVisibleActionCreated: set // A's REPORTPREVIEW is a real, visible message- lastActorAccountID: "" // the actor lives on the IOU report, not on the chat
isUnread() returns true for it, because there is no lastReadTime:
The rest of the app has no such guard. UnreadIndicatorUpdater calls plain isUnread(), so the browser tab title still counts this chat as (1) while its LHN row is not bold. The app contradicts itself on the same screen:
Why the guard exists, and why it is now only a stale proxy. It was added in Feb 2024 (617910c3b5a) so a chat whose only message was deleted would not stay bold, because lastVisibleActionCreated is not reset on delete. Look at what the delete path actually writes:
In the case the guard was written for, lastActorAccountID is falsy exactly whenlastMessageText is empty. Since then isUnread() has gained an isEmptyReport() check at the very top. It reads lastMessageText first and then the last visible message:
When a caller does not pass derivedIsEmptyReport, isEmptyReport() falls back to computing it (derivedIsEmptyReport ?? generateIsEmptyReport(...)), so every caller is covered:
So the deleted-message case is already answered inside isUnread(). The guard now matters only when a chat has a visible message but arrives without an actor. That is exactly this bug.
Why my original useMarkAsRead theory was wrong:findLastAccessedReport falls back to the report with the newest lastReadTime. This chat has none, so it is never the auto-opened report (Concierge is), readNewestAction never runs for it and lastReadTime stays unset. That also explains why a full page reload does not change the result.
What changes do you think we should make in order to solve the problem?
Remove the !!report.lastActorAccountID guard from all three UI call sites so they use the same unread signal as the tab title counter:
// SidebarUtils.getOptionData
- // When the only message of a report is deleted lastVisibleActionCreated is not reset leading to wrongly- // setting it Unread so we add additional condition here to avoid empty chat LHN from being bold.- result.isUnread = isUnread(report, oneTransactionThreadReport, isReportArchived, reportAttributes?.isEmpty) && !!report.lastActorAccountID;+ // Empty chats (e.g. the only message was deleted) are already excluded by isEmptyReport() inside isUnread().+ result.isUnread = isUnread(report, oneTransactionThreadReport, isReportArchived, reportAttributes?.isEmpty);
All three sites must change together. If only the LHN row changes, the row turns bold while the Unread tab still says "You're all caught up" and search still shows the chat as read.
Last message is the current user's own: still handled by the existing drivingActorAccountID === currentUser check inside isUnread().
Muted chats: the mute check in the Unread tab is unchanged.
The backend could also send lastActorAccountID in OpenApp for this chat, since OpenReport does. That would be a nice-to-have, but the App should not depend on the field for read state. Other chats that arrive without it would hit the same bug.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
In tests/unit/SidebarUtilsTest.ts and tests/unit/OptionsListUtilsTest.tsx:
A chat with no lastReadTime, lastActorAccountID: "" and a REPORTPREVIEW from another user (isEmpty: false). It is unread in getOptionData, it is included by getIsUnreadReportForInboxTab, and it is bold in the option list. These fail on main.
A chat where the last message is from the current user. It stays read.
What alternative solutions did you explore? (Optional)
Keep the guard and add an exception (|| !!report.iouReportID, or fall back to the last visible action's actor). This fixes this repro, but it keeps a second, divergent source of truth for "has a real message" that isEmptyReport() already owns. It also leaves the bug for any non-IOU chat that arrives with a message but no actor.
Gate useMarkAsRead / delay the split navigator (my first version). Rejected, because this chat is never auto-opened and never marked read, so neither change has any effect.
I reproduced this on dev web and the chat is not actually read. It only renders read.
Signed in as B in the same tab and opened the Inbox. The row for A's chat renders in regular weight, and the Unread tab says "No unread chats. You're all caught up."
In Onyx, B's copy of that chat (report_2827277120285184) has no lastReadTime at all, so nothing ever marked it read. Its actions are a CREATED and a REPORTPREVIEW from A (actorAccountID 23087835).
That chat carries lastActorAccountID: "", while the IOU report it previews carries "23087835". isUnread() returns true for it. The lastActorAccountID guard in getOptionData then turns the result back to false.
The report the split navigator auto-opened was Concierge (1736559253892187), and Concierge is also the only report the one-shot initial mark-as-read fired for. So the auto-mount path is not what makes A's chat look read.
A full page reload as B did not change anything. The row still rendered read and the Unread tab was still empty, so this is deterministic rather than a window during sign-in.
Observed state on the chat while the bug was on screen:
report_2827277120285184 // B's copy of the chat with A
+ lastVisibleActionCreated: "2026-09-24 04:24:50.326"+ reportActions: CREATED, REPORTPREVIEW (actor 23087835)+ reportAttributes.isEmpty: false // so isUnread() -> true- lastReadTime: never set // B has read nothing- lastActorAccountID: "" // the guard reads this and forces isUnread -> false
The guard sits in two places, which is why the bold row and the Unread tab both go quiet:
Its comment says it exists so a chat whose only message was deleted does not stay bold, because lastVisibleActionCreated is not reset on delete. That was a reasonable proxy when it landed in February 2024 (617910c). It is no longer needed. isUnread now takes derivedIsEmptyReport and gates on isEmptyReport before anything else:
// lastVisibleActionCreated and lastReadTime are both datetime strings and can be compared directly
generateIsEmptyReport is the purpose-built version of the same check. It falls through to getLastVisibleMessage, which resolves the action through getLastVisibleAction and its isReportActionVisibleAsLastAction filter, so a chat whose only message was deleted comes back empty and isUnread returns false on its own.
For B's chat with A the derived attribute is isEmpty: false, which is correct: the report preview is a real visible message. The stale proxy is the only thing suppressing the unread state.
flowchart TD
A["B's copy of the chat with A lands, no lastReadTime"] -->|"only visible action is a REPORTPREVIEW"| B["lastActorAccountID empty on the chat, 23087835 lives on the IOU report"]
B --> C["isUnread() returns true, reportAttributes.isEmpty is false"]
C -->|"lastActorAccountID guard reads empty"| D["getOptionData sets isUnread false, LHN row not bold"]
C -->|"same guard in getIsUnreadReportForInboxTab"| E["Unread tab: No unread chats"]
Loading
What changes do you think we should make in order to solve the problem?
Drop the lastActorAccountID guard at both sites and let isUnread do the emptiness check it already does. The two comments go with it, since the case they describe is now owned by isEmptyReport.
- // When the only message of a report is deleted lastVisibleActionCreated is not reset leading to wrongly- // setting it Unread so we add additional condition here to avoid empty chat LHN from being bold.- result.isUnread = isUnread(report, oneTransactionThreadReport, isReportArchived, reportAttributes?.isEmpty) && !!report.lastActorAccountID;+ result.isUnread = isUnread(report, oneTransactionThreadReport, isReportArchived, reportAttributes?.isEmpty);
and the same removal in getIsUnreadReportForInboxTab, keeping the mute check.
Both have to change together. Fixing only getOptionData would bold the row while the Unread tab still claimed there was nothing to read.
With this applied I reloaded the same session and B's chat with A renders bold, and the Unread tab shows it with a count of 1. I added two regression tests to tests/unit/SidebarUtilsTest.ts, one on getOptionData and one on getReportsToDisplayInLHN, both using a never-read chat with isEmpty: false and no lastActorAccountID. They fail on current main and pass with the removal, and the other 108 tests in that file still pass.
What alternative solutions did you explore? (Optional)
Gating the initial mark-as-read on screen focus and window visibility, or making ReportsSplitNavigator wait for IS_LOADING_APP before pinning a fallback report. Neither applies here. I watched the split navigator pin Concierge, not A's chat, and readNewestAction ran once, for Concierge. A's chat never got a lastReadTime from any path, so delaying or suppressing the auto-mount leaves the LHN showing exactly what it shows today.
Filling in the missing actor instead, for example falling back to the last visible action's actorAccountID when report.lastActorAccountID is empty. That fixes the symptom but keeps alive a guard that isEmptyReport already covers, and it adds an action lookup to a hot LHN path.
I also considered whether this is a server-side gap, since lastActorAccountID sits empty in Onyx after OpenApp. It may well be. The App does not need it either way: the emptiness signal it relies on is derived locally and was already correct here.
Please re-state the problem that we are trying to solve in this issue.
Account A sends a money request ("IOU") to an email that has no Expensify account yet, which creates a brand‑new pending account B. A signs out, and B signs in for the very first time (same browser tab, no other tab/window used). When B opens the Inbox, the DM with A — which B has never opened before — is already shown as read in the LHN, instead of unread.
What is the root cause of that problem?
isUnread() decides a report's read state in two steps: if the report has no lastReadTime it's unread, otherwise it compares lastReadTime to the last visible action's timestamp — unless the last action was written by the current user themselves, in which case it's treated as already read (so you don't see your own just‑sent message flagged unread):
The "self-authored" check compares drivingActorAccountID (the author of the report's last visible action) against a module‑level variable, deprecatedCurrentUserAccountID, instead of a value passed in as an argument. That variable is kept in sync with the logged-in user via an Onyx.connect on SESSION:
Notice the early return on line 1066-1068: // When signed out, val is undefined / if (!value) { return; }. When the session is cleared on sign‑out, this callback simply does nothing — it does not reset deprecatedCurrentUserAccountID back to undefined. Because sign‑out → sign‑in happens inside the same JS runtime (same tab), that variable keeps holding A's accountID all through the sign‑out and the start of B's sign‑in, until the new SESSION value (with B's accountID) is eventually merged into Onyx.
Now trace what happens for the report with A once B's account data streams in: the report was created for B as part of the money-request flow, so its per‑participant lastReadTime is already a real (truthy) timestamp close to the report's creation time — it does not hit the !report.lastReadTime early return. The IOU action itself (the last visible action) was authored by A, so drivingActorAccountID === A. If the LHN row for this report evaluates isUnread() (via SidebarUtils.getOptionData → isUnread, called from
) while deprecatedCurrentUserAccountID is still stale at A's ID, then drivingActorAccountID (A) === deprecatedCurrentUserAccountID (A) is true, and the "self‑authored" branch incorrectly fires — isUnread() returns false even though isUnreadFromTimestamp was true.
This is a one‑shot mistake, but it sticks: the LHN row component that renders this conversation only subscribes to useOnyx for that specific report's own keys (REPORT_ACTIONS, REPORT_NAME_VALUE_PAIRS, transactions, etc.) — it has no useOnyx(ONYXKEYS.SESSION) subscription: https://github.com/Expensify/App/blob/e029fad955164435583153ee7f862942711273cb/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx
Since B never opens the conversation in this repro, none of the report's own Onyx keys change again afterward, so there is nothing to make that row recompute isUnread() once deprecatedCurrentUserAccountID finally catches up to B — the wrong "read" result is left standing in the LHN.
This lines up exactly with the repro's "do not switch tabs/windows" constraint: a full page reload would re-initialize this module state cleanly from scratch, but a same‑tab sign‑out→sign‑in reuses the running JS module, so the previous user's leftover accountID can momentarily leak into the new user's first render.
Other, equivalent SESSION listeners in this codebase avoid this exact trap by resetting to undefined/a default on sign‑out instead of returning early, e.g.:
What changes do you think we should make in order to solve the problem?
Fix the SESSION listener in ReportUtils.ts so it stops leaving stale user data behind on sign‑out, matching the pattern already used elsewhere in the codebase (optional‑chain into the new value instead of early‑returning on falsy):
With this change, as soon as the session is cleared on sign‑out, deprecatedCurrentUserAccountID becomes undefined instead of staying pinned to the previous user's accountID. Even if the LHN evaluates isUnread() for B's reports before the new session finishes populating, drivingActorAccountID === deprecatedCurrentUserAccountID can never falsely match a leftover previous‑user ID (A === undefined is always false), so the "self‑authored" short‑circuit can no longer misfire across an account switch, and the conversation with A correctly renders as unread for B.
This is a minimal, targeted fix: it doesn't touch the isUnread() decision logic itself, only removes the stale-state window that lets a previous session's identity leak into a new session's first render — the same safeguard this file's sibling SESSION listeners already have.
[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.
It's more like a new requirements
[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.
Regression Test Proposal
Precondition:
Account A is an existing account.
Account B is an email address that does not have an Expensify account yet.
Test:
Sign in with account A.
Create an expense and send it to account B's email address.
Sign out of account A in the same tab.
Sign in with account B.
Go to Inbox.
Verify that the chat with account A is shown in bold (unread) in the LHN.
Open the Unread tab (filter).
Verify that the chat with account A appears in the Unread tab.
Open the search router and type account A's name or email.
Verify that the chat with account A appears in bold in the search results.
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
applause-bot commentedon Sep 24, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/726092c763a2f339444a1f6b0081de3a50c457e5ee85ba32ac9a4277630b26e3
MelvinBot commentedon Sep 24, 2026
Proposal
What is the root cause of that problem?
On a wide (desktop) layout the Inbox always mounts a report in the central pane, and merely mounting a report marks it as read — even though the user never opened it. So the chat with account A is auto-read within a second of B landing on the Inbox.
The chain:
REPORTscreen whenever only the sidebar is present —SplitRouter.ts:111-126. This is wide-layout only, which matches the report being macOS/Chrome-only.findLastAccessedReport. For a brand-new account there is no visit history, so it falls back to "the report with the newestlastReadTime" —ReportUtils.ts:2560-2567.ReportsSplitNavigatorsnapshots that ID in auseStateinitializer on the first render, with no "reports finished loading" guard —ReportsSplitNavigator.tsx:45-68.ReportRouteParamHandlerdoes have that guard and its comment names this exact hazard: picking from a partially loaded collection "can pin a report that isn't really the last accessed one… Neither can be corrected later" —ReportRouteParamHandler.tsx:50-60.openReportwithshouldMarkAsReaddefaulting to true (ReportFetchHandler.tsx:235-253), and the one-shot initial mark-as-read inuseMarkAsRead.ts:171-194callsreadNewestAction. That effect has no screen-focus and no visibility check — unlike the other two mark-as-read effects in the same hook, which requireisVisible && Visibility.hasFocus().readNewestActionwriteslastReadTime = nowand persists it to the server (Report/index.ts:3184-3216), so the chat is read permanently, not just visually.This also explains the odd precondition "do not switch to another tab or use another window": signing in in the same tab means no page reload, so the navigator mounts while B's reports are still streaming in from
OpenApp— and at that instant the chat with A may be the only report present.What changes do you think we should make in order to solve the problem?
Primary fix — a report the user did not explicitly open should not be marked as read. In
useMarkAsRead.ts:171-194, gate the one-shot initial mark-as-read on the same conditions the other two effects already use (screen focused and window visible/focused). Today a report auto-mounted in the central pane — even one sitting behind an onboarding modal — is marked read.Secondary fix — stop the navigator from pinning a report chosen from a half-loaded collection. In
ReportsSplitNavigator.tsx:45-68, apply the sameisLoadingOnyxValueguard thatReportRouteParamHandleruses before locking ininitialReportID.What alternative solutions did you explore?
Alternatives considered and evidence
Stale state left over from account A's session. Ruled out:
KEYS_TO_PRESERVE_ON_SIGN_OUT(SignInRedirect.ts:55-67) preserves no report, route, or read-state key, and the navigation state is reset on sign-out (getStateToResetAfterLogout.ts:27-35). A's optimisticlastReadTimecannot survive into B's session.The sender's
lastReadTimebeing sent to the server. Ruled out on the client: no IOU/money-request API parameter carries a read time — onlyReadNewestActionParams,MarkAsUnreadParams,MarkAllMessagesAsReadParams, andOpenReportParams.clientLastReadTimedo.Not fully ruled out (would need backend access): the server may already return a non-null
lastReadTimefor B's copy of the chat when it materialises the report for the newly created account. If so the fix is in Auth/Web-Expensify, not App, and needs an internal engineer. The decisive check is whether aReadNewestActionrequest is sent for that report within seconds of B signing in (→ App bug, as proposed above) or whetherlastReadTimeis already set in theOpenAppresponse (→ backend bug).A second, independent way the row can render non-bold: the LHN requires a truthy
lastActorAccountID—SidebarUtils.ts:839. If B's copy of the chat comes back without it, the row is not bold regardless oflastReadTime. Worth checking in Onyx during a repro.Verification status: I could not confirm this at runtime — the test session was handed over with the web app stuck on a blank page, so the repro was not executed. The conclusion rests on code reading only, hence medium confidence.
Possibly related issues
readNewestActionsequence.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/102117)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
melvin-bot commentedon Sep 24, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ZhenjaHorbach (
External)melvin-bot commentedon Sep 24, 2026
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
M00rish commentedon Sep 24, 2026
Melvin RCA doesn't hold. Nothing marks the chat as read. Reproduced on web and for the new user
lastReadTimeis unset andisUnread()returnstrue.The row isn't bold because the chat arrives with
lastActorAccountID: "", and the LHN (and the Unread tab) also require that field:App/src/libs/SidebarUtils.ts
Line 839 in e029fad
App/src/libs/SidebarUtils.ts
Line 992 in e029fad
Fix: also accept reports that hold a money request, in both places:
ZhenjaHorbach commentedon Sep 25, 2026
🆘 C+ Help Wanted
Abdulloh0109 commentedon Sep 25, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-09-25 17:50:13 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
A brand-new account B receives a money request from A, signs in and opens the Inbox. The chat with A is shown as read in the LHN (not bold, missing from the Unread tab) even though B never opened it.
What is the root cause of that problem?
The chat really is unread. Only the UI hides it.
B's copy of the chat comes back from
OpenAppwith:isUnread()returnstruefor it, because there is nolastReadTime:App/src/libs/ReportUtils.ts
Lines 9833 to 9845 in e029fad
Three UI call sites then AND that result with
!!report.lastActorAccountID.""is falsy, so each one turns the chat back to "read":getOptionData:App/src/libs/SidebarUtils.ts
Lines 837 to 839 in e029fad
getIsUnreadReportForInboxTab:App/src/libs/SidebarUtils.ts
Lines 987 to 994 in e029fad
shouldUnreadBeBold):App/src/libs/OptionsListUtils/index.ts
Line 2091 in e029fad
The rest of the app has no such guard.
UnreadIndicatorUpdatercalls plainisUnread(), so the browser tab title still counts this chat as(1)while its LHN row is not bold. The app contradicts itself on the same screen:App/src/libs/UnreadIndicatorUpdater/index.ts
Lines 105 to 107 in e029fad
The same holds for the GSD
IS_UNREADreason inreasonForReportToBeInOptionList:App/src/libs/ReportUtils.ts
Lines 10522 to 10526 in e029fad
Why the guard exists, and why it is now only a stale proxy. It was added in Feb 2024 (
617910c3b5a) so a chat whose only message was deleted would not stay bold, becauselastVisibleActionCreatedis not reset on delete. Look at what the delete path actually writes:App/src/libs/actions/Report/index.ts
Lines 5865 to 5871 in e029fad
In the case the guard was written for,
lastActorAccountIDis falsy exactly whenlastMessageTextis empty. Since thenisUnread()has gained anisEmptyReport()check at the very top. It readslastMessageTextfirst and then the last visible message:App/src/libs/ReportUtils.ts
Lines 9815 to 9830 in e029fad
When a caller does not pass
derivedIsEmptyReport,isEmptyReport()falls back to computing it (derivedIsEmptyReport ?? generateIsEmptyReport(...)), so every caller is covered:App/src/libs/ReportUtils.ts
Lines 9729 to 9734 in e029fad
So the deleted-message case is already answered inside
isUnread(). The guard now matters only when a chat has a visible message but arrives without an actor. That is exactly this bug.Why my original
useMarkAsReadtheory was wrong:findLastAccessedReportfalls back to the report with the newestlastReadTime. This chat has none, so it is never the auto-opened report (Concierge is),readNewestActionnever runs for it andlastReadTimestays unset. That also explains why a full page reload does not change the result.What changes do you think we should make in order to solve the problem?
Remove the
!!report.lastActorAccountIDguard from all three UI call sites so they use the same unread signal as the tab title counter:All three sites must change together. If only the LHN row changes, the row turns bold while the Unread tab still says "You're all caught up" and search still shows the chat as read.
Regression safety:
lastMessageTextbecomes''and the deleted action is not visible, soisEmptyReport()istrueandisUnread()returnsfalsebefore any timestamp check. The chat stays not bold.drivingActorAccountID === currentUsercheck insideisUnread().The backend could also send
lastActorAccountIDinOpenAppfor this chat, sinceOpenReportdoes. That would be a nice-to-have, but the App should not depend on the field for read state. Other chats that arrive without it would hit the same bug.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
In
tests/unit/SidebarUtilsTest.tsandtests/unit/OptionsListUtilsTest.tsx:lastReadTime,lastActorAccountID: ""and aREPORTPREVIEWfrom another user (isEmpty: false). It is unread ingetOptionData, it is included bygetIsUnreadReportForInboxTab, and it is bold in the option list. These fail onmain.CREATEDaction was deleted (lastMessageText: '',lastActorAccountID: 0,isEmpty: true). It stays read in all three places. This guards the original [$500] LHN - When you delete a message from a room, the conversation in the members remains bolded #36013 behavior.What alternative solutions did you explore? (Optional)
|| !!report.iouReportID, or fall back to the last visible action's actor). This fixes this repro, but it keeps a second, divergent source of truth for "has a real message" thatisEmptyReport()already owns. It also leaves the bug for any non-IOU chat that arrives with a message but no actor.useMarkAsRead/ delay the split navigator (my first version). Rejected, because this chat is never auto-opened and never marked read, so neither change has any effect.mukhrr commentedon Sep 25, 2026
Proposal
What is the root cause of that problem?
I reproduced this on dev web and the chat is not actually read. It only renders read.
report_2827277120285184) has nolastReadTimeat all, so nothing ever marked it read. Its actions are aCREATEDand aREPORTPREVIEWfrom A (actorAccountID23087835).lastActorAccountID: "", while the IOU report it previews carries"23087835".isUnread()returns true for it. ThelastActorAccountIDguard ingetOptionDatathen turns the result back to false.1736559253892187), and Concierge is also the only report the one-shot initial mark-as-read fired for. So the auto-mount path is not what makes A's chat look read.Observed state on the chat while the bug was on screen:
The guard sits in two places, which is why the bold row and the Unread tab both go quiet:
App/src/libs/SidebarUtils.ts
Lines 836 to 839 in e029fad
App/src/libs/SidebarUtils.ts
Lines 987 to 995 in e029fad
Its comment says it exists so a chat whose only message was deleted does not stay bold, because
lastVisibleActionCreatedis not reset on delete. That was a reasonable proxy when it landed in February 2024 (617910c). It is no longer needed.isUnreadnow takesderivedIsEmptyReportand gates onisEmptyReportbefore anything else:App/src/libs/ReportUtils.ts
Lines 9833 to 9845 in e029fad
generateIsEmptyReportis the purpose-built version of the same check. It falls through togetLastVisibleMessage, which resolves the action throughgetLastVisibleActionand itsisReportActionVisibleAsLastActionfilter, so a chat whose only message was deleted comes back empty andisUnreadreturns false on its own.App/src/libs/ReportUtils.ts
Lines 9819 to 9830 in e029fad
For B's chat with A the derived attribute is
isEmpty: false, which is correct: the report preview is a real visible message. The stale proxy is the only thing suppressing the unread state.flowchart TD A["B's copy of the chat with A lands, no lastReadTime"] -->|"only visible action is a REPORTPREVIEW"| B["lastActorAccountID empty on the chat, 23087835 lives on the IOU report"] B --> C["isUnread() returns true, reportAttributes.isEmpty is false"] C -->|"lastActorAccountID guard reads empty"| D["getOptionData sets isUnread false, LHN row not bold"] C -->|"same guard in getIsUnreadReportForInboxTab"| E["Unread tab: No unread chats"]What changes do you think we should make in order to solve the problem?
Drop the
lastActorAccountIDguard at both sites and letisUnreaddo the emptiness check it already does. The two comments go with it, since the case they describe is now owned byisEmptyReport.and the same removal in
getIsUnreadReportForInboxTab, keeping the mute check.Both have to change together. Fixing only
getOptionDatawould bold the row while the Unread tab still claimed there was nothing to read.With this applied I reloaded the same session and B's chat with A renders bold, and the Unread tab shows it with a count of 1. I added two regression tests to
tests/unit/SidebarUtilsTest.ts, one ongetOptionDataand one ongetReportsToDisplayInLHN, both using a never-read chat withisEmpty: falseand nolastActorAccountID. They fail on current main and pass with the removal, and the other 108 tests in that file still pass.What alternative solutions did you explore? (Optional)
Gating the initial mark-as-read on screen focus and window visibility, or making
ReportsSplitNavigatorwait forIS_LOADING_APPbefore pinning a fallback report. Neither applies here. I watched the split navigator pin Concierge, not A's chat, andreadNewestActionran once, for Concierge. A's chat never got alastReadTimefrom any path, so delaying or suppressing the auto-mount leaves the LHN showing exactly what it shows today.Filling in the missing actor instead, for example falling back to the last visible action's
actorAccountIDwhenreport.lastActorAccountIDis empty. That fixes the symptom but keeps alive a guard thatisEmptyReportalready covers, and it adds an action lookup to a hot LHN path.I also considered whether this is a server-side gap, since
lastActorAccountIDsits empty in Onyx afterOpenApp. It may well be. The App does not need it either way: the emptiness signal it relies on is derived locally and was already correct here.abbasifaizan70 commentedon Sep 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
Account A sends a money request ("IOU") to an email that has no Expensify account yet, which creates a brand‑new pending account B. A signs out, and B signs in for the very first time (same browser tab, no other tab/window used). When B opens the Inbox, the DM with A — which B has never opened before — is already shown as read in the LHN, instead of unread.
What is the root cause of that problem?
isUnread()decides a report's read state in two steps: if the report has nolastReadTimeit's unread, otherwise it compareslastReadTimeto the last visible action's timestamp — unless the last action was written by the current user themselves, in which case it's treated as already read (so you don't see your own just‑sent message flagged unread):App/src/libs/ReportUtils.ts
Lines 9842 to 9843 in e029fad
App/src/libs/ReportUtils.ts
Lines 9855 to 9860 in e029fad
The "self-authored" check compares
drivingActorAccountID(the author of the report's last visible action) against a module‑level variable,deprecatedCurrentUserAccountID, instead of a value passed in as an argument. That variable is kept in sync with the logged-in user via anOnyx.connectonSESSION:App/src/libs/ReportUtils.ts
Lines 1062 to 1075 in e029fad
Notice the early return on line 1066-1068:
// When signed out, val is undefined / if (!value) { return; }. When the session is cleared on sign‑out, this callback simply does nothing — it does not resetdeprecatedCurrentUserAccountIDback toundefined. Because sign‑out → sign‑in happens inside the same JS runtime (same tab), that variable keeps holding A's accountID all through the sign‑out and the start of B's sign‑in, until the newSESSIONvalue (with B's accountID) is eventually merged into Onyx.Now trace what happens for the report with A once B's account data streams in: the report was created for B as part of the money-request flow, so its per‑participant
lastReadTimeis already a real (truthy) timestamp close to the report's creation time — it does not hit the!report.lastReadTimeearly return. The IOU action itself (the last visible action) was authored by A, sodrivingActorAccountID === A. If the LHN row for this report evaluatesisUnread()(viaSidebarUtils.getOptionData→isUnread, called fromApp/src/libs/SidebarUtils.ts
Line 839 in e029fad
) while
deprecatedCurrentUserAccountIDis still stale at A's ID, thendrivingActorAccountID (A) === deprecatedCurrentUserAccountID (A)istrue, and the "self‑authored" branch incorrectly fires —isUnread()returnsfalseeven thoughisUnreadFromTimestampwastrue.This is a one‑shot mistake, but it sticks: the LHN row component that renders this conversation only subscribes to
useOnyxfor that specific report's own keys (REPORT_ACTIONS,REPORT_NAME_VALUE_PAIRS, transactions, etc.) — it has nouseOnyx(ONYXKEYS.SESSION)subscription:https://github.com/Expensify/App/blob/e029fad955164435583153ee7f862942711273cb/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx
Since B never opens the conversation in this repro, none of the report's own Onyx keys change again afterward, so there is nothing to make that row recompute
isUnread()oncedeprecatedCurrentUserAccountIDfinally catches up to B — the wrong "read" result is left standing in the LHN.This lines up exactly with the repro's "do not switch tabs/windows" constraint: a full page reload would re-initialize this module state cleanly from scratch, but a same‑tab sign‑out→sign‑in reuses the running JS module, so the previous user's leftover accountID can momentarily leak into the new user's first render.
Other, equivalent
SESSIONlisteners in this codebase avoid this exact trap by resetting toundefined/a default on sign‑out instead of returning early, e.g.:App/src/libs/UnreadIndicatorUpdater/index.ts
Lines 26 to 31 in e029fad
App/src/libs/Middleware/HandleUnusedOptimisticID.ts
Lines 23 to 27 in e029fad
What changes do you think we should make in order to solve the problem?
Fix the
SESSIONlistener inReportUtils.tsso it stops leaving stale user data behind on sign‑out, matching the pattern already used elsewhere in the codebase (optional‑chain into the new value instead of early‑returning on falsy):App/src/libs/ReportUtils.ts
Lines 1062 to 1075 in e029fad
With this change, as soon as the session is cleared on sign‑out,
deprecatedCurrentUserAccountIDbecomesundefinedinstead of staying pinned to the previous user's accountID. Even if the LHN evaluatesisUnread()for B's reports before the new session finishes populating,drivingActorAccountID === deprecatedCurrentUserAccountIDcan never falsely match a leftover previous‑user ID (A === undefinedis alwaysfalse), so the "self‑authored" short‑circuit can no longer misfire across an account switch, and the conversation with A correctly renders as unread for B.This is a minimal, targeted fix: it doesn't touch the
isUnread()decision logic itself, only removes the stale-state window that lets a previous session's identity leak into a new session's first render — the same safeguard this file's siblingSESSIONlisteners already have.79 remaining items
melvin-bot commentedon Oct 26, 2026
Payment Summary
Resolving PRs:
Stop requiring lastActorAccountID to show a chat as unread #102653
Reviewer: @ZhenjaHorbach owed $250 via NewDot
Reviewer: @mukhrr owed $250 via NewDot
BugZero Checklist (@mallenexpensify)
ZhenjaHorbach commentedon Oct 29, 2026
Contributor+ Checklist:
It's more like a new requirements
[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.
Regression Test Proposal
Precondition:
Test:
Do we agree 👍 or 👎
ZhenjaHorbach commentedon Oct 29, 2026
And there were no regressions here
melvin-bot commentedon Oct 29, 2026
@mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
mallenexpensify commentedon Oct 30, 2026
Payment Summary
Contributor: @mukhrr due $250 via NewDot
Contributor+: @ZhenjaHorbach due $250 via NewDot
mukhrr commentedon Oct 30, 2026
@mallenexpensify I think this is due $250 thanks
mallenexpensify commentedon Oct 30, 2026
@mukhrr you are correct! (not AI sending that, ha)
Price updated cuz
Help Wantedwas addedflaviadefaria commentedon Nov 9, 2026
Approved: @mukhrr due $250 via NewDot
garrettmknight commentedon Dec 1, 2026
$250 approved for @ZhenjaHorbach in Report ID: R003X3aVz75o.