Allow Fix Pipeline flow to iterate on the same MR

Problem

The current Fix Pipeline flow always creates a new MR, which doesn't distinguish between a MR context vs branch pipeline. This can cause a mess of nested MRs if the flow will be set to automatically trigger when pipelines fail:

  1. Pipeline fails on main branch
  2. Flow submits MR1 (targeting main) with fix
  3. MR1 pipeline fails
  4. Flow submits MR2 (targeting MR1 branch) with fix
  5. MR2 pipeline fails
  6. ...and so on recursively

Proposal

When the Flow is triggered in the context of an existing MR, it should push fixes to the same MR and leave an audit trail (e.g., comment with the session ID and summary of reasoning) rather than creating a new MR.

The Flow should iterate within the MR context in a loop rather than creating recursive MRs.

Ideal Flow

graph TD
    Start([Pipeline Failure Detected])
    Flow["Trigger Fix Pipeline Flow"] 
    isMRContext{Is this a<br/>MR context?}
    GatherContext["Gather pipeline contex"]
    GatherMRContext["Gather pipeline & MR context"]
    DecideApproach{Can fix<br/>confidently?}
    DecideApproachMR{Can fix<br/>confidently?}
    PipelineSuccess{Pipeline success?}
    CreatePlanMR["Plan and create fix for MR"]
    CreatePlanBranch["Plan and create fix"]
    OpenMR["Open new MR"]
    LeaveTrailMR["Leave trail in MR<br/> with plan and session ID"]
    MRCommentCannotFix["Leave comment in MR"]
    End([End])

    Start --> Flow   
    Flow --> isMRContext
    isMRContext -->|Yes - MR Context| MRFlow["<b>MR Context Flow</b><br/>Submit fix to existing MR"]
      MRFlow --> LeaveTrailMR --> GatherMRContext --> DecideApproachMR
      DecideApproachMR -->|Yes| CreatePlanMR --> PipelineSuccess
      DecideApproachMR --> |No| MRCommentCannotFix --> End
    isMRContext -->|No - Branch Pipeline| BranchFlow["<b>Branch Pipeline Flow</b><br/>Create new MR with fix"]
      BranchFlow --> GatherContext --> DecideApproach

      DecideApproach -->|Yes| CreatePlanBranch --> OpenMR --> PipelineSuccess
      DecideApproach -->|No| End([End])   

    PipelineSuccess -->|No| Start
    PipelineSuccess -->|Yes| End
    
    style Flow fill:#e0f5e0
    style BranchFlow fill:#e1f5ff
    style MRFlow fill:#fff3e0
    style MRCommentCannotFix fill:#f3e5f5

Key Behaviors

MR Context Flow:

  • Detect that the pipeline is running in an MR context
  • Push fixes directly to the existing MR branch
  • Leave an audit trail comment with session ID and reasoning summary
  • If unable to fix confidently, leave a comment explaining why

Branch Pipeline Flow:

  • Create a new MR targeting the branch
  • Standard fix pipeline behavior
Edited by 🤖 GitLab Bot 🤖