@mastra/inngest 1.0.0-beta.6 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,100 @@
1
1
  # @mastra/inngest
2
2
 
3
+ ## 1.0.0-beta.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Add `onFinish` and `onError` lifecycle callbacks to workflow options ([#11200](https://github.com/mastra-ai/mastra/pull/11200))
8
+
9
+ Workflows now support lifecycle callbacks for server-side handling of workflow completion and errors:
10
+ - `onFinish`: Called when workflow completes with any status (success, failed, suspended, tripwire)
11
+ - `onError`: Called only when workflow fails (failed or tripwire status)
12
+
13
+ ```typescript
14
+ const workflow = createWorkflow({
15
+ id: 'my-workflow',
16
+ inputSchema: z.object({ ... }),
17
+ outputSchema: z.object({ ... }),
18
+ options: {
19
+ onFinish: async (result) => {
20
+ // Handle any workflow completion
21
+ await updateJobStatus(result.status);
22
+ },
23
+ onError: async (errorInfo) => {
24
+ // Handle workflow failures
25
+ await logError(errorInfo.error);
26
+ },
27
+ },
28
+ });
29
+ ```
30
+
31
+ Both callbacks support sync and async functions. Callback errors are caught and logged, not propagated to the workflow result.
32
+
33
+ - Updated dependencies [[`919a22b`](https://github.com/mastra-ai/mastra/commit/919a22b25876f9ed5891efe5facbe682c30ff497)]:
34
+ - @mastra/core@1.0.0-beta.13
35
+
36
+ ## 1.0.0-beta.7
37
+
38
+ ### Patch Changes
39
+
40
+ - Preserve error details when thrown from workflow steps ([#10992](https://github.com/mastra-ai/mastra/pull/10992))
41
+ - Errors thrown in workflow steps now preserve full error details including `cause` chain and custom properties
42
+ - Added `SerializedError` type with proper cause chain support
43
+ - Added `SerializedStepResult` and `SerializedStepFailure` types for handling errors loaded from storage
44
+ - Enhanced `addErrorToJSON` to recursively serialize error cause chains with max depth protection
45
+ - Added `hydrateSerializedStepErrors` to convert serialized errors back to Error instances
46
+ - Fixed Inngest workflow error handling to extract original error from `NonRetriableError.cause`
47
+
48
+ - Refactor internal event system from Emitter to PubSub abstraction for workflow event handling. This change replaces the EventEmitter-based event system with a pluggable PubSub interface, enabling support for distributed workflow execution backends like Inngest. Adds `close()` method to PubSub implementations for proper cleanup. ([#11052](https://github.com/mastra-ai/mastra/pull/11052))
49
+
50
+ - Add `startAsync()` method and fix Inngest duplicate workflow execution bug ([#11093](https://github.com/mastra-ai/mastra/pull/11093))
51
+
52
+ **New Feature: `startAsync()` for fire-and-forget workflow execution**
53
+ - Add `Run.startAsync()` to base workflow class - starts workflow in background and returns `{ runId }` immediately
54
+ - Add `EventedRun.startAsync()` - publishes workflow start event without subscribing for completion
55
+ - Add `InngestRun.startAsync()` - sends Inngest event without polling for result
56
+
57
+ **Bug Fix: Prevent duplicate Inngest workflow executions**
58
+ - Fix `getRuns()` to properly handle rate limits (429), empty responses, and JSON parse errors with retry logic and exponential backoff
59
+ - Fix `getRunOutput()` to throw `NonRetriableError` when polling fails, preventing Inngest from retrying the parent function and re-triggering the workflow
60
+ - Add timeout to `getRunOutput()` polling (default 5 minutes) with `NonRetriableError` on timeout
61
+
62
+ This fixes a production issue where polling failures after successful workflow completion caused Inngest to retry the parent function, which fired a new workflow event and resulted in duplicate executions (e.g., duplicate Slack messages).
63
+
64
+ - Preserve error details when thrown from workflow steps ([#10992](https://github.com/mastra-ai/mastra/pull/10992))
65
+
66
+ Workflow errors now retain custom properties like `statusCode`, `responseHeaders`, and `cause` chains. This enables error-specific recovery logic in your applications.
67
+
68
+ **Before:**
69
+
70
+ ```typescript
71
+ const result = await workflow.execute({ input });
72
+ if (result.status === 'failed') {
73
+ // Custom error properties were lost
74
+ console.log(result.error); // "Step execution failed" (just a string)
75
+ }
76
+ ```
77
+
78
+ **After:**
79
+
80
+ ```typescript
81
+ const result = await workflow.execute({ input });
82
+ if (result.status === 'failed') {
83
+ // Custom properties are preserved
84
+ console.log(result.error.message); // "Step execution failed"
85
+ console.log(result.error.statusCode); // 429
86
+ console.log(result.error.cause?.name); // "RateLimitError"
87
+ }
88
+ ```
89
+
90
+ **Type change:** `WorkflowState.error` and `WorkflowRunState.error` types changed from `string | Error` to `SerializedError`.
91
+
92
+ Other changes:
93
+ - Added `UpdateWorkflowStateOptions` type for workflow state updates
94
+
95
+ - Updated dependencies [[`d5ed981`](https://github.com/mastra-ai/mastra/commit/d5ed981c8701c1b8a27a5f35a9a2f7d9244e695f), [`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808), [`932d63d`](https://github.com/mastra-ai/mastra/commit/932d63dd51be9c8bf1e00e3671fe65606c6fb9cd), [`b760b73`](https://github.com/mastra-ai/mastra/commit/b760b731aca7c8a3f041f61d57a7f125ae9cb215), [`695a621`](https://github.com/mastra-ai/mastra/commit/695a621528bdabeb87f83c2277cf2bb084c7f2b4), [`2b459f4`](https://github.com/mastra-ai/mastra/commit/2b459f466fd91688eeb2a44801dc23f7f8a887ab), [`486352b`](https://github.com/mastra-ai/mastra/commit/486352b66c746602b68a95839f830de14c7fb8c0), [`09e4bae`](https://github.com/mastra-ai/mastra/commit/09e4bae18dd5357d2ae078a4a95a2af32168ab08), [`24b76d8`](https://github.com/mastra-ai/mastra/commit/24b76d8e17656269c8ed09a0c038adb9cc2ae95a), [`243a823`](https://github.com/mastra-ai/mastra/commit/243a8239c5906f5c94e4f78b54676793f7510ae3), [`486352b`](https://github.com/mastra-ai/mastra/commit/486352b66c746602b68a95839f830de14c7fb8c0), [`c61fac3`](https://github.com/mastra-ai/mastra/commit/c61fac3add96f0dcce0208c07415279e2537eb62), [`6f14f70`](https://github.com/mastra-ai/mastra/commit/6f14f706ccaaf81b69544b6c1b75ab66a41e5317), [`09e4bae`](https://github.com/mastra-ai/mastra/commit/09e4bae18dd5357d2ae078a4a95a2af32168ab08), [`4524734`](https://github.com/mastra-ai/mastra/commit/45247343e384717a7c8404296275c56201d6470f), [`2a53598`](https://github.com/mastra-ai/mastra/commit/2a53598c6d8cfeb904a7fc74e57e526d751c8fa6), [`c7cd3c7`](https://github.com/mastra-ai/mastra/commit/c7cd3c7a187d7aaf79e2ca139de328bf609a14b4), [`847c212`](https://github.com/mastra-ai/mastra/commit/847c212caba7df0d6f2fc756b494ac3c75c3720d), [`6f941c4`](https://github.com/mastra-ai/mastra/commit/6f941c438ca5f578619788acc7608fc2e23bd176)]:
96
+ - @mastra/core@1.0.0-beta.12
97
+
3
98
  ## 1.0.0-beta.6
4
99
 
5
100
  ### Patch Changes
@@ -1,15 +1,18 @@
1
+ import type { SerializedError } from '@mastra/core/error';
2
+ import type { PubSub } from '@mastra/core/events';
1
3
  import type { Mastra } from '@mastra/core/mastra';
2
4
  import { DefaultExecutionEngine } from '@mastra/core/workflows';
3
- import type { ExecutionContext, Step, StepResult, Emitter, ExecutionEngineOptions, TimeTravelExecutionParams } from '@mastra/core/workflows';
5
+ import type { ExecutionContext, Step, StepResult, ExecutionEngineOptions, TimeTravelExecutionParams } from '@mastra/core/workflows';
4
6
  import type { Inngest, BaseContext } from 'inngest';
5
7
  export declare class InngestExecutionEngine extends DefaultExecutionEngine {
6
8
  private inngestStep;
7
9
  private inngestAttempts;
8
10
  constructor(mastra: Mastra, inngestStep: BaseContext<Inngest>['step'], inngestAttempts: number | undefined, options: ExecutionEngineOptions);
9
11
  /**
10
- * Format errors with stack traces for better debugging in Inngest
12
+ * Format errors while preserving Error instances and their custom properties.
13
+ * Uses getErrorFromUnknown to ensure all error properties are preserved.
11
14
  */
12
- protected formatResultError(error: Error | string | undefined, lastOutput: StepResult<any, any, any, any>): string;
15
+ protected formatResultError(error: Error | string | undefined, lastOutput: StepResult<any, any, any, any>): SerializedError;
13
16
  /**
14
17
  * Detect InngestWorkflow instances for special nested workflow handling
15
18
  */
@@ -38,7 +41,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
38
41
  ok: false;
39
42
  error: {
40
43
  status: 'failed';
41
- error: string;
44
+ error: Error;
42
45
  endedAt: number;
43
46
  };
44
47
  }>;
@@ -62,6 +65,27 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
62
65
  * Provide Inngest step primitive in engine context
63
66
  */
64
67
  getEngineContext(): Record<string, any>;
68
+ /**
69
+ * For Inngest, lifecycle callbacks are invoked in the workflow's finalize step
70
+ * (wrapped in step.run for durability), not in execute(). Override to skip.
71
+ */
72
+ invokeLifecycleCallbacks(_result: {
73
+ status: any;
74
+ result?: any;
75
+ error?: any;
76
+ steps: Record<string, any>;
77
+ tripwire?: any;
78
+ }): Promise<void>;
79
+ /**
80
+ * Actually invoke the lifecycle callbacks. Called from workflow.ts finalize step.
81
+ */
82
+ invokeLifecycleCallbacksInternal(result: {
83
+ status: any;
84
+ result?: any;
85
+ error?: any;
86
+ steps: Record<string, any>;
87
+ tripwire?: any;
88
+ }): Promise<void>;
65
89
  /**
66
90
  * Execute nested InngestWorkflow using inngestStep.invoke() for durability.
67
91
  * This MUST be called directly (not inside step.run()) due to Inngest constraints.
@@ -78,7 +102,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
78
102
  timeTravel?: TimeTravelExecutionParams;
79
103
  prevOutput: any;
80
104
  inputData: any;
81
- emitter: Emitter;
105
+ pubsub: PubSub;
82
106
  startedAt: number;
83
107
  }): Promise<StepResult<any, any, any, any> | null>;
84
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"execution-engine.d.ts","sourceRoot":"","sources":["../src/execution-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAmC,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,UAAU,EAEV,OAAO,EACP,sBAAsB,EACtB,yBAAyB,EAE1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGpD,qBAAa,sBAAuB,SAAQ,sBAAsB;IACh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