Page through older Duo Chat messages

What does this MR do and why?

With the duo_agentic_chat_paged_history flag on, the Duo Agentic Chat panel loads the newest 100 messages of a chat, and a "Show earlier messages" button loads the page before them. Since !264039 (merged), duoMessages returns only the newest 100 messages when its cap flag is on, so the panel had no way to show older ones.

Design notes

Loading:

  • A full load with the flag on requests messages(last: 100) instead of duoMessages, through an optional field in the checkpoint query (@include(if: $withMessagesPage)). With the flag off, the load is unchanged.
  • The page's hasPreviousPage decides whether the button shows, and its startCursor is where the next page ends.
  • The button loads messages(last: 100, before: startCursor) with get_workflow_messages_page.query.graphql and adds the page above the loaded messages. 100 is the largest page the GraphQL API returns.

Scroll position:

  • The scroll region measures the distance to the end of the conversation in a watcher on the new loadingOlderMessages prop. Vue watchers run before the render, so it measures the old layout, then restores the distance after $nextTick.
  • It also shifts the index of a pinned turn by the number of added turn boundaries, and measures the pin again.
  • The button sits in the scroll region's header slot. The message list's leave transition would keep it in the layout after the older messages render.

Send and retry:

  • A send pages back until a message with page context is loaded. Context injection looks for the last page context, and without it a send attaches AGENTS.md and chat rules again.
  • A retry pages back until the turn's prompt is loaded.
  • Both only run when older messages exist, so with the flag off the timing is unchanged.
  • A failed page load before a send stops the send and shows the error. Before a retry, it marks the retry as failed. An abort (thread switch, unmount) stops them without an error. A failed load from the button reports to Sentry and keeps the button.

Other notes:

  • Page requests use the thread load abort signal. The panel shares one Vuex store across mounts, so a page that arrives after the panel unmounts must not land in the next thread.
  • Both duoMessages and messages build the full history on the server and then slice it. The chat history cache from !258940 (merged) makes repeated pages cheap.
  • This is the second of three MRs split from !260497. It builds on !265824 (closed), and !260497 builds on it.

References

Screenshots or screen recordings

The only UI addition is a "Show earlier messages" button above the conversation. Screenshots to follow.

Before After

How to set up and validate locally

  1. In a Rails console, enable the flag: Feature.enable(:duo_agentic_chat_paged_history).
  2. In the same console, seed a chat with 150 messages for root with the snippet below. It prints the workflow's global ID.
  3. Open the project the snippet used on GDK, open the GitLab Duo panel, and open the chat "Seeded chat with 150 messages" from the chat history. Expect: the newest 100 messages, and a "Show earlier messages" button at the top.
  4. Scroll to the top and select "Show earlier messages". Expect: messages 0 to 49 appear above, the messages you were reading stay where they were, and the button disappears.
Seed snippet
user = User.find_by_username('root')
project = user.authorized_projects.first
workflow = Ai::DuoWorkflows::Workflow.create!(
  user: user,
  project: project,
  goal: 'Seeded chat with 150 messages',
  workflow_definition: 'chat',
  environment: :web,
  agent_privileges: [Ai::DuoWorkflows::Workflow::AgentPrivileges::READ_WRITE_FILES],
  pre_approved_agent_privileges: []
)
messages = Array.new(150) do |i|
  {
    'message_type' => i.even? ? 'user' : 'agent',
    'content' => "Message #{i}",
    'message_id' => "seed-#{i}",
    'timestamp' => (Time.current - (150 - i).minutes).iso8601,
    'status' => 'success'
  }
end
Ai::DuoWorkflows::Checkpoint.create!(
  workflow: workflow,
  project: project,
  thread_ts: Gitlab::Utils.uuid_v7,
  checkpoint: { 'channel_values' => { 'ui_chat_log' => messages } },
  metadata: { 'source' => 'seed' }
)
puts workflow.to_global_id
Edge cases
  • With the flag off, the chat loads all 150 messages and shows no button.
  • A chat with 100 messages or fewer shows no button.
  • Send a message in the seeded chat before selecting the button. Expect: the panel loads older pages first only when the loaded messages carry no page context.

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 Eduardo Bonet

Merge request reports

Loading
Loading