fix(inngest): throw error when resume runId is missing to prevent invalid workflow state#15826
fix(inngest): throw error when resume runId is missing to prevent invalid workflow state#15826Akash504-ai wants to merge 4 commits into
Conversation
…alid workflow state
🦋 Changeset detectedLatest commit: 529bca6 The changes in this PR will be included in the next version bump. 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 |
|
@Akash504-ai is attempting to deploy a commit to the Mastra Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughEnforces strict runId validation when resuming workflows: resume must use the suspended step's runId from its metadata; if absent, execution throws an error. Includes implementation, test, and changeset metadata. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Thank you for your contribution! Please ensure that your PR fixes an existing issue and that you have linked it in the description (e.g. with We use CodeRabbit for automated code reviews. Please address all feedback from CodeRabbit by either making changes to your PR or leaving a comment explaining why you disagree with the feedback. Since CodeRabbit is an AI, it may occasionally provide incorrect feedback. Addressing CodeRabbit's feedback will greatly increase the chances of your PR being merged. We appreciate your understanding and cooperation in helping us maintain high code quality standards. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.changeset/invalid-resume-runid.md:
- Line 5: Replace the commit-style line "fix: prevent invalid workflow resume by
throwing when runId is missing instead of generating a new one" with a
release-note style sentence that focuses on the outcome, e.g. "Prevent resuming
workflows without a runId by throwing an error instead of generating a new one",
avoiding commit-prefixes like "fix:" and using plain outcome-focused wording;
edit the line in .changeset/invalid-resume-runid.md accordingly.
In `@workflows/inngest/src/__tests__/execution-engine.test.ts`:
- Around line 20-21: The test currently passes a plain object for step so
executeWorkflowStep returns null and never hits the resume-runId guard; update
the test to pass a proper InngestWorkflow-compatible object (or construct/mocked
InngestWorkflow) for the step variable and include a runId source in stepResults
so the resume-runId branch is exercised; specifically ensure the test's step
implements the same shape checked by executeWorkflowStep (e.g., workflow
identifier/methods expected by InngestWorkflow) and that stepResults contains
the runId key used by the resume-runId guard.
In `@workflows/inngest/src/execution-engine.ts`:
- Around line 466-468: The thrown Error for missing runId (when runIdFromState
is falsy) is being caught by the surrounding try/catch and turned into fallback
behavior; move the validation out of that try or rethrow the Error so it fails
fast: in the resume logic around runIdFromState and resumeStepId (and the
similar block at the later section around lines 542-555), ensure the check for
missing runId happens before entering the try/catch or change the catch to
rethrow this specific Error (e.g., detect the "Invalid resume state" message or
a custom Error subclass) so you don't generate a fallback randomUUID() and
instead propagate the failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 39339503-cf6f-406b-917f-e0d49e067dcf
📒 Files selected for processing (3)
.changeset/invalid-resume-runid.mdworkflows/inngest/src/__tests__/execution-engine.test.tsworkflows/inngest/src/execution-engine.ts
…invalid resume state
Description
Fixes an issue where a new
runIdcould be silently generated during workflow resume when the originalrunIdis missing.Previous behavior
resume.steps[0]was missing or not found instepResults,randomUUID(),New behavior
runIdcannot be resolved,Related Issue(s)
N/A
Type of Change
Checklist
ELI5
When a paused workflow tries to continue, it must use the same original ID; this PR prevents the engine from silently making a new ID if the original is missing by throwing an error instead. That stops broken workflows and corrupted state.
Summary
This PR fixes an issue in the Inngest execution engine where resuming a workflow could silently generate a new
runIdwhen the originalrunIdwas missing from the suspended step state, causing broken continuity, incorrect state restoration, and inconsistent tracing. The engine now fails fast by throwing an error when the resumerunIdcannot be resolved.Problem
If the resume path referenced a step not present in
stepResults(or the suspended step's payload lacked the expected__workflow_meta.runId), the engine previously fell back torandomUUID(). That behavior created invalid workflow state and trace discontinuities.Solution
When handling resume flows, the engine now derives
runIdstrictly from the suspended step's metadata and throws an error (matched by /missing runId/) if that value is absent, eliminating therandomUUID()fallback and preventing silent corruption.Changes
runIdfrom suspended step state and throw on missingrunId(removed fallback to randomUUID()).stepResults.Type
Bug fix (non-breaking)
Tests
New tests added verifying the engine rejects resume attempts when the resume
runIdcannot be resolved.Notes