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_workloadThe 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
- Pipeline wrapper introduced in e65f9075 (!245862 (merged)), which also added
resource_parenttoEE::Ci::Pipeline. That MR rescuesArgumentError, which does not cover thisNoMethodError. resource_parentwas removed fromEE::Ci::Pipelineby accident in !237900 (merged) (11f237e3).- Reported on JiHu GitLab: https://jihulab.com/gitlab-cn/modelops/ai-assist/-/work_items/185
Screenshots or screen recordings
Not applicable, this is a backend fix with no UI change.
| Before | After |
|---|---|
![]() |
Workload pipeline is created |
How to set up and validate locally
- Create an external agent (third-party flow) in a project and add a flow trigger with the Pipeline events event type.
- Run a pipeline in that project and let it finish.
- Before this change,
PipelineHooksWorkerfails withNoMethodError: undefined method 'resource_parent' for an instance of Ci::Pipeline, four sessions appear with no CI job, and they fail withno_activityon the nextFailStuckWorkflowsWorkerrun. - 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.
