Fetch only the newest session messages on the session details page

What does this MR do and why?

On load, load only the newest 100 messages on the session details page. The next MR in the stack, Add a Load earlier messages button to session d... (!266039 - merged) • Allison Villa • 19.6, adds the "Load earlier messages" button for older ones.

Currently, the page loads every message in the session when it opens and on every 10 second poll, so long sessions return their whole history each time - see https://gitlab.com/gitlab-org/gitlab/-/work_items/635073+s

  • Read the newest 100 messages from the messages connection instead of duoMessages, matching the backend's page size
  • Keep new messages on the page as polling brings them in, so a page left open shows everything that arrived while it was open. A reload starts again from the newest 100
  • If 100 or more new messages arrive between two polls (usually 10 seconds apart, but longer in a background tab), replace the list with the newest 100, because any messages in between were never fetched
  • Only treat the first message as the session's goal when the list starts at the beginning of the session
  • Refetch the session with the same variables after an approval, so the cached session keeps its messages
  • Read the Agent todos panel from latestTodoDuoMessage, so it still shows when the latest todo update is more than 100 messages back
  • Add the dap_session_load_more_messages flag and gate the behaviour behind it

Note

With the flag on with the changes in this MR: When opening a session that already has more than 100 messages, it shows only the newest 100, plus any that arrive while the page is open. There's no way to read the older ones yet in this case, so the flag shouldn't be enabled until the next MR (adding the button) merges too

References

Screenshots or screen recordings

On a session that already has more than 100 messages:

Flag off Flag on
Screenshot_2026-10-29_at_1.46.43_PM Screenshot_2026-10-29_at_1.46.15_PM

Starting a session then keeping it open as it gets more than 100 messages will display as normal - the UX for this is discussed in the next MR here: !266039 (comment 4111649221)

How to set up and validate locally

  1. In the Rails console, enable the feature flag:
    Feature.enable(:dap_session_load_more_messages)
  2. Start a session that results in more than 100 messages. This prompt worked for me, as an example (but you'll need at least 60 work items/MRs in that project):
    Using duo developer and starting a workflow session, go through the merge requests in this project one at a time, oldest first. For each one, look it up on its own with a separate tool call, then after each tool call, reply with a single line: its ID and title. Do not batch several merge requests into one call, skip any, or summarize groups. When you run out of merge requests, continue the same way with the issues. Stop after 110 lookups in total.
  3. Go to AI > Sessions and open the session (/<project full path>/-/automate/agent-sessions/<session id>).
  4. Keep the page open while the session runs past 100 messages. New messages appear at the bottom, and the earlier ones stay on the page.
  5. Once the session has more than 100 messages, reload the page. Only the newest 100 messages show, starting partway through the session, and the session goal is not shown as the first message. There's no way to read the older messages in this MR, because the "Load earlier messages" button is added in !266039 (merged)
  6. Open the browser's Network tab and filter by getAgentFlow.
  7. Wait for the next poll, about 10 seconds. The response has 100 entries under latestCheckpoint.messages.edges and no duoMessages.
  8. In the Rails console, disable the feature flag:
    Feature.disable(:dap_session_load_more_messages)
  9. Reload the page. Every message in the session shows again, starting with the session goal.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Allison Villa

Merge request reports

Loading
Loading