Skip to main content

ralph_workflow/reducer/event/
awaiting_dev_fix.rs

1//! Events for AwaitingDevFix phase.
2//!
3//! This phase handles pipeline failure remediation by invoking the development
4//! agent to diagnose and fix the root cause before termination.
5
6use crate::agents::AgentRole;
7use serde::{Deserialize, Serialize};
8
9// Import PipelinePhase from the parent event module (defined in mod.rs)
10use crate::reducer::event::PipelinePhase;
11
12/// Events for AwaitingDevFix phase.
13///
14/// This phase handles pipeline failure remediation by invoking the development
15/// agent to diagnose and fix the root cause before termination.
16///
17/// # When This Occurs
18///
19/// The AwaitingDevFix phase is entered when the pipeline encounters a terminal
20/// failure condition (e.g., agent chain exhausted) in any phase. Instead of
21/// immediately terminating, the pipeline gives the development agent one final
22/// chance to diagnose and fix the issue.
23///
24/// # State Flow
25///
26/// 1. Terminal failure detected (e.g., AgentChainExhausted)
27/// 2. Reducer transitions to AwaitingDevFix phase
28/// 3. DevFixTriggered event emitted
29/// 4. Development agent invoked with failure context
30/// 5. DevFixCompleted event emitted
31/// 6. CompletionMarkerEmitted event signals transition to Interrupted
32/// 7. Checkpoint saved
33/// 8. Pipeline exits
34///
35/// # Emitted By
36///
37/// - Dev-fix flow handlers in `handler/dev_fix/`
38/// - Completion marker handlers
39#[derive(Clone, Serialize, Deserialize, Debug)]
40pub enum AwaitingDevFixEvent {
41    /// Dev-fix flow was triggered.
42    ///
43    /// Emitted when entering the dev-fix phase. Records which phase and agent
44    /// failed, providing context for the development agent.
45    DevFixTriggered {
46        /// Phase where the failure occurred.
47        failed_phase: PipelinePhase,
48        /// Agent role that failed.
49        failed_role: AgentRole,
50    },
51    /// Dev-fix flow was skipped (not yet implemented or disabled).
52    DevFixSkipped {
53        /// Reason for skipping.
54        reason: String,
55    },
56    /// Dev-fix flow completed (may or may not have fixed the issue).
57    ///
58    /// Emitted after the development agent finishes its fix attempt.
59    /// The `success` field indicates whether the agent believes it fixed
60    /// the issue, but does not guarantee the pipeline will succeed on retry.
61    DevFixCompleted {
62        /// Whether the fix attempt succeeded.
63        success: bool,
64        /// Optional summary of what was fixed.
65        summary: Option<String>,
66    },
67    /// Dev-fix agent is unavailable (quota/usage limit).
68    ///
69    /// Emitted when the dev-fix agent cannot be invoked due to resource limits.
70    /// The pipeline will proceed to termination without a fix attempt.
71    DevFixAgentUnavailable {
72        /// Phase where the failure occurred.
73        failed_phase: PipelinePhase,
74        /// Reason for unavailability.
75        reason: String,
76    },
77    /// Completion marker was emitted to filesystem.
78    ///
79    /// Emitted after writing the completion marker to `.agent/tmp/completion_marker`.
80    /// The reducer uses this event to transition from AwaitingDevFix to Interrupted,
81    /// enabling the pipeline to complete gracefully.
82    CompletionMarkerEmitted {
83        /// Whether this is a failure completion (true) or success (false).
84        is_failure: bool,
85    },
86}