Skip to content

Fix blocked goal unblocking with dependencies bug#17

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-f6b6c975-3855-4ee6-b8a7-15a9f4e9308a
Draft

Fix blocked goal unblocking with dependencies bug#17
Copilot wants to merge 2 commits intomainfrom
copilot/fix-f6b6c975-3855-4ee6-b8a7-15a9f4e9308a

Conversation

Copy link
Contributor

Copilot AI commented Aug 23, 2025

Fixed a bug in the goal state transition logic where blocked goals with dependencies would transition to incorrect states when unblocked.

Problem

The issue occurred in this scenario:

  1. Schedule a blocked goal
  2. Add dependencies to that goal
  3. Unblock the goal
  4. Goal would incorrectly transition to WAITING_FOR_DATE instead of the appropriate state

The root cause was in the _mark_as_unfailed() function, which always set goals to WAITING_FOR_DATE state regardless of their preconditions or date constraints.

Example

# Create a blocked goal with an unachieved dependency
precondition_goal = GoalFactory(state=GoalState.WAITING_FOR_WORKER)
blocked_goal = schedule(noop, blocked=True)
_add_precondition_goals(blocked_goal, [precondition_goal])

# Unblock the goal
unblock_retry_goal(blocked_goal.id)
blocked_goal.refresh_from_db()

# Before fix: blocked_goal.state == WAITING_FOR_DATE (incorrect)
# After fix:  blocked_goal.state == WAITING_FOR_PRECONDITIONS (correct)

Solution

Updated _mark_as_unfailed() to determine the correct state transition based on:

  • Future date: WAITING_FOR_DATE (preserves original behavior)
  • Current/past date + unachieved preconditions: WAITING_FOR_PRECONDITIONS
  • Current/past date + no preconditions: WAITING_FOR_DATE (let normal flow handle transition to WAITING_FOR_WORKER)

Also fixed:

  • Prevented waiting_for_failed_count from going negative by adding bounds checking
  • Added proper handling for PROCEED failure behavior when goals are unfailed

Testing

Added comprehensive test case test_blocked_goal_with_dependencies_unblock_transitions that covers both scenarios (achieved and unachieved preconditions). All existing tests continue to pass.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: SupraSummus <15822143+SupraSummus@users.noreply.github.com>
Copilot AI changed the title [WIP] i think there is a bug when we schedule blcked goal, add dependency, unblock the goal, allow it run.or maybe this is with one more inter-dependency in chain? pls check that Fix blocked goal unblocking with dependencies bug Aug 23, 2025
Copilot AI requested a review from SupraSummus August 23, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants