Skip to content

Fix GraphFlow state corruption on interrupt/resume#7220

Open
veeceey wants to merge 1 commit intomicrosoft:mainfrom
veeceey:fix/issue-7043-graphflow-state-recovery
Open

Fix GraphFlow state corruption on interrupt/resume#7220
veeceey wants to merge 1 commit intomicrosoft:mainfrom
veeceey:fix/issue-7043-graphflow-state-recovery

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

Fixes #7043

When a GraphFlow workflow is interrupted during agent transitions, the state can become corrupted with work remaining but an empty ready queue. This causes resume attempts to fail with "Digraph execution is complete" even though agents haven't finished executing.

Problem

The root cause is that the ready queue population happens during message processing (in update_message_thread), but if the workflow is interrupted between when an agent completes and when the next agent is enqueued, the state is saved with:

  • remaining shows work left to do
  • ready queue is empty (no agents enqueued)
  • Resume fails because _apply_termination_condition sees empty ready queue and terminates

Solution

Added state validation and repair logic:

  • New _validate_and_repair_state() method detects corrupted states on load
  • Checks if work remains but ready queue is empty (corrupted state indicator)
  • Reconstructs ready queue by finding nodes that should be ready:
    • For "all" activation: nodes with remaining count == 0
    • For "any" activation: nodes that were previously enqueued
  • Automatically called in load_state() to repair on every resume

Testing

Manual unit test confirms the fix works:

# Simulate corrupted state: A has run, B should be ready but queue is empty
manager._remaining['B']['B'] = 0  # B's dependency satisfied
manager._ready = deque([])  # Corrupted: empty despite B being ready

manager._validate_and_repair_state()

# After repair: B is correctly added to ready queue
assert 'B' in manager._ready  # ✓ Passes

This ensures workflows can always resume from saved state, even if interrupted mid-transition.

Fixes microsoft#7043

When a GraphFlow workflow is interrupted during agent transitions,
the state can become corrupted with work remaining but an empty ready
queue. This causes resume attempts to fail with "Digraph execution is
complete" even though agents haven't finished executing.

The root cause is that the ready queue population happens during
message processing (in update_message_thread), but if the workflow
is interrupted between when an agent completes and when the next
agent is enqueued, the state is saved with remaining work but no
agents ready.

Changes:
- Add _validate_and_repair_state() method to detect and repair
  corrupted states on load
- Check if work remains but ready queue is empty (corrupted state)
- Reconstruct ready queue by finding nodes that should be ready:
  - For "all" activation: nodes with remaining count = 0
  - For "any" activation: nodes that were previously enqueued
- Call validation automatically in load_state()

This ensures workflows can always resume from saved state, even if
interrupted mid-transition.

Signed-off-by: Varun Chawla <varun_6april@hotmail.com>
@veeceey
Copy link
Author

veeceey commented Feb 8, 2026

All checks passing, DCO signed, ready for merge

@veeceey
Copy link
Author

veeceey commented Feb 19, 2026

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

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.

GraphFlow State Persistence Bug: Workflow Gets Stuck After Interruption During Agent Transitions

1 participant

Comments