Draft: PoC: continuable Duo Developer sessions (do not merge)

PoC for reference. Do not merge. This branch belongs to the spike #633284 (closed) (epic gitlab-org#24022): Duo Developer sessions started from a mention or an assignment stay open after each answer. The owner can continue them from the session page, and a session that is only done for now shows as idle with no to-do or email. The real implementation will land as separate MRs per issue in the epic. Specs and docs were not kept up to date (several status-list specs fail on purpose).

Gateway side: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7413 (closed). Pre-push hooks and CI were skipped for this reference push.

What it does

  • Status idle (state 9, its own status group outside "needs attention"). It's resumable by the owner. The server capability idle_status_event tells the gateway this instance accepts it.
  • Turn ended ≠ session ended. WorkflowTurnEndedEvent fires at every turn end (idle, and finished for the one turn of ambient flows). It's built inside the status transition and carries the turn's final checkpoint and its callback context. Answer delivery (CallbackWorker) hangs on it, and WorkflowFinishedCloudEvent keeps meaning "the session ended". Delivery claims each turn once (TurnDeliveryClaim). The CI-job-ended backstop acts only for the session's latest workload.
  • Each turn's answer goes where the turn came from. A message that continues a session replaces messaging_callback_context. The session page and MCP pass none, so their answers stay on the session. Slack session privacy reads source_type instead of the callback context.
  • One decision for "may this user send now, and why not": Ai::DuoWorkflows::MessageAdmission.
    • Used by GraphQL DuoWorkflow.messageInput { enabled, reason } (experiment), POST /resume and MCP.
    • A per-session lease serializes sends, as a stopgap until ai-assist#2877.
    • Messages go through ExecuteRunService as input events. Decisions keep master's resume path and 403 answers, now with a reason.
  • Session page:
    • a reply box for conversational sessions the viewer owns, disabled with a reason when a message can't go now;
    • messages queue during a turn through the shared chat PromptQueue (drainMode: 'all', item states) and go out as one batch;
    • updates come from the workflowEventsUpdated subscription, with polling as the fallback.
  • Version: duo_developer_continuable_sessions makes the Developer definition resolve ^4.0.0 for new sessions. A resumed CI turn keeps its first job's constraint (master's behaviour).

Not behind the flag (on purpose, to ship sequenced)

Rails accepting idle, delivery on the turn-ended event for every messaging flow (two releases: handle, then publish and subscribe), serialized /resume, and the extra subscription push when a CI job ends.

Try it in GDK
  1. Enable duo_developer_continuable_sessions for your user and run the gateway branch.
  2. Mention @GitLabDuo on an issue. Expected: the answer lands in the thread, the session shows Idle, no to-do.
  3. Open the session and send a follow-up. Expected: a new CI job, the answer on the session page, no new note in the thread.
  4. Send two more messages while that turn runs. Expected: they queue and go out as one follow-up when the turn ends.
  5. Send twice at once through POST /api/v4/ai/duo_workflows/workflows/:id/resume. Expected: 201 and 409 with a reason, one CI job.
Known gaps
  • A batch accepted just before a page reload can show "Not sent", and Retry sends it twice. Fixed later with server-side message IDs.
  • Features that wait for "session finished" (for example !261137 (merged)) don't fire for resting sessions.
  • The GraphQL subscription sends workflowStatus: IDLE unprojected to older IDEs.
  • Workhorse has no "accepted" signal between enqueue and pickup.
  • Not measured: latency and cost of a follow-up turn on GitLab.com.

Merge request reports

Loading
Loading