Add view_ai_pipeline_results internal event tracking

What does this MR do and why?

Implements the Pipeline results reviewed funnel metric from the AI Pipeline Builder north-star metrics.

The metric tracks whether a user viewed the results of a pipeline generated by the AI Pipeline Builder, for the first time. It fires at most once per project, only for projects whose CI config was AI-generated, and only for pipelines created after the config was committed.

References

Database

Two new queries on ci_project_metrics, both filtered by project_id, which carries the UNIQUE index index_ci_project_metrics_on_project_id.

Ci::ProjectMetric.ai_pipeline_results_trackable? is the enqueue-side guard. It's a SELECT ... LIMIT 1 existence check that skips scheduling the worker unless the project has an AI-generated config with an open gate:

SELECT 1 AS one
FROM "ci_project_metrics"
WHERE "ci_project_metrics"."project_id" = 278964
  AND "ci_project_metrics"."ci_config_generated_by" IS NOT NULL
  AND "ci_project_metrics"."ci_config_first_generated_at" IS NOT NULL
  AND "ci_project_metrics"."first_ai_pipeline_results_viewed_at" IS NULL
LIMIT 1;

Plan: https://postgres.ai/console/gitlab/gitlab-production-ci/sessions/53194/commands/155123

Ci::ProjectMetric.mark_ai_pipeline_results_viewed is the event gate. It's a single-row UPDATE that stamps first_ai_pipeline_results_viewed_at only when the config is AI-generated and the viewed pipeline was created at or after the config was first generated:

UPDATE "ci_project_metrics"
SET "first_ai_pipeline_results_viewed_at" = '2026-06-25 12:00:00',
    "updated_at" = '2026-06-25 12:00:00'
WHERE "ci_project_metrics"."project_id" = 278964
  AND "ci_project_metrics"."ci_config_generated_by" IS NOT NULL
  AND "ci_project_metrics"."ci_config_first_generated_at" IS NOT NULL
  AND "ci_project_metrics"."first_ai_pipeline_results_viewed_at" IS NULL
  AND "ci_project_metrics"."ci_config_first_generated_at" <= '2026-06-25 12:00:00';

Plan: https://postgres.ai/console/gitlab/gitlab-production-ci/sessions/53194/commands/155097

How to set up and validate locally

  1. In rails console, seed a project metric record with an AI config:
    project = Project.find_by_full_path('your/project')
    Ci::ProjectMetric.track_ai_generated_config!(project.id, author_source: 'ci_expert_agent/v1')
  2. Run a pipeline on that project so at least one pipeline exists.
  3. Visit the pipeline show page as a signed-in user: http://gdk.test:3000/<namespace>/<project>/-/pipelines/<id>
  4. Check Sidekiq logs for Ci::TrackAiPipelineResultsViewedWorker executing.
  5. Verify the metric was recorded:
    Ci::ProjectMetric.find_by(project_id: project.id).first_ai_pipeline_results_viewed_at
  6. Visit the page again, and the worker should not be enqueued a second time.

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.

Depends on: Record ci_config_first_generated_at when tracki... (!240027 - merged) (this MR targets its branch). Related: CI Expert Agent — Success Metrics (Simplified, GA) (#594029)

Edited by Sahil Sharma

Merge request reports

Loading