Class: Aidp::Temporal::Workflows::StrategyBranchWorkflow

Inherits:
BaseWorkflow
  • Object
show all
Defined in:
lib/aidp/temporal/workflows/strategy_branch_workflow.rb

Constant Summary collapse

HEARTBEAT_TIMEOUT =

Must exceed the 30s heartbeat interval in ExecuteCliCommandActivity while staying below the agent/evaluator start_to_close budgets, so a missed beat does not time out a long-running CLI invocation.

120

Constants inherited from BaseWorkflow

BaseWorkflow::DEFAULT_ACTIVITY_OPTIONS

Instance Method Summary collapse

Methods inherited from BaseWorkflow

activity_options, workflow_name

Instance Method Details

#execute(input) ⇒ Object



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
# File 'lib/aidp/temporal/workflows/strategy_branch_workflow.rb', line 17

def execute(input)
  initialize_state(input)
  log_workflow("execute_started",
    branch_key: @branch&.dig(:key),
    strategy_id: @strategy_id,
    depth: @depth)

  @run = start_run
  log_workflow("run_started",
    run_id: @run[:id],
    branch_key: @branch&.dig(:key))

  agent_result = execute_agent
  fail_branch!(agent_result) unless agent_result[:success]
  log_workflow("agent_completed",
    run_id: @run[:id],
    branch_key: @branch&.dig(:key),
    artifact_count: Array(agent_result[:artifacts]).length)

  evaluations = execute_evaluators(agent_result)
  log_workflow("evaluator_completed",
    run_id: @run[:id],
    branch_key: @branch&.dig(:key),
    evaluator_count: evaluations.length,
    aggregate_score: aggregate_score(
      evaluations.filter_map { |evaluation| evaluation[:score]&.to_f },
      evaluations
    ))

  artifacts = record_artifacts(agent_result, evaluations)
  log_workflow("artifacts_recorded",
    run_id: @run[:id],
    branch_key: @branch&.dig(:key),
    artifact_count: artifacts.length)

  output = build_output(agent_result, evaluations, artifacts)
  complete_run("completed", output)

  log_workflow("run_completed",
    run_id: @run[:id],
    branch_key: @branch&.dig(:key),
    status: "completed",
    aggregate_score: output[:aggregate_score])

  output
rescue Temporalio::Error::CanceledError
  raise
rescue Aidp::StrategyExecution::CliProtocol::ProtocolError,
  Aidp::Database::Error => e
  Aidp.log_error("strategy_branch_workflow", "execute_failed",
    run_id: @run&.dig(:id),
    branch_key: @branch&.dig(:key),
    error: e.message,
    error_class: e.class.name)
  complete_run("failed", {error: e.message}) if @run && !run_completed?
  raise
end