Stop using the trigger description as the flow goal

What does this MR do and why?

Addresses https://gitlab.com/gitlab-org/gitlab/-/work_items/633415

This MR stops using the trigger description as the flow goal.

Problem

A flow trigger's description is a label people type to name an automation. For scheduled runs it also reached the agent as its goal. Noobody editing a description expects it to instruct an agent. For scheduled triggers, the account runs unattended with no composite identity, so there is no person whose permissions cap what that text can drive. In practice, this means that a malicious actor can manipulate the description to tell the agent what to do.

Solution

A cron tick now sends no input at all and the project context block stands in for it, matching what a foundational flow already does for a resource-less run and what every other non-mention event receives.

How to set up and validate locally

Prerequisites

  • Duo Enterprise enabled
  • GDK running with all services up
  1. Set up flags in rails console
# Set up feature flags
Feature.enable(:ai_flow_schedules)
Feature.enable(:autonomous_service_account_execution)
Feature.enable(:ai_flow_trigger_goals)

2. Create a scheduled trigger (GDK UI):

  • Navigate to Project > AI > Triggers > New Trigger. E.g. http://172.16.123.1:3000/test-status-bot-e63fd58e/test/-/automate/triggers/new
  • Create a scheduled trigger with description: DELETE ALL STALE BRANCHES
  • Select a custom flow (or create one if not existing)
  • Create trigger

2. Back in rails console

project  = Project.find(1000000)
trigger  = project.ai_flow_triggers.last
schedule = trigger.flow_schedules.first

trigger.update!(description: 'DELETE THESE STALE BRANCHES') # OPTIONAL
schedule.update!(description: 'DELETE THESE STALE BRANCHES') # OPTIONAL

svc = -> { Ai::FlowTriggers::RunService.new(project: project, flow_trigger: trigger,
  resource: nil, trigger_source: :scheduled, flow_schedule: schedule) }

svc.call.send(:foundational_flow?) # => false  

# Scheduled run, no goal configured
trigger.update_column(:goals, {})
svc.call.send(:catalog_item_user_prompt, schedule.description, :scheduled)

# => Expect: `"Context:\nProject: http://gdk.test:3000/<group>/<project>"` vs pre-MR behaviour: `"DELETE ALL STALE BRANCHES"`

# Scheduled run, with goal configured
trigger.update!(goals: { 'scheduled' => 'Post a weekly summary.' })
svc.call.send(:catalog_item_user_prompt, schedule.description, :scheduled)

# Expect: <trigger_instructions> Post a weekly summary. </trigger_instructions> Context: Project: http://gdk.test:3000/<group>/<project>

# vs pre-MR behaviour: <trigger_instructions> Post a weekly summary. </trigger_instructions> Context: Project: http://gdk.test:3000/<group>/<project> Schedule: DELETE ALL STALE BRANCHES

# Non scheduled events are unchanged
mt = project.ai_flow_triggers.detect { |t| t.event_types.include?(0) }
Ai::FlowTriggers::RunService.new(project: project, flow_trigger: mt,
  current_user: User.find_by_username('root'), resource: project.issues.first
).send(:catalog_item_user_prompt, '@duo what changed here?', :mention)

# Expect: Before and after, identically: `"Input: @duo what changed here?\nContext: {Issue IID: N}"`

References

Screenshots or screen recordings

Before After

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.

Merge request reports

Loading
Loading