Class: Aidp::Temporal::Activities::RunWorkLoopIterationActivity

Inherits:
BaseActivity
  • Object
show all
Defined in:
lib/aidp/temporal/activities/run_work_loop_iteration_activity.rb

Overview

Activity that runs a single work loop iteration Combines agent execution and testing in one activity Used by IssueToPrWorkflow for simplified orchestration

Instance Method Summary collapse

Methods inherited from BaseActivity

#activity_context, #cancellation_requested?, #check_cancellation!, #heartbeat

Instance Method Details

#execute(input) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/aidp/temporal/activities/run_work_loop_iteration_activity.rb', line 12

def execute(input)
  with_activity_context do
    project_dir = input[:project_dir]
    issue_number = input[:issue_number]
    plan = input[:plan]
    iteration = input[:iteration]
    injected_instructions = input[:injected_instructions] || []

    log_activity("running_work_loop_iteration",
      project_dir: project_dir,
      issue_number: issue_number,
      iteration: iteration)

    # Start heartbeat thread
    heartbeat_thread = start_heartbeat_thread(iteration: iteration)

    begin
      # Phase 1: Run agent
      heartbeat(phase: "agent", iteration: iteration)
      agent_result = run_agent(
        project_dir: project_dir,
        issue_number: issue_number,
        plan: plan,
        iteration: iteration,
        injected_instructions: injected_instructions
      )

      check_cancellation!

      unless agent_result[:success]
        return error_result("Agent failed: #{agent_result[:error]}",
          iteration: iteration,
          tests_passing: false)
      end

      # Phase 2: Run tests
      heartbeat(phase: "tests", iteration: iteration)
      test_result = run_tests(project_dir: project_dir)

      check_cancellation!

      # Phase 3: Handle result
      if test_result[:all_passing]
        success_result(
          result: {
            agent_output: agent_result[:output],
            test_results: test_result
          },
          iteration: iteration,
          tests_passing: true
        )
      else
        # Update prompt with failures for next iteration
        update_prompt_with_failures(project_dir, test_result)

        success_result(
          result: {
            agent_output: agent_result[:output],
            test_results: test_result
          },
          iteration: iteration,
          tests_passing: false
        )
      end
    ensure
      heartbeat_thread&.kill
    end
  end
end