fix(workflow): persist user context and harden resume state handling#1048
Conversation
🦋 Changeset detectedLatest commit: d2ff385 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughPersist Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Registry
participant Storage
participant Events
Client->>Registry: executeWorkflow(options { userId, conversationId, input })
Registry->>Storage: createWorkflowState({ ..., userId, conversationId, input })
Storage-->>Registry: stateCreated
Registry->>Storage: suspend / persist events
Storage-->>Events: store events
Client->>Registry: resumeWorkflow(executionId, resumeOptions?)
Registry->>Storage: loadWorkflowState(executionId)
Storage-->>Registry: workflowState (may lack input)
Registry->>Events: find "workflow-start" event for executionId
Events-->>Registry: workflow-start event (with input) OR none
Registry->>Registry: determine resumeOptions.userId/conversationId (state -> metadata fallback -> resumeOptions)
Registry->>Registry: choose input (workflowState.input || workflow-start.input || fail)
Registry->>Storage: update/resume with resolved input and user/context
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/core/src/workflow/suspend-resume.spec.ts`:
- Around line 1001-1055: The test accesses resumed?.error?.message but
WorkflowExecutionResult.error is typed unknown; add an explicit type guard
before reading message: assert that resumed?.status === "error" and that
resumed?.error is an instance of Error (e.g.,
expect(resumed?.error).toBeInstanceOf(Error) or use if (resumed?.error
instanceof Error)) and only then check resumed.error.message equals "Missing
resume input" so the assertion is type-safe (update the assertions around the
resumed variable returned by registry.resumeSuspendedWorkflow and any direct
access to .error.message).
🧹 Nitpick comments (1)
packages/core/src/workflow/suspend-resume.spec.ts (1)
899-999: Consider splitting the two precedence scenarios into separateitblocks.This single test contains two independent sub-scenarios (workflowA for top-level precedence, workflowB for metadata fallback). If one fails, the other won't run, and the test name won't clearly indicate which scenario broke. Splitting would improve debuggability.
Summary
userIdandconversationIdin workflow state at execution creation timeworkflowState.userId/workflowState.conversationIdwith metadata fallbackworkflow-startevent input when top-levelworkflowState.inputis missingTests
Closes #1047
Summary by cubic
Persisted userId and conversationId in workflow state and hardened resume handling with reliable input fallback. Fixes unreliable resumes and ensures correct user tracking, addressing Linear #1047.
New Features
Bug Fixes
Written for commit d2ff385. Summary will update on new commits.
Summary by CodeRabbit
Tests
Improvements