Skip to content

[CRITICAL] Task execution never starts after approval - state machine stuck in 'human_review' #509

@joelfuller2016

Description

@joelfuller2016

Summary

Severity: 🔴 CRITICAL - BREAKS CORE WORKFLOW
Affects: Multiple users (#480, #457, #416, #216, #214, #247)
File: apps/backend/implementation_plan/plan.py:163-179

Problem

Tasks successfully complete planning and get user approval, but the coding phase never starts. The task remains stuck in "human_review" status with 0 subtasks completed, even though all subtasks are marked as "pending" and ready to execute.

Root Cause

The state machine in update_status_from_subtasks() preserves "human_review"/"review" status when all subtasks are pending. This was intended for the pre-execution approval stage, but there is no mechanism to transition the plan to "in_progress" when execution begins after approval.

Buggy Code (lines 174-179)

else:
    # All subtasks pending
    # Preserve human_review/review status if it's for plan approval stage
    # (spec is complete, waiting for user to approve before coding starts)
    if self.status == "human_review" and self.planStatus == "review":
        # Keep the plan approval status - don't reset to backlog
        pass  # ❌ BUG: Status stays "human_review" FOREVER after approval!

Expected State Transitions

1. Planning creates plan → status: "in_progress", planStatus: "in_progress"
2. Planning completes → status: "human_review", planStatus: "review" (awaiting approval)
3. User approves → review_state.json: approved: true
4. Build starts → SHOULD transition to "in_progress" ← MISSING!
5. Coding begins → Execute subtasks

Actual Behavior

1-3. Same as above ✅
4. Build starts → Status STAYS "human_review"/"review" ❌
5. Coding never starts → Exits with "No pending subtasks found"

Impact

  • ✅ Spec creation works
  • ✅ Planning works
  • ✅ User approval works
  • Coding phase NEVER executes
  • ❌ Tasks show 0/N subtasks completed forever
  • ❌ Users cannot complete ANY tasks with approval enabled

Proposed Solution

Add logic to check if plan has been approved and transition state accordingly:

else:
    # All subtasks pending
    # Check if this is pre-approval (waiting for user) or post-approval (ready to code)
    if self.status == "human_review" and self.planStatus == "review":
        # Check if plan has been approved
        review_state = self._get_review_state()
        if review_state and review_state.get("approved"):
            # Approved - transition to in_progress so coding can start
            self.status = "in_progress"
            self.planStatus = "in_progress"
        else:
            # Still waiting for approval - keep human_review status
            pass
    else:
        # No subtasks started yet - default to backlog
        self.status = "backlog"
        self.planStatus = "backlog"

Testing Requirements

  • Create task with "require approval" enabled
  • Verify planning completes and status = "human_review"
  • Approve the plan
  • Verify status transitions to "in_progress"
  • Verify coding phase starts and executes subtasks
  • Verify subtask count increments (0/N → 1/N → 2/N...)

Related Issues

Implementation Progress

  • Fix implemented
  • Tests passing
  • Verified with manual testing
  • Ready for review

Labels

bug, priority/critical, area/backend, state-machine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions