summaryrefslogtreecommitdiff
path: root/makima/src/orchestration/directive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/orchestration/directive.rs')
-rw-r--r--makima/src/orchestration/directive.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/makima/src/orchestration/directive.rs b/makima/src/orchestration/directive.rs
index df44ee4..420b3e1 100644
--- a/makima/src/orchestration/directive.rs
+++ b/makima/src/orchestration/directive.rs
@@ -339,6 +339,27 @@ impl DirectiveOrchestrator {
"Directive goal updated — spawning re-planning task"
);
+ // If directive already has a PR, remove completed steps that were included in it
+ if directive.pr_url.is_some() || directive.pr_branch.is_some() {
+ match remove_already_merged_steps(&self.pool, directive.id).await {
+ Ok(count) if count > 0 => {
+ tracing::info!(
+ directive_id = %directive.id,
+ removed = count,
+ "Auto-removed completed steps already included in PR before replanning"
+ );
+ }
+ Err(e) => {
+ tracing::warn!(
+ directive_id = %directive.id,
+ error = %e,
+ "Failed to auto-remove merged steps before replanning"
+ );
+ }
+ _ => {}
+ }
+ }
+
let existing_steps =
repository::list_directive_steps(&self.pool, directive.id).await?;
let generation =
@@ -758,6 +779,25 @@ impl DirectiveOrchestrator {
}
repository::clear_completion_task(&self.pool, check.directive_id).await?;
+
+ // Auto-remove completed steps that were just included in the PR
+ match remove_already_merged_steps(&self.pool, check.directive_id).await {
+ Ok(count) if count > 0 => {
+ tracing::info!(
+ directive_id = %check.directive_id,
+ removed = count,
+ "Auto-removed completed steps after PR completion"
+ );
+ }
+ Err(e) => {
+ tracing::warn!(
+ directive_id = %check.directive_id,
+ error = %e,
+ "Failed to auto-remove merged steps after completion"
+ );
+ }
+ _ => {}
+ }
}
"failed" | "interrupted" => {
tracing::warn!(
@@ -915,6 +955,29 @@ impl DirectiveOrchestrator {
}
}
+/// Remove completed directive steps whose branches have already been included
+/// in a PR (i.e., the directive has a pr_url or pr_branch set).
+/// This prevents duplicate branch merges in subsequent PRs.
+pub async fn remove_already_merged_steps(
+ pool: &PgPool,
+ directive_id: Uuid,
+) -> Result<usize, anyhow::Error> {
+ let step_tasks = repository::get_completed_step_tasks(pool, directive_id).await?;
+ let mut removed = 0;
+ for st in &step_tasks {
+ if repository::delete_directive_step(pool, st.step_id).await? {
+ tracing::info!(
+ step_id = %st.step_id,
+ step_name = %st.step_name,
+ directive_id = %directive_id,
+ "Auto-removed completed step (already included in PR)"
+ );
+ removed += 1;
+ }
+ }
+ Ok(removed)
+}
+
/// Trigger a completion task (PR creation/update) for a directive.
///
/// This is the public entry point used by both the orchestrator tick and the