From 28b191cc0b0e69b864191673df9c141730c93e4f Mon Sep 17 00:00:00 2001 From: soryu Date: Wed, 18 Feb 2026 17:20:32 +0000 Subject: fix: prevent directive step failure when PR branch is deleted after merge Stop using pr_branch as base branch for step tasks since it may be auto-deleted by GitHub after PR merge. Instead always use continue_from_task_id or fall back to base_branch. Also add a safety net in create_worktree that detects when a base branch ref no longer exists and falls back to the repo's default branch. Co-Authored-By: Claude Opus 4.6 --- makima/src/orchestration/directive.rs | 45 +++++++++++++---------------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'makima/src/orchestration') diff --git a/makima/src/orchestration/directive.rs b/makima/src/orchestration/directive.rs index a6bb85b..af6b18c 100644 --- a/makima/src/orchestration/directive.rs +++ b/makima/src/orchestration/directive.rs @@ -103,36 +103,25 @@ impl DirectiveOrchestrator { }; let mut continue_from_task_id = dep_tasks.first().map(|d| d.task_id); - // If no dependency tasks resolved, try to continue from previous work: - // 1) Use the directive's PR branch as base (contains all previous merged work) - // 2) Fall back to the last completed step's task for worktree continuation + // If no dependency tasks resolved, try to continue from the last completed step's worktree. + // We never use pr_branch as base because it may have been deleted after PR merge. let effective_base_branch = if continue_from_task_id.is_none() { - if step.pr_branch.is_some() { - tracing::info!( - step_id = %step.step_id, - pr_branch = ?step.pr_branch, - "Step has no deps — using directive PR branch as base" - ); - step.pr_branch.as_deref() - } else { - // No PR branch yet — try to continue from the last completed step's worktree - match repository::get_last_completed_step_task_id( - &self.pool, - step.directive_id, - ) - .await - { - Ok(Some(task_id)) => { - tracing::info!( - step_id = %step.step_id, - continue_from = %task_id, - "Step has no deps, no PR branch — continuing from last completed task" - ); - continue_from_task_id = Some(task_id); - step.base_branch.as_deref() - } - _ => step.base_branch.as_deref(), + match repository::get_last_completed_step_task_id( + &self.pool, + step.directive_id, + ) + .await + { + Ok(Some(task_id)) => { + tracing::info!( + step_id = %step.step_id, + continue_from = %task_id, + "Step has no deps — continuing from last completed task" + ); + continue_from_task_id = Some(task_id); + step.base_branch.as_deref() } + _ => step.base_branch.as_deref(), } } else { step.base_branch.as_deref() -- cgit v1.2.3