huskies: merge 1178 bug MergeFailureFinal is a trap state: successful re-merge cannot mark the story done

This commit is contained in:
Huskies Agent
2026-07-16 14:19:55 +00:00
parent 61acf98909
commit e5df6232cf
6 changed files with 226 additions and 34 deletions
@@ -361,15 +361,23 @@ impl AgentPool {
}
let story_archived = crate::agents::lifecycle::move_story_to_done(story_id).is_ok();
if story_archived {
self.remove_agents_for_story(story_id).await;
}
let worktree_cleaned_up = if wt_path.exists() {
let config = crate::config::ProjectConfig::load(project_root).unwrap_or_default();
worktree::remove_worktree_by_story_id(project_root, story_id, &config)
.await
.is_ok()
// Story 1178: only delete the feature branch once the state transition
// to Done is confirmed. Deleting it unconditionally here meant a
// successful squash merge whose CRDT transition failed (e.g. the story
// was in a stage `move_story_to_done` didn't yet handle) would still
// lose its feature branch, making the failure unrecoverable — the
// story couldn't be retried because the branch it needed was gone.
let worktree_cleaned_up = if story_archived {
self.remove_agents_for_story(story_id).await;
if wt_path.exists() {
let config = crate::config::ProjectConfig::load(project_root).unwrap_or_default();
worktree::remove_worktree_by_story_id(project_root, story_id, &config)
.await
.is_ok()
} else {
false
}
} else {
false
};