Define resource_parent on CI pipelines

What does this MR do and why?

External agents (third-party flows) triggered by a pipeline event never start. The session is created but no CI job is ever created, and the session stays in created/running until FailStuckWorkflowsWorker drops it with no_activity 30-60 minutes later.

Ai::FlowTriggers::RunService#build_variables serializes the triggering pipeline into AI_FLOW_CONTEXT through Ai::AiResource::Wrapper. The wrapper authorizes the resource with Gitlab::Llm::Utils::Authorizer.resource, which calls resource.resource_parent. Ci::Pipeline no longer defines it, because the method was removed by accident in !237900 (merged), so the call raises:

NoMethodError: undefined method 'resource_parent' for an instance of Ci::Pipeline
  ee/lib/gitlab/llm/utils/authorizer.rb             Authorizer.resource
  ee/app/models/ai/ai_resource/wrapper.rb           Wrapper#wrap
  ee/app/services/ai/flow_triggers/run_service.rb   RunService#build_variables
  ee/app/services/ai/flow_triggers/run_service.rb   RunService#execute_workload

The exception happens after the workflow is created and before the workload is created, so the session is never dropped. PipelineHooksWorker (retry: 3) then retries, and every attempt leaves another stuck session, so one pipeline produces four sessions.

This MR restores Ci::Pipeline#resource_parent in CE, matching CommitStatus#resource_parent.

The existing Ai::AiResource::Wrapper spec stubs the authorizer, so it did not catch this. The new example runs the real authorizer against a pipeline.

References

Screenshots or screen recordings

Not applicable, this is a backend fix with no UI change.

Before After
image Workload pipeline is created

How to set up and validate locally

  1. Create an external agent (third-party flow) in a project and add a flow trigger with the Pipeline events event type.
  2. Run a pipeline in that project and let it finish.
  3. Before this change, PipelineHooksWorker fails with NoMethodError: undefined method 'resource_parent' for an instance of Ci::Pipeline, four sessions appear with no CI job, and they fail with no_activity on the next FailStuckWorkflowsWorker run.
  4. With this change, the wrapper resolves the pipeline:
    pipeline = Ci::Pipeline.last
    Ai::AiResource::Wrapper.new(pipeline.user, pipeline).wrap.serialize_for_ai

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.

🤖 Generated with Claude Code

Edited by Xingli Wu

Merge request reports

Loading
Loading