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:

  1. !267150 (merged): the paged read of getWorkflowLatestCheckpoint. Merged.
  2. !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 paged when the flag is on, keeps the cursor of the next older page, and prepends each page through setMessages. 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-messages and is-loading-older-messages to the view and loads a page on load-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 duplicate messages on master. It's closed, and this work reads messages instead.
  • messages isn't capped by duo_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.vue still reads the full history. Nothing on master uses it yet, and its first consumer is !250953.

References

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)
Scrolling a 120-message Duo Chat thread to the top; all messages are already loaded Scrolling a 120-message Duo Chat thread to the top; a loading icon shows while older messages are added above, twice
  • Before: one getWorkflowLatestCheckpoint request 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

  1. Enable the flag: Feature.enable(:duo_chat_lazy_load_messages).
  2. Open a Duo Chat thread with more than 50 messages.
  3. In the browser network tab, check that the getWorkflowLatestCheckpoint request has paged: true and returns 50 messages.
  4. 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.
  5. Keep scrolling up until the first message of the thread. No more requests are sent after it.
  6. Disable the flag and reopen the thread. The request asks for duoMessages and returns the full history.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Tomas Bulva

Merge request reports

Loading
Loading