From c2bad633593a8ec6ffa83d7ff10776560cf0f69f Mon Sep 17 00:00:00 2001 From: soryu Date: Fri, 13 Feb 2026 20:40:26 +0000 Subject: Rerun plan when directive goal is edited (#61) When a directive's goal is updated, pending/ready/failed/skipped steps are now automatically cleared so that replanning generates fresh steps aligned with the new goal. The planning prompt is also improved to clearly categorize existing steps by status and provide explicit instructions for re-evaluation. Changes: - Add clear_pending_directive_steps() repository function to remove non-started steps when the goal changes - Call step cleanup in the update_goal HTTP handler - Restructure the planning prompt to categorize steps (completed, running, pending, failed, skipped) with clear instructions for each category Co-authored-by: Claude Opus 4.6 --- makima/src/server/handlers/directives.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'makima/src/server/handlers') diff --git a/makima/src/server/handlers/directives.rs b/makima/src/server/handlers/directives.rs index 25b2dc4..929769c 100644 --- a/makima/src/server/handlers/directives.rs +++ b/makima/src/server/handlers/directives.rs @@ -824,7 +824,28 @@ pub async fn update_goal( }; match repository::update_directive_goal(pool, auth.owner_id, id, &req.goal).await { - Ok(Some(directive)) => Json(directive).into_response(), + Ok(Some(directive)) => { + // Clear non-started steps so replanning starts fresh + match repository::clear_pending_directive_steps(pool, id).await { + Ok(count) => { + if count > 0 { + tracing::info!( + directive_id = %id, + removed_steps = count, + "Cleared pending steps after goal update — replanning will generate new steps" + ); + } + } + Err(e) => { + tracing::warn!( + directive_id = %id, + error = %e, + "Failed to clear pending steps after goal update" + ); + } + } + Json(directive).into_response() + } Ok(None) => ( StatusCode::NOT_FOUND, Json(ApiError::new("NOT_FOUND", "Directive not found")), -- cgit v1.2.3