Add paging arguments to duoMessages
What does this MR do and why?
Opening a Duo Chat thread fetches the thread's whole duoMessages history, and that field has no way to return less. This MR adds a latestDuoMessages connection so a client can load the newest messages first and fetch older ones as the user scrolls up.
This is MR 2 of 3 for the work item. MR 1 stops the frontend from reading the full history where it doesn't need it. MR 3 will make duo-ui load the newest page on open and lazy-load older messages near the top. No frontend uses the new field yet.
What changes on DuoWorkflowEvent:
latestDuoMessagesis aDuoMessageConnectionover the same chat log asduoMessages, oldest first. Page backwards withlastandbefore:- Open:
latestDuoMessages(last: 50) { nodes { ... } pageInfo { startCursor hasPreviousPage } }. - Scroll up:
latestDuoMessages(last: 50, before: $startCursor). - Stop when
hasPreviousPageis false.
- Open:
- Page size is capped by the schema's default of 100.
duoMessagesdoesn't change. The agents platform page, the MCPget_duo_sessiontool and external clients such as VS Code still read the full list from it.
The new field is marked experiment: { milestone: '19.6' }, like the fields next to it.
This limits the response size, not the database reads. The page is sliced after the chat log is folded, so the server still reads and folds the whole history. Limiting the reads is a separate, larger change.
Why a new connection field, and why array offsets work as cursors
- Turning
duoMessagesinto a connection would change its type, which is a breaking change. Adding a separate field keeps the existing contract intact. Gitlab::Graphql::Pagination::ArrayConnectionencodes the array offset into the cursor. Within a branch,ui_chat_logonly grows, so a message's offset never changes once it exists. New messages that arrive while the user scrolls up don't move the older pages.- A retry starts a new branch. The client asks for that branch's alternatives through a separate endpoint, so this field doesn't affect retries.
latestDuoMessagesresolves through the sameBatchLoaderblock asduoMessages. A request that asks for both still folds each checkpoint once. A spec checks that adding the connection adds no queries.
The legacy header path (sessions that don't read from blobs yet) holds only the current compaction group, so offsets on that path restart after a compaction. The blob path, which is the target, covers every group.
References
Screenshots or screen recordings
Not applicable, backend only.
How to set up and validate locally
-
Open a Duo Chat session that has a few messages, and copy its workflow global ID.
-
In GraphiQL (
http://gdk.test:3000/-/graphql-explorer), run:query { duoWorkflowEvents(workflowId: "gid://gitlab/Ai::DuoWorkflows::Workflow/<id>") { nodes { all: duoMessages { content } newest: latestDuoMessages(last: 2) { nodes { content } pageInfo { startCursor hasPreviousPage } } } } } -
allmatches the current output, andnewestholds the last two messages. -
Run it again as
latestDuoMessages(last: 2, before: "<startCursor>")and check that you get the two messages before those. -
Keep paging until
hasPreviousPageisfalse.
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.