App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Chat - Opening a room at its oldest unread message never loads newer messages, so the newest messages stay hidden while the LHN shows them

Open mallenexpensify opened this issue 1 month ago • 59 comments

Version Number: 9.5.21-0 Reproducible in staging?: Unknown Reproducible in production?: Yes Email or phone of affected tester (no customers): Internal (@mallenexpensify) Issue reported by: @mallenexpensify Bug source: Internal Device used: MacOS desktop app App Component: Chat Report View

Action Performed

  1. Leave a busy room unread overnight while the desktop app is asleep and the session token expires.
  2. Wake the computer and open the room from the LHN right away.

No reliable reproduction steps are confirmed yet. This was seen once on 2026-10-27.

Expected Result

The chat shows every message up to the newest one, the same as the LHN preview. If the first page doesn't reach the newest message, the app loads newer messages.

Actual Result

  • The LHN preview shows the newest message, from 7:00 AM PDT.
  • The chat view stops at the 6:33:30 AM PDT message.
  • The 3 newer messages never show.
  • The room is still marked as read.
  • There are no errors in the console.

Workaround

Not confirmed. Opening another chat and coming back, or using Troubleshoot → Clear cache and restart, should load the missing messages.

Platforms

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [x] MacOS: Desktop

Screenshots/Videos

Screenshot to be added in a comment.

Analysis

Server timeline (2026-10-27, UTC)

Time Command Result
15:12:24.887 ReconnectApp 407, token expired
15:12:25.221 Authenticate 200
15:12:26.651 ReconnectApp (retry) 200
15:12:28.322 OpenReport reportID: 6549335221793525, useLastUnreadReportAction: true, clientLastReadTime: 2026-10-27 01:30:42.130 200
15:13:01.215 ReadNewestAction reportID: 6549335221793525 200

Between 15:12 and 15:40 there was no GetNewerActions call. GetOlderActions was called twice.

View in VMUI (internal)

Client state (Onyx export after the bug)

report_6549335221793525

  • lastVisibleActionCreated is 14:00:01.032, which the LHN uses.
  • lastReadTime is 15:13:00.895.

reportActions_6549335221793525 holds all of these actions:

reportActionID created (UTC) In page?
4369863963592747393 13:33:30.106 yes (newest in page)
7846867715777742571 13:33:42.558 no
2600890658472547730 13:42:31.609 no
6933217277101093990 14:00:01.032 no

reportActionsPages_6549335221793525

  • One page of 162 IDs, from 4369863963592747393 to 6279233242973018197.
  • The page has no -1 newest-end marker.
  • This is the only report out of 49 with pages that is missing the marker.

Likely cause

  1. OpenReport with useLastUnreadReportAction returns a page that starts at the oldest unread message. When a room has many unread messages, that page doesn't reach the newest one, so it has no -1 marker.
  2. The 3 newer actions reached Onyx some other way, most likely from the ReconnectApp retry. They aren't in any page, so getContinuousChain leaves them out.
  3. The client never calls GetNewerActions. One possibility is that because those actions are already in Onyx, the list believes it's at the newest message. This needs confirming in the code.
  4. ReadNewestAction marks the room read even though the newest messages aren't shown.

Questions

  • How does the report view decide whether it has newer actions after a linked or unread-based OpenReport? Does it count actions that are stored but not in a page?
  • Should actions that arrive through ReconnectApp or Pusher be merged into the page when the page doesn't reach the newest message?
  • Should ReadNewestAction wait until the newest action is actually shown?

Related: https://github.com/Expensify/App/issues/104900, which has the same trigger (wake + expired token → 407 → reauth). Reauthentication worked here, so this is a separate bug. Also https://github.com/Expensify/App/issues/99214, which has a similar symptom, but there the message never reached the client.

🤖 Generated with Claude Code

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

mallenexpensify avatar Oct 27 '26 23:10 mallenexpensify

Checking with C+ to see if they can repro

  • https://expensify.slack.com/archives/C02NK2DQWUX/p1793143461137159

mallenexpensify avatar Oct 27 '26 23:10 mallenexpensify

Looks like related to our ongoing PR https://github.com/Expensify/App/pull/104433, @mukhrr wdyt?

eh2077 avatar Oct 28 '26 00:10 eh2077

Looks like related to our ongoing PR #104433, @mukhrr wdyt?

@eh2077 hmmm.. GetNewerActions stops firing at the newest end. Nothing is rewound and all actions are in Onyx, just not in the page, so I dont think its related to #104433

mukhrr avatar Oct 28 '26 06:10 mukhrr

Meanwhile I able to reproduce this bug with following steps:

Steps

  1. Use two accounts, A (reader) and B (sender), in separate browsers.
  2. B starts a DM with A and sends one message. A opens the DM, then goes to Inbox.
  3. A closes the tab completely.
  4. B sends about 200 messages into the DM. Short ones are fine ("1", Enter, "2", Enter...) (or use console script to send once)
  5. A opens the app and waits about 10 seconds on Inbox.
  6. A opens the DM.
  7. A scrolls to the bottom of the chat and keeps scrolling.

Expected result

The chat loads newer messages until it reaches B's last message, the same one the LHN preview shows.

Actual result

  • The chat opens at B's first unread message, loads a page or two, then stops partway.
  • The LHN preview shows B's last message.
  • The DM is already marked read.
  • More scrolling at the bottom loads nothing.
  • Scrolling up until older messages load, then back down, loads one more page and stops again.

https://github.com/user-attachments/assets/a95bb6cc-5808-4300-ba7d-78c34f14c29e

@eh2077 can you pls try also?

mukhrr avatar Oct 28 '26 07:10 mukhrr

Meanwhile I able to reproduce this bug with following steps:

Steps

  1. Use two accounts, A (reader) and B (sender), in separate browsers.
  2. B starts a DM with A and sends one message. A opens the DM, then goes to Inbox.
  3. A closes the tab completely.
  4. B sends about 200 messages into the DM. Short ones are fine ("1", Enter, "2", Enter...) (or use console script to send once)
  5. A opens the app and waits about 10 seconds on Inbox.
  6. A opens the DM.
  7. A scrolls to the bottom of the chat and keeps scrolling.

Expected result

The chat loads newer messages until it reaches B's last message, the same one the LHN preview shows.

Actual result

  • The chat opens at B's first unread message, loads a page or two, then stops partway.
  • The LHN preview shows B's last message.
  • The DM is already marked read.
  • More scrolling at the bottom loads nothing.
  • Scrolling up until older messages load, then back down, loads one more page and stops again.

105204-before-web.mp4 @eh2077 can you pls try also?

@eh2077 kindly bump

mukhrr avatar Nov 02 '26 09:11 mukhrr

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

melvin-bot[bot] avatar Nov 04 '26 00:11 melvin-bot[bot]

Hard to reproduce

mallenexpensify avatar Nov 04 '26 00:11 mallenexpensify

@mallenexpensify 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Nov 04 '26 02:11 melvin-bot[bot]

@mallenexpensify Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Nov 09 '26 21:11 melvin-bot[bot]

@mukhrr , assigning you as C+, for once you've been onboarded.

mallenexpensify avatar Nov 11 '26 02:11 mallenexpensify

@mallenexpensify thanks. I think I am not able to have Melvin to propose a fix yet. but let me try at least.

@MelvinBot can you try to reproduce based on this and give a proposal?

mukhrr avatar Nov 11 '26 09:11 mukhrr

@MelvinBot can you try to reproduce based on this and give a proposal?

mukhrr avatar Nov 17 '26 11:11 mukhrr

@MelvinBot can you try to reproduce based on https://github.com/Expensify/App/issues/105204#issuecomment-6462959439 and give a proposal?

mallenexpensify avatar Nov 17 '26 18:11 mallenexpensify

🤖 Web test steps verification results: ❌ fail

The reproduction was blocked: this test environment supports only one pinned browser session, but the documented steps require two accounts in separate browsers and closing/reopening the reader’s tab. No product failure was confirmed, and no screenshots were captured.

Step Status
1. Open reader A and sender B in separate browsersA second account/browser session is unavailable.
❌
2. Send an initial DM; A opens it and returns to InboxNot executed because the two-account setup was blocked.
❌
3. Close A’s tab completelyNot executed; manually closing the pinned session is unsupported.
❌
4. B sends about 200 messagesNot executed because a separate sender session is unavailable.
❌
5. A reopens the app and waits 10 seconds on InboxNot executed because the prerequisites were blocked.
❌
6. A opens the DMNot executed because the required conversation was not created.
❌
7. Scroll repeatedly; compare chat, LHN preview, and read stateNot executed. The pagination stall and premature read state remain unverified.
❌
Preliminary proposal — code-supported hypothesis, not a confirmed fix

Proposal

What is the root cause of that problem?

Not confirmed. The strongest candidate is that the list’s “load newer” callback stays latched after loading a page. This could explain why scrolling farther down does nothing, but scrolling away and back permits another page.

Supporting evidence:

The premature read state remains unexplained: current automatic mark-as-read paths already check for unloaded newer actions.

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

First confirm that the callback remains latched during the reported stall. If confirmed, rearm newer-page loading when its leading boundary advances, without requiring scrolling away and back. Preserve duplicate-request protection.

Regression coverage should verify multiple consecutive newer pages, reaching the newest message without leaving the bottom, and keeping the report unread while newer messages remain unloaded.

What alternative solutions did you explore? (Optional)

Do not merge all cached messages into the displayed page or manufacture a newest-end marker: cached messages do not establish continuity.

Blocker: a two-account reproduction with callback/scroll-state capture is still needed before treating this as an implementation-ready proposal.


view run

MelvinBot avatar Nov 17 '26 18:11 MelvinBot

well thanks, Matt. I think we need to open this for contributors.

[!NOTE] Only proposals with before/after videos are reviewed to be sure if they really work

🆘 C+ Help Wanted

mukhrr avatar Nov 18 '26 02:11 mukhrr

🚨 Edited by proposal-police: This proposal was edited at 2026-11-18 04:38:46 UTC.

Proposal

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

When a chat opens in the middle of its history (oldest unread or a linked message) and the user scrolls to the bottom of what's loaded, newer messages stop loading after a page or two, so the newest messages stay hidden while the LHN shows them.

What is the root cause of that problem?

In the inbox chat, newer messages are only ever requested from the list's onStartReached

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/pages/inbox/report/ReportActionsList/useReportActionsListScroll.ts#L164-L175

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/pages/inbox/report/ReportActionsList/useReportActionsListScroll.ts#L199-L200

FlashList fires onStartReached only once each time the offset enters the start zone (0.75 * viewport here). It sets pendingStartReached and only clears it when the offset leaves the zone again. Unlike pendingEndReached, it's never reset when data changes (useBoundDetection.ts#L112-L122, compare with the end reset at #L165-L170):

const isNearStart = lastScrollOffset <= startThresholdDistance;

if (isNearStart && !pendingStartReached.current) {
  pendingStartReached.current = true;
  onStartReached();
}
pendingStartReached.current = isNearStart;

The only thing that moves the offset out of that zone after a newer page lands is MVCP. But we turn MVCP off while the user is within 250px of the bottom

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/hooks/useReportActionsScroll.ts#L203-L214

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/pages/inbox/report/ReportActionsList/ReportActionsListContent.tsx#L131

So with the user at the bottom of the loaded chunk:

  1. onStartReached fires once, GetNewerActions loads a page
  2. the page is added below with MVCP off, so the offset stays ~0, still in the start zone
  3. pendingStartReached stays true and onStartReached never fires again, even though hasNewerActions is still true (the page still has no -1 marker)

This is exactly the repro above: "loads a page or two, then stops", scrolling more at the bottom does nothing, and scrolling up (offset leaves the zone) and back down loads exactly one more page and stops again.

Our own pagination test only passes the second GetNewerActions because it fakes the MVCP offset jump by hand, scrolling to 500 and back to 0. A real user sitting at the bottom never does that

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/tests/ui/PaginationTest.tsx#L395-L398

I confirmed it in PaginationTest. With the user staying at offset 0 after the first newer page lands, main calls GetNewerActions with cursor 5 and never with cursor 10. The test fails right at the second call.

The original report (no GetNewerActions at all) is the same latch, just taken earlier. On wake the list mounts at the bottom with cached data and fires onStartReached while loadNewerChats still bails out (the cached page still has the -1 marker until OpenReport strips it, or the app is still reconnecting)

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/hooks/useLoadReportActions.ts#L102-L114

When the middle-slice OpenReport lands and hasNewerActions flips to true, FlashList is already latched, so nothing asks for the gap. The 3 actions from ReconnectApp stay in Onyx outside any page, and getContinuousChain correctly leaves them out.

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

We shouldn't rely on FlashList re-firing onStartReached while the user sits at the newest edge. When there are newer actions and the newer-actions cursor moves (a newer page landed, or OpenReport flipped hasNewerActions to true), and the user is still at the bottom, we request the next page ourselves.

We already auto-load newer pages for money request reports in useMoneyRequestReportPagination

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/components/MoneyRequestReportView/useMoneyRequestReportPagination.ts#L79-L101

In useReportActionsListScroll, after loadNewerChatsAfterTransitions:

const [newestFetchedReportActionID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_PAGINATION_STATE}${reportID}`, {selector: (state) => state?.newestFetchedReportActionID});
const newerPageAutoLoadKey = hasNewerActions ? (newestFetchedReportActionID ?? listData.at(0)?.reportActionID) : undefined;
const lastNewerPageAutoLoadKeyRef = useRef(newerPageAutoLoadKey);
const loadNewerChatsAtBottom = useEffectEvent(() => {
    if (hasScrolledOverThreshold) {
        return;
    }
    loadNewerChatsAfterTransitions();
});
useEffect(() => {
    if (!newerPageAutoLoadKey || lastNewerPageAutoLoadKeyRef.current === newerPageAutoLoadKey) {
        return;
    }
    lastNewerPageAutoLoadKeyRef.current = newerPageAutoLoadKey;
    loadNewerChatsAtBottom();
}, [newerPageAutoLoadKey]);
  • it's keyed on the same cursor loadNewerChats sends (newestFetchedReportActionID), not on the newest rendered row. The page and the pagination state are separate Onyx keys, so the page can render first, and keying on the row resends the old cursor and gets the same page back (I hit this on a real account, it stopped at the 3rd page)
  • the ref starts at the mount value, so we don't double up the first request that onStartReached already sends on open
  • it fires once per page that moves the newest edge, and stops once the server says there's nothing newer (-1 marker makes hasNewerActions false), so it can't loop on the same cursor
  • users who scrolled up (hasScrolledOverThreshold) keep the normal onStartReached path with MVCP
  • loadNewerChats still applies its offline/focus guards

Branch with the fix and tests (passes on the fix, fails on main): https://github.com/Expensify/App/compare/main...David-2002065:App:fix/105204-load-newer-at-bottom

Tested on staging with a real room of 300 messages, opening a link to an older message (Update 20) and scrolling to the bottom.

Before (stops at Update 143, no more GetNewerActions):

https://github.com/user-attachments/assets/93c737cf-3e79-4a13-8ec8-c6ddff15a70a

After (loads all the way to Update 300):

https://github.com/user-attachments/assets/bb8a503e-1006-4719-a4bb-76ace7d8aed1

What specific scenarios should we cover in automated tests?

In PaginationTest (GetNewerActions mock returns a list of page sizes, then an empty page meaning newest reached):

  1. Open a linked chat, stay at offset 0, backend has two more pages. Expect GetNewerActions with cursors 5, 10, 15 and 15 messages, without any extra scrolling. Fails on main at the 10 call.
  2. Update the existing "load newer messages" test so it no longer fakes the MVCP scroll. The second call (cursor 10) happens while staying at the bottom, and scrolling away and back once the newest is reached sends no more requests.
  3. Initial and older loading tests stay unchanged and keep passing.

What alternative solutions did you explore? (Optional)

  1. Keep MVCP on while hasNewerActions is true
const shouldMaintainVisibleContentPosition = hasScrolledOverThreshold || shouldFocusToTopOnMount || hasNewerActions;

A newer page added below then pushes the offset out of the start zone and releases the latch, so the next scroll down fires onStartReached. It's one line but the user has to scroll for every page, and it doesn't fix the original report where the latch was taken before hasNewerActions became true, so GetNewerActions would still never be sent there.

  1. Patch FlashList to reset pendingStartReached when data changes, same as pendingEndReached. That fixes it at the source, but it changes every list using onStartReached and adds another patch to maintain, so I'd keep it in the report list.

David-2002065 avatar Nov 18 '26 02:11 David-2002065

🚨 Edited by proposal-police: This proposal was edited at 2026-11-18 02:33:01 UTC.

Proposal

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

Opening a room at its oldest unread message can leave the chat permanently stuck at the end of the unread page: the newer messages that exist on the server are never loaded into the view, GetNewerActions is never called, and the room still gets marked as read even though the newest messages were never shown. The LHN preview shows the newest message while the chat view stops at an older one.

What is the root cause of that problem?

Two client-side gaps combine. All of the pagination state in the Onyx export is correct — the failure is that nothing acts on it, and one mark-as-read path ignores it.

1. The chat view requests newer actions only from a one-shot scroll event, so a single swallowed trigger means GetNewerActions is never sent.

OpenReport with useLastUnreadReportAction returns a page that starts at the oldest unread message. When a room has many unread messages, that page does not reach the newest action, so the stored page in reportActionsPages_ correctly has no -1 "synced to newest" marker — the pagination middleware only adds that marker when the server confirms nothing newer exists:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/libs/Middleware/Pagination.ts#L124-L127

The actions delivered by ReconnectApp are not paginated (the middleware only processes paginated commands), so they sit in reportActions_ without belonging to any page, and getContinuousChain correctly keeps them out of the rendered chain — the gap between the unread page and those actions is not proven contiguous. Because the page's first ID is not the -1 marker, getContinuousChain correctly reports that a newer page can be fetched:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/libs/PaginationUtils.ts#L451-L456

and the paginated hook exposes that as hasNewerActions:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/hooks/usePaginatedReportActions.ts#L121-L129

So the view knows newer actions exist. The problem is the trigger side: in the chat report list, loadNewerChats is invoked from exactly one place, the inverted list's onStartReached edge callback:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/pages/inbox/report/ReportActionsList.tsx#L576-L579

onStartReached is a crossing trigger: it fires when the scroll position enters the bottom region and does not fire again until a fresh crossing happens. Meanwhile loadNewerChats silently returns when any of its guards fail at that instant — screen not focused yet, no newest action yet, hasNewerActions still false because the OpenReport response has not merged yet (a cached page from the previous session can even still carry a stale -1 marker until the response strips it), or a brief offline window right after the device wakes:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/hooks/useLoadReportActions.ts#L102-L114

When the one firing is swallowed this way, there is no later re-check. The list is already resting at the bottom of the loaded window, no new crossing occurs, and GetNewerActions is never requested — which matches the server timeline: no GetNewerActions between 15:12 and 15:40, while GetOlderActions worked twice, because scrolling up keeps producing fresh onEndReached crossings.

The money-request report view had this same class of bug and solved it with a state-driven effect that keeps loading newer actions whenever hasNewerActions is true after the initial load, guarded by a cursor-advance check so it cannot loop:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/components/MoneyRequestReportView/useMoneyRequestReportPagination.ts#L79-L101

The chat report view never got an equivalent, so for chats it is possible to sit indefinitely in the state "newer actions exist" with no code path left that will ever fetch them.

2. One mark-as-read path ignores hasNewerActions, so the room is marked read without showing the newest messages.

The automatic mark-as-read paths deliberately refuse to run while newer actions are unloaded — the report-change path:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/hooks/useMarkAsRead.ts#L270-L287

and the app-visibility path, whose comment spells out the invariant ("newer actions outside the loaded slice would be consumed without ever being seen"):

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/hooks/useMarkAsRead.ts#L314-L319

But when the report-change path skips, it latches a pending read, and the completion path calls readNewestAction with no hasNewerActions guard at all:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/hooks/useMarkAsRead.ts#L346-L356

That completion is triggered whenever the unread-marker action is visible in the viewport:

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/hooks/useReportActionsScroll.ts#L233-L237

https://github.com/Expensify/App/blob/ad6df9f90c062dbf952dbb56dfd6d29fa1aebc9e/src/pages/inbox/report/useReportUnreadMessageScrollTracking.ts#L166-L169

An unread-anchored open positions the list exactly at that marker, so the marker is on screen, the latched read completes, and ReadNewestAction marks the room read even though the newest messages were never rendered — matching the ReadNewestAction at 15:13:01 in the timeline and the "room is still marked as read" symptom.

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

  1. Add an auto-load-newer convergence loop to the chat report list, modeled on the one the money-request view already uses, as a small dedicated hook called from the list's scroll/pagination hook that wires onStartReached. While the list rests at its newest edge, hasNewerActions is true, the screen is focused, the device is online, the initial OpenReport is no longer pending and no GetNewerActions request is in flight, call loadNewerChats. It re-runs whenever any of those inputs or the newer-actions cursor change, so a skipped onStartReached is retried as soon as the condition that swallowed it clears (e.g. the OpenReport response strips the stale -1 marker, or the device comes back online). Each cursor is requested at most once (onStartReached goes through the same recorder), so a response that doesn't advance the cursor can't cause a request loop and the edge event and the effect don't double-request. To support this, loadNewerChats returns whether it actually sent a request and useLoadReportActions exposes the cursor it sends, the same way it already exposes the loadOlderChats cursor. Gating on the newest edge (the same ACTION_VISIBLE_THRESHOLD the list already uses for "scrolled to end") keeps a deep link far back in history from paging through everything newer on its own; it only converges while the user is at the end of the loaded window, which is exactly where the newest messages should be.

  2. Make the latched-read completion respect the same invariant the automatic paths already enforce. In useMarkAsRead, have completeSkippedMarkAsRead keep the pending read latched while hasNewerActions is true instead of calling readNewestAction immediately. Loading the gap clears hasNewerActions without any scroll or viewability event, so also add a small effect that completes the held read when hasNewerActions flips to false while the list is scrolled to the end and the screen is focused. The room is then marked read only after the newest message is actually in view. The explicit user flows are unaffected: the "newest messages" pill already routes through a live-tail jump (openReport) when the newest action is not loaded, and only marks read directly when the newest action is already rendered.

Both changes are web/desktop/native-shared hook code; no backend change is needed, and ReadNewestAction semantics stay intact.

Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/105204-auto-load-newer-chat-actions?expand=1

What alternative solutions did you explore? (Optional)

  • Merging ReconnectApp- or Pusher-delivered actions into the stored page when the page does not reach the newest message. Rejected: those actions are separated from the fetched page by a gap of unknown contents, and treating them as contiguous would silently hide the gap messages — the pagination merge code explicitly refuses index-based continuity for exactly this reason. In this incident that would have rendered the room as fully caught up while 162 messages were missing.

  • Making the list re-fire onStartReached after data changes, or calling loadNewerChats unconditionally on mount. Rejected: it depends on list-library edge-event internals, still races the OpenReport response (the same guards can swallow the retry), and does not fix the mark-as-read half.

  • Changing the server so ReadNewestAction cannot advance past actions the client never displayed. Rejected: it requires a backend change, and only the client knows what was actually rendered; the client-side guard already exists on the other mark-as-read paths and just needs to cover the completion path.

wildan-m avatar Nov 18 '26 02:11 wildan-m

Job added to Upwork: https://www.upwork.com/jobs/~022122878351777980870

🤖 ProposalPolice™ is tracking duplicate proposals for this issue using an OpenAI Conversation. This comment stores that Conversation's ID and can be safely ignored.

github-actions[bot] avatar Nov 18 '26 02:11 github-actions[bot]

Proposal

What is the root cause of that problem?

After wake-up the room opens with the stale cached page. That page still has the -1 newest-end marker, so the list thinks it is already at the newest message. OpenReport with useLastUnreadReportAction then replaces it with a middle slice, which flips hasNewerActions to true. Nothing asks for the missing messages at that point. The user sees a chat that ends at 6:33:30 AM, while the LHN shows the 7:00 AM message from lastVisibleActionCreated.

Newer messages are only requested from a scroll-edge event (onStartReached in useReportActionsListScroll.ts). That event fires once, at mount, and loadNewerChats in useLoadReportActions.ts bails out at that moment:

https://github.com/Expensify/App/blob/bad5f3d3fb722578f151bedf622774ea9c49e8f4/src/hooks/useLoadReportActions.ts#L102-L114

The three actions that arrived through the ReconnectApp retry sit in reportActions_ but in no page. getContinuousChain correctly ignores them, so the list has no reason to show them. The result is no GetNewerActions call, which matches the server timeline.

Loading newer actions depends on a one-time scroll event, not on the state "the page has no newest-end marker". The load decision lives in the scroll hook, not in the hook that owns pagination.

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

  1. useLoadReportActions.ts, loadNewerChats: it already holds the guards for offline, focus and hasNewerActions. Add an effect in this hook that runs when hasNewerActions changes from false to true, or when the newest page ID changes while hasNewerActions is still true. The effect calls loadNewerChats once. This covers the case where OpenReport lands after the scroll event already fired and bailed. Because the effect lives next to the guards, offline and unfocused cases stay protected.
useEffect(() => {
    if (!hasNewerActions) {
        return;
    }
    loadNewerChats();
}, [hasNewerActions, newestPageFirstID]);
  1. Make the effect skip the request when loadNewerChats already has a request in flight, using the existing request-in-progress guard. If none exists, track the last requested cursor so the same one is not sent twice. This stops it from duplicating the request that onStartReached sends on a normal open.

  2. Once GetNewerActions returns, the page reaches the -1 marker and hasNewerActions becomes false. The effect then stops. The three ReconnectApp actions are included because the server response merges them into the page.

What alternative solutions did you explore? (Optional)

Merging every action stored in Onyx into the page would hide the gap without proving the messages are continuous. It could also show a chat with missing messages in the middle.

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

samranahm avatar Nov 18 '26 02:11 samranahm