Skip to content

fix(inngest): throw error when resume runId is missing to prevent invalid workflow state#15826

Open
Akash504-ai wants to merge 4 commits into
mastra-ai:mainfrom
Akash504-ai:fix/inngest-resume-runid
Open

fix(inngest): throw error when resume runId is missing to prevent invalid workflow state#15826
Akash504-ai wants to merge 4 commits into
mastra-ai:mainfrom
Akash504-ai:fix/inngest-resume-runid

Conversation

@Akash504-ai

@Akash504-ai Akash504-ai commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an issue where a new runId could be silently generated during workflow resume when the original runId is missing.

Previous behavior

  • If resume.steps[0] was missing or not found in stepResults,
  • The engine would fallback to randomUUID(),
  • This resulted in broken workflow continuity, incorrect state restoration, and inconsistent tracing.

New behavior

  • The engine now explicitly throws an error if the runId cannot be resolved,
  • Preventing silent corruption and ensuring workflow integrity.

Related Issue(s)

N/A


Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test update

Checklist

  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • I have addressed all Coderabbit comments on this PR

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 runId when the original runId was 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 resume runId cannot 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 to randomUUID(). That behavior created invalid workflow state and trace discontinuities.

Solution

When handling resume flows, the engine now derives runId strictly from the suspended step's metadata and throws an error (matched by /missing runId/) if that value is absent, eliminating the randomUUID() fallback and preventing silent corruption.

Changes

  • workflows/inngest/src/execution-engine.ts: Adjusted resume logic to require and extract runId from suspended step state and throw on missing runId (removed fallback to randomUUID()).
  • workflows/inngest/src/tests/execution-engine.test.ts: Added a test ("InngestExecutionEngine - resume safety") asserting resume fails with an error when the referenced resume step is missing from stepResults.
  • .changeset/invalid-resume-runid.md: Added Changesets entry documenting the patch release for @mastra/workflows-inngest.

Type

Bug fix (non-breaking)

Tests

New tests added verifying the engine rejects resume attempts when the resume runId cannot be resolved.

Notes

  • Documentation was not updated.
  • Coderabbit checklist comments were not fully addressed per the PR metadata.

@changeset-bot

changeset-bot Bot commented Apr 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest 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

@vercel

vercel Bot commented Apr 28, 2026

Copy link
Copy Markdown

@Akash504-ai is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 08745dc2-090f-4cc8-8979-933b66c8919a

📥 Commits

Reviewing files that changed from the base of the PR and between e619560 and 632aad3.

📒 Files selected for processing (3)
  • .changeset/invalid-resume-runid.md
  • workflows/inngest/src/__tests__/execution-engine.test.ts
  • workflows/inngest/src/execution-engine.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/invalid-resume-runid.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • workflows/inngest/src/tests/execution-engine.test.ts

Walkthrough

Enforces 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

Cohort / File(s) Summary
Changeset Metadata
.changeset/invalid-resume-runid.md
Adds a changeset entry documenting a patch for @mastra/workflows-inngest describing the runId resume behavior.
Resume Safety Validation & Tests
workflows/inngest/src/execution-engine.ts, workflows/inngest/src/__tests__/execution-engine.test.ts
executeWorkflowStep now derives runId from suspended step metadata and throws if missing (no fallback to generated ID). Adds a test asserting resume fails when runId is absent.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: throwing an error when resume runId is missing to prevent invalid workflow state, which directly matches the core fix in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dane-ai-mastra

Copy link
Copy Markdown
Contributor

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 Fixes #1234).

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 @coderabbitai review in case you want to trigger a review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c41e32 and e619560.

📒 Files selected for processing (3)
  • .changeset/invalid-resume-runid.md
  • workflows/inngest/src/__tests__/execution-engine.test.ts
  • workflows/inngest/src/execution-engine.ts

Comment thread .changeset/invalid-resume-runid.md Outdated
Comment thread workflows/inngest/src/__tests__/execution-engine.test.ts Outdated
Comment thread workflows/inngest/src/execution-engine.ts Outdated
@Akash504-ai Akash504-ai reopened this Apr 28, 2026
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.

1 participant