Lazy load Duo Chat history behind a feature flag
What does this MR do and why?
Opening a Duo Chat thread reads its whole message history in one call, however long the thread is. Behind the new duo_chat_lazy_load_messages flag, the chat reads only the newest 50 messages when a thread opens, and loads older ones as the user scrolls up.
This MR was split in three. It now only wires the flag in, on top of:
- !267150 (merged): the paged read of
getWorkflowLatestCheckpoint. Merged. - !267151 (merged): the older-messages trigger and scroll restore in
DuoChatScrollRegion. Merged.
The changes to review here are in duo_agentic_chat_state_manager.vue, its spec, the flag definition and gon_helper.rb.
What changes here:
- The state manager passes
pagedwhen the flag is on, keeps the cursor of the next older page, and prepends each page throughsetMessages. A page that lands after a thread switch is dropped. A failed page keeps the cursor, so scrolling to the top again retries. - It passes
has-older-messagesandis-loading-older-messagesto the view and loads a page onload-older-messages. - With the flag off, the chat sends the same query and variables as today.
This limits the response size, not the database read. The server still folds the whole chat log for every page. That's tracked separately.
Why this replaces the earlier plan
- !265137 (closed) added
latestDuoMessages, which turned out to duplicatemessageson master. It's closed, and this work readsmessagesinstead. messagesisn't capped byduo_workflow_cap_duo_messages, so paging reaches the first message whether that flag is on or off.
Known limits
- Expanded tool groups and other local message state can reset when a page is prepended, because duo-ui keys messages by position. The message-keying change in duo-ui!810 (merged) fixes that once it's released and bumped here.
- If the first page doesn't fill the chat window there's nothing to scroll, so no older page loads. 50 messages fill it in practice.
- The sessionStorage snapshot holds the newest 20 messages, so it fits inside the first page. If more than 30 messages were persisted since the snapshot was taken (for example from another tab), its oldest messages fall before the page, and the snapshot divergence report fires for them.
duo_agentic_chat_state_manager_light.vuestill reads the full history. Nothing on master uses it yet, and its first consumer is !250953.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/635129
- Rollout issue: #638616
- Follow-up: !260497 rebases onto this to skip the history read when the cached snapshot is current.
Screenshots or screen recordings
A 120-message thread in GDK, scrolled from the newest message to the first, with duo_chat_lazy_load_messages off and on.
| Before (flag off) | After (flag on) |
|---|---|
![]() |
![]() |
- Before: one
getWorkflowLatestCheckpointrequest with the full history. - After: three paged requests of 50, 50 and 20 messages. The message being read stays in place as each page is added.
How to set up and validate locally
- Enable the flag:
Feature.enable(:duo_chat_lazy_load_messages). - Open a Duo Chat thread with more than 50 messages.
- In the browser network tab, check that the
getWorkflowLatestCheckpointrequest haspaged: trueand returns 50 messages. - Scroll to the top of the chat. A loading icon shows, the next 50 messages appear above, and the message you were reading stays where it was.
- Keep scrolling up until the first message of the thread. No more requests are sent after it.
- Disable the flag and reopen the thread. The request asks for
duoMessagesand returns the full history.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.

