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
messagesconnection instead ofduoMessages, 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_messagesflag 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
- Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/635073+s
- Depends on the
messagesconnection added in Paginate the Duo session chat log and cap duoMe... (!264039 - merged) • Roman Eisner • 19.6 - Feature flag rollout: [Feature flag] Rollout of `dap_session_load_mor... (#636541) • Allison Villa • 19.7 • On track
- Followed by the "Load earlier messages" button in Add a Load earlier messages button to session d... (!266039 - merged) • Allison Villa • 19.6
Screenshots or screen recordings
On a session that already has more than 100 messages:
| Flag off | Flag on |
|---|---|
![]() |
![]() |
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
- In the Rails console, enable the feature flag:
Feature.enable(:dap_session_load_more_messages) - 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. - Go to AI > Sessions and open the session (
/<project full path>/-/automate/agent-sessions/<session id>). - 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.
- 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)
- Open the browser's Network tab and filter by
getAgentFlow. - Wait for the next poll, about 10 seconds. The response has 100 entries under
latestCheckpoint.messages.edgesand noduoMessages. - In the Rails console, disable the feature flag:
Feature.disable(:dap_session_load_more_messages) - 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.

