Problem
The create_next_states task in state-manager/app/tasks/create_next_states.py can create duplicate next states if the task is re-run or retried. This can happen due to task failures, retries, or other operational scenarios.
Proposed Solution
Implement an idempotency guard by:
- Computing a deterministic key (e.g., run_id + graph + next_identifier + canonicalized parents)
- Checking for existing states with that key before creating new ones
- Enforcing a unique index on that key at the database level
Context
This issue was identified during code review of PR #236 that introduces the bulk create_next_states functionality.
References: