Add WorkflowFinishedEvent for faster Duo messaging replies

What does this MR do and why?

@GitLabDuo note replies and Slack replies are currently delivered on the Ci::Workloads::WorkloadFinishedEvent, which fires only after the whole CI pipeline finalizes — significantly after the agent has already produced its answer. The answer is present in the workflow checkpoints earlier, at the workflow finish transition.

This MR publishes a new Ai::DuoWorkflows::WorkflowFinishedEvent on the running -> finished transition (scoped to messaging-triggered workflows, mirroring the existing WorkflowStartedEvent) and lets Ai::Messaging::CallbackWorker deliver the success reply on it.

Behind the default-off duo_workflow_finished_event_delivery flag:

  • Enabled: the success reply is delivered on the workflow event; the WorkloadFinishedEvent success path is skipped to avoid a double send. A completed workflow whose CI workload later reports a non-finished status (e.g. a job teardown error after the agent finished) does not post a failure over the already-delivered reply.
  • Disabled: behavior is unchanged — the WorkloadFinishedEvent (legacy) path delivers as before.

Failure paths (drop/stop) are unaffected: WorkflowFinishedEvent is only published on successful completion, so failures continue to ride the workload event.

Important

Do not enable the feature flag until the AI gateway change that defers the workflow finish transition until the terminal checkpoint is persisted is deployed to the managed fleet. Without it, delivering at finish time can race the final checkpoint write and produce a no_response reply.

How to set up and validate locally

  1. Enable the flag in the Rails console:
    Feature.enable(:duo_workflow_finished_event_delivery)
  2. Trigger a @GitLabDuo MR mention and confirm the reply is delivered by Ai::Messaging::CallbackWorker on the Ai::DuoWorkflows::WorkflowFinishedEvent (rather than waiting for CI pipeline finalization).
  3. Trigger a Slack bot mention and confirm the reply is still delivered.
  4. Disable the flag and confirm replies are still delivered via Ci::Workloads::WorkloadFinishedEvent (unchanged legacy path).

Local Testing: !245965 (comment 3568053845)

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.

References

Edited by Kinshuk Singh

Merge request reports

Loading