fix(convex): shard workflows by executionId to eliminate OCC contention#425
Conversation
The previous sharding used a deterministic hash of wfDefinitionId, which funnelled all concurrent executions of the same workflow definition into a single shard. This caused persistent OCC failures on pendingStart, runStatus, and pendingCompletion tables. Now the shard is derived from the unique executionId after insert, so concurrent starts of the same definition spread across all 4 component instances.
📝 WalkthroughWalkthroughThis pull request shifts the workflow engine's shard distribution mechanism from being based on workflow definition IDs to being based on execution IDs. The Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@services/platform/convex/workflow_engine/helpers/engine/start_workflow_handler.ts`:
- Around line 76-80: The call to handleStartWorkflow is passing a single
WorkflowManager instance (workflowManager) but the function signature expects
managers: WorkflowManager[]; update the caller in mutations.ts to pass the
four-element workflowManagers array instead of workflowManager so
managers[shardIndex] works; keep the existing getShardIndex(executionId)
sharding logic and ensure you're passing the same workflowManagers variable that
internal_mutations.ts uses to match the expected array type.
The public startWorkflow mutation was passing a single workflowManager instead of the managers array, which would crash on managers[shardIndex].
Summary
wfDefinitionIdhash to uniqueexecutionIdhashpendingStart(32 events),runStatus(13 events), andpendingCompletion(5 events)Test plan
shard.test.ts)Summary by CodeRabbit
Release Notes
Documentation
Tests
Refactor