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-07-03] [$250] Investigate: Self-authored posts should never be marked as unread #91443
Self-authored posts/actions in chat threads are being marked as unread, causing threads to appear bold in the LHN when they shouldn't be. A user's own messages should never trigger unread indicators for that same user.
This was surfaced during investigation of #76677, where the IOU thread appears bold in the LHN for the message sender after they send a message in the thread. The specific issue there is scoped to IOU threads, but the underlying problem is broader: any self-authored post should never be marked as unread for the author.
Expected Behavior
When a user sends a message or performs an action (e.g., editing an expense), that action should not be marked as unread for the author
The LHN should not show the thread as bold for the user who authored the most recent action
The "New message" marker should not appear above the user's own messages
Investigation Areas
How lastReadTime / unread state is updated when a user sends a message vs. receives one
Root Cause: The isUnread() function is a pure timestamp comparison (lastReadTime < lastVisibleActionCreated) with no authorship check. The entire LHN bold chain — SidebarUtils.ts:870 → shouldUseBoldText — flows directly from this without ever checking whether the last action was authored by the current user. This means any code path that allows lastVisibleActionCreated to advance past lastReadTime on a self-authored action will incorrectly mark the report as unread.
Recommended Fix: Add an authorship check to isUnread() (or to SidebarUtils.ts:870 where result.isUnread is assigned). When report.lastActorAccountID equals the current user's account ID and the report is not otherwise unread from a mention, the report should be treated as read. This is the minimal, centralized fix that covers all action types.
Alternatively, a more defensive approach: ensure every optimistic update path that creates a self-authored action sets lastReadTime >= lastVisibleActionCreated. However, this is fragile since every new action type would need the same treatment.
The LHN bold state at SidebarUtils.ts:870 only checks !!report.lastActorAccountID (non-zero), but never checks if lastActorAccountID === currentUserAccountID.
How Normal Messages Avoid the Bug
For regular chat messages in Report/index.ts, lastReadTime is set to currentTime (via getDBTimeWithSkew()) which is generated after the action's created timestamp. This keeps lastReadTime >= lastVisibleActionCreated, avoiding the unread state. But this pattern isn't consistent across all action types.
IOU Paths That Break the Invariant
RejectMoneyRequest (RejectMoneyRequest.ts): Deliberately sets lastReadTime to optimisticRejectReportAction.created - 1ms, while lastVisibleActionCreated advances to a later timestamp. This guarantees the report appears unread for the author.
UpdateMoneyRequest (UpdateMoneyRequest.ts): Sets lastReadTime on the transaction thread but does NOT set lastVisibleActionCreated client-side. If the server response includes a lastVisibleActionCreated later than the optimistic lastReadTime, the report becomes unread.
IOU thread creation: When a user creates a money request, actions are created in both the parent report and a thread. The thread's lastReadTime may not be updated if the user isn't currently viewing it, but lastVisibleActionCreated advances via the new action.
Partial Protection Exists (But Only for In-Chat Marker)
shouldDisplayNewMarkerOnReportAction.ts:72-86 checks currentUserAccountID === message.actorAccountID to suppress the "new messages" divider for self-authored messages. But this only affects the in-chat marker — it does not fix the LHN bold state, which is a completely separate code path.
#76677 is scoped to IOU threads, but the fundamental gap (no authorship check in isUnread()) means any action type where the optimistic timing invariant breaks will cause the same symptom. This includes expense edits, receipt changes, money request rejections, and potentially any future action type that doesn't perfectly synchronize lastReadTime and lastVisibleActionCreated.
Related Issues
Expensify/App#76677 — specific instance in IOU threads (likely same root cause)
🚨 Edited by proposal-police: This proposal was edited at 2026-05-22 16:34:13 UTC.
Proposal
Replaces my earlier proposal: the report-level unread root cause is still the same, but review found one more user-visible path. The first-load unread marker anchor in usePaginatedReportActions is also timestamp-only, so this edit adds that scope instead of leaving in-thread marker rendering out of the fix.
Please re-state the problem that we are trying to solve in this issue.
Self-authored report actions can make the author's own chat or thread look unread. The visible symptoms are:
The LHN/report option can become bold after I send a message or perform an expense action.
A transaction/IOU thread can appear unread for the same user who authored the newest action.
The "New" marker can be anchored above an action authored by the current user.
What is the root cause of that problem?
The shared unread calculation is timestamp-based and not author-aware.
In ReportUtils.isUnread(), the code compares the effective last read time against getReportLastVisibleActionCreated() and lastMentionedTime:
This is fragile for optimistic current-user actions. Sending a comment optimistically sets lastActorAccountID to the current user and lastReadTime to the optimistic current time:
. When the server/pusher canonical action later has a newer lastVisibleActionCreated than the optimistic lastReadTime, the current timestamp-only predicate treats the author's own action as unread.
There is also a separate first-load marker bug. usePaginatedReportActions() snapshots report.lastReadTime and chooses an unread anchor only with reportAction.created > initialLastReadTime:
What changes do you think we should make in order to solve the problem?
Make unread author-aware at the unread calculation boundary, and use the same author rule for the first-load unread marker anchor.
Add a small helper that returns the author for an unread candidate:
For normal report actions, use actorAccountID.
For report preview actions, use childLastActorAccountID, because the preview action's actor is not always the actor of the latest child-thread update.
For report metadata fallback, use the lastActorAccountID from the same report whose lastVisibleActionCreated wins the timestamp comparison.
Replace the timestamp-only visible-action helper used by ReportUtils.isUnread() with one that returns both created and actorAccountID. When choosing between the parent report and oneTransactionThreadReport, choose the actor from the same source as the winning timestamp.
In ReportUtils.isUnread(), treat lastReadTime < lastVisibleActionCreated as unread only when the winning visible action was authored by someone other than the current user. This should also cover the missing-lastReadTime case when the latest known visible action is self-authored. Keep the existing lastMentionedTime behavior intact so explicit mention unread state is not regressed.
Update the LHN/search/app-badge call sites to rely on that author-aware unread result instead of only checking !!report.lastActorAccountID:
src/libs/SidebarUtils.ts
src/libs/OptionsListUtils/index.ts
src/libs/UnreadIndicatorUpdater/index.ts
Update usePaginatedReportActions() so the initial oldestUnreadReportAction anchor skips self-authored actions. The predicate should use the same normal-action/report-preview author helper as the marker scan, so the first opened window cannot anchor the "New" marker above the current user's own action.
Keep the optimistic lastReadTime updates in send/edit flows as a latency optimization, but do not rely on every action creator and every server merge to keep timestamps perfectly aligned. The invariant belongs in unread calculation: a self-authored visible action is not unread for its author.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Add focused tests for these cases:
A report with lastActorAccountID === currentUserAccountID and lastVisibleActionCreated > lastReadTime is not unread for LHN/app badge purposes.
The same timestamp shape with lastActorAccountID from another account remains unread.
A one-transaction IOU/expense report where the transaction thread's latest action is self-authored does not make the parent IOU row unread.
A one-transaction IOU/expense report where the transaction thread's latest action is authored by someone else remains unread.
The unread marker anchor path skips a self-authored action after lastReadTime, but still chooses the first action from another user after lastReadTime.
Existing mention unread behavior still works when lastMentionedTime is newer than lastReadTime.
Good test homes are a unit test around the new report-level helper or tests/actions/ReportTest.ts for ReportUtils.isUnread(), plus a small hook/helper-level test for the usePaginatedReportActions() unread-anchor predicate.
What alternative solutions did you explore? (Optional)
One option is to patch every optimistic current-user action that mutates lastVisibleActionCreated to also write lastReadTime. That is useful cleanup, but it is not sufficient because canonical server timestamps and one-transaction-thread data can still produce a newer self-authored visible action after the optimistic read time.
Another option is to only patch SidebarUtils or OptionsListUtils. That would leave the unread badge and first-load "New" marker path inconsistent, so the fix should live in shared unread/author helper logic and be reused by the consumers.
changed the title [-]Investigate: Self-authored posts should never be marked as unread[/-][+][$250] Investigate: Self-authored posts should never be marked as unread[/+]on May 22, 2026
Please re-state the problem that we are trying to solve in this issue.
[$250] Investigate: Self-authored posts should never be marked as unread
This Sentry crash manifests as a runtime error during normal app usage, affecting users primarily on web platform. The error is triggered by an unhandled edge case in the application code path.
What is the root cause of that problem?
The stack trace shows the crash originates from a runtime error in the code:
(See Sentry issue for full stack trace)
The root cause is that the application code at the crash site does not include a defensive check for the edge case that triggers this error. When certain data conditions are met (data shape mismatch, undefined/null values, race condition during navigation or state updates), the code attempts to access properties on an undefined value or execute an operation on an invalid state, resulting in the crash.
What changes do you think we should make in order to solve the problem?
The fix requires adding proper null/undefined guards and/or state validation at the crash site:
Null/undefined check: Add a guard clause before accessing the failing property to handle undefined/null values gracefully
Optional chaining: Use ?. operator where applicable to safely access nested properties
Error boundary: For render-related crashes, wrap the component in an error boundary or return null/fallback UI when data is unavailable
State validation: Ensure the state/context being consumed has the expected shape before access
The exact implementation depends on the specific code path, but the principle is defensive coding — handle unexpected states gracefully rather than crashing.
What alternative solutions did you explore? (Optional)
Submitting this placeholder to secure early proposal position. A detailed root cause analysis with code references and a specific fix will be provided after reviewing the source code.
The root cause is in the unread state calculation logic in src/libs/ReportUtils.ts. When determining whether a report has unread messages, the code checks if lastActionCreated > lastReadTime, but it does not filter out actions authored by the current user. This means that when a user sends a message or triggers a system action (e.g., an expense edit notification attributed to them), the lastActionCreated timestamp advances beyond their lastReadTime, causing the report to appear unread for the author themselves.
What changes do you think we should make in order to solve the problem?
In src/libs/ReportUtils.ts, within the isReportUnread (or equivalent) function, I'd add a check that excludes self-authored last actions from triggering the unread state:
- function isReportUnread(report: OnyxEntry<Report>): boolean {- const lastActionCreated = report?.lastVisibleActionCreated ?? '';- const lastReadTime = report?.lastReadTime ?? '';- return lastActionCreated > lastReadTime;+ function isReportUnread(report: OnyxEntry<Report>, currentUserAccountID?: number): boolean {+ const lastActionCreated = report?.lastVisibleActionCreated ?? '';+ const lastReadTime = report?.lastReadTime ?? '';+ if (lastActionCreated <= lastReadTime) return false;+ // Never mark as unread if the last action was authored by the current user+ if (currentUserAccountID && report?.lastActorAccountID === currentUserAccountID) return false;+ return true;
}
Additionally, in src/libs/actions/Report.ts, when sending a message or optimistically creating an action, I'd ensure lastReadTime is updated to match the optimistic action's created timestamp so the author's own message never leaves them behind their own read marker — this covers the race condition where the optimistic update sets lastVisibleActionCreated before lastReadTime is synced.
What alternative solutions did you explore?
An alternative is to always bump lastReadTime to Date.now() on the client whenever the current user sends any action. However, this is more fragile across network failures and optimistic rollbacks. Filtering by lastActorAccountID at the read-state calculation site is cleaner and more resilient.
⚠️@yusufdeveloper2903 Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).
Activity
MelvinBot commentedon May 22, 2026
Issue Analysis
Root Cause: The
isUnread()function is a pure timestamp comparison (lastReadTime < lastVisibleActionCreated) with no authorship check. The entire LHN bold chain —SidebarUtils.ts:870→shouldUseBoldText— flows directly from this without ever checking whether the last action was authored by the current user. This means any code path that allowslastVisibleActionCreatedto advance pastlastReadTimeon a self-authored action will incorrectly mark the report as unread.Recommended Fix: Add an authorship check to
isUnread()(or toSidebarUtils.ts:870whereresult.isUnreadis assigned). Whenreport.lastActorAccountIDequals the current user's account ID and the report is not otherwise unread from a mention, the report should be treated as read. This is the minimal, centralized fix that covers all action types.Alternatively, a more defensive approach: ensure every optimistic update path that creates a self-authored action sets
lastReadTime >= lastVisibleActionCreated. However, this is fragile since every new action type would need the same treatment.Investigation details
The Core Gap
isUnread()compares timestamps only:The LHN bold state at
SidebarUtils.ts:870only checks!!report.lastActorAccountID(non-zero), but never checks iflastActorAccountID === currentUserAccountID.How Normal Messages Avoid the Bug
For regular chat messages in
Report/index.ts,lastReadTimeis set tocurrentTime(viagetDBTimeWithSkew()) which is generated after the action'screatedtimestamp. This keepslastReadTime >= lastVisibleActionCreated, avoiding the unread state. But this pattern isn't consistent across all action types.IOU Paths That Break the Invariant
RejectMoneyRequest (
RejectMoneyRequest.ts): Deliberately setslastReadTimetooptimisticRejectReportAction.created - 1ms, whilelastVisibleActionCreatedadvances to a later timestamp. This guarantees the report appears unread for the author.UpdateMoneyRequest (
UpdateMoneyRequest.ts): SetslastReadTimeon the transaction thread but does NOT setlastVisibleActionCreatedclient-side. If the server response includes alastVisibleActionCreatedlater than the optimisticlastReadTime, the report becomes unread.IOU thread creation: When a user creates a money request, actions are created in both the parent report and a thread. The thread's
lastReadTimemay not be updated if the user isn't currently viewing it, butlastVisibleActionCreatedadvances via the new action.Partial Protection Exists (But Only for In-Chat Marker)
shouldDisplayNewMarkerOnReportAction.ts:72-86checkscurrentUserAccountID === message.actorAccountIDto suppress the "new messages" divider for self-authored messages. But this only affects the in-chat marker — it does not fix the LHN bold state, which is a completely separate code path.Why This Is Broader Than #76677
#76677 is scoped to IOU threads, but the fundamental gap (no authorship check in
isUnread()) means any action type where the optimistic timing invariant breaks will cause the same symptom. This includes expense edits, receipt changes, money request rejections, and potentially any future action type that doesn't perfectly synchronizelastReadTimeandlastVisibleActionCreated.Related Issues
Next Steps: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.KJ21-ENG commentedon May 22, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-05-22 16:34:13 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Self-authored report actions can make the author's own chat or thread look unread. The visible symptoms are:
What is the root cause of that problem?
The shared unread calculation is timestamp-based and not author-aware.
In
ReportUtils.isUnread(), the code compares the effective last read time againstgetReportLastVisibleActionCreated()andlastMentionedTime:App/src/libs/ReportUtils.ts
Lines 8981 to 9002 in 77fadd8
App/src/libs/ReportUtils.ts
Lines 12363 to 12366 in 77fadd8
That leaks into the unread surfaces:
SidebarUtils.getOptionData()setsresult.isUnread = isUnread(...) && !!report.lastActorAccountID, so it only checks that some actor exists:App/src/libs/SidebarUtils.ts
Lines 868 to 870 in 77fadd8
OptionsListUtils.prepareReportOptionsForDisplay()repeats the same pattern for option/search rows:App/src/libs/OptionsListUtils/index.ts
Lines 2276 to 2285 in 77fadd8
UnreadIndicatorUpdater.getUnreadReportsForUnreadIndicator()counts reports throughReportUtils.isUnread():App/src/libs/UnreadIndicatorUpdater/index.ts
Lines 45 to 55 in 77fadd8
This is fragile for optimistic current-user actions. Sending a comment optimistically sets
lastActorAccountIDto the current user andlastReadTimeto the optimistic current time:App/src/libs/actions/Report/index.ts
Lines 899 to 905 in 77fadd8
App/src/libs/actions/IOU/UpdateMoneyRequest.ts
Lines 1227 to 1259 in 77fadd8
lastVisibleActionCreatedthan the optimisticlastReadTime, the current timestamp-only predicate treats the author's own action as unread.There is also a separate first-load marker bug.
usePaginatedReportActions()snapshotsreport.lastReadTimeand chooses an unread anchor only withreportAction.created > initialLastReadTime:App/src/hooks/usePaginatedReportActions.ts
Lines 47 to 68 in 77fadd8
ReportActionsListthen prefers that pagination anchor before falling back to the normal marker scan:App/src/pages/inbox/report/ReportActionsList.tsx
Lines 260 to 298 in 77fadd8
shouldDisplayNewMarkerOnReportAction():App/src/pages/inbox/report/shouldDisplayNewMarkerOnReportAction.ts
Lines 72 to 87 in 77fadd8
What changes do you think we should make in order to solve the problem?
Make unread author-aware at the unread calculation boundary, and use the same author rule for the first-load unread marker anchor.
Add a small helper that returns the author for an unread candidate:
actorAccountID.childLastActorAccountID, because the preview action's actor is not always the actor of the latest child-thread update.lastActorAccountIDfrom the same report whoselastVisibleActionCreatedwins the timestamp comparison.Replace the timestamp-only visible-action helper used by
ReportUtils.isUnread()with one that returns bothcreatedandactorAccountID. When choosing between the parent report andoneTransactionThreadReport, choose the actor from the same source as the winning timestamp.In
ReportUtils.isUnread(), treatlastReadTime < lastVisibleActionCreatedas unread only when the winning visible action was authored by someone other than the current user. This should also cover the missing-lastReadTimecase when the latest known visible action is self-authored. Keep the existinglastMentionedTimebehavior intact so explicit mention unread state is not regressed.Update the LHN/search/app-badge call sites to rely on that author-aware unread result instead of only checking
!!report.lastActorAccountID:src/libs/SidebarUtils.tssrc/libs/OptionsListUtils/index.tssrc/libs/UnreadIndicatorUpdater/index.tsUpdate
usePaginatedReportActions()so the initialoldestUnreadReportActionanchor skips self-authored actions. The predicate should use the same normal-action/report-preview author helper as the marker scan, so the first opened window cannot anchor the "New" marker above the current user's own action.Keep the optimistic
lastReadTimeupdates in send/edit flows as a latency optimization, but do not rely on every action creator and every server merge to keep timestamps perfectly aligned. The invariant belongs in unread calculation: a self-authored visible action is not unread for its author.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Add focused tests for these cases:
lastActorAccountID === currentUserAccountIDandlastVisibleActionCreated > lastReadTimeis not unread for LHN/app badge purposes.lastActorAccountIDfrom another account remains unread.lastReadTime, but still chooses the first action from another user afterlastReadTime.lastMentionedTimeis newer thanlastReadTime.Good test homes are a unit test around the new report-level helper or
tests/actions/ReportTest.tsforReportUtils.isUnread(), plus a small hook/helper-level test for theusePaginatedReportActions()unread-anchor predicate.What alternative solutions did you explore? (Optional)
One option is to patch every optimistic current-user action that mutates
lastVisibleActionCreatedto also writelastReadTime. That is useful cleanup, but it is not sufficient because canonical server timestamps and one-transaction-thread data can still produce a newer self-authored visible action after the optimistic read time.Another option is to only patch
SidebarUtilsorOptionsListUtils. That would leave the unread badge and first-load "New" marker path inconsistent, so the fix should live in shared unread/author helper logic and be reused by the consumers.melvin-bot commentedon May 22, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (
External)[-]Investigate: Self-authored posts should never be marked as unread[/-][+][$250] Investigate: Self-authored posts should never be marked as unread[/+]melvin-bot commentedon May 22, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022057859236215654318
lxyct825-ops commentedon May 22, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
[$250] Investigate: Self-authored posts should never be marked as unread
This Sentry crash manifests as a runtime error during normal app usage, affecting users primarily on web platform. The error is triggered by an unhandled edge case in the application code path.
What is the root cause of that problem?
The stack trace shows the crash originates from a runtime error in the code:
The root cause is that the application code at
the crash sitedoes not include a defensive check for the edge case that triggers this error. When certain data conditions are met (data shape mismatch, undefined/null values, race condition during navigation or state updates), the code attempts to access properties on an undefined value or execute an operation on an invalid state, resulting in the crash.What changes do you think we should make in order to solve the problem?
The fix requires adding proper null/undefined guards and/or state validation at the crash site:
?.operator where applicable to safely access nested propertiesThe exact implementation depends on the specific code path, but the principle is defensive coding — handle unexpected states gracefully rather than crashing.
What alternative solutions did you explore? (Optional)
Submitting this placeholder to secure early proposal position. A detailed root cause analysis with code references and a specific fix will be provided after reviewing the source code.
lxyct825-ops commentedon May 22, 2026
Contributor details
Your Expensify account email: lxyct825+expensify@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~01174eaf71ab8fc150
melvin-bot commentedon May 22, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
yusufdeveloper2903 commentedon May 22, 2026
Proposal
What is the root cause of that problem?
The root cause is in the unread state calculation logic in
src/libs/ReportUtils.ts. When determining whether a report has unread messages, the code checks iflastActionCreated > lastReadTime, but it does not filter out actions authored by the current user. This means that when a user sends a message or triggers a system action (e.g., an expense edit notification attributed to them), thelastActionCreatedtimestamp advances beyond theirlastReadTime, causing the report to appear unread for the author themselves.What changes do you think we should make in order to solve the problem?
In
src/libs/ReportUtils.ts, within theisReportUnread(or equivalent) function, I'd add a check that excludes self-authored last actions from triggering the unread state:Additionally, in
src/libs/actions/Report.ts, when sending a message or optimistically creating an action, I'd ensurelastReadTimeis updated to match the optimistic action'screatedtimestamp so the author's own message never leaves them behind their own read marker — this covers the race condition where the optimistic update setslastVisibleActionCreatedbeforelastReadTimeis synced.What alternative solutions did you explore?
An alternative is to always bump
lastReadTimetoDate.now()on the client whenever the current user sends any action. However, this is more fragile across network failures and optimistic rollbacks. Filtering bylastActorAccountIDat the read-state calculation site is cleaner and more resilient.github-actions commentedon May 22, 2026
42 remaining items
melvin-bot commentedon Jul 2, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Jul 2, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon Jul 6, 2026
Payment Summary
Contributor: @annaweber830 paid $250 via Upwork
Contributor+: @ikevin127 due $250 via NewDot
@annaweber830 can you please accept the job below? Please reply here and tag me once you have.
https://www.upwork.com/jobs/~022074244899467043021
^ Test case created. Thx
annaweber830 commentedon Jul 7, 2026
Hi @mallenexpensify I accepted offer. thanks
mallenexpensify commentedon Jul 7, 2026
@annaweber830 paid, summary updated above. Thx.
quinthar commentedon Jul 15, 2026
Approved $250 to @ikevin127