inngest 4.0.1 → 4.0.2

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,13 @@
1
1
  # inngest
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1387](https://github.com/inngest/inngest-js/pull/1387) [`983f527b`](https://github.com/inngest/inngest-js/commit/983f527bdc202845752d060d9429868ff80d8bb6) Thanks [@amh4r](https://github.com/amh4r)! - Fix checkpointing maxRuntime causing function run hang
8
+
9
+ - [#1387](https://github.com/inngest/inngest-js/pull/1387) [`983f527b`](https://github.com/inngest/inngest-js/commit/983f527bdc202845752d060d9429868ff80d8bb6) Thanks [@amh4r](https://github.com/amh4r)! - Fallback to async flow on checkpoint error
10
+
3
11
  ## 4.0.1
4
12
 
5
13
  ### Patch Changes
@@ -298,7 +298,14 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
298
298
  return;
299
299
  } catch (err) {
300
300
  this.devDebug("error checkpointing after step run, so falling back to async", err);
301
- if (stepResult) return stepRanHandler(stepResult);
301
+ const buffered = this.state.checkpointingStepBuffer;
302
+ if (buffered.length) return {
303
+ type: "steps-found",
304
+ ctx: this.fnArg,
305
+ ops: this.ops,
306
+ steps: buffered
307
+ };
308
+ return;
302
309
  } finally {
303
310
  this.state.checkpointingStepBuffer = [];
304
311
  }
@@ -346,7 +353,7 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
346
353
  "checkpointing-runtime-reached": () => {
347
354
  return this.checkpointAndSwitchToAsync([{
348
355
  op: require_types.StepOpCode.DiscoveryRequest,
349
- id: _internals.hashId("discovery-request")
356
+ id: _internals.hashId(`discovery-request-${Date.now()}`)
350
357
  }]);
351
358
  },
352
359
  "checkpointing-buffer-interval-reached": () => {
@@ -406,7 +413,10 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
406
413
  }
407
414
  },
408
415
  "function-rejected": async (checkpoint) => {
409
- if (this.state.checkpointingStepBuffer.length) await attemptCheckpointAndResume(void 0, false);
416
+ if (this.state.checkpointingStepBuffer.length) {
417
+ const fallback = await attemptCheckpointAndResume(void 0, false, true);
418
+ if (fallback) return fallback;
419
+ }
410
420
  return await this.transformOutput({ error: checkpoint.error });
411
421
  },
412
422
  "step-not-found": asyncHandlers["step-not-found"],
@@ -428,12 +438,18 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
428
438
  if (stepResult) {
429
439
  this.devDebug(`executed step "${stepResult.id}" successfully`);
430
440
  if (stepResult.error) {
431
- if (this.state.checkpointingStepBuffer.length) await attemptCheckpointAndResume(void 0, false, true);
441
+ if (this.state.checkpointingStepBuffer.length) {
442
+ const fallback = await attemptCheckpointAndResume(void 0, false, true);
443
+ if (fallback) return fallback;
444
+ }
432
445
  return stepRanHandler(stepResult);
433
446
  }
434
447
  return await attemptCheckpointAndResume(stepResult);
435
448
  }
436
- if (this.state.checkpointingStepBuffer.length) await attemptCheckpointAndResume(void 0, false, true);
449
+ if (this.state.checkpointingStepBuffer.length) {
450
+ const fallback = await attemptCheckpointAndResume(void 0, false, true);
451
+ if (fallback) return fallback;
452
+ }
437
453
  return maybeReturnNewSteps();
438
454
  }
439
455
  if (stepsToResume.length) {
@@ -451,7 +467,7 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
451
467
  ops: this.ops,
452
468
  steps: [{
453
469
  op: require_types.StepOpCode.DiscoveryRequest,
454
- id: _internals.hashId("discovery-request")
470
+ id: _internals.hashId(`discovery-request-${Date.now()}`)
455
471
  }]
456
472
  };
457
473
  },
@@ -1 +1 @@
1
- {"version":3,"file":"engine.cjs","names":["hashjs","createExecutionEngine: InngestExecutionFactory","InngestExecution","ExecutionVersion","options: InngestExecutionOptions","StepMode","MiddlewareManager","internalLoggerSymbol","trace","version","getAsyncLocalStorage","headerKeys","retryWithBackoff","defaultMaxRetries","commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"]","StepOpCode","serializeError","syncHandlers: CheckpointHandlers[StepMode.Sync]","asyncHandlers: CheckpointHandlers[StepMode.Async]","asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing]","step","UnreachableError","outgoingOp: OutgoingOp","getAsyncCtx","interval: GoInterval | undefined","runAsPromise","createDeferredPromise","goIntervalTiming","innerHandler: () => Promise<unknown>","err: Error","NonRetriableError","validateEvents","retriable: boolean | string","StepError","RetryAfterError","undefinedToNull","createDeferredPromiseWithStack","loop: ExecutionState[\"loop\"]","experimentStepRunSymbol","createGroupTools","z","jsonErrorSchema","deserializeError","foundStepsToReport: Map<string, FoundStep>","unhandledFoundStepsToReport: Map<string, FoundStep>","expectedNextStepIndexes: Map<string, number>","remainingStepCompletionOrder: string[]","foundStepsReportPromise: Promise<void> | undefined","ErrCode","extensionPromise: Promise<void>","resolveNextTick","resolveAfterPending","stepHandler: StepHandler","getStepOptions","extraOpts: Record<string, unknown> | undefined","step: FoundStep","createStepTools","createTimeoutPromise","STEP_INDEXING_SUFFIX"],"sources":["../../../src/components/execution/engine.ts"],"sourcesContent":["import { trace } from \"@opentelemetry/api\";\nimport hashjs from \"hash.js\";\nimport ms, { type StringValue } from \"ms\";\nimport { z } from \"zod/v3\";\n\nimport {\n defaultMaxRetries,\n ExecutionVersion,\n headerKeys,\n internalEvents,\n} from \"../../helpers/consts.ts\";\n\nimport {\n deserializeError,\n ErrCode,\n serializeError,\n} from \"../../helpers/errors.js\";\nimport { undefinedToNull } from \"../../helpers/functions.js\";\nimport {\n createDeferredPromise,\n createDeferredPromiseWithStack,\n createTimeoutPromise,\n type GoInterval,\n goIntervalTiming,\n resolveAfterPending,\n resolveNextTick,\n retryWithBackoff,\n runAsPromise,\n} from \"../../helpers/promises.ts\";\nimport * as Temporal from \"../../helpers/temporal.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport {\n type APIStepPayload,\n type Context,\n type EventPayload,\n type FailureEventArgs,\n type Handler,\n type HashedOp,\n jsonErrorSchema,\n type OutgoingOp,\n StepMode,\n StepOpCode,\n} from \"../../types.ts\";\nimport { version } from \"../../version.ts\";\nimport { internalLoggerSymbol } from \"../Inngest.ts\";\nimport { createGroupTools } from \"../InngestGroupTools.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n MetadataUpdate,\n} from \"../InngestMetadata.ts\";\nimport {\n createStepTools,\n type ExperimentStepTools,\n experimentStepRunSymbol,\n type FoundStep,\n getStepOptions,\n STEP_INDEXING_SUFFIX,\n type StepHandler,\n} from \"../InngestStepTools.ts\";\nimport { MiddlewareManager } from \"../middleware/index.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\nimport { UnreachableError } from \"../middleware/utils.ts\";\nimport { NonRetriableError } from \"../NonRetriableError.ts\";\nimport { RetryAfterError } from \"../RetryAfterError.ts\";\nimport { StepError } from \"../StepError.ts\";\nimport { validateEvents } from \"../triggers/utils.js\";\nimport { getAsyncCtx, getAsyncLocalStorage } from \"./als.ts\";\nimport {\n type BasicFoundStep,\n type ExecutionResult,\n type IInngestExecution,\n InngestExecution,\n type InngestExecutionFactory,\n type InngestExecutionOptions,\n type MemoizedOp,\n} from \"./InngestExecution.ts\";\nimport { clientProcessorMap } from \"./otel/access.ts\";\n\nconst { sha1 } = hashjs;\n\n/**\n * Retry configuration for checkpoint operations.\n *\n * Checkpoint calls use exponential backoff with jitter to handle transient\n * network failures (e.g., dev server temporarily down, cloud hiccup). If\n * retries exhaust, the error propagates up - for Sync mode this results in a\n * 500 error, for AsyncCheckpointing the caller handles fallback.\n */\nconst CHECKPOINT_RETRY_OPTIONS = { maxAttempts: 5, baseDelay: 100 };\nconst STEP_NOT_FOUND_MAX_FOUND_STEPS = 25;\n\nexport const createExecutionEngine: InngestExecutionFactory = (options) => {\n return new InngestExecutionEngine(options);\n};\n\nclass InngestExecutionEngine\n extends InngestExecution\n implements IInngestExecution\n{\n public version = ExecutionVersion.V2;\n\n private state: ExecutionState;\n private fnArg: Context.Any;\n private checkpointHandlers: CheckpointHandlers;\n private timeoutDuration = 1000 * 10;\n private execution: Promise<ExecutionResult> | undefined;\n private userFnToRun: Handler.Any;\n private middlewareManager: MiddlewareManager;\n\n /**\n * If we're supposed to run a particular step via `requestedRunStep`, this\n * will be a `Promise` that resolves after no steps have been found for\n * `timeoutDuration` milliseconds.\n *\n * If we're not supposed to run a particular step, this will be `undefined`.\n */\n private timeout?: ReturnType<typeof createTimeoutPromise>;\n private rootSpanId?: string;\n\n /**\n * If we're checkpointing and have been given a maximum runtime, this will be\n * a `Promise` that resolves after that duration has elapsed, allowing us to\n * ensure that we end the execution in good time, especially in serverless\n * environments.\n */\n private checkpointingMaxRuntimeTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n /**\n * If we're checkpointing and have been given a maximum buffer interval, this\n * will be a `Promise` that resolves after that duration has elapsed, allowing\n * us to periodically checkpoint even if the step buffer hasn't filled.\n */\n private checkpointingMaxBufferIntervalTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n constructor(rawOptions: InngestExecutionOptions) {\n const options: InngestExecutionOptions = {\n ...rawOptions,\n stepMode: rawOptions.stepMode ?? StepMode.Async,\n };\n\n super(options);\n\n /**\n * Check we have everything we need for checkpointing\n */\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.options.createResponse) {\n throw new Error(\"createResponse is required for sync step mode\");\n }\n }\n\n this.userFnToRun = this.getUserFnToRun();\n this.state = this.createExecutionState();\n this.fnArg = this.createFnArg();\n\n // Setup middleware\n const mwInstances =\n this.options.middlewareInstances ??\n (this.options.client.middleware || []).map((Cls) => {\n return new Cls({ client: this.options.client });\n });\n this.middlewareManager = new MiddlewareManager(\n this.fnArg,\n () => this.state.stepState,\n mwInstances,\n this.options.fn,\n this.options.client[internalLoggerSymbol],\n );\n\n this.checkpointHandlers = this.createCheckpointHandlers();\n this.initializeTimer(this.state);\n this.initializeCheckpointRuntimeTimer(this.state);\n\n this.devDebug(\n \"created new V1 execution for run;\",\n this.options.requestedRunStep\n ? `wanting to run step \"${this.options.requestedRunStep}\"`\n : \"discovering steps\",\n );\n\n this.devDebug(\"existing state keys:\", Object.keys(this.state.stepState));\n }\n\n /**\n * Idempotently start the execution of the user's function.\n */\n public start() {\n if (!this.execution) {\n this.devDebug(\"starting V1 execution\");\n\n const tracer = trace.getTracer(\"inngest\", version);\n\n this.execution = getAsyncLocalStorage().then((als) => {\n return als.run(\n {\n app: this.options.client,\n execution: {\n ctx: this.fnArg,\n instance: this,\n },\n },\n async () => {\n return tracer.startActiveSpan(\"inngest.execution\", (span) => {\n this.rootSpanId = span.spanContext().spanId;\n clientProcessorMap.get(this.options.client)?.declareStartingSpan({\n span,\n runId: this.options.runId,\n traceparent: this.options.headers[headerKeys.TraceParent],\n tracestate: this.options.headers[headerKeys.TraceState],\n });\n\n return this._start()\n .then((result) => {\n this.devDebug(\"result:\", result);\n return result;\n })\n .finally(() => {\n span.end();\n });\n });\n },\n );\n });\n }\n\n return this.execution;\n }\n\n public addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ) {\n if (!this.state.metadata) {\n this.state.metadata = new Map();\n }\n\n const updates = this.state.metadata.get(stepId) ?? [];\n updates.push({ kind, scope, op, values });\n this.state.metadata.set(stepId, updates);\n\n return true;\n }\n\n /**\n * Starts execution of the user's function and the core loop.\n */\n private async _start(): Promise<ExecutionResult> {\n try {\n const allCheckpointHandler = this.getCheckpointHandler(\"\");\n await this.startExecution();\n\n let i = 0;\n\n for await (const checkpoint of this.state.loop) {\n await allCheckpointHandler(checkpoint, i);\n\n const handler = this.getCheckpointHandler(checkpoint.type);\n const result = await handler(checkpoint, i++);\n\n if (result) {\n return result;\n }\n }\n } catch (error) {\n return this.transformOutput({ error });\n } finally {\n void this.state.loop.return();\n }\n\n /**\n * If we're here, the generator somehow finished without returning a value.\n * This should never happen.\n */\n throw new Error(\"Core loop finished without returning a value\");\n }\n\n private async checkpoint(steps: OutgoingOp[]): Promise<void> {\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.state.checkpointedRun) {\n // We have to start the run\n const res = await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointNewRun({\n runId: this.fnArg.runId,\n event: this.fnArg.event as APIStepPayload,\n steps,\n executionVersion: this.version,\n retries: this.fnArg.maxAttempts ?? defaultMaxRetries,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n\n this.state.checkpointedRun = {\n appId: res.data.app_id,\n fnId: res.data.fn_id,\n token: res.data.token,\n };\n } else {\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointSteps({\n appId: this.state.checkpointedRun!.appId,\n fnId: this.state.checkpointedRun!.fnId,\n runId: this.fnArg.runId,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n }\n } else if (this.options.stepMode === StepMode.AsyncCheckpointing) {\n if (!this.options.queueItemId) {\n throw new Error(\n \"Missing queueItemId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n if (!this.options.internalFnId) {\n throw new Error(\n \"Missing internalFnId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointStepsAsync({\n runId: this.fnArg.runId,\n fnId: this.options.internalFnId!,\n queueItemId: this.options.queueItemId!,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n } else {\n throw new Error(\n \"Checkpointing is only supported in Sync and AsyncCheckpointing step modes. This is a bug in the Inngest SDK.\",\n );\n }\n }\n\n private async checkpointAndSwitchToAsync(\n steps: OutgoingOp[],\n ): Promise<ExecutionResult> {\n await this.checkpoint(steps);\n\n if (!this.state.checkpointedRun?.token) {\n throw new Error(\"Failed to checkpoint and switch to async mode\");\n }\n\n return {\n type: \"change-mode\",\n ctx: this.fnArg,\n ops: this.ops,\n to: StepMode.Async,\n token: this.state.checkpointedRun?.token!,\n };\n }\n\n /**\n * Returns whether we're in the final attempt of execution, or `null` if we\n * can't determine this in the SDK.\n */\n private inFinalAttempt(): boolean | null {\n if (typeof this.fnArg.maxAttempts !== \"number\") {\n return null;\n }\n\n return this.fnArg.attempt + 1 >= this.fnArg.maxAttempts;\n }\n\n /**\n * Creates a handler for every checkpoint type, defining what to do when we\n * reach that checkpoint in the core loop.\n */\n private createCheckpointHandlers(): CheckpointHandlers {\n const commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"] = (\n checkpoint,\n ) => {\n this.devDebug(`${this.options.stepMode} checkpoint:`, checkpoint);\n };\n\n const stepRanHandler = async (\n stepResult: OutgoingOp,\n ): Promise<ExecutionResult> => {\n const transformResult = await this.transformOutput(stepResult);\n\n /**\n * Transforming output will always return either function rejection or\n * resolution. In most cases, this can be immediately returned, but in\n * this particular case we want to handle it differently.\n */\n if (transformResult.type === \"function-resolved\") {\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n step: {\n ...stepResult,\n data: transformResult.data,\n },\n };\n } else if (transformResult.type === \"function-rejected\") {\n const stepForResponse = {\n ...stepResult,\n error: transformResult.error,\n };\n\n if (stepResult.op === StepOpCode.StepFailed) {\n const ser = serializeError(transformResult.error);\n stepForResponse.data = {\n __serialized: true,\n name: ser.name,\n message: ser.message,\n stack: \"\",\n };\n }\n\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n retriable: transformResult.retriable,\n step: stepForResponse,\n };\n }\n\n return transformResult;\n };\n\n const maybeReturnNewSteps = async (): Promise<\n ExecutionResult | undefined\n > => {\n const newSteps = await this.filterNewSteps(\n Array.from(this.state.steps.values()),\n );\n if (newSteps) {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: newSteps,\n };\n }\n\n return;\n };\n\n const attemptCheckpointAndResume = async (\n stepResult?: OutgoingOp,\n resume = true,\n force = false,\n ) => {\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n if (stepResult) {\n const stepToResume = this.resumeStepWithResult(stepResult, resume);\n\n // Clear `executingStep` immediately after resuming, before any await.\n // `resumeStepWithResult` resolves the step's promise, queuing a\n // microtask for the function to continue. Any subsequent await (e.g.\n // the `transformOutput` hook) yields and lets that microtask run, so\n // `executingStep` must already be cleared to avoid a false positive\n // NESTING_STEPS warning in the next step's handler.\n delete this.state.executingStep;\n\n // Buffer a copy with transformed data for checkpointing\n this.state.checkpointingStepBuffer.push({\n ...stepToResume,\n data: stepResult.data,\n });\n }\n\n if (\n force ||\n !this.options.checkpointingConfig?.bufferedSteps ||\n this.state.checkpointingStepBuffer.length >=\n this.options.checkpointingConfig.bufferedSteps\n ) {\n this.devDebug(\"checkpointing and resuming execution after step run\");\n\n try {\n this.devDebug(\n `checkpointing all buffered steps:`,\n this.state.checkpointingStepBuffer\n .map((op) => op.displayName || op.id)\n .join(\", \"),\n );\n\n return void (await this.checkpoint(\n this.state.checkpointingStepBuffer,\n ));\n } catch (err) {\n // If checkpointing fails for any reason, fall back to the async\n // flow\n this.devDebug(\n \"error checkpointing after step run, so falling back to async\",\n err,\n );\n\n if (stepResult) {\n return stepRanHandler(stepResult);\n }\n } finally {\n // Clear the checkpointing buffer\n this.state.checkpointingStepBuffer = [];\n }\n } else {\n this.devDebug(\n `not checkpointing yet, continuing execution as we haven't reached buffered step limit of ${this.options.checkpointingConfig?.bufferedSteps}`,\n );\n }\n\n return;\n };\n\n const syncHandlers: CheckpointHandlers[StepMode.Sync] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n \"function-resolved\": async (checkpoint, i) => {\n const transformedData = checkpoint.data;\n\n await this.checkpoint([\n {\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: await this.options.createResponse!(transformedData),\n },\n ]);\n\n // Apply middleware transformation before returning\n return await this.transformOutput({ data: checkpoint.data });\n },\n\n \"function-rejected\": async (checkpoint) => {\n // If the function throws during sync execution, we want to switch to\n // async mode so that we can retry. The exception is that we're already\n // at max attempts, in which case we do actually want to reject.\n if (this.inFinalAttempt()) {\n // Apply middleware transformation before returning\n return await this.transformOutput({ error: checkpoint.error });\n }\n\n // Otherwise, checkpoint the error and switch to async mode\n return this.checkpointAndSwitchToAsync([\n {\n id: _internals.hashId(\"complete\"), // ID is not important here\n op: StepOpCode.StepError,\n error: checkpoint.error,\n },\n ]);\n },\n\n \"step-not-found\": () => {\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n error: new Error(\n \"Step not found when checkpointing; this should never happen\",\n ),\n ops: this.ops,\n retriable: false,\n };\n },\n\n \"steps-found\": async ({ steps }) => {\n // If we're entering parallelism or async mode, checkpoint and switch\n // to async.\n if (steps.length !== 1 || steps[0].mode !== StepMode.Sync) {\n return this.checkpointAndSwitchToAsync(\n steps.map((step) => ({ ...step, id: step.hashedId })),\n );\n }\n\n // Otherwise we're good to start executing things right now.\n const result = await this.executeStep(steps[0]);\n\n if (result.error) {\n return this.checkpointAndSwitchToAsync([result]);\n }\n\n // Resume the step with original data for user code\n const stepToResume = this.resumeStepWithResult(result);\n\n // Clear executingStep now that the step result has been processed.\n // Without this, the next step discovery would see stale state and\n // emit a false positive NESTING_STEPS warning.\n delete this.state.executingStep;\n\n return void (await this.checkpoint([stepToResume]));\n },\n\n \"checkpointing-runtime-reached\": () => {\n return this.checkpointAndSwitchToAsync([\n {\n op: StepOpCode.DiscoveryRequest,\n id: _internals.hashId(\"discovery-request\"), // ID doesn't matter\n },\n ]);\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n const asyncHandlers: CheckpointHandlers[StepMode.Async] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n /**\n * The user's function has completed and returned a value.\n */\n \"function-resolved\": async ({ data }) => {\n // Check for unreported new steps (e.g. from `Promise.race` where\n // the winning branch completed before losing branches reported)\n const newStepsResult = await maybeReturnNewSteps();\n if (newStepsResult) {\n return newStepsResult;\n }\n\n // We need to do this even here for async, as we could be returning\n // data from an API endpoint, even if we were triggered async.\n if (this.options.createResponse) {\n data = await this.options.createResponse(data);\n }\n\n return await this.transformOutput({ data });\n },\n\n /**\n * The user's function has thrown an error.\n */\n \"function-rejected\": async (checkpoint) => {\n return await this.transformOutput({ error: checkpoint.error });\n },\n\n /**\n * We've found one or more steps. Here we may want to run a step or report\n * them back to Inngest.\n */\n \"steps-found\": async ({ steps }) => {\n const stepResult = await this.tryExecuteStep(steps);\n if (stepResult) {\n return stepRanHandler(stepResult);\n }\n\n return maybeReturnNewSteps();\n },\n\n /**\n * While trying to find a step that Inngest has told us to run, we've\n * timed out or have otherwise decided that it doesn't exist.\n */\n \"step-not-found\": ({ step }) => {\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n return {\n type: \"step-not-found\",\n ctx: this.fnArg,\n ops: this.ops,\n step,\n foundSteps,\n totalFoundSteps,\n };\n },\n\n \"checkpointing-runtime-reached\": () => {\n throw new Error(\n \"Checkpointing maximum runtime reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n throw new Error(\n \"Checkpointing maximum buffer interval reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n };\n\n const asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing] =\n {\n \"\": commonCheckpointHandler,\n \"function-resolved\": async (checkpoint, i) => {\n const output = await asyncHandlers[\"function-resolved\"](\n checkpoint,\n i,\n );\n if (output?.type === \"function-resolved\") {\n const steps = this.state.checkpointingStepBuffer.concat({\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: output.data,\n });\n\n if (isNonEmpty(steps)) {\n return {\n type: \"steps-found\",\n ctx: output.ctx,\n ops: output.ops,\n steps,\n };\n }\n }\n\n return;\n },\n \"function-rejected\": async (checkpoint) => {\n // If we have buffered steps, attempt checkpointing them first\n if (this.state.checkpointingStepBuffer.length) {\n await attemptCheckpointAndResume(undefined, false);\n }\n\n return await this.transformOutput({ error: checkpoint.error });\n },\n \"step-not-found\": asyncHandlers[\"step-not-found\"],\n \"steps-found\": async ({ steps }) => {\n // Note that if we have a requested run step, we'll never be\n // checkpointing, as that's an async parallel execution mode.\n\n // Break found steps in to { stepsToResume, newSteps }\n const { stepsToResume, newSteps } = steps.reduce(\n (acc, step) => {\n if (!step.hasStepState) {\n acc.newSteps.push(step);\n } else if (!step.fulfilled) {\n acc.stepsToResume.push(step);\n }\n\n return acc;\n },\n { stepsToResume: [], newSteps: [] } as {\n stepsToResume: FoundStep[];\n newSteps: FoundStep[];\n },\n );\n\n this.devDebug(\"split found steps in to:\", {\n stepsToResume: stepsToResume.length,\n newSteps: newSteps.length,\n });\n\n // Got new steps? Exit early.\n if (!this.options.requestedRunStep && newSteps.length) {\n const stepResult = await this.tryExecuteStep(newSteps);\n if (stepResult) {\n this.devDebug(`executed step \"${stepResult.id}\" successfully`);\n\n // We executed a step!\n //\n // We know that because we're in this mode, we're always free to\n // checkpoint and continue if we ran a step and it was successful.\n if (stepResult.error) {\n // Flush buffered steps before falling back to async,\n // so previously-successful steps aren't lost.\n if (this.state.checkpointingStepBuffer.length) {\n await attemptCheckpointAndResume(undefined, false, true);\n }\n\n // If we failed, go back to the regular async flow.\n return stepRanHandler(stepResult);\n }\n\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n return await attemptCheckpointAndResume(stepResult);\n }\n\n // Flush any buffered checkpoint steps before returning\n // new steps to the executor. Without this, steps executed\n // in-process during AsyncCheckpointing but not yet\n // checkpointed would be lost. When the executor later calls\n // back with requestedRunStep, those steps would be missing\n // from stepState, causing \"step not found\" errors.\n if (this.state.checkpointingStepBuffer.length) {\n await attemptCheckpointAndResume(undefined, false, true);\n }\n\n return maybeReturnNewSteps();\n }\n\n // If we have stepsToResume, resume as many as possible and resume execution\n if (stepsToResume.length) {\n this.devDebug(`resuming ${stepsToResume.length} steps`);\n\n for (const st of stepsToResume) {\n this.resumeStepWithResult({\n ...st,\n id: st.hashedId,\n });\n }\n }\n\n return;\n },\n \"checkpointing-runtime-reached\": async () => {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: [\n {\n op: StepOpCode.DiscoveryRequest,\n id: _internals.hashId(\"discovery-request\"), // ID doesn't matter\n },\n ],\n };\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n return {\n [StepMode.Async]: asyncHandlers,\n [StepMode.Sync]: syncHandlers,\n [StepMode.AsyncCheckpointing]: asyncCheckpointingHandlers,\n };\n }\n\n private getCheckpointHandler(type: keyof CheckpointHandlers[StepMode]) {\n return this.checkpointHandlers[this.options.stepMode][type] as (\n checkpoint: Checkpoint,\n iteration: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n }\n\n private async tryExecuteStep(\n steps: FoundStep[],\n ): Promise<OutgoingOp | undefined> {\n const hashedStepIdToRun =\n this.options.requestedRunStep || this.getEarlyExecRunStep(steps);\n if (!hashedStepIdToRun) {\n return;\n }\n\n const step = steps.find(\n (step) => step.hashedId === hashedStepIdToRun && step.fn,\n );\n\n if (step) {\n return await this.executeStep(step);\n }\n\n /**\n * Ensure we reset the timeout if we have a requested run step but couldn't\n * find it, but also that we don't reset if we found and executed it.\n */\n return void this.timeout?.reset();\n }\n\n /**\n * Given a list of outgoing ops, decide if we can execute an op early and\n * return the ID of the step to execute if we can.\n */\n private getEarlyExecRunStep(steps: FoundStep[]): string | undefined {\n /**\n * We may have been disabled due to parallelism, in which case we can't\n * immediately execute unless explicitly requested.\n */\n if (this.options.disableImmediateExecution) return;\n\n const unfulfilledSteps = steps.filter((step) => !step.fulfilled);\n if (unfulfilledSteps.length !== 1) return;\n\n const op = unfulfilledSteps[0];\n\n if (\n op &&\n op.op === StepOpCode.StepPlanned\n // TODO We must individually check properties here that we do not want to\n // execute on, such as retry counts. Nothing exists here that falls in to\n // this case, but should be accounted for when we add them.\n // && typeof op.opts === \"undefined\"\n ) {\n return op.hashedId;\n }\n\n return;\n }\n\n private async filterNewSteps(\n foundSteps: FoundStep[],\n ): Promise<[OutgoingOp, ...OutgoingOp[]] | undefined> {\n if (this.options.requestedRunStep) {\n return;\n }\n\n const newSteps = foundSteps.reduce((acc, step) => {\n if (!step.hasStepState) {\n acc.push(step);\n }\n\n return acc;\n }, [] as FoundStep[]);\n\n if (!newSteps.length) {\n return;\n }\n\n await this.middlewareManager.onMemoizationEnd();\n\n const stepList = newSteps.map<OutgoingOp>((step) => {\n return {\n displayName: step.displayName,\n op: step.op,\n id: step.hashedId,\n name: step.name,\n opts: step.opts,\n userland: step.userland,\n };\n });\n\n if (!isNonEmpty(stepList)) {\n throw new UnreachableError(\"stepList is empty\");\n }\n\n return stepList;\n }\n\n private async executeStep(foundStep: FoundStep): Promise<OutgoingOp> {\n const { id, name, opts, fn, displayName, userland, hashedId } = foundStep;\n const { stepInfo, wrappedHandler, setActualHandler } = foundStep.middleware;\n\n this.devDebug(`preparing to execute step \"${id}\"`);\n\n this.timeout?.clear();\n\n const outgoingOp: OutgoingOp = {\n id: hashedId,\n op: StepOpCode.StepRun,\n name,\n opts,\n displayName,\n userland,\n };\n this.state.executingStep = outgoingOp;\n\n const store = await getAsyncCtx();\n\n if (store?.execution) {\n store.execution.executingStep = {\n id,\n name: displayName,\n };\n }\n\n this.devDebug(`executing step \"${id}\"`);\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.declareStepExecution(\n this.rootSpanId,\n hashedId,\n this.options.data?.attempt ?? 0,\n );\n }\n\n let interval: GoInterval | undefined;\n\n // `fn` already has middleware-transformed args baked in via `fnArgs` (i.e.\n // the `transformStepInput` middleware hook already ran).\n const actualHandler = () => runAsPromise(fn);\n\n await this.middlewareManager.onMemoizationEnd();\n await this.middlewareManager.onStepStart(stepInfo);\n\n // If wrappedHandler hasn't been called yet (no deferred from discovery),\n // set one up so wrapStep's next() still blocks until memoization.\n if (!foundStep.memoizationDeferred) {\n const deferred = createDeferredPromise<unknown>();\n foundStep.memoizationDeferred = deferred;\n setActualHandler(() => deferred.promise);\n foundStep.transformedResultPromise = wrappedHandler();\n foundStep.transformedResultPromise.catch(() => {\n // Swallow — errors handled by handle()\n });\n }\n\n // Build wrapStepHandler chain around the actual handler\n const wrappedActualHandler =\n this.middlewareManager.buildWrapStepHandlerChain(actualHandler, stepInfo);\n\n return goIntervalTiming(() => wrappedActualHandler())\n .finally(() => {\n this.devDebug(`finished executing step \"${id}\"`);\n\n this.state.executingStep = undefined;\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.clearStepExecution(this.rootSpanId);\n }\n\n if (store?.execution) {\n delete store.execution.executingStep;\n }\n })\n .then<OutgoingOp>(async ({ resultPromise, interval: _interval }) => {\n interval = _interval;\n const metadata = this.state.metadata?.get(id);\n const serverData = await resultPromise;\n\n // Don't resolve memoizationDeferred here. wrapStep's next() must\n // block until the step is actually memoized (i.e. handle() fires\n // with confirmed data from the server). handle() resolves it.\n await this.middlewareManager.onStepComplete(stepInfo, serverData);\n\n return {\n ...outgoingOp,\n data: serverData,\n ...(metadata && metadata.length > 0 ? { metadata: metadata } : {}),\n };\n })\n .catch<OutgoingOp>((error) => {\n // Don't reject memoizationDeferred — handle() will reject it when\n // the error is memoized.\n return this.buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n });\n })\n .then((op) => ({\n ...op,\n timing: interval,\n }));\n }\n\n /**\n * Starts execution of the user's function, including triggering checkpoints\n * and middleware hooks where appropriate.\n */\n private async startExecution(): Promise<void> {\n /**\n * Start the timer to time out the run if needed.\n */\n void this.timeout?.start();\n void this.checkpointingMaxRuntimeTimer?.start();\n void this.checkpointingMaxBufferIntervalTimer?.start();\n\n const fnInputResult = await this.middlewareManager.transformFunctionInput();\n this.applyFunctionInputMutations(fnInputResult);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (this.state.stepsToFulfill === 0 && this.fnArg.attempt === 0) {\n await this.middlewareManager.onRunStart();\n }\n\n const innerHandler: () => Promise<unknown> = async () => {\n await this.validateEventSchemas();\n return this.userFnToRun(this.fnArg);\n };\n\n const runHandler = this.middlewareManager.wrapRunHandler(innerHandler);\n\n runAsPromise(runHandler)\n .then(async (data) => {\n await this.middlewareManager.onRunComplete(data);\n this.state.setCheckpoint({ type: \"function-resolved\", data });\n })\n .catch(async (error) => {\n // Preserve Error instances; stringify non-Error throws (e.g. `throw {}`)\n let err: Error;\n if (error instanceof Error) {\n err = error;\n } else if (typeof error === \"object\") {\n err = new Error(JSON.stringify(error));\n } else {\n err = new Error(String(error));\n }\n\n await this.middlewareManager.onRunError(err, this.isFinalAttempt(err));\n this.state.setCheckpoint({ type: \"function-rejected\", error: err });\n });\n }\n\n /**\n * Whether this error will not be retried (NonRetriableError or last attempt).\n */\n private isFinalAttempt(error: unknown): boolean {\n if (\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\"\n ) {\n return true;\n }\n\n return Boolean(\n this.fnArg.maxAttempts &&\n this.fnArg.maxAttempts - 1 === this.fnArg.attempt,\n );\n }\n\n /**\n * Build the OutgoingOp for a failed step, notifying middleware and choosing\n * retriable vs non-retriable opcode.\n */\n private async buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n }: {\n error: unknown;\n id: string;\n outgoingOp: OutgoingOp;\n stepInfo: Middleware.StepInfo;\n }): Promise<OutgoingOp> {\n const isFinal = this.isFinalAttempt(error);\n const metadata = this.state.metadata?.get(id);\n\n await this.middlewareManager.onStepError(\n stepInfo,\n error instanceof Error ? error : new Error(String(error)),\n isFinal,\n );\n\n return {\n ...outgoingOp,\n error,\n op: isFinal ? StepOpCode.StepFailed : StepOpCode.StepError,\n ...(metadata && metadata.length > 0 ? { metadata } : {}),\n };\n }\n\n /**\n * Validate event data against schemas defined in function triggers.\n */\n private async validateEventSchemas(): Promise<void> {\n const triggers = this.options.fn.opts.triggers;\n if (!triggers || triggers.length === 0) return;\n\n const fnArgEvents = this.fnArg.events;\n if (!fnArgEvents || fnArgEvents.length === 0) return;\n\n const events = fnArgEvents.map((event) => ({\n name: event.name,\n data: event.data,\n }));\n\n await validateEvents(events, triggers);\n }\n\n /**\n * Using middleware, transform output before returning.\n */\n private transformOutput(dataOrError: {\n data?: unknown;\n error?: unknown;\n }): ExecutionResult {\n const { data, error } = dataOrError;\n\n if (typeof error !== \"undefined\") {\n /**\n * Ensure we give middleware the chance to decide on retriable behaviour\n * by looking at the error returned from output transformation.\n */\n let retriable: boolean | string = !(\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\" ||\n (error instanceof StepError &&\n error === this.state.recentlyRejectedStepError)\n );\n if (\n retriable &&\n (error instanceof RetryAfterError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"RetryAfterError\")\n ) {\n retriable = (error as RetryAfterError).retryAfter;\n }\n\n const serializedError = serializeError(error);\n\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n ops: this.ops,\n error: serializedError,\n retriable,\n };\n }\n\n return {\n type: \"function-resolved\",\n ctx: this.fnArg,\n ops: this.ops,\n data: undefinedToNull(data),\n };\n }\n\n private createExecutionState(): ExecutionState {\n const d = createDeferredPromiseWithStack<Checkpoint>();\n let checkpointResolve = d.deferred.resolve;\n const checkpointResults = d.results;\n\n const loop: ExecutionState[\"loop\"] = (async function* (\n cleanUp?: () => void,\n ) {\n try {\n while (true) {\n const res = (await checkpointResults.next()).value;\n if (res) {\n yield res;\n }\n }\n } finally {\n cleanUp?.();\n }\n })(() => {\n this.timeout?.clear();\n this.checkpointingMaxRuntimeTimer?.clear();\n this.checkpointingMaxBufferIntervalTimer?.clear();\n void checkpointResults.return();\n });\n\n const stepsToFulfill = Object.keys(this.options.stepState).length;\n\n const state: ExecutionState = {\n stepState: this.options.stepState,\n stepsToFulfill,\n steps: new Map(),\n loop,\n hasSteps: Boolean(stepsToFulfill),\n stepCompletionOrder: [...this.options.stepCompletionOrder],\n remainingStepsToBeSeen: new Set(this.options.stepCompletionOrder),\n setCheckpoint: (checkpoint: Checkpoint) => {\n this.devDebug(\"setting checkpoint:\", checkpoint.type);\n\n ({ resolve: checkpointResolve } = checkpointResolve(checkpoint));\n },\n allStateUsed: () => {\n return this.state.remainingStepsToBeSeen.size === 0;\n },\n checkpointingStepBuffer: [],\n metadata: new Map(),\n };\n\n return state;\n }\n\n get ops(): Record<string, MemoizedOp> {\n return Object.fromEntries(this.state.steps);\n }\n\n private createFnArg(): Context.Any {\n const step = this.createStepTools();\n const experimentStepRun = (step as unknown as ExperimentStepTools)[\n experimentStepRunSymbol\n ];\n\n let fnArg = {\n ...(this.options.data as { event: EventPayload }),\n step,\n group: createGroupTools({ experimentStepRun }),\n } as Context.Any;\n\n /**\n * Handle use of the `onFailure` option by deserializing the error.\n */\n if (this.options.isFailureHandler) {\n const eventData = z\n .object({ error: jsonErrorSchema })\n .parse(fnArg.event?.data);\n\n (fnArg as Partial<Pick<FailureEventArgs, \"error\">>) = {\n ...fnArg,\n error: deserializeError(eventData.error),\n };\n }\n\n return this.options.transformCtx?.(fnArg) ?? fnArg;\n }\n\n /**\n * Apply mutations from `transformFunctionInput` back to execution state.\n * Allows middleware to modify event data, step tools, memoized step data,\n * and inject custom fields into the handler context.\n */\n private applyFunctionInputMutations(\n result: Middleware.TransformFunctionInputArgs,\n ): void {\n const { event, events, step, ...extensions } = result.ctx;\n\n // Mutate in place so the ALS store's reference to this.fnArg stays valid.\n if (event !== this.fnArg.event) {\n this.fnArg.event = event;\n }\n\n if (events !== this.fnArg.events) {\n this.fnArg.events = events;\n }\n\n if (step !== this.fnArg.step) {\n this.fnArg.step = step;\n }\n\n if (Object.keys(extensions).length > 0) {\n Object.assign(this.fnArg, extensions);\n }\n\n // Apply step data mutations\n for (const [hashedId, stepData] of Object.entries(result.steps)) {\n const existing = this.state.stepState[hashedId];\n if (\n existing &&\n stepData &&\n stepData.type === \"data\" &&\n stepData.data !== existing.data\n ) {\n this.state.stepState[hashedId] = { ...existing, data: stepData.data };\n }\n }\n }\n\n private createStepTools(): ReturnType<typeof createStepTools> {\n /**\n * A list of steps that have been found and are being rolled up before being\n * reported to the core loop.\n */\n const foundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the subset of found steps to report that have not yet been\n * handled. Used for fast access to steps that need to be handled in order.\n */\n const unhandledFoundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the latest sequential step indexes found for each step ID. Used\n * to ensure that we don't index steps in parallel.\n *\n * Note that these must be sequential; if we've seen or assigned `a:1`,\n * `a:2` and `a:4`, the latest sequential step index is `2`.\n *\n */\n const expectedNextStepIndexes: Map<string, number> = new Map();\n\n /**\n * An ordered list of step IDs that have yet to be handled in this\n * execution. Used to ensure that we handle steps in the order they were\n * found and based on the `stepCompletionOrder` in this execution's state.\n */\n const remainingStepCompletionOrder: string[] =\n this.state.stepCompletionOrder.slice();\n\n /**\n * A promise that's used to ensure that step reporting cannot be run more than\n * once in a given asynchronous time span.\n */\n let foundStepsReportPromise: Promise<void> | undefined;\n\n /**\n * A flag used to ensure that we only warn about parallel indexing once per\n * execution to avoid spamming the console.\n */\n let warnOfParallelIndexing = false;\n\n /**\n * Counts the number of times we've extended this tick.\n */\n let tickExtensionCount = 0;\n\n /**\n * Given a colliding step ID, maybe warn the user about parallel indexing.\n */\n const maybeWarnOfParallelIndexing = (userlandCollisionId: string) => {\n if (warnOfParallelIndexing) {\n return;\n }\n\n const hashedCollisionId = _internals.hashId(userlandCollisionId);\n\n const stepExists = this.state.steps.has(hashedCollisionId);\n if (stepExists) {\n const stepFoundThisTick = foundStepsToReport.has(hashedCollisionId);\n if (!stepFoundThisTick) {\n warnOfParallelIndexing = true;\n\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n {\n message: `Duplicate step ID \"${userlandCollisionId}\" detected across parallel chains`,\n explanation:\n \"Using the same ID for steps in different parallel chains can cause unexpected behaviour. Your function is still running.\",\n action:\n \"Use a unique ID for each step, especially those in parallel.\",\n code: ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n },\n );\n }\n }\n };\n\n /**\n * A helper used to report steps to the core loop. Used after adding an item\n * to `foundStepsToReport`.\n */\n const reportNextTick = () => {\n // Being explicit instead of using `??=` to appease TypeScript.\n if (foundStepsReportPromise) {\n return;\n }\n\n let extensionPromise: Promise<void>;\n if (++tickExtensionCount >= 10) {\n tickExtensionCount = 0;\n extensionPromise = resolveNextTick();\n } else {\n extensionPromise = resolveAfterPending();\n }\n\n foundStepsReportPromise = extensionPromise.then(() => {\n foundStepsReportPromise = undefined;\n\n for (let i = 0; i < remainingStepCompletionOrder.length; i++) {\n const nextStepId = remainingStepCompletionOrder[i];\n if (!nextStepId) {\n // Strange - skip this empty index\n continue;\n }\n\n const handled = unhandledFoundStepsToReport.get(nextStepId)?.handle();\n if (handled) {\n remainingStepCompletionOrder.splice(i, 1);\n unhandledFoundStepsToReport.delete(nextStepId);\n return void reportNextTick();\n }\n }\n\n // If we've handled no steps in this \"tick,\" roll up everything we've\n // found and report it.\n const steps = [...foundStepsToReport.values()];\n foundStepsToReport.clear();\n unhandledFoundStepsToReport.clear();\n\n if (!isNonEmpty(steps)) {\n return;\n }\n\n return void this.state.setCheckpoint({\n type: \"steps-found\",\n steps: steps,\n });\n });\n };\n\n /**\n * A helper used to push a step to the list of steps to report.\n */\n const pushStepToReport = (step: FoundStep) => {\n foundStepsToReport.set(step.hashedId, step);\n unhandledFoundStepsToReport.set(step.hashedId, step);\n reportNextTick();\n };\n\n const stepHandler: StepHandler = async ({\n args,\n matchOp,\n opts,\n }): Promise<unknown> => {\n const stepOptions = getStepOptions(args[0]);\n const opId = matchOp(stepOptions, ...args.slice(1));\n\n if (this.state.executingStep) {\n /**\n * If a step is found after asynchronous actions during another step's\n * execution, everything is fine. The problem here is if we've found\n * that a step nested inside another a step, which is something we don't\n * support at the time of writing.\n *\n * In this case, we could use something like Async Hooks to understand\n * how the step is being triggered, though this isn't available in all\n * environments.\n *\n * Therefore, we'll only show a warning here to indicate that this is\n * potentially an issue.\n */\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.NESTING_STEPS,\n {\n message: `Nested step tooling detected in \"${opId.displayName ?? opId.id}\"`,\n explanation:\n \"Nesting step.* calls is not supported. This warning may also appear if steps are separated by regular async calls, which is fine.\",\n action:\n \"Avoid using step.* inside other step.* calls. Use a separate async function or promise chaining to compose steps.\",\n code: ErrCode.NESTING_STEPS,\n },\n );\n }\n\n // Apply middleware transformations (may change step ID, affecting\n // memoization lookup)\n const {\n hashedId,\n isFulfilled,\n setActualHandler,\n stepInfo,\n stepState,\n wrappedHandler,\n } = await this.applyMiddlewareToStep(\n opId,\n expectedNextStepIndexes,\n maybeWarnOfParallelIndexing,\n );\n\n const { promise, resolve, reject } = createDeferredPromise();\n\n let extraOpts: Record<string, unknown> | undefined;\n let fnArgs = [...args];\n\n if (\n typeof stepState?.input !== \"undefined\" &&\n Array.isArray(stepState.input)\n ) {\n switch (opId.op) {\n // `step.run()` has its function input affected\n case StepOpCode.StepPlanned: {\n fnArgs = [...args.slice(0, 2), ...stepState.input];\n\n extraOpts = { input: [...stepState.input] };\n break;\n }\n\n // `step.ai.infer()` has its body affected\n case StepOpCode.AiGateway: {\n extraOpts = {\n body: {\n ...(typeof opId.opts?.body === \"object\"\n ? { ...opId.opts.body }\n : {}),\n ...stepState.input[0],\n },\n };\n break;\n }\n }\n }\n\n // If transformStepInput middleware may have changed the input, update\n // `fnArgs` so `fn` uses the transformed values. Skip if replay already\n // set `extraOpts`.\n if (!extraOpts && Array.isArray(stepInfo.input)) {\n fnArgs = [...args.slice(0, 2), ...stepInfo.input];\n }\n\n const step: FoundStep = {\n ...opId,\n opts: { ...opId.opts, ...extraOpts },\n rawArgs: fnArgs,\n hashedId,\n input: stepState?.input,\n\n fn: opts?.fn ? () => opts.fn?.(this.fnArg, ...fnArgs) : undefined,\n promise,\n fulfilled: isFulfilled,\n hasStepState: Boolean(stepState),\n displayName: opId.displayName ?? opId.id,\n handled: false,\n\n // Middleware context for deferred handler pattern\n middleware: {\n wrappedHandler,\n stepInfo,\n setActualHandler,\n },\n\n handle: () => {\n if (step.handled) {\n return false;\n }\n\n this.devDebug(`handling step \"${hashedId}\"`);\n\n step.handled = true;\n\n // Refetch step state because it may have been changed since we found\n // the step. This could be due to checkpointing, where we run this\n // live and then return to the function.\n const result = this.state.stepState[hashedId];\n\n if (step.fulfilled && result) {\n result.fulfilled = true;\n\n // For some execution scenarios such as testing, `data`, `error`,\n // and `input` may be `Promises`. This could also be the case for\n // future middleware applications. For this reason, we'll make sure\n // the values are fully resolved before continuing.\n void Promise.all([result.data, result.error, result.input]).then(\n async () => {\n // If the wrapStep chain already ran during discovery in this\n // same request (checkpointing), reuse its result instead of\n // firing wrappedHandler() again. This prevents middleware from\n // seeing a duplicate wrapStep call per step per request.\n if (step.transformedResultPromise) {\n // Resolve the memoization deferred so wrapStep's next()\n // unblocks. The step data is now confirmed memoized.\n if (step.memoizationDeferred) {\n if (typeof result.data !== \"undefined\") {\n step.memoizationDeferred.resolve(await result.data);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n step.memoizationDeferred.reject(stepError);\n }\n }\n\n step.transformedResultPromise.then(resolve, reject);\n return;\n }\n\n // The wrapStep chain is about to fire again to resolve the\n // step promise through middleware (e.g. deserialization).\n // Mark the step as memoized so middleware can distinguish\n // this from the original execution call.\n //\n // This need for this change was discovered when checkpointing +\n // middleware's \"double `wrapStep` call\" behavior had `memoized:\n // false` on the 2nd call\n step.middleware.stepInfo.memoized = true;\n\n if (typeof result.data !== \"undefined\") {\n // Validate waitForEvent results against the schema if present\n // Skip validation if result.data is null (timeout case)\n if (\n opId.op === StepOpCode.WaitForEvent &&\n result.data !== null\n ) {\n const { event } = (step.rawArgs?.[1] ?? {}) as {\n event: unknown;\n };\n if (!event) {\n // Unreachable\n throw new Error(\"Missing event option in waitForEvent\");\n }\n try {\n await validateEvents(\n [result.data],\n\n // @ts-expect-error - This is a full event object at runtime\n [{ event }],\n );\n } catch (err) {\n this.state.recentlyRejectedStepError = new StepError(\n opId.id,\n err,\n );\n reject(this.state.recentlyRejectedStepError);\n return;\n }\n }\n\n // Set inner handler to return memoized data\n step.middleware.setActualHandler(() =>\n Promise.resolve(result.data),\n );\n\n step.middleware.wrappedHandler().then(resolve);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n\n // Set inner handler to reject with step error\n step.middleware.setActualHandler(() =>\n Promise.reject(stepError),\n );\n\n step.middleware.wrappedHandler().catch(reject);\n }\n },\n );\n }\n\n return true;\n },\n };\n\n this.state.steps.set(hashedId, step);\n this.state.hasSteps = true;\n\n const isNewStepWithHandler = !isFulfilled && !stepState && step.fn;\n if (isNewStepWithHandler) {\n // New, never-seen step with a handler (e.g. `step.run`). Kick off the\n // middleware wrapStep chain now so it runs during discovery, not later\n // in executeStep.\n //\n // This is necessary so that middleware can inject their own steps.\n // Reporting is deferred to the center of the onion so that if\n // middleware throws or injects prerequisites, the step is never\n // reported.\n const deferred = createDeferredPromise<unknown>();\n step.memoizationDeferred = deferred;\n\n setActualHandler(() => {\n pushStepToReport(step);\n return deferred.promise;\n });\n\n step.transformedResultPromise = wrappedHandler();\n step.transformedResultPromise.catch((error) => {\n reject(error);\n });\n } else {\n pushStepToReport(step);\n }\n\n return promise;\n };\n\n return createStepTools(this.options.client, this, stepHandler);\n }\n\n /**\n * Applies middleware transformations to a step, resolves ID collisions,\n * and performs memoization lookup.\n */\n private async applyMiddlewareToStep(\n opId: HashedOp,\n expectedNextStepIndexes: Map<string, number>,\n maybeWarnOfParallelIndexing: (userlandCollisionId: string) => void,\n ): Promise<MiddlewareApplicationResult> {\n // 1. Resolve initial collision with original ID\n const initialCollision = resolveStepIdCollision({\n baseId: opId.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (initialCollision.finalId !== opId.id) {\n maybeWarnOfParallelIndexing(opId.id);\n opId.id = initialCollision.finalId;\n if (initialCollision.index !== undefined) {\n opId.userland.index = initialCollision.index;\n }\n }\n\n const originalId = opId.userland.id;\n let hashedId = _internals.hashId(opId.id);\n\n // 2. Apply middleware (stepType, input extraction, deferred handler).\n // Pass preliminary memoization status so middleware sees it.\n const prepared = await this.middlewareManager.applyToStep({\n displayName: opId.displayName ?? opId.userland.id,\n hashedId,\n memoized:\n Boolean(this.state.stepState[hashedId]) &&\n typeof this.state.stepState[hashedId]?.input === \"undefined\",\n op: opId.op,\n opts: opId.opts,\n userlandId: opId.userland.id,\n });\n const { entryPoint, opName, opOpts, setActualHandler, stepInfo } = prepared;\n\n if (opName !== undefined) {\n opId.name = opName;\n }\n if (opOpts !== undefined) {\n opId.opts = opOpts;\n }\n\n // 3. If middleware changed the step ID, re-resolve collisions\n if (stepInfo.options.id !== originalId) {\n opId.id = stepInfo.options.id;\n opId.userland.id = stepInfo.options.id;\n\n const secondCollision = resolveStepIdCollision({\n baseId: stepInfo.options.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (secondCollision.finalId !== stepInfo.options.id) {\n opId.id = secondCollision.finalId;\n opId.userland.id = secondCollision.finalId;\n stepInfo.options.id = secondCollision.finalId;\n if (secondCollision.index !== undefined) {\n opId.userland.index = secondCollision.index;\n }\n }\n\n // Recompute hashedId with final ID\n hashedId = _internals.hashId(opId.id);\n stepInfo.hashedId = hashedId;\n }\n\n // 4. Final memoization lookup with potentially modified hashedId.\n // Also marks step as seen and may trigger onMemoizationEnd.\n const stepState = this.state.stepState[hashedId];\n let isFulfilled = false;\n if (stepState) {\n stepState.seen = true;\n this.state.remainingStepsToBeSeen.delete(hashedId);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (typeof stepState.input === \"undefined\") {\n isFulfilled = true;\n }\n stepInfo.memoized = isFulfilled;\n } else {\n stepInfo.memoized = false;\n }\n\n // 5. Build wrapStep chain after all mutations so middleware sees final values\n const wrappedHandler = this.middlewareManager.buildWrapStepChain(\n entryPoint,\n stepInfo,\n );\n\n return {\n hashedId,\n stepInfo,\n wrappedHandler,\n setActualHandler,\n stepState,\n isFulfilled,\n };\n }\n\n private resumeStepWithResult(resultOp: OutgoingOp, resume = true): FoundStep {\n const userlandStep = this.state.steps.get(resultOp.id);\n if (!userlandStep) {\n throw new Error(\n \"Step not found in memoization state during async checkpointing; this should never happen and is a bug in the Inngest SDK\",\n );\n }\n\n const data = undefinedToNull(resultOp.data);\n\n userlandStep.data = data;\n userlandStep.timing = resultOp.timing;\n userlandStep.op = resultOp.op;\n userlandStep.id = resultOp.id;\n\n if (resume) {\n userlandStep.fulfilled = true;\n userlandStep.hasStepState = true;\n this.state.stepState[resultOp.id] = userlandStep;\n\n userlandStep.handle();\n }\n\n return userlandStep;\n }\n\n private getUserFnToRun(): Handler.Any {\n if (!this.options.isFailureHandler) {\n return this.options.fn[\"fn\"];\n }\n\n if (!this.options.fn[\"onFailureFn\"]) {\n /**\n * Somehow, we've ended up detecting that this is a failure handler but\n * doesn't have an `onFailure` function. This should never happen.\n */\n throw new Error(\"Cannot find function `onFailure` handler\");\n }\n\n return this.options.fn[\"onFailureFn\"];\n }\n\n private initializeTimer(state: ExecutionState): void {\n if (!this.options.requestedRunStep) {\n return;\n }\n\n this.timeout = createTimeoutPromise(this.timeoutDuration);\n\n void this.timeout.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n state.setCheckpoint({\n type: \"step-not-found\",\n step: {\n id: this.options.requestedRunStep as string,\n op: StepOpCode.StepNotFound,\n },\n foundSteps,\n totalFoundSteps,\n });\n });\n }\n\n private getStepNotFoundDetails(): {\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n } {\n const foundSteps = [...this.state.steps.values()]\n .filter((step) => !step.hasStepState)\n .map<BasicFoundStep>((step) => ({\n id: step.hashedId,\n name: step.name,\n displayName: step.displayName,\n }))\n .sort((a, b) => a.id.localeCompare(b.id));\n\n return {\n foundSteps: foundSteps.slice(0, STEP_NOT_FOUND_MAX_FOUND_STEPS),\n totalFoundSteps: foundSteps.length,\n };\n }\n\n private initializeCheckpointRuntimeTimer(state: ExecutionState): void {\n this.devDebug(\n \"initializing checkpointing runtime timers\",\n this.options.checkpointingConfig,\n );\n\n if (this.options.checkpointingConfig?.maxRuntime) {\n const maxRuntimeMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxRuntime,\n )\n ? this.options.checkpointingConfig.maxRuntime.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxRuntime === \"string\"\n ? ms(this.options.checkpointingConfig.maxRuntime as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxRuntime as number);\n\n // 0 or negative max runtime? Skip.\n if (Number.isFinite(maxRuntimeMs) && maxRuntimeMs > 0) {\n this.checkpointingMaxRuntimeTimer = createTimeoutPromise(maxRuntimeMs);\n\n void this.checkpointingMaxRuntimeTimer.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n state.setCheckpoint({\n type: \"checkpointing-runtime-reached\",\n });\n });\n }\n }\n\n if (this.options.checkpointingConfig?.maxInterval) {\n const maxIntervalMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxInterval,\n )\n ? this.options.checkpointingConfig.maxInterval.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxInterval === \"string\"\n ? ms(this.options.checkpointingConfig.maxInterval as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxInterval as number);\n\n // 0 or negative max interval? Skip.\n if (Number.isFinite(maxIntervalMs) && maxIntervalMs > 0) {\n this.checkpointingMaxBufferIntervalTimer =\n createTimeoutPromise(maxIntervalMs);\n\n void this.checkpointingMaxBufferIntervalTimer.then(async () => {\n // Note that this will not immediately run; it will be queued like all\n // other checkpoints so that we're never running multiple checkpoints\n // at the same time and it's easier to reason about those decision\n // points.\n //\n // A change in the future may be to make this particular checkpointing\n // action immediate and have the checkpoint action itself be\n // idempotent.\n state.setCheckpoint({\n type: \"checkpointing-buffer-interval-reached\",\n });\n\n this.checkpointingMaxBufferIntervalTimer?.reset();\n });\n }\n }\n }\n}\n\n/**\n * Types of checkpoints that can be reached during execution.\n */\nexport interface Checkpoints {\n \"steps-found\": { steps: [FoundStep, ...FoundStep[]] };\n \"function-rejected\": { error: unknown };\n \"function-resolved\": { data: unknown };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n \"checkpointing-runtime-reached\": {};\n \"checkpointing-buffer-interval-reached\": {};\n}\n\ntype Checkpoint = {\n [K in keyof Checkpoints]: Simplify<{ type: K } & Checkpoints[K]>;\n}[keyof Checkpoints];\n\ntype CheckpointHandlers = Record<\n StepMode,\n {\n [C in Checkpoint as C[\"type\"]]: (\n checkpoint: C,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n } & {\n \"\": (\n checkpoint: Checkpoint,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<void>;\n }\n>;\n\nexport interface ExecutionState {\n /**\n * A value that indicates that we're executing this step. Can be used to\n * ensure steps are not accidentally nested until we support this across all\n * platforms.\n */\n executingStep?: Readonly<Omit<OutgoingOp, \"id\">>;\n\n /**\n * A map of step IDs to their data, used to fill previously-completed steps\n * with state from the executor.\n */\n stepState: Record<string, MemoizedOp>;\n\n /**\n * The number of steps we expect to fulfil based on the state passed from the\n * Executor.\n */\n stepsToFulfill: number;\n\n /**\n * A map of step IDs to their functions to run. The executor can request a\n * specific step to run, so we need to store the function to run here.\n */\n steps: Map<string, FoundStep>;\n\n /**\n * A flag which represents whether or not steps are understood to be used in\n * this function. This is used to determine whether or not we should run\n * some steps (such as `step.sendEvent`) inline as they are found.\n */\n hasSteps: boolean;\n\n /**\n * The core loop - a generator used to take an action upon finding the next\n * checkpoint. Manages the flow of execution and cleaning up after itself.\n */\n loop: AsyncGenerator<Checkpoint, void, void>;\n\n /**\n * A function that resolves the `Promise` returned by `waitForNextDecision`.\n */\n setCheckpoint: (data: Checkpoint) => void;\n\n /**\n * Returns whether or not all state passed from the executor has been used to\n * fulfill found steps.\n */\n allStateUsed: () => boolean;\n\n /**\n * An ordered list of step IDs that represents the order in which their\n * execution was completed.\n */\n stepCompletionOrder: string[];\n\n /**\n * An set of step IDs that have yet to be seen in this execution. Used to\n * decide when to trigger middleware based on the current state.\n */\n remainingStepsToBeSeen: Set<string>;\n\n /**\n * If defined, this is the error that purposefully thrown when memoizing step\n * state in order to support per-step errors.\n *\n * We use this so that if the function itself rejects with the same error, we\n * know that it was entirely uncaught (or at the very least rethrown), so we\n * should send a `NonRetriableError` to stop needless execution of a function\n * that will continue to fail.\n *\n * TODO This is imperfect, as this state is currently kept around for longer\n * than it needs to be. It should disappear as soon as we've seen that the\n * error did not immediately throw. It may need to be refactored to work a\n * little more smoothly with the core loop.\n */\n recentlyRejectedStepError?: StepError;\n\n /**\n * If defined, this indicates that we're running a checkpointed function run,\n * and contains the data needed to report progress back to Inngest.\n */\n checkpointedRun?: {\n fnId: string;\n appId: string;\n token?: string;\n };\n\n /**\n * A buffer of steps that are currently queued to be checkpointed.\n */\n checkpointingStepBuffer: OutgoingOp[];\n\n /**\n * Metadata collected during execution to be sent with outgoing ops.\n */\n metadata?: Map<string, Array<MetadataUpdate>>;\n}\n\nconst hashId = (id: string): string => {\n return sha1().update(id).digest(\"hex\");\n};\n\nconst hashOp = (op: OutgoingOp): OutgoingOp => {\n return {\n ...op,\n id: hashId(op.id),\n };\n};\n\n/**\n * Result of resolving a step ID collision.\n */\ninterface CollisionResolutionResult {\n /** The final ID to use (either original or with index suffix). */\n finalId: string;\n\n /** The index used, if collision was detected. */\n index?: number;\n}\n\n/** Result of applying middleware to a step. */\ninterface MiddlewareApplicationResult {\n hashedId: string;\n isFulfilled: boolean;\n setActualHandler: (handler: () => Promise<unknown>) => void;\n stepInfo: Middleware.StepInfo;\n stepState: MemoizedOp | undefined;\n wrappedHandler: () => Promise<unknown>;\n}\n\n/**\n * Resolves step ID collisions by appending an index suffix if needed.\n * Consolidates the duplicated collision detection logic.\n *\n * @param baseId - The original step ID\n * @param stepsMap - Map of existing steps (keyed by hashed ID)\n * @param expectedIndexes - Map tracking expected next index for each base ID\n * @returns The final ID to use and optional index\n */\nfunction resolveStepIdCollision({\n baseId,\n expectedIndexes,\n stepsMap,\n}: {\n baseId: string;\n expectedIndexes: Map<string, number>;\n stepsMap: Map<string, FoundStep>;\n}): CollisionResolutionResult {\n const hashedBaseId = hashId(baseId);\n\n // Check both stepsMap (steps added to state) and expectedIndexes (claimed by\n // concurrent in-progress step handlers that haven't been added to state yet).\n if (!stepsMap.has(hashedBaseId) && !expectedIndexes.has(baseId)) {\n // No collision. Claim this base ID so concurrent callers detect collision.\n expectedIndexes.set(baseId, 1);\n return { finalId: baseId };\n }\n\n // Collision detected. Find next available index\n const expectedNextIndex = expectedIndexes.get(baseId) ?? 1;\n const maxIndex = expectedNextIndex + stepsMap.size + 1;\n for (let i = expectedNextIndex; i < maxIndex; i++) {\n const indexedId = baseId + STEP_INDEXING_SUFFIX + i;\n const hashedIndexedId = hashId(indexedId);\n\n if (!stepsMap.has(hashedIndexedId)) {\n expectedIndexes.set(baseId, i + 1);\n return { finalId: indexedId, index: i };\n }\n }\n\n throw new UnreachableError(\n `Could not resolve step ID collision for \"${baseId}\" after ${stepsMap.size + 1} attempts`,\n );\n}\n\nfunction isNonEmpty<T>(arr: T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Exported for testing.\n */\nexport const _internals = { hashOp, hashId, resolveStepIdCollision };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAM,EAAE,SAASA;;;;;;;;;AAUjB,MAAM,2BAA2B;CAAE,aAAa;CAAG,WAAW;CAAK;AACnE,MAAM,iCAAiC;AAEvC,MAAaC,yBAAkD,YAAY;AACzE,QAAO,IAAI,uBAAuB,QAAQ;;AAG5C,IAAM,yBAAN,cACUC,0CAEV;CACE,AAAO,UAAUC,gCAAiB;CAElC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB,MAAO;CACjC,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;CASR,AAAQ;CACR,AAAQ;;;;;;;CAQR,AAAQ;;;;;;CASR,AAAQ;CAIR,YAAY,YAAqC;EAC/C,MAAMC,UAAmC;GACvC,GAAG;GACH,UAAU,WAAW,YAAYC,uBAAS;GAC3C;AAED,QAAM,QAAQ;;;;AAKd,MAAI,KAAK,QAAQ,aAAaA,uBAAS,MACrC;OAAI,CAAC,KAAK,QAAQ,eAChB,OAAM,IAAI,MAAM,gDAAgD;;AAIpE,OAAK,cAAc,KAAK,gBAAgB;AACxC,OAAK,QAAQ,KAAK,sBAAsB;AACxC,OAAK,QAAQ,KAAK,aAAa;EAG/B,MAAM,cACJ,KAAK,QAAQ,wBACZ,KAAK,QAAQ,OAAO,cAAc,EAAE,EAAE,KAAK,QAAQ;AAClD,UAAO,IAAI,IAAI,EAAE,QAAQ,KAAK,QAAQ,QAAQ,CAAC;IAC/C;AACJ,OAAK,oBAAoB,IAAIC,kCAC3B,KAAK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,YAAY;AAS7D,WAAM,cAAc,EAClB,MAAM,yCACP,CAAC;AAEF,UAAK,qCAAqC,OAAO;MACjD;;;;;AA0JV,MAAM,UAAU,OAAuB;AACrC,QAAO,MAAM,CAAC,OAAO,GAAG,CAAC,OAAO,MAAM;;AAGxC,MAAM,UAAU,OAA+B;AAC7C,QAAO;EACL,GAAG;EACH,IAAI,OAAO,GAAG,GAAG;EAClB;;;;;;;;;;;AAiCH,SAAS,uBAAuB,EAC9B,QACA,iBACA,YAK4B;CAC5B,MAAM,eAAe,OAAO,OAAO;AAInC,KAAI,CAAC,SAAS,IAAI,aAAa,IAAI,CAAC,gBAAgB,IAAI,OAAO,EAAE;AAE/D,kBAAgB,IAAI,QAAQ,EAAE;AAC9B,SAAO,EAAE,SAAS,QAAQ;;CAI5B,MAAM,oBAAoB,gBAAgB,IAAI,OAAO,IAAI;CACzD,MAAM,WAAW,oBAAoB,SAAS,OAAO;AACrD,MAAK,IAAI,IAAI,mBAAmB,IAAI,UAAU,KAAK;EACjD,MAAM,YAAY,SAASC,gDAAuB;EAClD,MAAM,kBAAkB,OAAO,UAAU;AAEzC,MAAI,CAAC,SAAS,IAAI,gBAAgB,EAAE;AAClC,mBAAgB,IAAI,QAAQ,IAAI,EAAE;AAClC,UAAO;IAAE,SAAS;IAAW,OAAO;IAAG;;;AAI3C,OAAM,IAAIrC,+BACR,4CAA4C,OAAO,UAAU,SAAS,OAAO,EAAE,WAChF;;AAGH,SAAS,WAAc,KAA8B;AACnD,QAAO,IAAI,SAAS;;;;;AAMtB,MAAa,aAAa;CAAE;CAAQ;CAAQ;CAAwB"}
1
+ {"version":3,"file":"engine.cjs","names":["hashjs","createExecutionEngine: InngestExecutionFactory","InngestExecution","ExecutionVersion","options: InngestExecutionOptions","StepMode","MiddlewareManager","internalLoggerSymbol","trace","version","getAsyncLocalStorage","headerKeys","retryWithBackoff","defaultMaxRetries","commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"]","StepOpCode","serializeError","syncHandlers: CheckpointHandlers[StepMode.Sync]","asyncHandlers: CheckpointHandlers[StepMode.Async]","asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing]","step","UnreachableError","outgoingOp: OutgoingOp","getAsyncCtx","interval: GoInterval | undefined","runAsPromise","createDeferredPromise","goIntervalTiming","innerHandler: () => Promise<unknown>","err: Error","NonRetriableError","validateEvents","retriable: boolean | string","StepError","RetryAfterError","undefinedToNull","createDeferredPromiseWithStack","loop: ExecutionState[\"loop\"]","experimentStepRunSymbol","createGroupTools","z","jsonErrorSchema","deserializeError","foundStepsToReport: Map<string, FoundStep>","unhandledFoundStepsToReport: Map<string, FoundStep>","expectedNextStepIndexes: Map<string, number>","remainingStepCompletionOrder: string[]","foundStepsReportPromise: Promise<void> | undefined","ErrCode","extensionPromise: Promise<void>","resolveNextTick","resolveAfterPending","stepHandler: StepHandler","getStepOptions","extraOpts: Record<string, unknown> | undefined","step: FoundStep","createStepTools","createTimeoutPromise","STEP_INDEXING_SUFFIX"],"sources":["../../../src/components/execution/engine.ts"],"sourcesContent":["import { trace } from \"@opentelemetry/api\";\nimport hashjs from \"hash.js\";\nimport ms, { type StringValue } from \"ms\";\nimport { z } from \"zod/v3\";\n\nimport {\n defaultMaxRetries,\n ExecutionVersion,\n headerKeys,\n internalEvents,\n} from \"../../helpers/consts.ts\";\n\nimport {\n deserializeError,\n ErrCode,\n serializeError,\n} from \"../../helpers/errors.js\";\nimport { undefinedToNull } from \"../../helpers/functions.js\";\nimport {\n createDeferredPromise,\n createDeferredPromiseWithStack,\n createTimeoutPromise,\n type GoInterval,\n goIntervalTiming,\n resolveAfterPending,\n resolveNextTick,\n retryWithBackoff,\n runAsPromise,\n} from \"../../helpers/promises.ts\";\nimport * as Temporal from \"../../helpers/temporal.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport {\n type APIStepPayload,\n type Context,\n type EventPayload,\n type FailureEventArgs,\n type Handler,\n type HashedOp,\n jsonErrorSchema,\n type OutgoingOp,\n StepMode,\n StepOpCode,\n} from \"../../types.ts\";\nimport { version } from \"../../version.ts\";\nimport { internalLoggerSymbol } from \"../Inngest.ts\";\nimport { createGroupTools } from \"../InngestGroupTools.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n MetadataUpdate,\n} from \"../InngestMetadata.ts\";\nimport {\n createStepTools,\n type ExperimentStepTools,\n experimentStepRunSymbol,\n type FoundStep,\n getStepOptions,\n STEP_INDEXING_SUFFIX,\n type StepHandler,\n} from \"../InngestStepTools.ts\";\nimport { MiddlewareManager } from \"../middleware/index.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\nimport { UnreachableError } from \"../middleware/utils.ts\";\nimport { NonRetriableError } from \"../NonRetriableError.ts\";\nimport { RetryAfterError } from \"../RetryAfterError.ts\";\nimport { StepError } from \"../StepError.ts\";\nimport { validateEvents } from \"../triggers/utils.js\";\nimport { getAsyncCtx, getAsyncLocalStorage } from \"./als.ts\";\nimport {\n type BasicFoundStep,\n type ExecutionResult,\n type IInngestExecution,\n InngestExecution,\n type InngestExecutionFactory,\n type InngestExecutionOptions,\n type MemoizedOp,\n} from \"./InngestExecution.ts\";\nimport { clientProcessorMap } from \"./otel/access.ts\";\n\nconst { sha1 } = hashjs;\n\n/**\n * Retry configuration for checkpoint operations.\n *\n * Checkpoint calls use exponential backoff with jitter to handle transient\n * network failures (e.g., dev server temporarily down, cloud hiccup). If\n * retries exhaust, the error propagates up - for Sync mode this results in a\n * 500 error, for AsyncCheckpointing the caller handles fallback.\n */\nconst CHECKPOINT_RETRY_OPTIONS = { maxAttempts: 5, baseDelay: 100 };\nconst STEP_NOT_FOUND_MAX_FOUND_STEPS = 25;\n\nexport const createExecutionEngine: InngestExecutionFactory = (options) => {\n return new InngestExecutionEngine(options);\n};\n\nclass InngestExecutionEngine\n extends InngestExecution\n implements IInngestExecution\n{\n public version = ExecutionVersion.V2;\n\n private state: ExecutionState;\n private fnArg: Context.Any;\n private checkpointHandlers: CheckpointHandlers;\n private timeoutDuration = 1000 * 10;\n private execution: Promise<ExecutionResult> | undefined;\n private userFnToRun: Handler.Any;\n private middlewareManager: MiddlewareManager;\n\n /**\n * If we're supposed to run a particular step via `requestedRunStep`, this\n * will be a `Promise` that resolves after no steps have been found for\n * `timeoutDuration` milliseconds.\n *\n * If we're not supposed to run a particular step, this will be `undefined`.\n */\n private timeout?: ReturnType<typeof createTimeoutPromise>;\n private rootSpanId?: string;\n\n /**\n * If we're checkpointing and have been given a maximum runtime, this will be\n * a `Promise` that resolves after that duration has elapsed, allowing us to\n * ensure that we end the execution in good time, especially in serverless\n * environments.\n */\n private checkpointingMaxRuntimeTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n /**\n * If we're checkpointing and have been given a maximum buffer interval, this\n * will be a `Promise` that resolves after that duration has elapsed, allowing\n * us to periodically checkpoint even if the step buffer hasn't filled.\n */\n private checkpointingMaxBufferIntervalTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n constructor(rawOptions: InngestExecutionOptions) {\n const options: InngestExecutionOptions = {\n ...rawOptions,\n stepMode: rawOptions.stepMode ?? StepMode.Async,\n };\n\n super(options);\n\n /**\n * Check we have everything we need for checkpointing\n */\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.options.createResponse) {\n throw new Error(\"createResponse is required for sync step mode\");\n }\n }\n\n this.userFnToRun = this.getUserFnToRun();\n this.state = this.createExecutionState();\n this.fnArg = this.createFnArg();\n\n // Setup middleware\n const mwInstances =\n this.options.middlewareInstances ??\n (this.options.client.middleware || []).map((Cls) => {\n return new Cls({ client: this.options.client });\n });\n this.middlewareManager = new MiddlewareManager(\n this.fnArg,\n () => this.state.stepState,\n mwInstances,\n this.options.fn,\n this.options.client[internalLoggerSymbol],\n );\n\n this.checkpointHandlers = this.createCheckpointHandlers();\n this.initializeTimer(this.state);\n this.initializeCheckpointRuntimeTimer(this.state);\n\n this.devDebug(\n \"created new V1 execution for run;\",\n this.options.requestedRunStep\n ? `wanting to run step \"${this.options.requestedRunStep}\"`\n : \"discovering steps\",\n );\n\n this.devDebug(\"existing state keys:\", Object.keys(this.state.stepState));\n }\n\n /**\n * Idempotently start the execution of the user's function.\n */\n public start() {\n if (!this.execution) {\n this.devDebug(\"starting V1 execution\");\n\n const tracer = trace.getTracer(\"inngest\", version);\n\n this.execution = getAsyncLocalStorage().then((als) => {\n return als.run(\n {\n app: this.options.client,\n execution: {\n ctx: this.fnArg,\n instance: this,\n },\n },\n async () => {\n return tracer.startActiveSpan(\"inngest.execution\", (span) => {\n this.rootSpanId = span.spanContext().spanId;\n clientProcessorMap.get(this.options.client)?.declareStartingSpan({\n span,\n runId: this.options.runId,\n traceparent: this.options.headers[headerKeys.TraceParent],\n tracestate: this.options.headers[headerKeys.TraceState],\n });\n\n return this._start()\n .then((result) => {\n this.devDebug(\"result:\", result);\n return result;\n })\n .finally(() => {\n span.end();\n });\n });\n },\n );\n });\n }\n\n return this.execution;\n }\n\n public addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ) {\n if (!this.state.metadata) {\n this.state.metadata = new Map();\n }\n\n const updates = this.state.metadata.get(stepId) ?? [];\n updates.push({ kind, scope, op, values });\n this.state.metadata.set(stepId, updates);\n\n return true;\n }\n\n /**\n * Starts execution of the user's function and the core loop.\n */\n private async _start(): Promise<ExecutionResult> {\n try {\n const allCheckpointHandler = this.getCheckpointHandler(\"\");\n await this.startExecution();\n\n let i = 0;\n\n for await (const checkpoint of this.state.loop) {\n await allCheckpointHandler(checkpoint, i);\n\n const handler = this.getCheckpointHandler(checkpoint.type);\n const result = await handler(checkpoint, i++);\n\n if (result) {\n return result;\n }\n }\n } catch (error) {\n return this.transformOutput({ error });\n } finally {\n void this.state.loop.return();\n }\n\n /**\n * If we're here, the generator somehow finished without returning a value.\n * This should never happen.\n */\n throw new Error(\"Core loop finished without returning a value\");\n }\n\n private async checkpoint(steps: OutgoingOp[]): Promise<void> {\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.state.checkpointedRun) {\n // We have to start the run\n const res = await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointNewRun({\n runId: this.fnArg.runId,\n event: this.fnArg.event as APIStepPayload,\n steps,\n executionVersion: this.version,\n retries: this.fnArg.maxAttempts ?? defaultMaxRetries,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n\n this.state.checkpointedRun = {\n appId: res.data.app_id,\n fnId: res.data.fn_id,\n token: res.data.token,\n };\n } else {\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointSteps({\n appId: this.state.checkpointedRun!.appId,\n fnId: this.state.checkpointedRun!.fnId,\n runId: this.fnArg.runId,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n }\n } else if (this.options.stepMode === StepMode.AsyncCheckpointing) {\n if (!this.options.queueItemId) {\n throw new Error(\n \"Missing queueItemId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n if (!this.options.internalFnId) {\n throw new Error(\n \"Missing internalFnId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointStepsAsync({\n runId: this.fnArg.runId,\n fnId: this.options.internalFnId!,\n queueItemId: this.options.queueItemId!,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n } else {\n throw new Error(\n \"Checkpointing is only supported in Sync and AsyncCheckpointing step modes. This is a bug in the Inngest SDK.\",\n );\n }\n }\n\n private async checkpointAndSwitchToAsync(\n steps: OutgoingOp[],\n ): Promise<ExecutionResult> {\n await this.checkpoint(steps);\n\n if (!this.state.checkpointedRun?.token) {\n throw new Error(\"Failed to checkpoint and switch to async mode\");\n }\n\n return {\n type: \"change-mode\",\n ctx: this.fnArg,\n ops: this.ops,\n to: StepMode.Async,\n token: this.state.checkpointedRun?.token!,\n };\n }\n\n /**\n * Returns whether we're in the final attempt of execution, or `null` if we\n * can't determine this in the SDK.\n */\n private inFinalAttempt(): boolean | null {\n if (typeof this.fnArg.maxAttempts !== \"number\") {\n return null;\n }\n\n return this.fnArg.attempt + 1 >= this.fnArg.maxAttempts;\n }\n\n /**\n * Creates a handler for every checkpoint type, defining what to do when we\n * reach that checkpoint in the core loop.\n */\n private createCheckpointHandlers(): CheckpointHandlers {\n const commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"] = (\n checkpoint,\n ) => {\n this.devDebug(`${this.options.stepMode} checkpoint:`, checkpoint);\n };\n\n const stepRanHandler = async (\n stepResult: OutgoingOp,\n ): Promise<ExecutionResult> => {\n const transformResult = await this.transformOutput(stepResult);\n\n /**\n * Transforming output will always return either function rejection or\n * resolution. In most cases, this can be immediately returned, but in\n * this particular case we want to handle it differently.\n */\n if (transformResult.type === \"function-resolved\") {\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n step: {\n ...stepResult,\n data: transformResult.data,\n },\n };\n } else if (transformResult.type === \"function-rejected\") {\n const stepForResponse = {\n ...stepResult,\n error: transformResult.error,\n };\n\n if (stepResult.op === StepOpCode.StepFailed) {\n const ser = serializeError(transformResult.error);\n stepForResponse.data = {\n __serialized: true,\n name: ser.name,\n message: ser.message,\n stack: \"\",\n };\n }\n\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n retriable: transformResult.retriable,\n step: stepForResponse,\n };\n }\n\n return transformResult;\n };\n\n const maybeReturnNewSteps = async (): Promise<\n ExecutionResult | undefined\n > => {\n const newSteps = await this.filterNewSteps(\n Array.from(this.state.steps.values()),\n );\n if (newSteps) {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: newSteps,\n };\n }\n\n return;\n };\n\n const attemptCheckpointAndResume = async (\n stepResult?: OutgoingOp,\n resume = true,\n force = false,\n ): Promise<ExecutionResult | undefined> => {\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n if (stepResult) {\n const stepToResume = this.resumeStepWithResult(stepResult, resume);\n\n // Clear `executingStep` immediately after resuming, before any await.\n // `resumeStepWithResult` resolves the step's promise, queuing a\n // microtask for the function to continue. Any subsequent await (e.g.\n // the `transformOutput` hook) yields and lets that microtask run, so\n // `executingStep` must already be cleared to avoid a false positive\n // NESTING_STEPS warning in the next step's handler.\n delete this.state.executingStep;\n\n // Buffer a copy with transformed data for checkpointing\n this.state.checkpointingStepBuffer.push({\n ...stepToResume,\n data: stepResult.data,\n });\n }\n\n if (\n force ||\n !this.options.checkpointingConfig?.bufferedSteps ||\n this.state.checkpointingStepBuffer.length >=\n this.options.checkpointingConfig.bufferedSteps\n ) {\n this.devDebug(\"checkpointing and resuming execution after step run\");\n\n try {\n this.devDebug(\n `checkpointing all buffered steps:`,\n this.state.checkpointingStepBuffer\n .map((op) => op.displayName || op.id)\n .join(\", \"),\n );\n\n return void (await this.checkpoint(\n this.state.checkpointingStepBuffer,\n ));\n } catch (err) {\n // If checkpointing fails for any reason, fall back to returning\n // ALL buffered steps to the executor via the normal async flow.\n // The executor persists completed steps and rediscovers any\n // parallel/errored steps on the next invocation.\n this.devDebug(\n \"error checkpointing after step run, so falling back to async\",\n err,\n );\n\n const buffered = this.state.checkpointingStepBuffer;\n\n if (buffered.length) {\n return {\n type: \"steps-found\" as const,\n ctx: this.fnArg,\n ops: this.ops,\n steps: buffered as [OutgoingOp, ...OutgoingOp[]],\n };\n }\n\n return;\n } finally {\n // Clear the checkpointing buffer\n this.state.checkpointingStepBuffer = [];\n }\n } else {\n this.devDebug(\n `not checkpointing yet, continuing execution as we haven't reached buffered step limit of ${this.options.checkpointingConfig?.bufferedSteps}`,\n );\n }\n\n return;\n };\n\n const syncHandlers: CheckpointHandlers[StepMode.Sync] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n \"function-resolved\": async (checkpoint, i) => {\n const transformedData = checkpoint.data;\n\n await this.checkpoint([\n {\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: await this.options.createResponse!(transformedData),\n },\n ]);\n\n // Apply middleware transformation before returning\n return await this.transformOutput({ data: checkpoint.data });\n },\n\n \"function-rejected\": async (checkpoint) => {\n // If the function throws during sync execution, we want to switch to\n // async mode so that we can retry. The exception is that we're already\n // at max attempts, in which case we do actually want to reject.\n if (this.inFinalAttempt()) {\n // Apply middleware transformation before returning\n return await this.transformOutput({ error: checkpoint.error });\n }\n\n // Otherwise, checkpoint the error and switch to async mode\n return this.checkpointAndSwitchToAsync([\n {\n id: _internals.hashId(\"complete\"), // ID is not important here\n op: StepOpCode.StepError,\n error: checkpoint.error,\n },\n ]);\n },\n\n \"step-not-found\": () => {\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n error: new Error(\n \"Step not found when checkpointing; this should never happen\",\n ),\n ops: this.ops,\n retriable: false,\n };\n },\n\n \"steps-found\": async ({ steps }) => {\n // If we're entering parallelism or async mode, checkpoint and switch\n // to async.\n if (steps.length !== 1 || steps[0].mode !== StepMode.Sync) {\n return this.checkpointAndSwitchToAsync(\n steps.map((step) => ({ ...step, id: step.hashedId })),\n );\n }\n\n // Otherwise we're good to start executing things right now.\n const result = await this.executeStep(steps[0]);\n\n if (result.error) {\n return this.checkpointAndSwitchToAsync([result]);\n }\n\n // Resume the step with original data for user code\n const stepToResume = this.resumeStepWithResult(result);\n\n // Clear executingStep now that the step result has been processed.\n // Without this, the next step discovery would see stale state and\n // emit a false positive NESTING_STEPS warning.\n delete this.state.executingStep;\n\n return void (await this.checkpoint([stepToResume]));\n },\n\n \"checkpointing-runtime-reached\": () => {\n return this.checkpointAndSwitchToAsync([\n {\n op: StepOpCode.DiscoveryRequest,\n\n // Append with time because we don't want Executor-side\n // idempotency to dedupe. There may have been a previous\n // discovery request.\n id: _internals.hashId(`discovery-request-${Date.now()}`),\n },\n ]);\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n const asyncHandlers: CheckpointHandlers[StepMode.Async] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n /**\n * The user's function has completed and returned a value.\n */\n \"function-resolved\": async ({ data }) => {\n // Check for unreported new steps (e.g. from `Promise.race` where\n // the winning branch completed before losing branches reported)\n const newStepsResult = await maybeReturnNewSteps();\n if (newStepsResult) {\n return newStepsResult;\n }\n\n // We need to do this even here for async, as we could be returning\n // data from an API endpoint, even if we were triggered async.\n if (this.options.createResponse) {\n data = await this.options.createResponse(data);\n }\n\n return await this.transformOutput({ data });\n },\n\n /**\n * The user's function has thrown an error.\n */\n \"function-rejected\": async (checkpoint) => {\n return await this.transformOutput({ error: checkpoint.error });\n },\n\n /**\n * We've found one or more steps. Here we may want to run a step or report\n * them back to Inngest.\n */\n \"steps-found\": async ({ steps }) => {\n const stepResult = await this.tryExecuteStep(steps);\n if (stepResult) {\n return stepRanHandler(stepResult);\n }\n\n return maybeReturnNewSteps();\n },\n\n /**\n * While trying to find a step that Inngest has told us to run, we've\n * timed out or have otherwise decided that it doesn't exist.\n */\n \"step-not-found\": ({ step }) => {\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n return {\n type: \"step-not-found\",\n ctx: this.fnArg,\n ops: this.ops,\n step,\n foundSteps,\n totalFoundSteps,\n };\n },\n\n \"checkpointing-runtime-reached\": () => {\n throw new Error(\n \"Checkpointing maximum runtime reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n throw new Error(\n \"Checkpointing maximum buffer interval reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n };\n\n const asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing] =\n {\n \"\": commonCheckpointHandler,\n \"function-resolved\": async (checkpoint, i) => {\n const output = await asyncHandlers[\"function-resolved\"](\n checkpoint,\n i,\n );\n if (output?.type === \"function-resolved\") {\n const steps = this.state.checkpointingStepBuffer.concat({\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: output.data,\n });\n\n if (isNonEmpty(steps)) {\n return {\n type: \"steps-found\",\n ctx: output.ctx,\n ops: output.ops,\n steps,\n };\n }\n }\n\n return;\n },\n \"function-rejected\": async (checkpoint) => {\n // If we have buffered steps, attempt checkpointing them first\n if (this.state.checkpointingStepBuffer.length) {\n const fallback = await attemptCheckpointAndResume(\n undefined,\n false,\n true,\n );\n if (fallback) {\n return fallback;\n }\n }\n\n return await this.transformOutput({ error: checkpoint.error });\n },\n \"step-not-found\": asyncHandlers[\"step-not-found\"],\n \"steps-found\": async ({ steps }) => {\n // Note that if we have a requested run step, we'll never be\n // checkpointing, as that's an async parallel execution mode.\n\n // Break found steps in to { stepsToResume, newSteps }\n const { stepsToResume, newSteps } = steps.reduce(\n (acc, step) => {\n if (!step.hasStepState) {\n acc.newSteps.push(step);\n } else if (!step.fulfilled) {\n acc.stepsToResume.push(step);\n }\n\n return acc;\n },\n { stepsToResume: [], newSteps: [] } as {\n stepsToResume: FoundStep[];\n newSteps: FoundStep[];\n },\n );\n\n this.devDebug(\"split found steps in to:\", {\n stepsToResume: stepsToResume.length,\n newSteps: newSteps.length,\n });\n\n // Got new steps? Exit early.\n if (!this.options.requestedRunStep && newSteps.length) {\n const stepResult = await this.tryExecuteStep(newSteps);\n if (stepResult) {\n this.devDebug(`executed step \"${stepResult.id}\" successfully`);\n\n // We executed a step!\n //\n // We know that because we're in this mode, we're always free to\n // checkpoint and continue if we ran a step and it was successful.\n if (stepResult.error) {\n // Flush buffered steps before falling back to async,\n // so previously-successful steps aren't lost.\n if (this.state.checkpointingStepBuffer.length) {\n const fallback = await attemptCheckpointAndResume(\n undefined,\n false,\n true,\n );\n if (fallback) {\n return fallback;\n }\n }\n\n // If we failed, go back to the regular async flow.\n return stepRanHandler(stepResult);\n }\n\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n return await attemptCheckpointAndResume(stepResult);\n }\n\n // Flush any buffered checkpoint steps before returning\n // new steps to the executor. Without this, steps executed\n // in-process during AsyncCheckpointing but not yet\n // checkpointed would be lost. When the executor later calls\n // back with requestedRunStep, those steps would be missing\n // from stepState, causing \"step not found\" errors.\n if (this.state.checkpointingStepBuffer.length) {\n const fallback = await attemptCheckpointAndResume(\n undefined,\n false,\n true,\n );\n if (fallback) {\n return fallback;\n }\n }\n\n return maybeReturnNewSteps();\n }\n\n // If we have stepsToResume, resume as many as possible and resume execution\n if (stepsToResume.length) {\n this.devDebug(`resuming ${stepsToResume.length} steps`);\n\n for (const st of stepsToResume) {\n this.resumeStepWithResult({\n ...st,\n id: st.hashedId,\n });\n }\n }\n\n return;\n },\n \"checkpointing-runtime-reached\": async () => {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: [\n {\n op: StepOpCode.DiscoveryRequest,\n\n // Append with time because we don't want Executor-side\n // idempotency to dedupe. There may have been a previous\n // discovery request.\n id: _internals.hashId(`discovery-request-${Date.now()}`),\n },\n ],\n };\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n return {\n [StepMode.Async]: asyncHandlers,\n [StepMode.Sync]: syncHandlers,\n [StepMode.AsyncCheckpointing]: asyncCheckpointingHandlers,\n };\n }\n\n private getCheckpointHandler(type: keyof CheckpointHandlers[StepMode]) {\n return this.checkpointHandlers[this.options.stepMode][type] as (\n checkpoint: Checkpoint,\n iteration: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n }\n\n private async tryExecuteStep(\n steps: FoundStep[],\n ): Promise<OutgoingOp | undefined> {\n const hashedStepIdToRun =\n this.options.requestedRunStep || this.getEarlyExecRunStep(steps);\n if (!hashedStepIdToRun) {\n return;\n }\n\n const step = steps.find(\n (step) => step.hashedId === hashedStepIdToRun && step.fn,\n );\n\n if (step) {\n return await this.executeStep(step);\n }\n\n /**\n * Ensure we reset the timeout if we have a requested run step but couldn't\n * find it, but also that we don't reset if we found and executed it.\n */\n return void this.timeout?.reset();\n }\n\n /**\n * Given a list of outgoing ops, decide if we can execute an op early and\n * return the ID of the step to execute if we can.\n */\n private getEarlyExecRunStep(steps: FoundStep[]): string | undefined {\n /**\n * We may have been disabled due to parallelism, in which case we can't\n * immediately execute unless explicitly requested.\n */\n if (this.options.disableImmediateExecution) return;\n\n const unfulfilledSteps = steps.filter((step) => !step.fulfilled);\n if (unfulfilledSteps.length !== 1) return;\n\n const op = unfulfilledSteps[0];\n\n if (\n op &&\n op.op === StepOpCode.StepPlanned\n // TODO We must individually check properties here that we do not want to\n // execute on, such as retry counts. Nothing exists here that falls in to\n // this case, but should be accounted for when we add them.\n // && typeof op.opts === \"undefined\"\n ) {\n return op.hashedId;\n }\n\n return;\n }\n\n private async filterNewSteps(\n foundSteps: FoundStep[],\n ): Promise<[OutgoingOp, ...OutgoingOp[]] | undefined> {\n if (this.options.requestedRunStep) {\n return;\n }\n\n const newSteps = foundSteps.reduce((acc, step) => {\n if (!step.hasStepState) {\n acc.push(step);\n }\n\n return acc;\n }, [] as FoundStep[]);\n\n if (!newSteps.length) {\n return;\n }\n\n await this.middlewareManager.onMemoizationEnd();\n\n const stepList = newSteps.map<OutgoingOp>((step) => {\n return {\n displayName: step.displayName,\n op: step.op,\n id: step.hashedId,\n name: step.name,\n opts: step.opts,\n userland: step.userland,\n };\n });\n\n if (!isNonEmpty(stepList)) {\n throw new UnreachableError(\"stepList is empty\");\n }\n\n return stepList;\n }\n\n private async executeStep(foundStep: FoundStep): Promise<OutgoingOp> {\n const { id, name, opts, fn, displayName, userland, hashedId } = foundStep;\n const { stepInfo, wrappedHandler, setActualHandler } = foundStep.middleware;\n\n this.devDebug(`preparing to execute step \"${id}\"`);\n\n this.timeout?.clear();\n\n const outgoingOp: OutgoingOp = {\n id: hashedId,\n op: StepOpCode.StepRun,\n name,\n opts,\n displayName,\n userland,\n };\n this.state.executingStep = outgoingOp;\n\n const store = await getAsyncCtx();\n\n if (store?.execution) {\n store.execution.executingStep = {\n id,\n name: displayName,\n };\n }\n\n this.devDebug(`executing step \"${id}\"`);\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.declareStepExecution(\n this.rootSpanId,\n hashedId,\n this.options.data?.attempt ?? 0,\n );\n }\n\n let interval: GoInterval | undefined;\n\n // `fn` already has middleware-transformed args baked in via `fnArgs` (i.e.\n // the `transformStepInput` middleware hook already ran).\n const actualHandler = () => runAsPromise(fn);\n\n await this.middlewareManager.onMemoizationEnd();\n await this.middlewareManager.onStepStart(stepInfo);\n\n // If wrappedHandler hasn't been called yet (no deferred from discovery),\n // set one up so wrapStep's next() still blocks until memoization.\n if (!foundStep.memoizationDeferred) {\n const deferred = createDeferredPromise<unknown>();\n foundStep.memoizationDeferred = deferred;\n setActualHandler(() => deferred.promise);\n foundStep.transformedResultPromise = wrappedHandler();\n foundStep.transformedResultPromise.catch(() => {\n // Swallow — errors handled by handle()\n });\n }\n\n // Build wrapStepHandler chain around the actual handler\n const wrappedActualHandler =\n this.middlewareManager.buildWrapStepHandlerChain(actualHandler, stepInfo);\n\n return goIntervalTiming(() => wrappedActualHandler())\n .finally(() => {\n this.devDebug(`finished executing step \"${id}\"`);\n\n this.state.executingStep = undefined;\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.clearStepExecution(this.rootSpanId);\n }\n\n if (store?.execution) {\n delete store.execution.executingStep;\n }\n })\n .then<OutgoingOp>(async ({ resultPromise, interval: _interval }) => {\n interval = _interval;\n const metadata = this.state.metadata?.get(id);\n const serverData = await resultPromise;\n\n // Don't resolve memoizationDeferred here. wrapStep's next() must\n // block until the step is actually memoized (i.e. handle() fires\n // with confirmed data from the server). handle() resolves it.\n await this.middlewareManager.onStepComplete(stepInfo, serverData);\n\n return {\n ...outgoingOp,\n data: serverData,\n ...(metadata && metadata.length > 0 ? { metadata: metadata } : {}),\n };\n })\n .catch<OutgoingOp>((error) => {\n // Don't reject memoizationDeferred — handle() will reject it when\n // the error is memoized.\n return this.buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n });\n })\n .then((op) => ({\n ...op,\n timing: interval,\n }));\n }\n\n /**\n * Starts execution of the user's function, including triggering checkpoints\n * and middleware hooks where appropriate.\n */\n private async startExecution(): Promise<void> {\n /**\n * Start the timer to time out the run if needed.\n */\n void this.timeout?.start();\n void this.checkpointingMaxRuntimeTimer?.start();\n void this.checkpointingMaxBufferIntervalTimer?.start();\n\n const fnInputResult = await this.middlewareManager.transformFunctionInput();\n this.applyFunctionInputMutations(fnInputResult);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (this.state.stepsToFulfill === 0 && this.fnArg.attempt === 0) {\n await this.middlewareManager.onRunStart();\n }\n\n const innerHandler: () => Promise<unknown> = async () => {\n await this.validateEventSchemas();\n return this.userFnToRun(this.fnArg);\n };\n\n const runHandler = this.middlewareManager.wrapRunHandler(innerHandler);\n\n runAsPromise(runHandler)\n .then(async (data) => {\n await this.middlewareManager.onRunComplete(data);\n this.state.setCheckpoint({ type: \"function-resolved\", data });\n })\n .catch(async (error) => {\n // Preserve Error instances; stringify non-Error throws (e.g. `throw {}`)\n let err: Error;\n if (error instanceof Error) {\n err = error;\n } else if (typeof error === \"object\") {\n err = new Error(JSON.stringify(error));\n } else {\n err = new Error(String(error));\n }\n\n await this.middlewareManager.onRunError(err, this.isFinalAttempt(err));\n this.state.setCheckpoint({ type: \"function-rejected\", error: err });\n });\n }\n\n /**\n * Whether this error will not be retried (NonRetriableError or last attempt).\n */\n private isFinalAttempt(error: unknown): boolean {\n if (\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\"\n ) {\n return true;\n }\n\n return Boolean(\n this.fnArg.maxAttempts &&\n this.fnArg.maxAttempts - 1 === this.fnArg.attempt,\n );\n }\n\n /**\n * Build the OutgoingOp for a failed step, notifying middleware and choosing\n * retriable vs non-retriable opcode.\n */\n private async buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n }: {\n error: unknown;\n id: string;\n outgoingOp: OutgoingOp;\n stepInfo: Middleware.StepInfo;\n }): Promise<OutgoingOp> {\n const isFinal = this.isFinalAttempt(error);\n const metadata = this.state.metadata?.get(id);\n\n await this.middlewareManager.onStepError(\n stepInfo,\n error instanceof Error ? error : new Error(String(error)),\n isFinal,\n );\n\n return {\n ...outgoingOp,\n error,\n op: isFinal ? StepOpCode.StepFailed : StepOpCode.StepError,\n ...(metadata && metadata.length > 0 ? { metadata } : {}),\n };\n }\n\n /**\n * Validate event data against schemas defined in function triggers.\n */\n private async validateEventSchemas(): Promise<void> {\n const triggers = this.options.fn.opts.triggers;\n if (!triggers || triggers.length === 0) return;\n\n const fnArgEvents = this.fnArg.events;\n if (!fnArgEvents || fnArgEvents.length === 0) return;\n\n const events = fnArgEvents.map((event) => ({\n name: event.name,\n data: event.data,\n }));\n\n await validateEvents(events, triggers);\n }\n\n /**\n * Using middleware, transform output before returning.\n */\n private transformOutput(dataOrError: {\n data?: unknown;\n error?: unknown;\n }): ExecutionResult {\n const { data, error } = dataOrError;\n\n if (typeof error !== \"undefined\") {\n /**\n * Ensure we give middleware the chance to decide on retriable behaviour\n * by looking at the error returned from output transformation.\n */\n let retriable: boolean | string = !(\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\" ||\n (error instanceof StepError &&\n error === this.state.recentlyRejectedStepError)\n );\n if (\n retriable &&\n (error instanceof RetryAfterError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"RetryAfterError\")\n ) {\n retriable = (error as RetryAfterError).retryAfter;\n }\n\n const serializedError = serializeError(error);\n\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n ops: this.ops,\n error: serializedError,\n retriable,\n };\n }\n\n return {\n type: \"function-resolved\",\n ctx: this.fnArg,\n ops: this.ops,\n data: undefinedToNull(data),\n };\n }\n\n private createExecutionState(): ExecutionState {\n const d = createDeferredPromiseWithStack<Checkpoint>();\n let checkpointResolve = d.deferred.resolve;\n const checkpointResults = d.results;\n\n const loop: ExecutionState[\"loop\"] = (async function* (\n cleanUp?: () => void,\n ) {\n try {\n while (true) {\n const res = (await checkpointResults.next()).value;\n if (res) {\n yield res;\n }\n }\n } finally {\n cleanUp?.();\n }\n })(() => {\n this.timeout?.clear();\n this.checkpointingMaxRuntimeTimer?.clear();\n this.checkpointingMaxBufferIntervalTimer?.clear();\n void checkpointResults.return();\n });\n\n const stepsToFulfill = Object.keys(this.options.stepState).length;\n\n const state: ExecutionState = {\n stepState: this.options.stepState,\n stepsToFulfill,\n steps: new Map(),\n loop,\n hasSteps: Boolean(stepsToFulfill),\n stepCompletionOrder: [...this.options.stepCompletionOrder],\n remainingStepsToBeSeen: new Set(this.options.stepCompletionOrder),\n setCheckpoint: (checkpoint: Checkpoint) => {\n this.devDebug(\"setting checkpoint:\", checkpoint.type);\n\n ({ resolve: checkpointResolve } = checkpointResolve(checkpoint));\n },\n allStateUsed: () => {\n return this.state.remainingStepsToBeSeen.size === 0;\n },\n checkpointingStepBuffer: [],\n metadata: new Map(),\n };\n\n return state;\n }\n\n get ops(): Record<string, MemoizedOp> {\n return Object.fromEntries(this.state.steps);\n }\n\n private createFnArg(): Context.Any {\n const step = this.createStepTools();\n const experimentStepRun = (step as unknown as ExperimentStepTools)[\n experimentStepRunSymbol\n ];\n\n let fnArg = {\n ...(this.options.data as { event: EventPayload }),\n step,\n group: createGroupTools({ experimentStepRun }),\n } as Context.Any;\n\n /**\n * Handle use of the `onFailure` option by deserializing the error.\n */\n if (this.options.isFailureHandler) {\n const eventData = z\n .object({ error: jsonErrorSchema })\n .parse(fnArg.event?.data);\n\n (fnArg as Partial<Pick<FailureEventArgs, \"error\">>) = {\n ...fnArg,\n error: deserializeError(eventData.error),\n };\n }\n\n return this.options.transformCtx?.(fnArg) ?? fnArg;\n }\n\n /**\n * Apply mutations from `transformFunctionInput` back to execution state.\n * Allows middleware to modify event data, step tools, memoized step data,\n * and inject custom fields into the handler context.\n */\n private applyFunctionInputMutations(\n result: Middleware.TransformFunctionInputArgs,\n ): void {\n const { event, events, step, ...extensions } = result.ctx;\n\n // Mutate in place so the ALS store's reference to this.fnArg stays valid.\n if (event !== this.fnArg.event) {\n this.fnArg.event = event;\n }\n\n if (events !== this.fnArg.events) {\n this.fnArg.events = events;\n }\n\n if (step !== this.fnArg.step) {\n this.fnArg.step = step;\n }\n\n if (Object.keys(extensions).length > 0) {\n Object.assign(this.fnArg, extensions);\n }\n\n // Apply step data mutations\n for (const [hashedId, stepData] of Object.entries(result.steps)) {\n const existing = this.state.stepState[hashedId];\n if (\n existing &&\n stepData &&\n stepData.type === \"data\" &&\n stepData.data !== existing.data\n ) {\n this.state.stepState[hashedId] = { ...existing, data: stepData.data };\n }\n }\n }\n\n private createStepTools(): ReturnType<typeof createStepTools> {\n /**\n * A list of steps that have been found and are being rolled up before being\n * reported to the core loop.\n */\n const foundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the subset of found steps to report that have not yet been\n * handled. Used for fast access to steps that need to be handled in order.\n */\n const unhandledFoundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the latest sequential step indexes found for each step ID. Used\n * to ensure that we don't index steps in parallel.\n *\n * Note that these must be sequential; if we've seen or assigned `a:1`,\n * `a:2` and `a:4`, the latest sequential step index is `2`.\n *\n */\n const expectedNextStepIndexes: Map<string, number> = new Map();\n\n /**\n * An ordered list of step IDs that have yet to be handled in this\n * execution. Used to ensure that we handle steps in the order they were\n * found and based on the `stepCompletionOrder` in this execution's state.\n */\n const remainingStepCompletionOrder: string[] =\n this.state.stepCompletionOrder.slice();\n\n /**\n * A promise that's used to ensure that step reporting cannot be run more than\n * once in a given asynchronous time span.\n */\n let foundStepsReportPromise: Promise<void> | undefined;\n\n /**\n * A flag used to ensure that we only warn about parallel indexing once per\n * execution to avoid spamming the console.\n */\n let warnOfParallelIndexing = false;\n\n /**\n * Counts the number of times we've extended this tick.\n */\n let tickExtensionCount = 0;\n\n /**\n * Given a colliding step ID, maybe warn the user about parallel indexing.\n */\n const maybeWarnOfParallelIndexing = (userlandCollisionId: string) => {\n if (warnOfParallelIndexing) {\n return;\n }\n\n const hashedCollisionId = _internals.hashId(userlandCollisionId);\n\n const stepExists = this.state.steps.has(hashedCollisionId);\n if (stepExists) {\n const stepFoundThisTick = foundStepsToReport.has(hashedCollisionId);\n if (!stepFoundThisTick) {\n warnOfParallelIndexing = true;\n\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n {\n message: `Duplicate step ID \"${userlandCollisionId}\" detected across parallel chains`,\n explanation:\n \"Using the same ID for steps in different parallel chains can cause unexpected behaviour. Your function is still running.\",\n action:\n \"Use a unique ID for each step, especially those in parallel.\",\n code: ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n },\n );\n }\n }\n };\n\n /**\n * A helper used to report steps to the core loop. Used after adding an item\n * to `foundStepsToReport`.\n */\n const reportNextTick = () => {\n // Being explicit instead of using `??=` to appease TypeScript.\n if (foundStepsReportPromise) {\n return;\n }\n\n let extensionPromise: Promise<void>;\n if (++tickExtensionCount >= 10) {\n tickExtensionCount = 0;\n extensionPromise = resolveNextTick();\n } else {\n extensionPromise = resolveAfterPending();\n }\n\n foundStepsReportPromise = extensionPromise.then(() => {\n foundStepsReportPromise = undefined;\n\n for (let i = 0; i < remainingStepCompletionOrder.length; i++) {\n const nextStepId = remainingStepCompletionOrder[i];\n if (!nextStepId) {\n // Strange - skip this empty index\n continue;\n }\n\n const handled = unhandledFoundStepsToReport.get(nextStepId)?.handle();\n if (handled) {\n remainingStepCompletionOrder.splice(i, 1);\n unhandledFoundStepsToReport.delete(nextStepId);\n return void reportNextTick();\n }\n }\n\n // If we've handled no steps in this \"tick,\" roll up everything we've\n // found and report it.\n const steps = [...foundStepsToReport.values()];\n foundStepsToReport.clear();\n unhandledFoundStepsToReport.clear();\n\n if (!isNonEmpty(steps)) {\n return;\n }\n\n return void this.state.setCheckpoint({\n type: \"steps-found\",\n steps: steps,\n });\n });\n };\n\n /**\n * A helper used to push a step to the list of steps to report.\n */\n const pushStepToReport = (step: FoundStep) => {\n foundStepsToReport.set(step.hashedId, step);\n unhandledFoundStepsToReport.set(step.hashedId, step);\n reportNextTick();\n };\n\n const stepHandler: StepHandler = async ({\n args,\n matchOp,\n opts,\n }): Promise<unknown> => {\n const stepOptions = getStepOptions(args[0]);\n const opId = matchOp(stepOptions, ...args.slice(1));\n\n if (this.state.executingStep) {\n /**\n * If a step is found after asynchronous actions during another step's\n * execution, everything is fine. The problem here is if we've found\n * that a step nested inside another a step, which is something we don't\n * support at the time of writing.\n *\n * In this case, we could use something like Async Hooks to understand\n * how the step is being triggered, though this isn't available in all\n * environments.\n *\n * Therefore, we'll only show a warning here to indicate that this is\n * potentially an issue.\n */\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.NESTING_STEPS,\n {\n message: `Nested step tooling detected in \"${opId.displayName ?? opId.id}\"`,\n explanation:\n \"Nesting step.* calls is not supported. This warning may also appear if steps are separated by regular async calls, which is fine.\",\n action:\n \"Avoid using step.* inside other step.* calls. Use a separate async function or promise chaining to compose steps.\",\n code: ErrCode.NESTING_STEPS,\n },\n );\n }\n\n // Apply middleware transformations (may change step ID, affecting\n // memoization lookup)\n const {\n hashedId,\n isFulfilled,\n setActualHandler,\n stepInfo,\n stepState,\n wrappedHandler,\n } = await this.applyMiddlewareToStep(\n opId,\n expectedNextStepIndexes,\n maybeWarnOfParallelIndexing,\n );\n\n const { promise, resolve, reject } = createDeferredPromise();\n\n let extraOpts: Record<string, unknown> | undefined;\n let fnArgs = [...args];\n\n if (\n typeof stepState?.input !== \"undefined\" &&\n Array.isArray(stepState.input)\n ) {\n switch (opId.op) {\n // `step.run()` has its function input affected\n case StepOpCode.StepPlanned: {\n fnArgs = [...args.slice(0, 2), ...stepState.input];\n\n extraOpts = { input: [...stepState.input] };\n break;\n }\n\n // `step.ai.infer()` has its body affected\n case StepOpCode.AiGateway: {\n extraOpts = {\n body: {\n ...(typeof opId.opts?.body === \"object\"\n ? { ...opId.opts.body }\n : {}),\n ...stepState.input[0],\n },\n };\n break;\n }\n }\n }\n\n // If transformStepInput middleware may have changed the input, update\n // `fnArgs` so `fn` uses the transformed values. Skip if replay already\n // set `extraOpts`.\n if (!extraOpts && Array.isArray(stepInfo.input)) {\n fnArgs = [...args.slice(0, 2), ...stepInfo.input];\n }\n\n const step: FoundStep = {\n ...opId,\n opts: { ...opId.opts, ...extraOpts },\n rawArgs: fnArgs,\n hashedId,\n input: stepState?.input,\n\n fn: opts?.fn ? () => opts.fn?.(this.fnArg, ...fnArgs) : undefined,\n promise,\n fulfilled: isFulfilled,\n hasStepState: Boolean(stepState),\n displayName: opId.displayName ?? opId.id,\n handled: false,\n\n // Middleware context for deferred handler pattern\n middleware: {\n wrappedHandler,\n stepInfo,\n setActualHandler,\n },\n\n handle: () => {\n if (step.handled) {\n return false;\n }\n\n this.devDebug(`handling step \"${hashedId}\"`);\n\n step.handled = true;\n\n // Refetch step state because it may have been changed since we found\n // the step. This could be due to checkpointing, where we run this\n // live and then return to the function.\n const result = this.state.stepState[hashedId];\n\n if (step.fulfilled && result) {\n result.fulfilled = true;\n\n // For some execution scenarios such as testing, `data`, `error`,\n // and `input` may be `Promises`. This could also be the case for\n // future middleware applications. For this reason, we'll make sure\n // the values are fully resolved before continuing.\n void Promise.all([result.data, result.error, result.input]).then(\n async () => {\n // If the wrapStep chain already ran during discovery in this\n // same request (checkpointing), reuse its result instead of\n // firing wrappedHandler() again. This prevents middleware from\n // seeing a duplicate wrapStep call per step per request.\n if (step.transformedResultPromise) {\n // Resolve the memoization deferred so wrapStep's next()\n // unblocks. The step data is now confirmed memoized.\n if (step.memoizationDeferred) {\n if (typeof result.data !== \"undefined\") {\n step.memoizationDeferred.resolve(await result.data);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n step.memoizationDeferred.reject(stepError);\n }\n }\n\n step.transformedResultPromise.then(resolve, reject);\n return;\n }\n\n // The wrapStep chain is about to fire again to resolve the\n // step promise through middleware (e.g. deserialization).\n // Mark the step as memoized so middleware can distinguish\n // this from the original execution call.\n //\n // This need for this change was discovered when checkpointing +\n // middleware's \"double `wrapStep` call\" behavior had `memoized:\n // false` on the 2nd call\n step.middleware.stepInfo.memoized = true;\n\n if (typeof result.data !== \"undefined\") {\n // Validate waitForEvent results against the schema if present\n // Skip validation if result.data is null (timeout case)\n if (\n opId.op === StepOpCode.WaitForEvent &&\n result.data !== null\n ) {\n const { event } = (step.rawArgs?.[1] ?? {}) as {\n event: unknown;\n };\n if (!event) {\n // Unreachable\n throw new Error(\"Missing event option in waitForEvent\");\n }\n try {\n await validateEvents(\n [result.data],\n\n // @ts-expect-error - This is a full event object at runtime\n [{ event }],\n );\n } catch (err) {\n this.state.recentlyRejectedStepError = new StepError(\n opId.id,\n err,\n );\n reject(this.state.recentlyRejectedStepError);\n return;\n }\n }\n\n // Set inner handler to return memoized data\n step.middleware.setActualHandler(() =>\n Promise.resolve(result.data),\n );\n\n step.middleware.wrappedHandler().then(resolve);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n\n // Set inner handler to reject with step error\n step.middleware.setActualHandler(() =>\n Promise.reject(stepError),\n );\n\n step.middleware.wrappedHandler().catch(reject);\n }\n },\n );\n }\n\n return true;\n },\n };\n\n this.state.steps.set(hashedId, step);\n this.state.hasSteps = true;\n\n const isNewStepWithHandler = !isFulfilled && !stepState && step.fn;\n if (isNewStepWithHandler) {\n // New, never-seen step with a handler (e.g. `step.run`). Kick off the\n // middleware wrapStep chain now so it runs during discovery, not later\n // in executeStep.\n //\n // This is necessary so that middleware can inject their own steps.\n // Reporting is deferred to the center of the onion so that if\n // middleware throws or injects prerequisites, the step is never\n // reported.\n const deferred = createDeferredPromise<unknown>();\n step.memoizationDeferred = deferred;\n\n setActualHandler(() => {\n pushStepToReport(step);\n return deferred.promise;\n });\n\n step.transformedResultPromise = wrappedHandler();\n step.transformedResultPromise.catch((error) => {\n reject(error);\n });\n } else {\n pushStepToReport(step);\n }\n\n return promise;\n };\n\n return createStepTools(this.options.client, this, stepHandler);\n }\n\n /**\n * Applies middleware transformations to a step, resolves ID collisions,\n * and performs memoization lookup.\n */\n private async applyMiddlewareToStep(\n opId: HashedOp,\n expectedNextStepIndexes: Map<string, number>,\n maybeWarnOfParallelIndexing: (userlandCollisionId: string) => void,\n ): Promise<MiddlewareApplicationResult> {\n // 1. Resolve initial collision with original ID\n const initialCollision = resolveStepIdCollision({\n baseId: opId.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (initialCollision.finalId !== opId.id) {\n maybeWarnOfParallelIndexing(opId.id);\n opId.id = initialCollision.finalId;\n if (initialCollision.index !== undefined) {\n opId.userland.index = initialCollision.index;\n }\n }\n\n const originalId = opId.userland.id;\n let hashedId = _internals.hashId(opId.id);\n\n // 2. Apply middleware (stepType, input extraction, deferred handler).\n // Pass preliminary memoization status so middleware sees it.\n const prepared = await this.middlewareManager.applyToStep({\n displayName: opId.displayName ?? opId.userland.id,\n hashedId,\n memoized:\n Boolean(this.state.stepState[hashedId]) &&\n typeof this.state.stepState[hashedId]?.input === \"undefined\",\n op: opId.op,\n opts: opId.opts,\n userlandId: opId.userland.id,\n });\n const { entryPoint, opName, opOpts, setActualHandler, stepInfo } = prepared;\n\n if (opName !== undefined) {\n opId.name = opName;\n }\n if (opOpts !== undefined) {\n opId.opts = opOpts;\n }\n\n // 3. If middleware changed the step ID, re-resolve collisions\n if (stepInfo.options.id !== originalId) {\n opId.id = stepInfo.options.id;\n opId.userland.id = stepInfo.options.id;\n\n const secondCollision = resolveStepIdCollision({\n baseId: stepInfo.options.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (secondCollision.finalId !== stepInfo.options.id) {\n opId.id = secondCollision.finalId;\n opId.userland.id = secondCollision.finalId;\n stepInfo.options.id = secondCollision.finalId;\n if (secondCollision.index !== undefined) {\n opId.userland.index = secondCollision.index;\n }\n }\n\n // Recompute hashedId with final ID\n hashedId = _internals.hashId(opId.id);\n stepInfo.hashedId = hashedId;\n }\n\n // 4. Final memoization lookup with potentially modified hashedId.\n // Also marks step as seen and may trigger onMemoizationEnd.\n const stepState = this.state.stepState[hashedId];\n let isFulfilled = false;\n if (stepState) {\n stepState.seen = true;\n this.state.remainingStepsToBeSeen.delete(hashedId);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (typeof stepState.input === \"undefined\") {\n isFulfilled = true;\n }\n stepInfo.memoized = isFulfilled;\n } else {\n stepInfo.memoized = false;\n }\n\n // 5. Build wrapStep chain after all mutations so middleware sees final values\n const wrappedHandler = this.middlewareManager.buildWrapStepChain(\n entryPoint,\n stepInfo,\n );\n\n return {\n hashedId,\n stepInfo,\n wrappedHandler,\n setActualHandler,\n stepState,\n isFulfilled,\n };\n }\n\n private resumeStepWithResult(resultOp: OutgoingOp, resume = true): FoundStep {\n const userlandStep = this.state.steps.get(resultOp.id);\n if (!userlandStep) {\n throw new Error(\n \"Step not found in memoization state during async checkpointing; this should never happen and is a bug in the Inngest SDK\",\n );\n }\n\n const data = undefinedToNull(resultOp.data);\n\n userlandStep.data = data;\n userlandStep.timing = resultOp.timing;\n userlandStep.op = resultOp.op;\n userlandStep.id = resultOp.id;\n\n if (resume) {\n userlandStep.fulfilled = true;\n userlandStep.hasStepState = true;\n this.state.stepState[resultOp.id] = userlandStep;\n\n userlandStep.handle();\n }\n\n return userlandStep;\n }\n\n private getUserFnToRun(): Handler.Any {\n if (!this.options.isFailureHandler) {\n return this.options.fn[\"fn\"];\n }\n\n if (!this.options.fn[\"onFailureFn\"]) {\n /**\n * Somehow, we've ended up detecting that this is a failure handler but\n * doesn't have an `onFailure` function. This should never happen.\n */\n throw new Error(\"Cannot find function `onFailure` handler\");\n }\n\n return this.options.fn[\"onFailureFn\"];\n }\n\n private initializeTimer(state: ExecutionState): void {\n if (!this.options.requestedRunStep) {\n return;\n }\n\n this.timeout = createTimeoutPromise(this.timeoutDuration);\n\n void this.timeout.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n state.setCheckpoint({\n type: \"step-not-found\",\n step: {\n id: this.options.requestedRunStep as string,\n op: StepOpCode.StepNotFound,\n },\n foundSteps,\n totalFoundSteps,\n });\n });\n }\n\n private getStepNotFoundDetails(): {\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n } {\n const foundSteps = [...this.state.steps.values()]\n .filter((step) => !step.hasStepState)\n .map<BasicFoundStep>((step) => ({\n id: step.hashedId,\n name: step.name,\n displayName: step.displayName,\n }))\n .sort((a, b) => a.id.localeCompare(b.id));\n\n return {\n foundSteps: foundSteps.slice(0, STEP_NOT_FOUND_MAX_FOUND_STEPS),\n totalFoundSteps: foundSteps.length,\n };\n }\n\n private initializeCheckpointRuntimeTimer(state: ExecutionState): void {\n this.devDebug(\n \"initializing checkpointing runtime timers\",\n this.options.checkpointingConfig,\n );\n\n if (this.options.checkpointingConfig?.maxRuntime) {\n const maxRuntimeMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxRuntime,\n )\n ? this.options.checkpointingConfig.maxRuntime.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxRuntime === \"string\"\n ? ms(this.options.checkpointingConfig.maxRuntime as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxRuntime as number);\n\n // 0 or negative max runtime? Skip.\n if (Number.isFinite(maxRuntimeMs) && maxRuntimeMs > 0) {\n this.checkpointingMaxRuntimeTimer = createTimeoutPromise(maxRuntimeMs);\n\n void this.checkpointingMaxRuntimeTimer.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n state.setCheckpoint({\n type: \"checkpointing-runtime-reached\",\n });\n });\n }\n }\n\n if (this.options.checkpointingConfig?.maxInterval) {\n const maxIntervalMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxInterval,\n )\n ? this.options.checkpointingConfig.maxInterval.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxInterval === \"string\"\n ? ms(this.options.checkpointingConfig.maxInterval as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxInterval as number);\n\n // 0 or negative max interval? Skip.\n if (Number.isFinite(maxIntervalMs) && maxIntervalMs > 0) {\n this.checkpointingMaxBufferIntervalTimer =\n createTimeoutPromise(maxIntervalMs);\n\n void this.checkpointingMaxBufferIntervalTimer.then(async () => {\n // Note that this will not immediately run; it will be queued like all\n // other checkpoints so that we're never running multiple checkpoints\n // at the same time and it's easier to reason about those decision\n // points.\n //\n // A change in the future may be to make this particular checkpointing\n // action immediate and have the checkpoint action itself be\n // idempotent.\n state.setCheckpoint({\n type: \"checkpointing-buffer-interval-reached\",\n });\n\n this.checkpointingMaxBufferIntervalTimer?.reset();\n });\n }\n }\n }\n}\n\n/**\n * Types of checkpoints that can be reached during execution.\n */\nexport interface Checkpoints {\n \"steps-found\": { steps: [FoundStep, ...FoundStep[]] };\n \"function-rejected\": { error: unknown };\n \"function-resolved\": { data: unknown };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n \"checkpointing-runtime-reached\": {};\n \"checkpointing-buffer-interval-reached\": {};\n}\n\ntype Checkpoint = {\n [K in keyof Checkpoints]: Simplify<{ type: K } & Checkpoints[K]>;\n}[keyof Checkpoints];\n\ntype CheckpointHandlers = Record<\n StepMode,\n {\n [C in Checkpoint as C[\"type\"]]: (\n checkpoint: C,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n } & {\n \"\": (\n checkpoint: Checkpoint,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<void>;\n }\n>;\n\nexport interface ExecutionState {\n /**\n * A value that indicates that we're executing this step. Can be used to\n * ensure steps are not accidentally nested until we support this across all\n * platforms.\n */\n executingStep?: Readonly<Omit<OutgoingOp, \"id\">>;\n\n /**\n * A map of step IDs to their data, used to fill previously-completed steps\n * with state from the executor.\n */\n stepState: Record<string, MemoizedOp>;\n\n /**\n * The number of steps we expect to fulfil based on the state passed from the\n * Executor.\n */\n stepsToFulfill: number;\n\n /**\n * A map of step IDs to their functions to run. The executor can request a\n * specific step to run, so we need to store the function to run here.\n */\n steps: Map<string, FoundStep>;\n\n /**\n * A flag which represents whether or not steps are understood to be used in\n * this function. This is used to determine whether or not we should run\n * some steps (such as `step.sendEvent`) inline as they are found.\n */\n hasSteps: boolean;\n\n /**\n * The core loop - a generator used to take an action upon finding the next\n * checkpoint. Manages the flow of execution and cleaning up after itself.\n */\n loop: AsyncGenerator<Checkpoint, void, void>;\n\n /**\n * A function that resolves the `Promise` returned by `waitForNextDecision`.\n */\n setCheckpoint: (data: Checkpoint) => void;\n\n /**\n * Returns whether or not all state passed from the executor has been used to\n * fulfill found steps.\n */\n allStateUsed: () => boolean;\n\n /**\n * An ordered list of step IDs that represents the order in which their\n * execution was completed.\n */\n stepCompletionOrder: string[];\n\n /**\n * An set of step IDs that have yet to be seen in this execution. Used to\n * decide when to trigger middleware based on the current state.\n */\n remainingStepsToBeSeen: Set<string>;\n\n /**\n * If defined, this is the error that purposefully thrown when memoizing step\n * state in order to support per-step errors.\n *\n * We use this so that if the function itself rejects with the same error, we\n * know that it was entirely uncaught (or at the very least rethrown), so we\n * should send a `NonRetriableError` to stop needless execution of a function\n * that will continue to fail.\n *\n * TODO This is imperfect, as this state is currently kept around for longer\n * than it needs to be. It should disappear as soon as we've seen that the\n * error did not immediately throw. It may need to be refactored to work a\n * little more smoothly with the core loop.\n */\n recentlyRejectedStepError?: StepError;\n\n /**\n * If defined, this indicates that we're running a checkpointed function run,\n * and contains the data needed to report progress back to Inngest.\n */\n checkpointedRun?: {\n fnId: string;\n appId: string;\n token?: string;\n };\n\n /**\n * A buffer of steps that are currently queued to be checkpointed.\n */\n checkpointingStepBuffer: OutgoingOp[];\n\n /**\n * Metadata collected during execution to be sent with outgoing ops.\n */\n metadata?: Map<string, Array<MetadataUpdate>>;\n}\n\nconst hashId = (id: string): string => {\n return sha1().update(id).digest(\"hex\");\n};\n\nconst hashOp = (op: OutgoingOp): OutgoingOp => {\n return {\n ...op,\n id: hashId(op.id),\n };\n};\n\n/**\n * Result of resolving a step ID collision.\n */\ninterface CollisionResolutionResult {\n /** The final ID to use (either original or with index suffix). */\n finalId: string;\n\n /** The index used, if collision was detected. */\n index?: number;\n}\n\n/** Result of applying middleware to a step. */\ninterface MiddlewareApplicationResult {\n hashedId: string;\n isFulfilled: boolean;\n setActualHandler: (handler: () => Promise<unknown>) => void;\n stepInfo: Middleware.StepInfo;\n stepState: MemoizedOp | undefined;\n wrappedHandler: () => Promise<unknown>;\n}\n\n/**\n * Resolves step ID collisions by appending an index suffix if needed.\n * Consolidates the duplicated collision detection logic.\n *\n * @param baseId - The original step ID\n * @param stepsMap - Map of existing steps (keyed by hashed ID)\n * @param expectedIndexes - Map tracking expected next index for each base ID\n * @returns The final ID to use and optional index\n */\nfunction resolveStepIdCollision({\n baseId,\n expectedIndexes,\n stepsMap,\n}: {\n baseId: string;\n expectedIndexes: Map<string, number>;\n stepsMap: Map<string, FoundStep>;\n}): CollisionResolutionResult {\n const hashedBaseId = hashId(baseId);\n\n // Check both stepsMap (steps added to state) and expectedIndexes (claimed by\n // concurrent in-progress step handlers that haven't been added to state yet).\n if (!stepsMap.has(hashedBaseId) && !expectedIndexes.has(baseId)) {\n // No collision. Claim this base ID so concurrent callers detect collision.\n expectedIndexes.set(baseId, 1);\n return { finalId: baseId };\n }\n\n // Collision detected. Find next available index\n const expectedNextIndex = expectedIndexes.get(baseId) ?? 1;\n const maxIndex = expectedNextIndex + stepsMap.size + 1;\n for (let i = expectedNextIndex; i < maxIndex; i++) {\n const indexedId = baseId + STEP_INDEXING_SUFFIX + i;\n const hashedIndexedId = hashId(indexedId);\n\n if (!stepsMap.has(hashedIndexedId)) {\n expectedIndexes.set(baseId, i + 1);\n return { finalId: indexedId, index: i };\n }\n }\n\n throw new UnreachableError(\n `Could not resolve step ID collision for \"${baseId}\" after ${stepsMap.size + 1} attempts`,\n );\n}\n\nfunction isNonEmpty<T>(arr: T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Exported for testing.\n */\nexport const _internals = { hashOp, hashId, resolveStepIdCollision };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAM,EAAE,SAASA;;;;;;;;;AAUjB,MAAM,2BAA2B;CAAE,aAAa;CAAG,WAAW;CAAK;AACnE,MAAM,iCAAiC;AAEvC,MAAaC,yBAAkD,YAAY;AACzE,QAAO,IAAI,uBAAuB,QAAQ;;AAG5C,IAAM,yBAAN,cACUC,0CAEV;CACE,AAAO,UAAUC,gCAAiB;CAElC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB,MAAO;CACjC,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;CASR,AAAQ;CACR,AAAQ;;;;;;;CAQR,AAAQ;;;;;;CASR,AAAQ;CAIR,YAAY,YAAqC;EAC/C,MAAMC,UAAmC;GACvC,GAAG;GACH,UAAU,WAAW,YAAYC,uBAAS;GAC3C;AAED,QAAM,QAAQ;;;;AAKd,M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;;;;;;;;;;;iBA2BD,sBAAA;;;;;;mBAMU;YACP,YAAY;IACpB;;;;cAoCS;eAjFO,eAAa"}
@@ -296,7 +296,14 @@ var InngestExecutionEngine = class extends InngestExecution {
296
296
  return;
297
297
  } catch (err) {
298
298
  this.devDebug("error checkpointing after step run, so falling back to async", err);
299
- if (stepResult) return stepRanHandler(stepResult);
299
+ const buffered = this.state.checkpointingStepBuffer;
300
+ if (buffered.length) return {
301
+ type: "steps-found",
302
+ ctx: this.fnArg,
303
+ ops: this.ops,
304
+ steps: buffered
305
+ };
306
+ return;
300
307
  } finally {
301
308
  this.state.checkpointingStepBuffer = [];
302
309
  }
@@ -344,7 +351,7 @@ var InngestExecutionEngine = class extends InngestExecution {
344
351
  "checkpointing-runtime-reached": () => {
345
352
  return this.checkpointAndSwitchToAsync([{
346
353
  op: StepOpCode.DiscoveryRequest,
347
- id: _internals.hashId("discovery-request")
354
+ id: _internals.hashId(`discovery-request-${Date.now()}`)
348
355
  }]);
349
356
  },
350
357
  "checkpointing-buffer-interval-reached": () => {
@@ -404,7 +411,10 @@ var InngestExecutionEngine = class extends InngestExecution {
404
411
  }
405
412
  },
406
413
  "function-rejected": async (checkpoint) => {
407
- if (this.state.checkpointingStepBuffer.length) await attemptCheckpointAndResume(void 0, false);
414
+ if (this.state.checkpointingStepBuffer.length) {
415
+ const fallback = await attemptCheckpointAndResume(void 0, false, true);
416
+ if (fallback) return fallback;
417
+ }
408
418
  return await this.transformOutput({ error: checkpoint.error });
409
419
  },
410
420
  "step-not-found": asyncHandlers["step-not-found"],
@@ -426,12 +436,18 @@ var InngestExecutionEngine = class extends InngestExecution {
426
436
  if (stepResult) {
427
437
  this.devDebug(`executed step "${stepResult.id}" successfully`);
428
438
  if (stepResult.error) {
429
- if (this.state.checkpointingStepBuffer.length) await attemptCheckpointAndResume(void 0, false, true);
439
+ if (this.state.checkpointingStepBuffer.length) {
440
+ const fallback = await attemptCheckpointAndResume(void 0, false, true);
441
+ if (fallback) return fallback;
442
+ }
430
443
  return stepRanHandler(stepResult);
431
444
  }
432
445
  return await attemptCheckpointAndResume(stepResult);
433
446
  }
434
- if (this.state.checkpointingStepBuffer.length) await attemptCheckpointAndResume(void 0, false, true);
447
+ if (this.state.checkpointingStepBuffer.length) {
448
+ const fallback = await attemptCheckpointAndResume(void 0, false, true);
449
+ if (fallback) return fallback;
450
+ }
435
451
  return maybeReturnNewSteps();
436
452
  }
437
453
  if (stepsToResume.length) {
@@ -449,7 +465,7 @@ var InngestExecutionEngine = class extends InngestExecution {
449
465
  ops: this.ops,
450
466
  steps: [{
451
467
  op: StepOpCode.DiscoveryRequest,
452
- id: _internals.hashId("discovery-request")
468
+ id: _internals.hashId(`discovery-request-${Date.now()}`)
453
469
  }]
454
470
  };
455
471
  },
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","names":["createExecutionEngine: InngestExecutionFactory","options: InngestExecutionOptions","commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"]","syncHandlers: CheckpointHandlers[StepMode.Sync]","asyncHandlers: CheckpointHandlers[StepMode.Async]","asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing]","step","outgoingOp: OutgoingOp","interval: GoInterval | undefined","innerHandler: () => Promise<unknown>","err: Error","retriable: boolean | string","loop: ExecutionState[\"loop\"]","foundStepsToReport: Map<string, FoundStep>","unhandledFoundStepsToReport: Map<string, FoundStep>","expectedNextStepIndexes: Map<string, number>","remainingStepCompletionOrder: string[]","foundStepsReportPromise: Promise<void> | undefined","extensionPromise: Promise<void>","stepHandler: StepHandler","extraOpts: Record<string, unknown> | undefined","step: FoundStep","Temporal.isTemporalDuration"],"sources":["../../../src/components/execution/engine.ts"],"sourcesContent":["import { trace } from \"@opentelemetry/api\";\nimport hashjs from \"hash.js\";\nimport ms, { type StringValue } from \"ms\";\nimport { z } from \"zod/v3\";\n\nimport {\n defaultMaxRetries,\n ExecutionVersion,\n headerKeys,\n internalEvents,\n} from \"../../helpers/consts.ts\";\n\nimport {\n deserializeError,\n ErrCode,\n serializeError,\n} from \"../../helpers/errors.js\";\nimport { undefinedToNull } from \"../../helpers/functions.js\";\nimport {\n createDeferredPromise,\n createDeferredPromiseWithStack,\n createTimeoutPromise,\n type GoInterval,\n goIntervalTiming,\n resolveAfterPending,\n resolveNextTick,\n retryWithBackoff,\n runAsPromise,\n} from \"../../helpers/promises.ts\";\nimport * as Temporal from \"../../helpers/temporal.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport {\n type APIStepPayload,\n type Context,\n type EventPayload,\n type FailureEventArgs,\n type Handler,\n type HashedOp,\n jsonErrorSchema,\n type OutgoingOp,\n StepMode,\n StepOpCode,\n} from \"../../types.ts\";\nimport { version } from \"../../version.ts\";\nimport { internalLoggerSymbol } from \"../Inngest.ts\";\nimport { createGroupTools } from \"../InngestGroupTools.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n MetadataUpdate,\n} from \"../InngestMetadata.ts\";\nimport {\n createStepTools,\n type ExperimentStepTools,\n experimentStepRunSymbol,\n type FoundStep,\n getStepOptions,\n STEP_INDEXING_SUFFIX,\n type StepHandler,\n} from \"../InngestStepTools.ts\";\nimport { MiddlewareManager } from \"../middleware/index.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\nimport { UnreachableError } from \"../middleware/utils.ts\";\nimport { NonRetriableError } from \"../NonRetriableError.ts\";\nimport { RetryAfterError } from \"../RetryAfterError.ts\";\nimport { StepError } from \"../StepError.ts\";\nimport { validateEvents } from \"../triggers/utils.js\";\nimport { getAsyncCtx, getAsyncLocalStorage } from \"./als.ts\";\nimport {\n type BasicFoundStep,\n type ExecutionResult,\n type IInngestExecution,\n InngestExecution,\n type InngestExecutionFactory,\n type InngestExecutionOptions,\n type MemoizedOp,\n} from \"./InngestExecution.ts\";\nimport { clientProcessorMap } from \"./otel/access.ts\";\n\nconst { sha1 } = hashjs;\n\n/**\n * Retry configuration for checkpoint operations.\n *\n * Checkpoint calls use exponential backoff with jitter to handle transient\n * network failures (e.g., dev server temporarily down, cloud hiccup). If\n * retries exhaust, the error propagates up - for Sync mode this results in a\n * 500 error, for AsyncCheckpointing the caller handles fallback.\n */\nconst CHECKPOINT_RETRY_OPTIONS = { maxAttempts: 5, baseDelay: 100 };\nconst STEP_NOT_FOUND_MAX_FOUND_STEPS = 25;\n\nexport const createExecutionEngine: InngestExecutionFactory = (options) => {\n return new InngestExecutionEngine(options);\n};\n\nclass InngestExecutionEngine\n extends InngestExecution\n implements IInngestExecution\n{\n public version = ExecutionVersion.V2;\n\n private state: ExecutionState;\n private fnArg: Context.Any;\n private checkpointHandlers: CheckpointHandlers;\n private timeoutDuration = 1000 * 10;\n private execution: Promise<ExecutionResult> | undefined;\n private userFnToRun: Handler.Any;\n private middlewareManager: MiddlewareManager;\n\n /**\n * If we're supposed to run a particular step via `requestedRunStep`, this\n * will be a `Promise` that resolves after no steps have been found for\n * `timeoutDuration` milliseconds.\n *\n * If we're not supposed to run a particular step, this will be `undefined`.\n */\n private timeout?: ReturnType<typeof createTimeoutPromise>;\n private rootSpanId?: string;\n\n /**\n * If we're checkpointing and have been given a maximum runtime, this will be\n * a `Promise` that resolves after that duration has elapsed, allowing us to\n * ensure that we end the execution in good time, especially in serverless\n * environments.\n */\n private checkpointingMaxRuntimeTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n /**\n * If we're checkpointing and have been given a maximum buffer interval, this\n * will be a `Promise` that resolves after that duration has elapsed, allowing\n * us to periodically checkpoint even if the step buffer hasn't filled.\n */\n private checkpointingMaxBufferIntervalTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n constructor(rawOptions: InngestExecutionOptions) {\n const options: InngestExecutionOptions = {\n ...rawOptions,\n stepMode: rawOptions.stepMode ?? StepMode.Async,\n };\n\n super(options);\n\n /**\n * Check we have everything we need for checkpointing\n */\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.options.createResponse) {\n throw new Error(\"createResponse is required for sync step mode\");\n }\n }\n\n this.userFnToRun = this.getUserFnToRun();\n this.state = this.createExecutionState();\n this.fnArg = this.createFnArg();\n\n // Setup middleware\n const mwInstances =\n this.options.middlewareInstances ??\n (this.options.client.middleware || []).map((Cls) => {\n return new Cls({ client: this.options.client });\n });\n this.middlewareManager = new MiddlewareManager(\n this.fnArg,\n () => this.state.stepState,\n mwInstances,\n this.options.fn,\n this.options.client[internalLoggerSymbol],\n );\n\n this.checkpointHandlers = this.createCheckpointHandlers();\n this.initializeTimer(this.state);\n this.initializeCheckpointRuntimeTimer(this.state);\n\n this.devDebug(\n \"created new V1 execution for run;\",\n this.options.requestedRunStep\n ? `wanting to run step \"${this.options.requestedRunStep}\"`\n : \"discovering steps\",\n );\n\n this.devDebug(\"existing state keys:\", Object.keys(this.state.stepState));\n }\n\n /**\n * Idempotently start the execution of the user's function.\n */\n public start() {\n if (!this.execution) {\n this.devDebug(\"starting V1 execution\");\n\n const tracer = trace.getTracer(\"inngest\", version);\n\n this.execution = getAsyncLocalStorage().then((als) => {\n return als.run(\n {\n app: this.options.client,\n execution: {\n ctx: this.fnArg,\n instance: this,\n },\n },\n async () => {\n return tracer.startActiveSpan(\"inngest.execution\", (span) => {\n this.rootSpanId = span.spanContext().spanId;\n clientProcessorMap.get(this.options.client)?.declareStartingSpan({\n span,\n runId: this.options.runId,\n traceparent: this.options.headers[headerKeys.TraceParent],\n tracestate: this.options.headers[headerKeys.TraceState],\n });\n\n return this._start()\n .then((result) => {\n this.devDebug(\"result:\", result);\n return result;\n })\n .finally(() => {\n span.end();\n });\n });\n },\n );\n });\n }\n\n return this.execution;\n }\n\n public addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ) {\n if (!this.state.metadata) {\n this.state.metadata = new Map();\n }\n\n const updates = this.state.metadata.get(stepId) ?? [];\n updates.push({ kind, scope, op, values });\n this.state.metadata.set(stepId, updates);\n\n return true;\n }\n\n /**\n * Starts execution of the user's function and the core loop.\n */\n private async _start(): Promise<ExecutionResult> {\n try {\n const allCheckpointHandler = this.getCheckpointHandler(\"\");\n await this.startExecution();\n\n let i = 0;\n\n for await (const checkpoint of this.state.loop) {\n await allCheckpointHandler(checkpoint, i);\n\n const handler = this.getCheckpointHandler(checkpoint.type);\n const result = await handler(checkpoint, i++);\n\n if (result) {\n return result;\n }\n }\n } catch (error) {\n return this.transformOutput({ error });\n } finally {\n void this.state.loop.return();\n }\n\n /**\n * If we're here, the generator somehow finished without returning a value.\n * This should never happen.\n */\n throw new Error(\"Core loop finished without returning a value\");\n }\n\n private async checkpoint(steps: OutgoingOp[]): Promise<void> {\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.state.checkpointedRun) {\n // We have to start the run\n const res = await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointNewRun({\n runId: this.fnArg.runId,\n event: this.fnArg.event as APIStepPayload,\n steps,\n executionVersion: this.version,\n retries: this.fnArg.maxAttempts ?? defaultMaxRetries,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n\n this.state.checkpointedRun = {\n appId: res.data.app_id,\n fnId: res.data.fn_id,\n token: res.data.token,\n };\n } else {\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointSteps({\n appId: this.state.checkpointedRun!.appId,\n fnId: this.state.checkpointedRun!.fnId,\n runId: this.fnArg.runId,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n }\n } else if (this.options.stepMode === StepMode.AsyncCheckpointing) {\n if (!this.options.queueItemId) {\n throw new Error(\n \"Missing queueItemId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n if (!this.options.internalFnId) {\n throw new Error(\n \"Missing internalFnId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointStepsAsync({\n runId: this.fnArg.runId,\n fnId: this.options.internalFnId!,\n queueItemId: this.options.queueItemId!,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n } else {\n throw new Error(\n \"Checkpointing is only supported in Sync and AsyncCheckpointing step modes. This is a bug in the Inngest SDK.\",\n );\n }\n }\n\n private async checkpointAndSwitchToAsync(\n steps: OutgoingOp[],\n ): Promise<ExecutionResult> {\n await this.checkpoint(steps);\n\n if (!this.state.checkpointedRun?.token) {\n throw new Error(\"Failed to checkpoint and switch to async mode\");\n }\n\n return {\n type: \"change-mode\",\n ctx: this.fnArg,\n ops: this.ops,\n to: StepMode.Async,\n token: this.state.checkpointedRun?.token!,\n };\n }\n\n /**\n * Returns whether we're in the final attempt of execution, or `null` if we\n * can't determine this in the SDK.\n */\n private inFinalAttempt(): boolean | null {\n if (typeof this.fnArg.maxAttempts !== \"number\") {\n return null;\n }\n\n return this.fnArg.attempt + 1 >= this.fnArg.maxAttempts;\n }\n\n /**\n * Creates a handler for every checkpoint type, defining what to do when we\n * reach that checkpoint in the core loop.\n */\n private createCheckpointHandlers(): CheckpointHandlers {\n const commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"] = (\n checkpoint,\n ) => {\n this.devDebug(`${this.options.stepMode} checkpoint:`, checkpoint);\n };\n\n const stepRanHandler = async (\n stepResult: OutgoingOp,\n ): Promise<ExecutionResult> => {\n const transformResult = await this.transformOutput(stepResult);\n\n /**\n * Transforming output will always return either function rejection or\n * resolution. In most cases, this can be immediately returned, but in\n * this particular case we want to handle it differently.\n */\n if (transformResult.type === \"function-resolved\") {\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n step: {\n ...stepResult,\n data: transformResult.data,\n },\n };\n } else if (transformResult.type === \"function-rejected\") {\n const stepForResponse = {\n ...stepResult,\n error: transformResult.error,\n };\n\n if (stepResult.op === StepOpCode.StepFailed) {\n const ser = serializeError(transformResult.error);\n stepForResponse.data = {\n __serialized: true,\n name: ser.name,\n message: ser.message,\n stack: \"\",\n };\n }\n\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n retriable: transformResult.retriable,\n step: stepForResponse,\n };\n }\n\n return transformResult;\n };\n\n const maybeReturnNewSteps = async (): Promise<\n ExecutionResult | undefined\n > => {\n const newSteps = await this.filterNewSteps(\n Array.from(this.state.steps.values()),\n );\n if (newSteps) {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: newSteps,\n };\n }\n\n return;\n };\n\n const attemptCheckpointAndResume = async (\n stepResult?: OutgoingOp,\n resume = true,\n force = false,\n ) => {\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n if (stepResult) {\n const stepToResume = this.resumeStepWithResult(stepResult, resume);\n\n // Clear `executingStep` immediately after resuming, before any await.\n // `resumeStepWithResult` resolves the step's promise, queuing a\n // microtask for the function to continue. Any subsequent await (e.g.\n // the `transformOutput` hook) yields and lets that microtask run, so\n // `executingStep` must already be cleared to avoid a false positive\n // NESTING_STEPS warning in the next step's handler.\n delete this.state.executingStep;\n\n // Buffer a copy with transformed data for checkpointing\n this.state.checkpointingStepBuffer.push({\n ...stepToResume,\n data: stepResult.data,\n });\n }\n\n if (\n force ||\n !this.options.checkpointingConfig?.bufferedSteps ||\n this.state.checkpointingStepBuffer.length >=\n this.options.checkpointingConfig.bufferedSteps\n ) {\n this.devDebug(\"checkpointing and resuming execution after step run\");\n\n try {\n this.devDebug(\n `checkpointing all buffered steps:`,\n this.state.checkpointingStepBuffer\n .map((op) => op.displayName || op.id)\n .join(\", \"),\n );\n\n return void (await this.checkpoint(\n this.state.checkpointingStepBuffer,\n ));\n } catch (err) {\n // If checkpointing fails for any reason, fall back to the async\n // flow\n this.devDebug(\n \"error checkpointing after step run, so falling back to async\",\n err,\n );\n\n if (stepResult) {\n return stepRanHandler(stepResult);\n }\n } finally {\n // Clear the checkpointing buffer\n this.state.checkpointingStepBuffer = [];\n }\n } else {\n this.devDebug(\n `not checkpointing yet, continuing execution as we haven't reached buffered step limit of ${this.options.checkpointingConfig?.bufferedSteps}`,\n );\n }\n\n return;\n };\n\n const syncHandlers: CheckpointHandlers[StepMode.Sync] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n \"function-resolved\": async (checkpoint, i) => {\n const transformedData = checkpoint.data;\n\n await this.checkpoint([\n {\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: await this.options.createResponse!(transformedData),\n },\n ]);\n\n // Apply middleware transformation before returning\n return await this.transformOutput({ data: checkpoint.data });\n },\n\n \"function-rejected\": async (checkpoint) => {\n // If the function throws during sync execution, we want to switch to\n // async mode so that we can retry. The exception is that we're already\n // at max attempts, in which case we do actually want to reject.\n if (this.inFinalAttempt()) {\n // Apply middleware transformation before returning\n return await this.transformOutput({ error: checkpoint.error });\n }\n\n // Otherwise, checkpoint the error and switch to async mode\n return this.checkpointAndSwitchToAsync([\n {\n id: _internals.hashId(\"complete\"), // ID is not important here\n op: StepOpCode.StepError,\n error: checkpoint.error,\n },\n ]);\n },\n\n \"step-not-found\": () => {\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n error: new Error(\n \"Step not found when checkpointing; this should never happen\",\n ),\n ops: this.ops,\n retriable: false,\n };\n },\n\n \"steps-found\": async ({ steps }) => {\n // If we're entering parallelism or async mode, checkpoint and switch\n // to async.\n if (steps.length !== 1 || steps[0].mode !== StepMode.Sync) {\n return this.checkpointAndSwitchToAsync(\n steps.map((step) => ({ ...step, id: step.hashedId })),\n );\n }\n\n // Otherwise we're good to start executing things right now.\n const result = await this.executeStep(steps[0]);\n\n if (result.error) {\n return this.checkpointAndSwitchToAsync([result]);\n }\n\n // Resume the step with original data for user code\n const stepToResume = this.resumeStepWithResult(result);\n\n // Clear executingStep now that the step result has been processed.\n // Without this, the next step discovery would see stale state and\n // emit a false positive NESTING_STEPS warning.\n delete this.state.executingStep;\n\n return void (await this.checkpoint([stepToResume]));\n },\n\n \"checkpointing-runtime-reached\": () => {\n return this.checkpointAndSwitchToAsync([\n {\n op: StepOpCode.DiscoveryRequest,\n id: _internals.hashId(\"discovery-request\"), // ID doesn't matter\n },\n ]);\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n const asyncHandlers: CheckpointHandlers[StepMode.Async] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n /**\n * The user's function has completed and returned a value.\n */\n \"function-resolved\": async ({ data }) => {\n // Check for unreported new steps (e.g. from `Promise.race` where\n // the winning branch completed before losing branches reported)\n const newStepsResult = await maybeReturnNewSteps();\n if (newStepsResult) {\n return newStepsResult;\n }\n\n // We need to do this even here for async, as we could be returning\n // data from an API endpoint, even if we were triggered async.\n if (this.options.createResponse) {\n data = await this.options.createResponse(data);\n }\n\n return await this.transformOutput({ data });\n },\n\n /**\n * The user's function has thrown an error.\n */\n \"function-rejected\": async (checkpoint) => {\n return await this.transformOutput({ error: checkpoint.error });\n },\n\n /**\n * We've found one or more steps. Here we may want to run a step or report\n * them back to Inngest.\n */\n \"steps-found\": async ({ steps }) => {\n const stepResult = await this.tryExecuteStep(steps);\n if (stepResult) {\n return stepRanHandler(stepResult);\n }\n\n return maybeReturnNewSteps();\n },\n\n /**\n * While trying to find a step that Inngest has told us to run, we've\n * timed out or have otherwise decided that it doesn't exist.\n */\n \"step-not-found\": ({ step }) => {\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n return {\n type: \"step-not-found\",\n ctx: this.fnArg,\n ops: this.ops,\n step,\n foundSteps,\n totalFoundSteps,\n };\n },\n\n \"checkpointing-runtime-reached\": () => {\n throw new Error(\n \"Checkpointing maximum runtime reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n throw new Error(\n \"Checkpointing maximum buffer interval reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n };\n\n const asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing] =\n {\n \"\": commonCheckpointHandler,\n \"function-resolved\": async (checkpoint, i) => {\n const output = await asyncHandlers[\"function-resolved\"](\n checkpoint,\n i,\n );\n if (output?.type === \"function-resolved\") {\n const steps = this.state.checkpointingStepBuffer.concat({\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: output.data,\n });\n\n if (isNonEmpty(steps)) {\n return {\n type: \"steps-found\",\n ctx: output.ctx,\n ops: output.ops,\n steps,\n };\n }\n }\n\n return;\n },\n \"function-rejected\": async (checkpoint) => {\n // If we have buffered steps, attempt checkpointing them first\n if (this.state.checkpointingStepBuffer.length) {\n await attemptCheckpointAndResume(undefined, false);\n }\n\n return await this.transformOutput({ error: checkpoint.error });\n },\n \"step-not-found\": asyncHandlers[\"step-not-found\"],\n \"steps-found\": async ({ steps }) => {\n // Note that if we have a requested run step, we'll never be\n // checkpointing, as that's an async parallel execution mode.\n\n // Break found steps in to { stepsToResume, newSteps }\n const { stepsToResume, newSteps } = steps.reduce(\n (acc, step) => {\n if (!step.hasStepState) {\n acc.newSteps.push(step);\n } else if (!step.fulfilled) {\n acc.stepsToResume.push(step);\n }\n\n return acc;\n },\n { stepsToResume: [], newSteps: [] } as {\n stepsToResume: FoundStep[];\n newSteps: FoundStep[];\n },\n );\n\n this.devDebug(\"split found steps in to:\", {\n stepsToResume: stepsToResume.length,\n newSteps: newSteps.length,\n });\n\n // Got new steps? Exit early.\n if (!this.options.requestedRunStep && newSteps.length) {\n const stepResult = await this.tryExecuteStep(newSteps);\n if (stepResult) {\n this.devDebug(`executed step \"${stepResult.id}\" successfully`);\n\n // We executed a step!\n //\n // We know that because we're in this mode, we're always free to\n // checkpoint and continue if we ran a step and it was successful.\n if (stepResult.error) {\n // Flush buffered steps before falling back to async,\n // so previously-successful steps aren't lost.\n if (this.state.checkpointingStepBuffer.length) {\n await attemptCheckpointAndResume(undefined, false, true);\n }\n\n // If we failed, go back to the regular async flow.\n return stepRanHandler(stepResult);\n }\n\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n return await attemptCheckpointAndResume(stepResult);\n }\n\n // Flush any buffered checkpoint steps before returning\n // new steps to the executor. Without this, steps executed\n // in-process during AsyncCheckpointing but not yet\n // checkpointed would be lost. When the executor later calls\n // back with requestedRunStep, those steps would be missing\n // from stepState, causing \"step not found\" errors.\n if (this.state.checkpointingStepBuffer.length) {\n await attemptCheckpointAndResume(undefined, false, true);\n }\n\n return maybeReturnNewSteps();\n }\n\n // If we have stepsToResume, resume as many as possible and resume execution\n if (stepsToResume.length) {\n this.devDebug(`resuming ${stepsToResume.length} steps`);\n\n for (const st of stepsToResume) {\n this.resumeStepWithResult({\n ...st,\n id: st.hashedId,\n });\n }\n }\n\n return;\n },\n \"checkpointing-runtime-reached\": async () => {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: [\n {\n op: StepOpCode.DiscoveryRequest,\n id: _internals.hashId(\"discovery-request\"), // ID doesn't matter\n },\n ],\n };\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n return {\n [StepMode.Async]: asyncHandlers,\n [StepMode.Sync]: syncHandlers,\n [StepMode.AsyncCheckpointing]: asyncCheckpointingHandlers,\n };\n }\n\n private getCheckpointHandler(type: keyof CheckpointHandlers[StepMode]) {\n return this.checkpointHandlers[this.options.stepMode][type] as (\n checkpoint: Checkpoint,\n iteration: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n }\n\n private async tryExecuteStep(\n steps: FoundStep[],\n ): Promise<OutgoingOp | undefined> {\n const hashedStepIdToRun =\n this.options.requestedRunStep || this.getEarlyExecRunStep(steps);\n if (!hashedStepIdToRun) {\n return;\n }\n\n const step = steps.find(\n (step) => step.hashedId === hashedStepIdToRun && step.fn,\n );\n\n if (step) {\n return await this.executeStep(step);\n }\n\n /**\n * Ensure we reset the timeout if we have a requested run step but couldn't\n * find it, but also that we don't reset if we found and executed it.\n */\n return void this.timeout?.reset();\n }\n\n /**\n * Given a list of outgoing ops, decide if we can execute an op early and\n * return the ID of the step to execute if we can.\n */\n private getEarlyExecRunStep(steps: FoundStep[]): string | undefined {\n /**\n * We may have been disabled due to parallelism, in which case we can't\n * immediately execute unless explicitly requested.\n */\n if (this.options.disableImmediateExecution) return;\n\n const unfulfilledSteps = steps.filter((step) => !step.fulfilled);\n if (unfulfilledSteps.length !== 1) return;\n\n const op = unfulfilledSteps[0];\n\n if (\n op &&\n op.op === StepOpCode.StepPlanned\n // TODO We must individually check properties here that we do not want to\n // execute on, such as retry counts. Nothing exists here that falls in to\n // this case, but should be accounted for when we add them.\n // && typeof op.opts === \"undefined\"\n ) {\n return op.hashedId;\n }\n\n return;\n }\n\n private async filterNewSteps(\n foundSteps: FoundStep[],\n ): Promise<[OutgoingOp, ...OutgoingOp[]] | undefined> {\n if (this.options.requestedRunStep) {\n return;\n }\n\n const newSteps = foundSteps.reduce((acc, step) => {\n if (!step.hasStepState) {\n acc.push(step);\n }\n\n return acc;\n }, [] as FoundStep[]);\n\n if (!newSteps.length) {\n return;\n }\n\n await this.middlewareManager.onMemoizationEnd();\n\n const stepList = newSteps.map<OutgoingOp>((step) => {\n return {\n displayName: step.displayName,\n op: step.op,\n id: step.hashedId,\n name: step.name,\n opts: step.opts,\n userland: step.userland,\n };\n });\n\n if (!isNonEmpty(stepList)) {\n throw new UnreachableError(\"stepList is empty\");\n }\n\n return stepList;\n }\n\n private async executeStep(foundStep: FoundStep): Promise<OutgoingOp> {\n const { id, name, opts, fn, displayName, userland, hashedId } = foundStep;\n const { stepInfo, wrappedHandler, setActualHandler } = foundStep.middleware;\n\n this.devDebug(`preparing to execute step \"${id}\"`);\n\n this.timeout?.clear();\n\n const outgoingOp: OutgoingOp = {\n id: hashedId,\n op: StepOpCode.StepRun,\n name,\n opts,\n displayName,\n userland,\n };\n this.state.executingStep = outgoingOp;\n\n const store = await getAsyncCtx();\n\n if (store?.execution) {\n store.execution.executingStep = {\n id,\n name: displayName,\n };\n }\n\n this.devDebug(`executing step \"${id}\"`);\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.declareStepExecution(\n this.rootSpanId,\n hashedId,\n this.options.data?.attempt ?? 0,\n );\n }\n\n let interval: GoInterval | undefined;\n\n // `fn` already has middleware-transformed args baked in via `fnArgs` (i.e.\n // the `transformStepInput` middleware hook already ran).\n const actualHandler = () => runAsPromise(fn);\n\n await this.middlewareManager.onMemoizationEnd();\n await this.middlewareManager.onStepStart(stepInfo);\n\n // If wrappedHandler hasn't been called yet (no deferred from discovery),\n // set one up so wrapStep's next() still blocks until memoization.\n if (!foundStep.memoizationDeferred) {\n const deferred = createDeferredPromise<unknown>();\n foundStep.memoizationDeferred = deferred;\n setActualHandler(() => deferred.promise);\n foundStep.transformedResultPromise = wrappedHandler();\n foundStep.transformedResultPromise.catch(() => {\n // Swallow — errors handled by handle()\n });\n }\n\n // Build wrapStepHandler chain around the actual handler\n const wrappedActualHandler =\n this.middlewareManager.buildWrapStepHandlerChain(actualHandler, stepInfo);\n\n return goIntervalTiming(() => wrappedActualHandler())\n .finally(() => {\n this.devDebug(`finished executing step \"${id}\"`);\n\n this.state.executingStep = undefined;\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.clearStepExecution(this.rootSpanId);\n }\n\n if (store?.execution) {\n delete store.execution.executingStep;\n }\n })\n .then<OutgoingOp>(async ({ resultPromise, interval: _interval }) => {\n interval = _interval;\n const metadata = this.state.metadata?.get(id);\n const serverData = await resultPromise;\n\n // Don't resolve memoizationDeferred here. wrapStep's next() must\n // block until the step is actually memoized (i.e. handle() fires\n // with confirmed data from the server). handle() resolves it.\n await this.middlewareManager.onStepComplete(stepInfo, serverData);\n\n return {\n ...outgoingOp,\n data: serverData,\n ...(metadata && metadata.length > 0 ? { metadata: metadata } : {}),\n };\n })\n .catch<OutgoingOp>((error) => {\n // Don't reject memoizationDeferred — handle() will reject it when\n // the error is memoized.\n return this.buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n });\n })\n .then((op) => ({\n ...op,\n timing: interval,\n }));\n }\n\n /**\n * Starts execution of the user's function, including triggering checkpoints\n * and middleware hooks where appropriate.\n */\n private async startExecution(): Promise<void> {\n /**\n * Start the timer to time out the run if needed.\n */\n void this.timeout?.start();\n void this.checkpointingMaxRuntimeTimer?.start();\n void this.checkpointingMaxBufferIntervalTimer?.start();\n\n const fnInputResult = await this.middlewareManager.transformFunctionInput();\n this.applyFunctionInputMutations(fnInputResult);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (this.state.stepsToFulfill === 0 && this.fnArg.attempt === 0) {\n await this.middlewareManager.onRunStart();\n }\n\n const innerHandler: () => Promise<unknown> = async () => {\n await this.validateEventSchemas();\n return this.userFnToRun(this.fnArg);\n };\n\n const runHandler = this.middlewareManager.wrapRunHandler(innerHandler);\n\n runAsPromise(runHandler)\n .then(async (data) => {\n await this.middlewareManager.onRunComplete(data);\n this.state.setCheckpoint({ type: \"function-resolved\", data });\n })\n .catch(async (error) => {\n // Preserve Error instances; stringify non-Error throws (e.g. `throw {}`)\n let err: Error;\n if (error instanceof Error) {\n err = error;\n } else if (typeof error === \"object\") {\n err = new Error(JSON.stringify(error));\n } else {\n err = new Error(String(error));\n }\n\n await this.middlewareManager.onRunError(err, this.isFinalAttempt(err));\n this.state.setCheckpoint({ type: \"function-rejected\", error: err });\n });\n }\n\n /**\n * Whether this error will not be retried (NonRetriableError or last attempt).\n */\n private isFinalAttempt(error: unknown): boolean {\n if (\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\"\n ) {\n return true;\n }\n\n return Boolean(\n this.fnArg.maxAttempts &&\n this.fnArg.maxAttempts - 1 === this.fnArg.attempt,\n );\n }\n\n /**\n * Build the OutgoingOp for a failed step, notifying middleware and choosing\n * retriable vs non-retriable opcode.\n */\n private async buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n }: {\n error: unknown;\n id: string;\n outgoingOp: OutgoingOp;\n stepInfo: Middleware.StepInfo;\n }): Promise<OutgoingOp> {\n const isFinal = this.isFinalAttempt(error);\n const metadata = this.state.metadata?.get(id);\n\n await this.middlewareManager.onStepError(\n stepInfo,\n error instanceof Error ? error : new Error(String(error)),\n isFinal,\n );\n\n return {\n ...outgoingOp,\n error,\n op: isFinal ? StepOpCode.StepFailed : StepOpCode.StepError,\n ...(metadata && metadata.length > 0 ? { metadata } : {}),\n };\n }\n\n /**\n * Validate event data against schemas defined in function triggers.\n */\n private async validateEventSchemas(): Promise<void> {\n const triggers = this.options.fn.opts.triggers;\n if (!triggers || triggers.length === 0) return;\n\n const fnArgEvents = this.fnArg.events;\n if (!fnArgEvents || fnArgEvents.length === 0) return;\n\n const events = fnArgEvents.map((event) => ({\n name: event.name,\n data: event.data,\n }));\n\n await validateEvents(events, triggers);\n }\n\n /**\n * Using middleware, transform output before returning.\n */\n private transformOutput(dataOrError: {\n data?: unknown;\n error?: unknown;\n }): ExecutionResult {\n const { data, error } = dataOrError;\n\n if (typeof error !== \"undefined\") {\n /**\n * Ensure we give middleware the chance to decide on retriable behaviour\n * by looking at the error returned from output transformation.\n */\n let retriable: boolean | string = !(\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\" ||\n (error instanceof StepError &&\n error === this.state.recentlyRejectedStepError)\n );\n if (\n retriable &&\n (error instanceof RetryAfterError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"RetryAfterError\")\n ) {\n retriable = (error as RetryAfterError).retryAfter;\n }\n\n const serializedError = serializeError(error);\n\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n ops: this.ops,\n error: serializedError,\n retriable,\n };\n }\n\n return {\n type: \"function-resolved\",\n ctx: this.fnArg,\n ops: this.ops,\n data: undefinedToNull(data),\n };\n }\n\n private createExecutionState(): ExecutionState {\n const d = createDeferredPromiseWithStack<Checkpoint>();\n let checkpointResolve = d.deferred.resolve;\n const checkpointResults = d.results;\n\n const loop: ExecutionState[\"loop\"] = (async function* (\n cleanUp?: () => void,\n ) {\n try {\n while (true) {\n const res = (await checkpointResults.next()).value;\n if (res) {\n yield res;\n }\n }\n } finally {\n cleanUp?.();\n }\n })(() => {\n this.timeout?.clear();\n this.checkpointingMaxRuntimeTimer?.clear();\n this.checkpointingMaxBufferIntervalTimer?.clear();\n void checkpointResults.return();\n });\n\n const stepsToFulfill = Object.keys(this.options.stepState).length;\n\n const state: ExecutionState = {\n stepState: this.options.stepState,\n stepsToFulfill,\n steps: new Map(),\n loop,\n hasSteps: Boolean(stepsToFulfill),\n stepCompletionOrder: [...this.options.stepCompletionOrder],\n remainingStepsToBeSeen: new Set(this.options.stepCompletionOrder),\n setCheckpoint: (checkpoint: Checkpoint) => {\n this.devDebug(\"setting checkpoint:\", checkpoint.type);\n\n ({ resolve: checkpointResolve } = checkpointResolve(checkpoint));\n },\n allStateUsed: () => {\n return this.state.remainingStepsToBeSeen.size === 0;\n },\n checkpointingStepBuffer: [],\n metadata: new Map(),\n };\n\n return state;\n }\n\n get ops(): Record<string, MemoizedOp> {\n return Object.fromEntries(this.state.steps);\n }\n\n private createFnArg(): Context.Any {\n const step = this.createStepTools();\n const experimentStepRun = (step as unknown as ExperimentStepTools)[\n experimentStepRunSymbol\n ];\n\n let fnArg = {\n ...(this.options.data as { event: EventPayload }),\n step,\n group: createGroupTools({ experimentStepRun }),\n } as Context.Any;\n\n /**\n * Handle use of the `onFailure` option by deserializing the error.\n */\n if (this.options.isFailureHandler) {\n const eventData = z\n .object({ error: jsonErrorSchema })\n .parse(fnArg.event?.data);\n\n (fnArg as Partial<Pick<FailureEventArgs, \"error\">>) = {\n ...fnArg,\n error: deserializeError(eventData.error),\n };\n }\n\n return this.options.transformCtx?.(fnArg) ?? fnArg;\n }\n\n /**\n * Apply mutations from `transformFunctionInput` back to execution state.\n * Allows middleware to modify event data, step tools, memoized step data,\n * and inject custom fields into the handler context.\n */\n private applyFunctionInputMutations(\n result: Middleware.TransformFunctionInputArgs,\n ): void {\n const { event, events, step, ...extensions } = result.ctx;\n\n // Mutate in place so the ALS store's reference to this.fnArg stays valid.\n if (event !== this.fnArg.event) {\n this.fnArg.event = event;\n }\n\n if (events !== this.fnArg.events) {\n this.fnArg.events = events;\n }\n\n if (step !== this.fnArg.step) {\n this.fnArg.step = step;\n }\n\n if (Object.keys(extensions).length > 0) {\n Object.assign(this.fnArg, extensions);\n }\n\n // Apply step data mutations\n for (const [hashedId, stepData] of Object.entries(result.steps)) {\n const existing = this.state.stepState[hashedId];\n if (\n existing &&\n stepData &&\n stepData.type === \"data\" &&\n stepData.data !== existing.data\n ) {\n this.state.stepState[hashedId] = { ...existing, data: stepData.data };\n }\n }\n }\n\n private createStepTools(): ReturnType<typeof createStepTools> {\n /**\n * A list of steps that have been found and are being rolled up before being\n * reported to the core loop.\n */\n const foundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the subset of found steps to report that have not yet been\n * handled. Used for fast access to steps that need to be handled in order.\n */\n const unhandledFoundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the latest sequential step indexes found for each step ID. Used\n * to ensure that we don't index steps in parallel.\n *\n * Note that these must be sequential; if we've seen or assigned `a:1`,\n * `a:2` and `a:4`, the latest sequential step index is `2`.\n *\n */\n const expectedNextStepIndexes: Map<string, number> = new Map();\n\n /**\n * An ordered list of step IDs that have yet to be handled in this\n * execution. Used to ensure that we handle steps in the order they were\n * found and based on the `stepCompletionOrder` in this execution's state.\n */\n const remainingStepCompletionOrder: string[] =\n this.state.stepCompletionOrder.slice();\n\n /**\n * A promise that's used to ensure that step reporting cannot be run more than\n * once in a given asynchronous time span.\n */\n let foundStepsReportPromise: Promise<void> | undefined;\n\n /**\n * A flag used to ensure that we only warn about parallel indexing once per\n * execution to avoid spamming the console.\n */\n let warnOfParallelIndexing = false;\n\n /**\n * Counts the number of times we've extended this tick.\n */\n let tickExtensionCount = 0;\n\n /**\n * Given a colliding step ID, maybe warn the user about parallel indexing.\n */\n const maybeWarnOfParallelIndexing = (userlandCollisionId: string) => {\n if (warnOfParallelIndexing) {\n return;\n }\n\n const hashedCollisionId = _internals.hashId(userlandCollisionId);\n\n const stepExists = this.state.steps.has(hashedCollisionId);\n if (stepExists) {\n const stepFoundThisTick = foundStepsToReport.has(hashedCollisionId);\n if (!stepFoundThisTick) {\n warnOfParallelIndexing = true;\n\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n {\n message: `Duplicate step ID \"${userlandCollisionId}\" detected across parallel chains`,\n explanation:\n \"Using the same ID for steps in different parallel chains can cause unexpected behaviour. Your function is still running.\",\n action:\n \"Use a unique ID for each step, especially those in parallel.\",\n code: ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n },\n );\n }\n }\n };\n\n /**\n * A helper used to report steps to the core loop. Used after adding an item\n * to `foundStepsToReport`.\n */\n const reportNextTick = () => {\n // Being explicit instead of using `??=` to appease TypeScript.\n if (foundStepsReportPromise) {\n return;\n }\n\n let extensionPromise: Promise<void>;\n if (++tickExtensionCount >= 10) {\n tickExtensionCount = 0;\n extensionPromise = resolveNextTick();\n } else {\n extensionPromise = resolveAfterPending();\n }\n\n foundStepsReportPromise = extensionPromise.then(() => {\n foundStepsReportPromise = undefined;\n\n for (let i = 0; i < remainingStepCompletionOrder.length; i++) {\n const nextStepId = remainingStepCompletionOrder[i];\n if (!nextStepId) {\n // Strange - skip this empty index\n continue;\n }\n\n const handled = unhandledFoundStepsToReport.get(nextStepId)?.handle();\n if (handled) {\n remainingStepCompletionOrder.splice(i, 1);\n unhandledFoundStepsToReport.delete(nextStepId);\n return void reportNextTick();\n }\n }\n\n // If we've handled no steps in this \"tick,\" roll up everything we've\n // found and report it.\n const steps = [...foundStepsToReport.values()];\n foundStepsToReport.clear();\n unhandledFoundStepsToReport.clear();\n\n if (!isNonEmpty(steps)) {\n return;\n }\n\n return void this.state.setCheckpoint({\n type: \"steps-found\",\n steps: steps,\n });\n });\n };\n\n /**\n * A helper used to push a step to the list of steps to report.\n */\n const pushStepToReport = (step: FoundStep) => {\n foundStepsToReport.set(step.hashedId, step);\n unhandledFoundStepsToReport.set(step.hashedId, step);\n reportNextTick();\n };\n\n const stepHandler: StepHandler = async ({\n args,\n matchOp,\n opts,\n }): Promise<unknown> => {\n const stepOptions = getStepOptions(args[0]);\n const opId = matchOp(stepOptions, ...args.slice(1));\n\n if (this.state.executingStep) {\n /**\n * If a step is found after asynchronous actions during another step's\n * execution, everything is fine. The problem here is if we've found\n * that a step nested inside another a step, which is something we don't\n * support at the time of writing.\n *\n * In this case, we could use something like Async Hooks to understand\n * how the step is being triggered, though this isn't available in all\n * environments.\n *\n * Therefore, we'll only show a warning here to indicate that this is\n * potentially an issue.\n */\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.NESTING_STEPS,\n {\n message: `Nested step tooling detected in \"${opId.displayName ?? opId.id}\"`,\n explanation:\n \"Nesting step.* calls is not supported. This warning may also appear if steps are separated by regular async calls, which is fine.\",\n action:\n \"Avoid using step.* inside other step.* calls. Use a separate async function or promise chaining to compose steps.\",\n code: ErrCode.NESTING_STEPS,\n },\n );\n }\n\n // Apply middleware transformations (may change step ID, affecting\n // memoization lookup)\n const {\n hashedId,\n isFulfilled,\n setActualHandler,\n stepInfo,\n stepState,\n wrappedHandler,\n } = await this.applyMiddlewareToStep(\n opId,\n expectedNextStepIndexes,\n maybeWarnOfParallelIndexing,\n );\n\n const { promise, resolve, reject } = createDeferredPromise();\n\n let extraOpts: Record<string, unknown> | undefined;\n let fnArgs = [...args];\n\n if (\n typeof stepState?.input !== \"undefined\" &&\n Array.isArray(stepState.input)\n ) {\n switch (opId.op) {\n // `step.run()` has its function input affected\n case StepOpCode.StepPlanned: {\n fnArgs = [...args.slice(0, 2), ...stepState.input];\n\n extraOpts = { input: [...stepState.input] };\n break;\n }\n\n // `step.ai.infer()` has its body affected\n case StepOpCode.AiGateway: {\n extraOpts = {\n body: {\n ...(typeof opId.opts?.body === \"object\"\n ? { ...opId.opts.body }\n : {}),\n ...stepState.input[0],\n },\n };\n break;\n }\n }\n }\n\n // If transformStepInput middleware may have changed the input, update\n // `fnArgs` so `fn` uses the transformed values. Skip if replay already\n // set `extraOpts`.\n if (!extraOpts && Array.isArray(stepInfo.input)) {\n fnArgs = [...args.slice(0, 2), ...stepInfo.input];\n }\n\n const step: FoundStep = {\n ...opId,\n opts: { ...opId.opts, ...extraOpts },\n rawArgs: fnArgs,\n hashedId,\n input: stepState?.input,\n\n fn: opts?.fn ? () => opts.fn?.(this.fnArg, ...fnArgs) : undefined,\n promise,\n fulfilled: isFulfilled,\n hasStepState: Boolean(stepState),\n displayName: opId.displayName ?? opId.id,\n handled: false,\n\n // Middleware context for deferred handler pattern\n middleware: {\n wrappedHandler,\n stepInfo,\n setActualHandler,\n },\n\n handle: () => {\n if (step.handled) {\n return false;\n }\n\n this.devDebug(`handling step \"${hashedId}\"`);\n\n step.handled = true;\n\n // Refetch step state because it may have been changed since we found\n // the step. This could be due to checkpointing, where we run this\n // live and then return to the function.\n const result = this.state.stepState[hashedId];\n\n if (step.fulfilled && result) {\n result.fulfilled = true;\n\n // For some execution scenarios such as testing, `data`, `error`,\n // and `input` may be `Promises`. This could also be the case for\n // future middleware applications. For this reason, we'll make sure\n // the values are fully resolved before continuing.\n void Promise.all([result.data, result.error, result.input]).then(\n async () => {\n // If the wrapStep chain already ran during discovery in this\n // same request (checkpointing), reuse its result instead of\n // firing wrappedHandler() again. This prevents middleware from\n // seeing a duplicate wrapStep call per step per request.\n if (step.transformedResultPromise) {\n // Resolve the memoization deferred so wrapStep's next()\n // unblocks. The step data is now confirmed memoized.\n if (step.memoizationDeferred) {\n if (typeof result.data !== \"undefined\") {\n step.memoizationDeferred.resolve(await result.data);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n step.memoizationDeferred.reject(stepError);\n }\n }\n\n step.transformedResultPromise.then(resolve, reject);\n return;\n }\n\n // The wrapStep chain is about to fire again to resolve the\n // step promise through middleware (e.g. deserialization).\n // Mark the step as memoized so middleware can distinguish\n // this from the original execution call.\n //\n // This need for this change was discovered when checkpointing +\n // middleware's \"double `wrapStep` call\" behavior had `memoized:\n // false` on the 2nd call\n step.middleware.stepInfo.memoized = true;\n\n if (typeof result.data !== \"undefined\") {\n // Validate waitForEvent results against the schema if present\n // Skip validation if result.data is null (timeout case)\n if (\n opId.op === StepOpCode.WaitForEvent &&\n result.data !== null\n ) {\n const { event } = (step.rawArgs?.[1] ?? {}) as {\n event: unknown;\n };\n if (!event) {\n // Unreachable\n throw new Error(\"Missing event option in waitForEvent\");\n }\n try {\n await validateEvents(\n [result.data],\n\n // @ts-expect-error - This is a full event object at runtime\n [{ event }],\n );\n } catch (err) {\n this.state.recentlyRejectedStepError = new StepError(\n opId.id,\n err,\n );\n reject(this.state.recentlyRejectedStepError);\n return;\n }\n }\n\n // Set inner handler to return memoized data\n step.middleware.setActualHandler(() =>\n Promise.resolve(result.data),\n );\n\n step.middleware.wrappedHandler().then(resolve);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n\n // Set inner handler to reject with step error\n step.middleware.setActualHandler(() =>\n Promise.reject(stepError),\n );\n\n step.middleware.wrappedHandler().catch(reject);\n }\n },\n );\n }\n\n return true;\n },\n };\n\n this.state.steps.set(hashedId, step);\n this.state.hasSteps = true;\n\n const isNewStepWithHandler = !isFulfilled && !stepState && step.fn;\n if (isNewStepWithHandler) {\n // New, never-seen step with a handler (e.g. `step.run`). Kick off the\n // middleware wrapStep chain now so it runs during discovery, not later\n // in executeStep.\n //\n // This is necessary so that middleware can inject their own steps.\n // Reporting is deferred to the center of the onion so that if\n // middleware throws or injects prerequisites, the step is never\n // reported.\n const deferred = createDeferredPromise<unknown>();\n step.memoizationDeferred = deferred;\n\n setActualHandler(() => {\n pushStepToReport(step);\n return deferred.promise;\n });\n\n step.transformedResultPromise = wrappedHandler();\n step.transformedResultPromise.catch((error) => {\n reject(error);\n });\n } else {\n pushStepToReport(step);\n }\n\n return promise;\n };\n\n return createStepTools(this.options.client, this, stepHandler);\n }\n\n /**\n * Applies middleware transformations to a step, resolves ID collisions,\n * and performs memoization lookup.\n */\n private async applyMiddlewareToStep(\n opId: HashedOp,\n expectedNextStepIndexes: Map<string, number>,\n maybeWarnOfParallelIndexing: (userlandCollisionId: string) => void,\n ): Promise<MiddlewareApplicationResult> {\n // 1. Resolve initial collision with original ID\n const initialCollision = resolveStepIdCollision({\n baseId: opId.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (initialCollision.finalId !== opId.id) {\n maybeWarnOfParallelIndexing(opId.id);\n opId.id = initialCollision.finalId;\n if (initialCollision.index !== undefined) {\n opId.userland.index = initialCollision.index;\n }\n }\n\n const originalId = opId.userland.id;\n let hashedId = _internals.hashId(opId.id);\n\n // 2. Apply middleware (stepType, input extraction, deferred handler).\n // Pass preliminary memoization status so middleware sees it.\n const prepared = await this.middlewareManager.applyToStep({\n displayName: opId.displayName ?? opId.userland.id,\n hashedId,\n memoized:\n Boolean(this.state.stepState[hashedId]) &&\n typeof this.state.stepState[hashedId]?.input === \"undefined\",\n op: opId.op,\n opts: opId.opts,\n userlandId: opId.userland.id,\n });\n const { entryPoint, opName, opOpts, setActualHandler, stepInfo } = prepared;\n\n if (opName !== undefined) {\n opId.name = opName;\n }\n if (opOpts !== undefined) {\n opId.opts = opOpts;\n }\n\n // 3. If middleware changed the step ID, re-resolve collisions\n if (stepInfo.options.id !== originalId) {\n opId.id = stepInfo.options.id;\n opId.userland.id = stepInfo.options.id;\n\n const secondCollision = resolveStepIdCollision({\n baseId: stepInfo.options.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (secondCollision.finalId !== stepInfo.options.id) {\n opId.id = secondCollision.finalId;\n opId.userland.id = secondCollision.finalId;\n stepInfo.options.id = secondCollision.finalId;\n if (secondCollision.index !== undefined) {\n opId.userland.index = secondCollision.index;\n }\n }\n\n // Recompute hashedId with final ID\n hashedId = _internals.hashId(opId.id);\n stepInfo.hashedId = hashedId;\n }\n\n // 4. Final memoization lookup with potentially modified hashedId.\n // Also marks step as seen and may trigger onMemoizationEnd.\n const stepState = this.state.stepState[hashedId];\n let isFulfilled = false;\n if (stepState) {\n stepState.seen = true;\n this.state.remainingStepsToBeSeen.delete(hashedId);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (typeof stepState.input === \"undefined\") {\n isFulfilled = true;\n }\n stepInfo.memoized = isFulfilled;\n } else {\n stepInfo.memoized = false;\n }\n\n // 5. Build wrapStep chain after all mutations so middleware sees final values\n const wrappedHandler = this.middlewareManager.buildWrapStepChain(\n entryPoint,\n stepInfo,\n );\n\n return {\n hashedId,\n stepInfo,\n wrappedHandler,\n setActualHandler,\n stepState,\n isFulfilled,\n };\n }\n\n private resumeStepWithResult(resultOp: OutgoingOp, resume = true): FoundStep {\n const userlandStep = this.state.steps.get(resultOp.id);\n if (!userlandStep) {\n throw new Error(\n \"Step not found in memoization state during async checkpointing; this should never happen and is a bug in the Inngest SDK\",\n );\n }\n\n const data = undefinedToNull(resultOp.data);\n\n userlandStep.data = data;\n userlandStep.timing = resultOp.timing;\n userlandStep.op = resultOp.op;\n userlandStep.id = resultOp.id;\n\n if (resume) {\n userlandStep.fulfilled = true;\n userlandStep.hasStepState = true;\n this.state.stepState[resultOp.id] = userlandStep;\n\n userlandStep.handle();\n }\n\n return userlandStep;\n }\n\n private getUserFnToRun(): Handler.Any {\n if (!this.options.isFailureHandler) {\n return this.options.fn[\"fn\"];\n }\n\n if (!this.options.fn[\"onFailureFn\"]) {\n /**\n * Somehow, we've ended up detecting that this is a failure handler but\n * doesn't have an `onFailure` function. This should never happen.\n */\n throw new Error(\"Cannot find function `onFailure` handler\");\n }\n\n return this.options.fn[\"onFailureFn\"];\n }\n\n private initializeTimer(state: ExecutionState): void {\n if (!this.options.requestedRunStep) {\n return;\n }\n\n this.timeout = createTimeoutPromise(this.timeoutDuration);\n\n void this.timeout.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n state.setCheckpoint({\n type: \"step-not-found\",\n step: {\n id: this.options.requestedRunStep as string,\n op: StepOpCode.StepNotFound,\n },\n foundSteps,\n totalFoundSteps,\n });\n });\n }\n\n private getStepNotFoundDetails(): {\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n } {\n const foundSteps = [...this.state.steps.values()]\n .filter((step) => !step.hasStepState)\n .map<BasicFoundStep>((step) => ({\n id: step.hashedId,\n name: step.name,\n displayName: step.displayName,\n }))\n .sort((a, b) => a.id.localeCompare(b.id));\n\n return {\n foundSteps: foundSteps.slice(0, STEP_NOT_FOUND_MAX_FOUND_STEPS),\n totalFoundSteps: foundSteps.length,\n };\n }\n\n private initializeCheckpointRuntimeTimer(state: ExecutionState): void {\n this.devDebug(\n \"initializing checkpointing runtime timers\",\n this.options.checkpointingConfig,\n );\n\n if (this.options.checkpointingConfig?.maxRuntime) {\n const maxRuntimeMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxRuntime,\n )\n ? this.options.checkpointingConfig.maxRuntime.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxRuntime === \"string\"\n ? ms(this.options.checkpointingConfig.maxRuntime as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxRuntime as number);\n\n // 0 or negative max runtime? Skip.\n if (Number.isFinite(maxRuntimeMs) && maxRuntimeMs > 0) {\n this.checkpointingMaxRuntimeTimer = createTimeoutPromise(maxRuntimeMs);\n\n void this.checkpointingMaxRuntimeTimer.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n state.setCheckpoint({\n type: \"checkpointing-runtime-reached\",\n });\n });\n }\n }\n\n if (this.options.checkpointingConfig?.maxInterval) {\n const maxIntervalMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxInterval,\n )\n ? this.options.checkpointingConfig.maxInterval.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxInterval === \"string\"\n ? ms(this.options.checkpointingConfig.maxInterval as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxInterval as number);\n\n // 0 or negative max interval? Skip.\n if (Number.isFinite(maxIntervalMs) && maxIntervalMs > 0) {\n this.checkpointingMaxBufferIntervalTimer =\n createTimeoutPromise(maxIntervalMs);\n\n void this.checkpointingMaxBufferIntervalTimer.then(async () => {\n // Note that this will not immediately run; it will be queued like all\n // other checkpoints so that we're never running multiple checkpoints\n // at the same time and it's easier to reason about those decision\n // points.\n //\n // A change in the future may be to make this particular checkpointing\n // action immediate and have the checkpoint action itself be\n // idempotent.\n state.setCheckpoint({\n type: \"checkpointing-buffer-interval-reached\",\n });\n\n this.checkpointingMaxBufferIntervalTimer?.reset();\n });\n }\n }\n }\n}\n\n/**\n * Types of checkpoints that can be reached during execution.\n */\nexport interface Checkpoints {\n \"steps-found\": { steps: [FoundStep, ...FoundStep[]] };\n \"function-rejected\": { error: unknown };\n \"function-resolved\": { data: unknown };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n \"checkpointing-runtime-reached\": {};\n \"checkpointing-buffer-interval-reached\": {};\n}\n\ntype Checkpoint = {\n [K in keyof Checkpoints]: Simplify<{ type: K } & Checkpoints[K]>;\n}[keyof Checkpoints];\n\ntype CheckpointHandlers = Record<\n StepMode,\n {\n [C in Checkpoint as C[\"type\"]]: (\n checkpoint: C,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n } & {\n \"\": (\n checkpoint: Checkpoint,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<void>;\n }\n>;\n\nexport interface ExecutionState {\n /**\n * A value that indicates that we're executing this step. Can be used to\n * ensure steps are not accidentally nested until we support this across all\n * platforms.\n */\n executingStep?: Readonly<Omit<OutgoingOp, \"id\">>;\n\n /**\n * A map of step IDs to their data, used to fill previously-completed steps\n * with state from the executor.\n */\n stepState: Record<string, MemoizedOp>;\n\n /**\n * The number of steps we expect to fulfil based on the state passed from the\n * Executor.\n */\n stepsToFulfill: number;\n\n /**\n * A map of step IDs to their functions to run. The executor can request a\n * specific step to run, so we need to store the function to run here.\n */\n steps: Map<string, FoundStep>;\n\n /**\n * A flag which represents whether or not steps are understood to be used in\n * this function. This is used to determine whether or not we should run\n * some steps (such as `step.sendEvent`) inline as they are found.\n */\n hasSteps: boolean;\n\n /**\n * The core loop - a generator used to take an action upon finding the next\n * checkpoint. Manages the flow of execution and cleaning up after itself.\n */\n loop: AsyncGenerator<Checkpoint, void, void>;\n\n /**\n * A function that resolves the `Promise` returned by `waitForNextDecision`.\n */\n setCheckpoint: (data: Checkpoint) => void;\n\n /**\n * Returns whether or not all state passed from the executor has been used to\n * fulfill found steps.\n */\n allStateUsed: () => boolean;\n\n /**\n * An ordered list of step IDs that represents the order in which their\n * execution was completed.\n */\n stepCompletionOrder: string[];\n\n /**\n * An set of step IDs that have yet to be seen in this execution. Used to\n * decide when to trigger middleware based on the current state.\n */\n remainingStepsToBeSeen: Set<string>;\n\n /**\n * If defined, this is the error that purposefully thrown when memoizing step\n * state in order to support per-step errors.\n *\n * We use this so that if the function itself rejects with the same error, we\n * know that it was entirely uncaught (or at the very least rethrown), so we\n * should send a `NonRetriableError` to stop needless execution of a function\n * that will continue to fail.\n *\n * TODO This is imperfect, as this state is currently kept around for longer\n * than it needs to be. It should disappear as soon as we've seen that the\n * error did not immediately throw. It may need to be refactored to work a\n * little more smoothly with the core loop.\n */\n recentlyRejectedStepError?: StepError;\n\n /**\n * If defined, this indicates that we're running a checkpointed function run,\n * and contains the data needed to report progress back to Inngest.\n */\n checkpointedRun?: {\n fnId: string;\n appId: string;\n token?: string;\n };\n\n /**\n * A buffer of steps that are currently queued to be checkpointed.\n */\n checkpointingStepBuffer: OutgoingOp[];\n\n /**\n * Metadata collected during execution to be sent with outgoing ops.\n */\n metadata?: Map<string, Array<MetadataUpdate>>;\n}\n\nconst hashId = (id: string): string => {\n return sha1().update(id).digest(\"hex\");\n};\n\nconst hashOp = (op: OutgoingOp): OutgoingOp => {\n return {\n ...op,\n id: hashId(op.id),\n };\n};\n\n/**\n * Result of resolving a step ID collision.\n */\ninterface CollisionResolutionResult {\n /** The final ID to use (either original or with index suffix). */\n finalId: string;\n\n /** The index used, if collision was detected. */\n index?: number;\n}\n\n/** Result of applying middleware to a step. */\ninterface MiddlewareApplicationResult {\n hashedId: string;\n isFulfilled: boolean;\n setActualHandler: (handler: () => Promise<unknown>) => void;\n stepInfo: Middleware.StepInfo;\n stepState: MemoizedOp | undefined;\n wrappedHandler: () => Promise<unknown>;\n}\n\n/**\n * Resolves step ID collisions by appending an index suffix if needed.\n * Consolidates the duplicated collision detection logic.\n *\n * @param baseId - The original step ID\n * @param stepsMap - Map of existing steps (keyed by hashed ID)\n * @param expectedIndexes - Map tracking expected next index for each base ID\n * @returns The final ID to use and optional index\n */\nfunction resolveStepIdCollision({\n baseId,\n expectedIndexes,\n stepsMap,\n}: {\n baseId: string;\n expectedIndexes: Map<string, number>;\n stepsMap: Map<string, FoundStep>;\n}): CollisionResolutionResult {\n const hashedBaseId = hashId(baseId);\n\n // Check both stepsMap (steps added to state) and expectedIndexes (claimed by\n // concurrent in-progress step handlers that haven't been added to state yet).\n if (!stepsMap.has(hashedBaseId) && !expectedIndexes.has(baseId)) {\n // No collision. Claim this base ID so concurrent callers detect collision.\n expectedIndexes.set(baseId, 1);\n return { finalId: baseId };\n }\n\n // Collision detected. Find next available index\n const expectedNextIndex = expectedIndexes.get(baseId) ?? 1;\n const maxIndex = expectedNextIndex + stepsMap.size + 1;\n for (let i = expectedNextIndex; i < maxIndex; i++) {\n const indexedId = baseId + STEP_INDEXING_SUFFIX + i;\n const hashedIndexedId = hashId(indexedId);\n\n if (!stepsMap.has(hashedIndexedId)) {\n expectedIndexes.set(baseId, i + 1);\n return { finalId: indexedId, index: i };\n }\n }\n\n throw new UnreachableError(\n `Could not resolve step ID collision for \"${baseId}\" after ${stepsMap.size + 1} attempts`,\n );\n}\n\nfunction isNonEmpty<T>(arr: T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Exported for testing.\n */\nexport const _internals = { hashOp, hashId, resolveStepIdCollision };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAM,EAAE,SAAS;;;;;;;;;AAUjB,MAAM,2BAA2B;CAAE,aAAa;CAAG,WAAW;CAAK;AACnE,MAAM,iCAAiC;AAEvC,MAAaA,yBAAkD,YAAY;AACzE,QAAO,IAAI,uBAAuB,QAAQ;;AAG5C,IAAM,yBAAN,cACU,iBAEV;CACE,AAAO,UAAU,iBAAiB;CAElC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB,MAAO;CACjC,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;CASR,AAAQ;CACR,AAAQ;;;;;;;CAQR,AAAQ;;;;;;CASR,AAAQ;CAIR,YAAY,YAAqC;EAC/C,MAAMC,UAAmC;GACvC,GAAG;GACH,UAAU,WAAW,YAAY,SAAS;GAC3C;AAED,QAAM,QAAQ;;;;AAKd,MAAI,KAAK,QAAQ,aAAa,SAAS,MACrC;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B"}
1
+ {"version":3,"file":"engine.js","names":["createExecutionEngine: InngestExecutionFactory","options: InngestExecutionOptions","commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"]","syncHandlers: CheckpointHandlers[StepMode.Sync]","asyncHandlers: CheckpointHandlers[StepMode.Async]","asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing]","step","outgoingOp: OutgoingOp","interval: GoInterval | undefined","innerHandler: () => Promise<unknown>","err: Error","retriable: boolean | string","loop: ExecutionState[\"loop\"]","foundStepsToReport: Map<string, FoundStep>","unhandledFoundStepsToReport: Map<string, FoundStep>","expectedNextStepIndexes: Map<string, number>","remainingStepCompletionOrder: string[]","foundStepsReportPromise: Promise<void> | undefined","extensionPromise: Promise<void>","stepHandler: StepHandler","extraOpts: Record<string, unknown> | undefined","step: FoundStep","Temporal.isTemporalDuration"],"sources":["../../../src/components/execution/engine.ts"],"sourcesContent":["import { trace } from \"@opentelemetry/api\";\nimport hashjs from \"hash.js\";\nimport ms, { type StringValue } from \"ms\";\nimport { z } from \"zod/v3\";\n\nimport {\n defaultMaxRetries,\n ExecutionVersion,\n headerKeys,\n internalEvents,\n} from \"../../helpers/consts.ts\";\n\nimport {\n deserializeError,\n ErrCode,\n serializeError,\n} from \"../../helpers/errors.js\";\nimport { undefinedToNull } from \"../../helpers/functions.js\";\nimport {\n createDeferredPromise,\n createDeferredPromiseWithStack,\n createTimeoutPromise,\n type GoInterval,\n goIntervalTiming,\n resolveAfterPending,\n resolveNextTick,\n retryWithBackoff,\n runAsPromise,\n} from \"../../helpers/promises.ts\";\nimport * as Temporal from \"../../helpers/temporal.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport {\n type APIStepPayload,\n type Context,\n type EventPayload,\n type FailureEventArgs,\n type Handler,\n type HashedOp,\n jsonErrorSchema,\n type OutgoingOp,\n StepMode,\n StepOpCode,\n} from \"../../types.ts\";\nimport { version } from \"../../version.ts\";\nimport { internalLoggerSymbol } from \"../Inngest.ts\";\nimport { createGroupTools } from \"../InngestGroupTools.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n MetadataUpdate,\n} from \"../InngestMetadata.ts\";\nimport {\n createStepTools,\n type ExperimentStepTools,\n experimentStepRunSymbol,\n type FoundStep,\n getStepOptions,\n STEP_INDEXING_SUFFIX,\n type StepHandler,\n} from \"../InngestStepTools.ts\";\nimport { MiddlewareManager } from \"../middleware/index.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\nimport { UnreachableError } from \"../middleware/utils.ts\";\nimport { NonRetriableError } from \"../NonRetriableError.ts\";\nimport { RetryAfterError } from \"../RetryAfterError.ts\";\nimport { StepError } from \"../StepError.ts\";\nimport { validateEvents } from \"../triggers/utils.js\";\nimport { getAsyncCtx, getAsyncLocalStorage } from \"./als.ts\";\nimport {\n type BasicFoundStep,\n type ExecutionResult,\n type IInngestExecution,\n InngestExecution,\n type InngestExecutionFactory,\n type InngestExecutionOptions,\n type MemoizedOp,\n} from \"./InngestExecution.ts\";\nimport { clientProcessorMap } from \"./otel/access.ts\";\n\nconst { sha1 } = hashjs;\n\n/**\n * Retry configuration for checkpoint operations.\n *\n * Checkpoint calls use exponential backoff with jitter to handle transient\n * network failures (e.g., dev server temporarily down, cloud hiccup). If\n * retries exhaust, the error propagates up - for Sync mode this results in a\n * 500 error, for AsyncCheckpointing the caller handles fallback.\n */\nconst CHECKPOINT_RETRY_OPTIONS = { maxAttempts: 5, baseDelay: 100 };\nconst STEP_NOT_FOUND_MAX_FOUND_STEPS = 25;\n\nexport const createExecutionEngine: InngestExecutionFactory = (options) => {\n return new InngestExecutionEngine(options);\n};\n\nclass InngestExecutionEngine\n extends InngestExecution\n implements IInngestExecution\n{\n public version = ExecutionVersion.V2;\n\n private state: ExecutionState;\n private fnArg: Context.Any;\n private checkpointHandlers: CheckpointHandlers;\n private timeoutDuration = 1000 * 10;\n private execution: Promise<ExecutionResult> | undefined;\n private userFnToRun: Handler.Any;\n private middlewareManager: MiddlewareManager;\n\n /**\n * If we're supposed to run a particular step via `requestedRunStep`, this\n * will be a `Promise` that resolves after no steps have been found for\n * `timeoutDuration` milliseconds.\n *\n * If we're not supposed to run a particular step, this will be `undefined`.\n */\n private timeout?: ReturnType<typeof createTimeoutPromise>;\n private rootSpanId?: string;\n\n /**\n * If we're checkpointing and have been given a maximum runtime, this will be\n * a `Promise` that resolves after that duration has elapsed, allowing us to\n * ensure that we end the execution in good time, especially in serverless\n * environments.\n */\n private checkpointingMaxRuntimeTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n /**\n * If we're checkpointing and have been given a maximum buffer interval, this\n * will be a `Promise` that resolves after that duration has elapsed, allowing\n * us to periodically checkpoint even if the step buffer hasn't filled.\n */\n private checkpointingMaxBufferIntervalTimer?: ReturnType<\n typeof createTimeoutPromise\n >;\n\n constructor(rawOptions: InngestExecutionOptions) {\n const options: InngestExecutionOptions = {\n ...rawOptions,\n stepMode: rawOptions.stepMode ?? StepMode.Async,\n };\n\n super(options);\n\n /**\n * Check we have everything we need for checkpointing\n */\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.options.createResponse) {\n throw new Error(\"createResponse is required for sync step mode\");\n }\n }\n\n this.userFnToRun = this.getUserFnToRun();\n this.state = this.createExecutionState();\n this.fnArg = this.createFnArg();\n\n // Setup middleware\n const mwInstances =\n this.options.middlewareInstances ??\n (this.options.client.middleware || []).map((Cls) => {\n return new Cls({ client: this.options.client });\n });\n this.middlewareManager = new MiddlewareManager(\n this.fnArg,\n () => this.state.stepState,\n mwInstances,\n this.options.fn,\n this.options.client[internalLoggerSymbol],\n );\n\n this.checkpointHandlers = this.createCheckpointHandlers();\n this.initializeTimer(this.state);\n this.initializeCheckpointRuntimeTimer(this.state);\n\n this.devDebug(\n \"created new V1 execution for run;\",\n this.options.requestedRunStep\n ? `wanting to run step \"${this.options.requestedRunStep}\"`\n : \"discovering steps\",\n );\n\n this.devDebug(\"existing state keys:\", Object.keys(this.state.stepState));\n }\n\n /**\n * Idempotently start the execution of the user's function.\n */\n public start() {\n if (!this.execution) {\n this.devDebug(\"starting V1 execution\");\n\n const tracer = trace.getTracer(\"inngest\", version);\n\n this.execution = getAsyncLocalStorage().then((als) => {\n return als.run(\n {\n app: this.options.client,\n execution: {\n ctx: this.fnArg,\n instance: this,\n },\n },\n async () => {\n return tracer.startActiveSpan(\"inngest.execution\", (span) => {\n this.rootSpanId = span.spanContext().spanId;\n clientProcessorMap.get(this.options.client)?.declareStartingSpan({\n span,\n runId: this.options.runId,\n traceparent: this.options.headers[headerKeys.TraceParent],\n tracestate: this.options.headers[headerKeys.TraceState],\n });\n\n return this._start()\n .then((result) => {\n this.devDebug(\"result:\", result);\n return result;\n })\n .finally(() => {\n span.end();\n });\n });\n },\n );\n });\n }\n\n return this.execution;\n }\n\n public addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ) {\n if (!this.state.metadata) {\n this.state.metadata = new Map();\n }\n\n const updates = this.state.metadata.get(stepId) ?? [];\n updates.push({ kind, scope, op, values });\n this.state.metadata.set(stepId, updates);\n\n return true;\n }\n\n /**\n * Starts execution of the user's function and the core loop.\n */\n private async _start(): Promise<ExecutionResult> {\n try {\n const allCheckpointHandler = this.getCheckpointHandler(\"\");\n await this.startExecution();\n\n let i = 0;\n\n for await (const checkpoint of this.state.loop) {\n await allCheckpointHandler(checkpoint, i);\n\n const handler = this.getCheckpointHandler(checkpoint.type);\n const result = await handler(checkpoint, i++);\n\n if (result) {\n return result;\n }\n }\n } catch (error) {\n return this.transformOutput({ error });\n } finally {\n void this.state.loop.return();\n }\n\n /**\n * If we're here, the generator somehow finished without returning a value.\n * This should never happen.\n */\n throw new Error(\"Core loop finished without returning a value\");\n }\n\n private async checkpoint(steps: OutgoingOp[]): Promise<void> {\n if (this.options.stepMode === StepMode.Sync) {\n if (!this.state.checkpointedRun) {\n // We have to start the run\n const res = await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointNewRun({\n runId: this.fnArg.runId,\n event: this.fnArg.event as APIStepPayload,\n steps,\n executionVersion: this.version,\n retries: this.fnArg.maxAttempts ?? defaultMaxRetries,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n\n this.state.checkpointedRun = {\n appId: res.data.app_id,\n fnId: res.data.fn_id,\n token: res.data.token,\n };\n } else {\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointSteps({\n appId: this.state.checkpointedRun!.appId,\n fnId: this.state.checkpointedRun!.fnId,\n runId: this.fnArg.runId,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n }\n } else if (this.options.stepMode === StepMode.AsyncCheckpointing) {\n if (!this.options.queueItemId) {\n throw new Error(\n \"Missing queueItemId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n if (!this.options.internalFnId) {\n throw new Error(\n \"Missing internalFnId for async checkpointing. This is a bug in the Inngest SDK.\",\n );\n }\n\n await retryWithBackoff(\n () =>\n this.options.client[\"inngestApi\"].checkpointStepsAsync({\n runId: this.fnArg.runId,\n fnId: this.options.internalFnId!,\n queueItemId: this.options.queueItemId!,\n steps,\n }),\n CHECKPOINT_RETRY_OPTIONS,\n );\n } else {\n throw new Error(\n \"Checkpointing is only supported in Sync and AsyncCheckpointing step modes. This is a bug in the Inngest SDK.\",\n );\n }\n }\n\n private async checkpointAndSwitchToAsync(\n steps: OutgoingOp[],\n ): Promise<ExecutionResult> {\n await this.checkpoint(steps);\n\n if (!this.state.checkpointedRun?.token) {\n throw new Error(\"Failed to checkpoint and switch to async mode\");\n }\n\n return {\n type: \"change-mode\",\n ctx: this.fnArg,\n ops: this.ops,\n to: StepMode.Async,\n token: this.state.checkpointedRun?.token!,\n };\n }\n\n /**\n * Returns whether we're in the final attempt of execution, or `null` if we\n * can't determine this in the SDK.\n */\n private inFinalAttempt(): boolean | null {\n if (typeof this.fnArg.maxAttempts !== \"number\") {\n return null;\n }\n\n return this.fnArg.attempt + 1 >= this.fnArg.maxAttempts;\n }\n\n /**\n * Creates a handler for every checkpoint type, defining what to do when we\n * reach that checkpoint in the core loop.\n */\n private createCheckpointHandlers(): CheckpointHandlers {\n const commonCheckpointHandler: CheckpointHandlers[StepMode][\"\"] = (\n checkpoint,\n ) => {\n this.devDebug(`${this.options.stepMode} checkpoint:`, checkpoint);\n };\n\n const stepRanHandler = async (\n stepResult: OutgoingOp,\n ): Promise<ExecutionResult> => {\n const transformResult = await this.transformOutput(stepResult);\n\n /**\n * Transforming output will always return either function rejection or\n * resolution. In most cases, this can be immediately returned, but in\n * this particular case we want to handle it differently.\n */\n if (transformResult.type === \"function-resolved\") {\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n step: {\n ...stepResult,\n data: transformResult.data,\n },\n };\n } else if (transformResult.type === \"function-rejected\") {\n const stepForResponse = {\n ...stepResult,\n error: transformResult.error,\n };\n\n if (stepResult.op === StepOpCode.StepFailed) {\n const ser = serializeError(transformResult.error);\n stepForResponse.data = {\n __serialized: true,\n name: ser.name,\n message: ser.message,\n stack: \"\",\n };\n }\n\n return {\n type: \"step-ran\",\n ctx: transformResult.ctx,\n ops: transformResult.ops,\n retriable: transformResult.retriable,\n step: stepForResponse,\n };\n }\n\n return transformResult;\n };\n\n const maybeReturnNewSteps = async (): Promise<\n ExecutionResult | undefined\n > => {\n const newSteps = await this.filterNewSteps(\n Array.from(this.state.steps.values()),\n );\n if (newSteps) {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: newSteps,\n };\n }\n\n return;\n };\n\n const attemptCheckpointAndResume = async (\n stepResult?: OutgoingOp,\n resume = true,\n force = false,\n ): Promise<ExecutionResult | undefined> => {\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n if (stepResult) {\n const stepToResume = this.resumeStepWithResult(stepResult, resume);\n\n // Clear `executingStep` immediately after resuming, before any await.\n // `resumeStepWithResult` resolves the step's promise, queuing a\n // microtask for the function to continue. Any subsequent await (e.g.\n // the `transformOutput` hook) yields and lets that microtask run, so\n // `executingStep` must already be cleared to avoid a false positive\n // NESTING_STEPS warning in the next step's handler.\n delete this.state.executingStep;\n\n // Buffer a copy with transformed data for checkpointing\n this.state.checkpointingStepBuffer.push({\n ...stepToResume,\n data: stepResult.data,\n });\n }\n\n if (\n force ||\n !this.options.checkpointingConfig?.bufferedSteps ||\n this.state.checkpointingStepBuffer.length >=\n this.options.checkpointingConfig.bufferedSteps\n ) {\n this.devDebug(\"checkpointing and resuming execution after step run\");\n\n try {\n this.devDebug(\n `checkpointing all buffered steps:`,\n this.state.checkpointingStepBuffer\n .map((op) => op.displayName || op.id)\n .join(\", \"),\n );\n\n return void (await this.checkpoint(\n this.state.checkpointingStepBuffer,\n ));\n } catch (err) {\n // If checkpointing fails for any reason, fall back to returning\n // ALL buffered steps to the executor via the normal async flow.\n // The executor persists completed steps and rediscovers any\n // parallel/errored steps on the next invocation.\n this.devDebug(\n \"error checkpointing after step run, so falling back to async\",\n err,\n );\n\n const buffered = this.state.checkpointingStepBuffer;\n\n if (buffered.length) {\n return {\n type: \"steps-found\" as const,\n ctx: this.fnArg,\n ops: this.ops,\n steps: buffered as [OutgoingOp, ...OutgoingOp[]],\n };\n }\n\n return;\n } finally {\n // Clear the checkpointing buffer\n this.state.checkpointingStepBuffer = [];\n }\n } else {\n this.devDebug(\n `not checkpointing yet, continuing execution as we haven't reached buffered step limit of ${this.options.checkpointingConfig?.bufferedSteps}`,\n );\n }\n\n return;\n };\n\n const syncHandlers: CheckpointHandlers[StepMode.Sync] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n \"function-resolved\": async (checkpoint, i) => {\n const transformedData = checkpoint.data;\n\n await this.checkpoint([\n {\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: await this.options.createResponse!(transformedData),\n },\n ]);\n\n // Apply middleware transformation before returning\n return await this.transformOutput({ data: checkpoint.data });\n },\n\n \"function-rejected\": async (checkpoint) => {\n // If the function throws during sync execution, we want to switch to\n // async mode so that we can retry. The exception is that we're already\n // at max attempts, in which case we do actually want to reject.\n if (this.inFinalAttempt()) {\n // Apply middleware transformation before returning\n return await this.transformOutput({ error: checkpoint.error });\n }\n\n // Otherwise, checkpoint the error and switch to async mode\n return this.checkpointAndSwitchToAsync([\n {\n id: _internals.hashId(\"complete\"), // ID is not important here\n op: StepOpCode.StepError,\n error: checkpoint.error,\n },\n ]);\n },\n\n \"step-not-found\": () => {\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n error: new Error(\n \"Step not found when checkpointing; this should never happen\",\n ),\n ops: this.ops,\n retriable: false,\n };\n },\n\n \"steps-found\": async ({ steps }) => {\n // If we're entering parallelism or async mode, checkpoint and switch\n // to async.\n if (steps.length !== 1 || steps[0].mode !== StepMode.Sync) {\n return this.checkpointAndSwitchToAsync(\n steps.map((step) => ({ ...step, id: step.hashedId })),\n );\n }\n\n // Otherwise we're good to start executing things right now.\n const result = await this.executeStep(steps[0]);\n\n if (result.error) {\n return this.checkpointAndSwitchToAsync([result]);\n }\n\n // Resume the step with original data for user code\n const stepToResume = this.resumeStepWithResult(result);\n\n // Clear executingStep now that the step result has been processed.\n // Without this, the next step discovery would see stale state and\n // emit a false positive NESTING_STEPS warning.\n delete this.state.executingStep;\n\n return void (await this.checkpoint([stepToResume]));\n },\n\n \"checkpointing-runtime-reached\": () => {\n return this.checkpointAndSwitchToAsync([\n {\n op: StepOpCode.DiscoveryRequest,\n\n // Append with time because we don't want Executor-side\n // idempotency to dedupe. There may have been a previous\n // discovery request.\n id: _internals.hashId(`discovery-request-${Date.now()}`),\n },\n ]);\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n const asyncHandlers: CheckpointHandlers[StepMode.Async] = {\n /**\n * Run for all checkpoints. Best used for logging or common actions.\n * Use other handlers to return values and interrupt the core loop.\n */\n \"\": commonCheckpointHandler,\n\n /**\n * The user's function has completed and returned a value.\n */\n \"function-resolved\": async ({ data }) => {\n // Check for unreported new steps (e.g. from `Promise.race` where\n // the winning branch completed before losing branches reported)\n const newStepsResult = await maybeReturnNewSteps();\n if (newStepsResult) {\n return newStepsResult;\n }\n\n // We need to do this even here for async, as we could be returning\n // data from an API endpoint, even if we were triggered async.\n if (this.options.createResponse) {\n data = await this.options.createResponse(data);\n }\n\n return await this.transformOutput({ data });\n },\n\n /**\n * The user's function has thrown an error.\n */\n \"function-rejected\": async (checkpoint) => {\n return await this.transformOutput({ error: checkpoint.error });\n },\n\n /**\n * We've found one or more steps. Here we may want to run a step or report\n * them back to Inngest.\n */\n \"steps-found\": async ({ steps }) => {\n const stepResult = await this.tryExecuteStep(steps);\n if (stepResult) {\n return stepRanHandler(stepResult);\n }\n\n return maybeReturnNewSteps();\n },\n\n /**\n * While trying to find a step that Inngest has told us to run, we've\n * timed out or have otherwise decided that it doesn't exist.\n */\n \"step-not-found\": ({ step }) => {\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n return {\n type: \"step-not-found\",\n ctx: this.fnArg,\n ops: this.ops,\n step,\n foundSteps,\n totalFoundSteps,\n };\n },\n\n \"checkpointing-runtime-reached\": () => {\n throw new Error(\n \"Checkpointing maximum runtime reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n throw new Error(\n \"Checkpointing maximum buffer interval reached, but this is not in a checkpointing step mode. This is a bug in the Inngest SDK.\",\n );\n },\n };\n\n const asyncCheckpointingHandlers: CheckpointHandlers[StepMode.AsyncCheckpointing] =\n {\n \"\": commonCheckpointHandler,\n \"function-resolved\": async (checkpoint, i) => {\n const output = await asyncHandlers[\"function-resolved\"](\n checkpoint,\n i,\n );\n if (output?.type === \"function-resolved\") {\n const steps = this.state.checkpointingStepBuffer.concat({\n op: StepOpCode.RunComplete,\n id: _internals.hashId(\"complete\"), // ID is not important here\n data: output.data,\n });\n\n if (isNonEmpty(steps)) {\n return {\n type: \"steps-found\",\n ctx: output.ctx,\n ops: output.ops,\n steps,\n };\n }\n }\n\n return;\n },\n \"function-rejected\": async (checkpoint) => {\n // If we have buffered steps, attempt checkpointing them first\n if (this.state.checkpointingStepBuffer.length) {\n const fallback = await attemptCheckpointAndResume(\n undefined,\n false,\n true,\n );\n if (fallback) {\n return fallback;\n }\n }\n\n return await this.transformOutput({ error: checkpoint.error });\n },\n \"step-not-found\": asyncHandlers[\"step-not-found\"],\n \"steps-found\": async ({ steps }) => {\n // Note that if we have a requested run step, we'll never be\n // checkpointing, as that's an async parallel execution mode.\n\n // Break found steps in to { stepsToResume, newSteps }\n const { stepsToResume, newSteps } = steps.reduce(\n (acc, step) => {\n if (!step.hasStepState) {\n acc.newSteps.push(step);\n } else if (!step.fulfilled) {\n acc.stepsToResume.push(step);\n }\n\n return acc;\n },\n { stepsToResume: [], newSteps: [] } as {\n stepsToResume: FoundStep[];\n newSteps: FoundStep[];\n },\n );\n\n this.devDebug(\"split found steps in to:\", {\n stepsToResume: stepsToResume.length,\n newSteps: newSteps.length,\n });\n\n // Got new steps? Exit early.\n if (!this.options.requestedRunStep && newSteps.length) {\n const stepResult = await this.tryExecuteStep(newSteps);\n if (stepResult) {\n this.devDebug(`executed step \"${stepResult.id}\" successfully`);\n\n // We executed a step!\n //\n // We know that because we're in this mode, we're always free to\n // checkpoint and continue if we ran a step and it was successful.\n if (stepResult.error) {\n // Flush buffered steps before falling back to async,\n // so previously-successful steps aren't lost.\n if (this.state.checkpointingStepBuffer.length) {\n const fallback = await attemptCheckpointAndResume(\n undefined,\n false,\n true,\n );\n if (fallback) {\n return fallback;\n }\n }\n\n // If we failed, go back to the regular async flow.\n return stepRanHandler(stepResult);\n }\n\n // If we're here, we successfully ran a step, so we may now need\n // to checkpoint it depending on the step buffer configured.\n return await attemptCheckpointAndResume(stepResult);\n }\n\n // Flush any buffered checkpoint steps before returning\n // new steps to the executor. Without this, steps executed\n // in-process during AsyncCheckpointing but not yet\n // checkpointed would be lost. When the executor later calls\n // back with requestedRunStep, those steps would be missing\n // from stepState, causing \"step not found\" errors.\n if (this.state.checkpointingStepBuffer.length) {\n const fallback = await attemptCheckpointAndResume(\n undefined,\n false,\n true,\n );\n if (fallback) {\n return fallback;\n }\n }\n\n return maybeReturnNewSteps();\n }\n\n // If we have stepsToResume, resume as many as possible and resume execution\n if (stepsToResume.length) {\n this.devDebug(`resuming ${stepsToResume.length} steps`);\n\n for (const st of stepsToResume) {\n this.resumeStepWithResult({\n ...st,\n id: st.hashedId,\n });\n }\n }\n\n return;\n },\n \"checkpointing-runtime-reached\": async () => {\n return {\n type: \"steps-found\",\n ctx: this.fnArg,\n ops: this.ops,\n steps: [\n {\n op: StepOpCode.DiscoveryRequest,\n\n // Append with time because we don't want Executor-side\n // idempotency to dedupe. There may have been a previous\n // discovery request.\n id: _internals.hashId(`discovery-request-${Date.now()}`),\n },\n ],\n };\n },\n\n \"checkpointing-buffer-interval-reached\": () => {\n return attemptCheckpointAndResume(undefined, false, true);\n },\n };\n\n return {\n [StepMode.Async]: asyncHandlers,\n [StepMode.Sync]: syncHandlers,\n [StepMode.AsyncCheckpointing]: asyncCheckpointingHandlers,\n };\n }\n\n private getCheckpointHandler(type: keyof CheckpointHandlers[StepMode]) {\n return this.checkpointHandlers[this.options.stepMode][type] as (\n checkpoint: Checkpoint,\n iteration: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n }\n\n private async tryExecuteStep(\n steps: FoundStep[],\n ): Promise<OutgoingOp | undefined> {\n const hashedStepIdToRun =\n this.options.requestedRunStep || this.getEarlyExecRunStep(steps);\n if (!hashedStepIdToRun) {\n return;\n }\n\n const step = steps.find(\n (step) => step.hashedId === hashedStepIdToRun && step.fn,\n );\n\n if (step) {\n return await this.executeStep(step);\n }\n\n /**\n * Ensure we reset the timeout if we have a requested run step but couldn't\n * find it, but also that we don't reset if we found and executed it.\n */\n return void this.timeout?.reset();\n }\n\n /**\n * Given a list of outgoing ops, decide if we can execute an op early and\n * return the ID of the step to execute if we can.\n */\n private getEarlyExecRunStep(steps: FoundStep[]): string | undefined {\n /**\n * We may have been disabled due to parallelism, in which case we can't\n * immediately execute unless explicitly requested.\n */\n if (this.options.disableImmediateExecution) return;\n\n const unfulfilledSteps = steps.filter((step) => !step.fulfilled);\n if (unfulfilledSteps.length !== 1) return;\n\n const op = unfulfilledSteps[0];\n\n if (\n op &&\n op.op === StepOpCode.StepPlanned\n // TODO We must individually check properties here that we do not want to\n // execute on, such as retry counts. Nothing exists here that falls in to\n // this case, but should be accounted for when we add them.\n // && typeof op.opts === \"undefined\"\n ) {\n return op.hashedId;\n }\n\n return;\n }\n\n private async filterNewSteps(\n foundSteps: FoundStep[],\n ): Promise<[OutgoingOp, ...OutgoingOp[]] | undefined> {\n if (this.options.requestedRunStep) {\n return;\n }\n\n const newSteps = foundSteps.reduce((acc, step) => {\n if (!step.hasStepState) {\n acc.push(step);\n }\n\n return acc;\n }, [] as FoundStep[]);\n\n if (!newSteps.length) {\n return;\n }\n\n await this.middlewareManager.onMemoizationEnd();\n\n const stepList = newSteps.map<OutgoingOp>((step) => {\n return {\n displayName: step.displayName,\n op: step.op,\n id: step.hashedId,\n name: step.name,\n opts: step.opts,\n userland: step.userland,\n };\n });\n\n if (!isNonEmpty(stepList)) {\n throw new UnreachableError(\"stepList is empty\");\n }\n\n return stepList;\n }\n\n private async executeStep(foundStep: FoundStep): Promise<OutgoingOp> {\n const { id, name, opts, fn, displayName, userland, hashedId } = foundStep;\n const { stepInfo, wrappedHandler, setActualHandler } = foundStep.middleware;\n\n this.devDebug(`preparing to execute step \"${id}\"`);\n\n this.timeout?.clear();\n\n const outgoingOp: OutgoingOp = {\n id: hashedId,\n op: StepOpCode.StepRun,\n name,\n opts,\n displayName,\n userland,\n };\n this.state.executingStep = outgoingOp;\n\n const store = await getAsyncCtx();\n\n if (store?.execution) {\n store.execution.executingStep = {\n id,\n name: displayName,\n };\n }\n\n this.devDebug(`executing step \"${id}\"`);\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.declareStepExecution(\n this.rootSpanId,\n hashedId,\n this.options.data?.attempt ?? 0,\n );\n }\n\n let interval: GoInterval | undefined;\n\n // `fn` already has middleware-transformed args baked in via `fnArgs` (i.e.\n // the `transformStepInput` middleware hook already ran).\n const actualHandler = () => runAsPromise(fn);\n\n await this.middlewareManager.onMemoizationEnd();\n await this.middlewareManager.onStepStart(stepInfo);\n\n // If wrappedHandler hasn't been called yet (no deferred from discovery),\n // set one up so wrapStep's next() still blocks until memoization.\n if (!foundStep.memoizationDeferred) {\n const deferred = createDeferredPromise<unknown>();\n foundStep.memoizationDeferred = deferred;\n setActualHandler(() => deferred.promise);\n foundStep.transformedResultPromise = wrappedHandler();\n foundStep.transformedResultPromise.catch(() => {\n // Swallow — errors handled by handle()\n });\n }\n\n // Build wrapStepHandler chain around the actual handler\n const wrappedActualHandler =\n this.middlewareManager.buildWrapStepHandlerChain(actualHandler, stepInfo);\n\n return goIntervalTiming(() => wrappedActualHandler())\n .finally(() => {\n this.devDebug(`finished executing step \"${id}\"`);\n\n this.state.executingStep = undefined;\n\n if (this.rootSpanId && this.options.checkpointingConfig) {\n clientProcessorMap\n .get(this.options.client)\n ?.clearStepExecution(this.rootSpanId);\n }\n\n if (store?.execution) {\n delete store.execution.executingStep;\n }\n })\n .then<OutgoingOp>(async ({ resultPromise, interval: _interval }) => {\n interval = _interval;\n const metadata = this.state.metadata?.get(id);\n const serverData = await resultPromise;\n\n // Don't resolve memoizationDeferred here. wrapStep's next() must\n // block until the step is actually memoized (i.e. handle() fires\n // with confirmed data from the server). handle() resolves it.\n await this.middlewareManager.onStepComplete(stepInfo, serverData);\n\n return {\n ...outgoingOp,\n data: serverData,\n ...(metadata && metadata.length > 0 ? { metadata: metadata } : {}),\n };\n })\n .catch<OutgoingOp>((error) => {\n // Don't reject memoizationDeferred — handle() will reject it when\n // the error is memoized.\n return this.buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n });\n })\n .then((op) => ({\n ...op,\n timing: interval,\n }));\n }\n\n /**\n * Starts execution of the user's function, including triggering checkpoints\n * and middleware hooks where appropriate.\n */\n private async startExecution(): Promise<void> {\n /**\n * Start the timer to time out the run if needed.\n */\n void this.timeout?.start();\n void this.checkpointingMaxRuntimeTimer?.start();\n void this.checkpointingMaxBufferIntervalTimer?.start();\n\n const fnInputResult = await this.middlewareManager.transformFunctionInput();\n this.applyFunctionInputMutations(fnInputResult);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (this.state.stepsToFulfill === 0 && this.fnArg.attempt === 0) {\n await this.middlewareManager.onRunStart();\n }\n\n const innerHandler: () => Promise<unknown> = async () => {\n await this.validateEventSchemas();\n return this.userFnToRun(this.fnArg);\n };\n\n const runHandler = this.middlewareManager.wrapRunHandler(innerHandler);\n\n runAsPromise(runHandler)\n .then(async (data) => {\n await this.middlewareManager.onRunComplete(data);\n this.state.setCheckpoint({ type: \"function-resolved\", data });\n })\n .catch(async (error) => {\n // Preserve Error instances; stringify non-Error throws (e.g. `throw {}`)\n let err: Error;\n if (error instanceof Error) {\n err = error;\n } else if (typeof error === \"object\") {\n err = new Error(JSON.stringify(error));\n } else {\n err = new Error(String(error));\n }\n\n await this.middlewareManager.onRunError(err, this.isFinalAttempt(err));\n this.state.setCheckpoint({ type: \"function-rejected\", error: err });\n });\n }\n\n /**\n * Whether this error will not be retried (NonRetriableError or last attempt).\n */\n private isFinalAttempt(error: unknown): boolean {\n if (\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\"\n ) {\n return true;\n }\n\n return Boolean(\n this.fnArg.maxAttempts &&\n this.fnArg.maxAttempts - 1 === this.fnArg.attempt,\n );\n }\n\n /**\n * Build the OutgoingOp for a failed step, notifying middleware and choosing\n * retriable vs non-retriable opcode.\n */\n private async buildStepErrorOp({\n error,\n id,\n outgoingOp,\n stepInfo,\n }: {\n error: unknown;\n id: string;\n outgoingOp: OutgoingOp;\n stepInfo: Middleware.StepInfo;\n }): Promise<OutgoingOp> {\n const isFinal = this.isFinalAttempt(error);\n const metadata = this.state.metadata?.get(id);\n\n await this.middlewareManager.onStepError(\n stepInfo,\n error instanceof Error ? error : new Error(String(error)),\n isFinal,\n );\n\n return {\n ...outgoingOp,\n error,\n op: isFinal ? StepOpCode.StepFailed : StepOpCode.StepError,\n ...(metadata && metadata.length > 0 ? { metadata } : {}),\n };\n }\n\n /**\n * Validate event data against schemas defined in function triggers.\n */\n private async validateEventSchemas(): Promise<void> {\n const triggers = this.options.fn.opts.triggers;\n if (!triggers || triggers.length === 0) return;\n\n const fnArgEvents = this.fnArg.events;\n if (!fnArgEvents || fnArgEvents.length === 0) return;\n\n const events = fnArgEvents.map((event) => ({\n name: event.name,\n data: event.data,\n }));\n\n await validateEvents(events, triggers);\n }\n\n /**\n * Using middleware, transform output before returning.\n */\n private transformOutput(dataOrError: {\n data?: unknown;\n error?: unknown;\n }): ExecutionResult {\n const { data, error } = dataOrError;\n\n if (typeof error !== \"undefined\") {\n /**\n * Ensure we give middleware the chance to decide on retriable behaviour\n * by looking at the error returned from output transformation.\n */\n let retriable: boolean | string = !(\n error instanceof NonRetriableError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"NonRetriableError\" ||\n (error instanceof StepError &&\n error === this.state.recentlyRejectedStepError)\n );\n if (\n retriable &&\n (error instanceof RetryAfterError ||\n // biome-ignore lint/suspicious/noExplicitAny: instanceof fails across module boundaries\n (error as any)?.name === \"RetryAfterError\")\n ) {\n retriable = (error as RetryAfterError).retryAfter;\n }\n\n const serializedError = serializeError(error);\n\n return {\n type: \"function-rejected\",\n ctx: this.fnArg,\n ops: this.ops,\n error: serializedError,\n retriable,\n };\n }\n\n return {\n type: \"function-resolved\",\n ctx: this.fnArg,\n ops: this.ops,\n data: undefinedToNull(data),\n };\n }\n\n private createExecutionState(): ExecutionState {\n const d = createDeferredPromiseWithStack<Checkpoint>();\n let checkpointResolve = d.deferred.resolve;\n const checkpointResults = d.results;\n\n const loop: ExecutionState[\"loop\"] = (async function* (\n cleanUp?: () => void,\n ) {\n try {\n while (true) {\n const res = (await checkpointResults.next()).value;\n if (res) {\n yield res;\n }\n }\n } finally {\n cleanUp?.();\n }\n })(() => {\n this.timeout?.clear();\n this.checkpointingMaxRuntimeTimer?.clear();\n this.checkpointingMaxBufferIntervalTimer?.clear();\n void checkpointResults.return();\n });\n\n const stepsToFulfill = Object.keys(this.options.stepState).length;\n\n const state: ExecutionState = {\n stepState: this.options.stepState,\n stepsToFulfill,\n steps: new Map(),\n loop,\n hasSteps: Boolean(stepsToFulfill),\n stepCompletionOrder: [...this.options.stepCompletionOrder],\n remainingStepsToBeSeen: new Set(this.options.stepCompletionOrder),\n setCheckpoint: (checkpoint: Checkpoint) => {\n this.devDebug(\"setting checkpoint:\", checkpoint.type);\n\n ({ resolve: checkpointResolve } = checkpointResolve(checkpoint));\n },\n allStateUsed: () => {\n return this.state.remainingStepsToBeSeen.size === 0;\n },\n checkpointingStepBuffer: [],\n metadata: new Map(),\n };\n\n return state;\n }\n\n get ops(): Record<string, MemoizedOp> {\n return Object.fromEntries(this.state.steps);\n }\n\n private createFnArg(): Context.Any {\n const step = this.createStepTools();\n const experimentStepRun = (step as unknown as ExperimentStepTools)[\n experimentStepRunSymbol\n ];\n\n let fnArg = {\n ...(this.options.data as { event: EventPayload }),\n step,\n group: createGroupTools({ experimentStepRun }),\n } as Context.Any;\n\n /**\n * Handle use of the `onFailure` option by deserializing the error.\n */\n if (this.options.isFailureHandler) {\n const eventData = z\n .object({ error: jsonErrorSchema })\n .parse(fnArg.event?.data);\n\n (fnArg as Partial<Pick<FailureEventArgs, \"error\">>) = {\n ...fnArg,\n error: deserializeError(eventData.error),\n };\n }\n\n return this.options.transformCtx?.(fnArg) ?? fnArg;\n }\n\n /**\n * Apply mutations from `transformFunctionInput` back to execution state.\n * Allows middleware to modify event data, step tools, memoized step data,\n * and inject custom fields into the handler context.\n */\n private applyFunctionInputMutations(\n result: Middleware.TransformFunctionInputArgs,\n ): void {\n const { event, events, step, ...extensions } = result.ctx;\n\n // Mutate in place so the ALS store's reference to this.fnArg stays valid.\n if (event !== this.fnArg.event) {\n this.fnArg.event = event;\n }\n\n if (events !== this.fnArg.events) {\n this.fnArg.events = events;\n }\n\n if (step !== this.fnArg.step) {\n this.fnArg.step = step;\n }\n\n if (Object.keys(extensions).length > 0) {\n Object.assign(this.fnArg, extensions);\n }\n\n // Apply step data mutations\n for (const [hashedId, stepData] of Object.entries(result.steps)) {\n const existing = this.state.stepState[hashedId];\n if (\n existing &&\n stepData &&\n stepData.type === \"data\" &&\n stepData.data !== existing.data\n ) {\n this.state.stepState[hashedId] = { ...existing, data: stepData.data };\n }\n }\n }\n\n private createStepTools(): ReturnType<typeof createStepTools> {\n /**\n * A list of steps that have been found and are being rolled up before being\n * reported to the core loop.\n */\n const foundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the subset of found steps to report that have not yet been\n * handled. Used for fast access to steps that need to be handled in order.\n */\n const unhandledFoundStepsToReport: Map<string, FoundStep> = new Map();\n\n /**\n * A map of the latest sequential step indexes found for each step ID. Used\n * to ensure that we don't index steps in parallel.\n *\n * Note that these must be sequential; if we've seen or assigned `a:1`,\n * `a:2` and `a:4`, the latest sequential step index is `2`.\n *\n */\n const expectedNextStepIndexes: Map<string, number> = new Map();\n\n /**\n * An ordered list of step IDs that have yet to be handled in this\n * execution. Used to ensure that we handle steps in the order they were\n * found and based on the `stepCompletionOrder` in this execution's state.\n */\n const remainingStepCompletionOrder: string[] =\n this.state.stepCompletionOrder.slice();\n\n /**\n * A promise that's used to ensure that step reporting cannot be run more than\n * once in a given asynchronous time span.\n */\n let foundStepsReportPromise: Promise<void> | undefined;\n\n /**\n * A flag used to ensure that we only warn about parallel indexing once per\n * execution to avoid spamming the console.\n */\n let warnOfParallelIndexing = false;\n\n /**\n * Counts the number of times we've extended this tick.\n */\n let tickExtensionCount = 0;\n\n /**\n * Given a colliding step ID, maybe warn the user about parallel indexing.\n */\n const maybeWarnOfParallelIndexing = (userlandCollisionId: string) => {\n if (warnOfParallelIndexing) {\n return;\n }\n\n const hashedCollisionId = _internals.hashId(userlandCollisionId);\n\n const stepExists = this.state.steps.has(hashedCollisionId);\n if (stepExists) {\n const stepFoundThisTick = foundStepsToReport.has(hashedCollisionId);\n if (!stepFoundThisTick) {\n warnOfParallelIndexing = true;\n\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n {\n message: `Duplicate step ID \"${userlandCollisionId}\" detected across parallel chains`,\n explanation:\n \"Using the same ID for steps in different parallel chains can cause unexpected behaviour. Your function is still running.\",\n action:\n \"Use a unique ID for each step, especially those in parallel.\",\n code: ErrCode.AUTOMATIC_PARALLEL_INDEXING,\n },\n );\n }\n }\n };\n\n /**\n * A helper used to report steps to the core loop. Used after adding an item\n * to `foundStepsToReport`.\n */\n const reportNextTick = () => {\n // Being explicit instead of using `??=` to appease TypeScript.\n if (foundStepsReportPromise) {\n return;\n }\n\n let extensionPromise: Promise<void>;\n if (++tickExtensionCount >= 10) {\n tickExtensionCount = 0;\n extensionPromise = resolveNextTick();\n } else {\n extensionPromise = resolveAfterPending();\n }\n\n foundStepsReportPromise = extensionPromise.then(() => {\n foundStepsReportPromise = undefined;\n\n for (let i = 0; i < remainingStepCompletionOrder.length; i++) {\n const nextStepId = remainingStepCompletionOrder[i];\n if (!nextStepId) {\n // Strange - skip this empty index\n continue;\n }\n\n const handled = unhandledFoundStepsToReport.get(nextStepId)?.handle();\n if (handled) {\n remainingStepCompletionOrder.splice(i, 1);\n unhandledFoundStepsToReport.delete(nextStepId);\n return void reportNextTick();\n }\n }\n\n // If we've handled no steps in this \"tick,\" roll up everything we've\n // found and report it.\n const steps = [...foundStepsToReport.values()];\n foundStepsToReport.clear();\n unhandledFoundStepsToReport.clear();\n\n if (!isNonEmpty(steps)) {\n return;\n }\n\n return void this.state.setCheckpoint({\n type: \"steps-found\",\n steps: steps,\n });\n });\n };\n\n /**\n * A helper used to push a step to the list of steps to report.\n */\n const pushStepToReport = (step: FoundStep) => {\n foundStepsToReport.set(step.hashedId, step);\n unhandledFoundStepsToReport.set(step.hashedId, step);\n reportNextTick();\n };\n\n const stepHandler: StepHandler = async ({\n args,\n matchOp,\n opts,\n }): Promise<unknown> => {\n const stepOptions = getStepOptions(args[0]);\n const opId = matchOp(stepOptions, ...args.slice(1));\n\n if (this.state.executingStep) {\n /**\n * If a step is found after asynchronous actions during another step's\n * execution, everything is fine. The problem here is if we've found\n * that a step nested inside another a step, which is something we don't\n * support at the time of writing.\n *\n * In this case, we could use something like Async Hooks to understand\n * how the step is being triggered, though this isn't available in all\n * environments.\n *\n * Therefore, we'll only show a warning here to indicate that this is\n * potentially an issue.\n */\n this.options.client[\"warnMetadata\"](\n { run_id: this.fnArg.runId },\n ErrCode.NESTING_STEPS,\n {\n message: `Nested step tooling detected in \"${opId.displayName ?? opId.id}\"`,\n explanation:\n \"Nesting step.* calls is not supported. This warning may also appear if steps are separated by regular async calls, which is fine.\",\n action:\n \"Avoid using step.* inside other step.* calls. Use a separate async function or promise chaining to compose steps.\",\n code: ErrCode.NESTING_STEPS,\n },\n );\n }\n\n // Apply middleware transformations (may change step ID, affecting\n // memoization lookup)\n const {\n hashedId,\n isFulfilled,\n setActualHandler,\n stepInfo,\n stepState,\n wrappedHandler,\n } = await this.applyMiddlewareToStep(\n opId,\n expectedNextStepIndexes,\n maybeWarnOfParallelIndexing,\n );\n\n const { promise, resolve, reject } = createDeferredPromise();\n\n let extraOpts: Record<string, unknown> | undefined;\n let fnArgs = [...args];\n\n if (\n typeof stepState?.input !== \"undefined\" &&\n Array.isArray(stepState.input)\n ) {\n switch (opId.op) {\n // `step.run()` has its function input affected\n case StepOpCode.StepPlanned: {\n fnArgs = [...args.slice(0, 2), ...stepState.input];\n\n extraOpts = { input: [...stepState.input] };\n break;\n }\n\n // `step.ai.infer()` has its body affected\n case StepOpCode.AiGateway: {\n extraOpts = {\n body: {\n ...(typeof opId.opts?.body === \"object\"\n ? { ...opId.opts.body }\n : {}),\n ...stepState.input[0],\n },\n };\n break;\n }\n }\n }\n\n // If transformStepInput middleware may have changed the input, update\n // `fnArgs` so `fn` uses the transformed values. Skip if replay already\n // set `extraOpts`.\n if (!extraOpts && Array.isArray(stepInfo.input)) {\n fnArgs = [...args.slice(0, 2), ...stepInfo.input];\n }\n\n const step: FoundStep = {\n ...opId,\n opts: { ...opId.opts, ...extraOpts },\n rawArgs: fnArgs,\n hashedId,\n input: stepState?.input,\n\n fn: opts?.fn ? () => opts.fn?.(this.fnArg, ...fnArgs) : undefined,\n promise,\n fulfilled: isFulfilled,\n hasStepState: Boolean(stepState),\n displayName: opId.displayName ?? opId.id,\n handled: false,\n\n // Middleware context for deferred handler pattern\n middleware: {\n wrappedHandler,\n stepInfo,\n setActualHandler,\n },\n\n handle: () => {\n if (step.handled) {\n return false;\n }\n\n this.devDebug(`handling step \"${hashedId}\"`);\n\n step.handled = true;\n\n // Refetch step state because it may have been changed since we found\n // the step. This could be due to checkpointing, where we run this\n // live and then return to the function.\n const result = this.state.stepState[hashedId];\n\n if (step.fulfilled && result) {\n result.fulfilled = true;\n\n // For some execution scenarios such as testing, `data`, `error`,\n // and `input` may be `Promises`. This could also be the case for\n // future middleware applications. For this reason, we'll make sure\n // the values are fully resolved before continuing.\n void Promise.all([result.data, result.error, result.input]).then(\n async () => {\n // If the wrapStep chain already ran during discovery in this\n // same request (checkpointing), reuse its result instead of\n // firing wrappedHandler() again. This prevents middleware from\n // seeing a duplicate wrapStep call per step per request.\n if (step.transformedResultPromise) {\n // Resolve the memoization deferred so wrapStep's next()\n // unblocks. The step data is now confirmed memoized.\n if (step.memoizationDeferred) {\n if (typeof result.data !== \"undefined\") {\n step.memoizationDeferred.resolve(await result.data);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n step.memoizationDeferred.reject(stepError);\n }\n }\n\n step.transformedResultPromise.then(resolve, reject);\n return;\n }\n\n // The wrapStep chain is about to fire again to resolve the\n // step promise through middleware (e.g. deserialization).\n // Mark the step as memoized so middleware can distinguish\n // this from the original execution call.\n //\n // This need for this change was discovered when checkpointing +\n // middleware's \"double `wrapStep` call\" behavior had `memoized:\n // false` on the 2nd call\n step.middleware.stepInfo.memoized = true;\n\n if (typeof result.data !== \"undefined\") {\n // Validate waitForEvent results against the schema if present\n // Skip validation if result.data is null (timeout case)\n if (\n opId.op === StepOpCode.WaitForEvent &&\n result.data !== null\n ) {\n const { event } = (step.rawArgs?.[1] ?? {}) as {\n event: unknown;\n };\n if (!event) {\n // Unreachable\n throw new Error(\"Missing event option in waitForEvent\");\n }\n try {\n await validateEvents(\n [result.data],\n\n // @ts-expect-error - This is a full event object at runtime\n [{ event }],\n );\n } catch (err) {\n this.state.recentlyRejectedStepError = new StepError(\n opId.id,\n err,\n );\n reject(this.state.recentlyRejectedStepError);\n return;\n }\n }\n\n // Set inner handler to return memoized data\n step.middleware.setActualHandler(() =>\n Promise.resolve(result.data),\n );\n\n step.middleware.wrappedHandler().then(resolve);\n } else {\n const stepError = new StepError(opId.id, result.error);\n this.state.recentlyRejectedStepError = stepError;\n\n // Set inner handler to reject with step error\n step.middleware.setActualHandler(() =>\n Promise.reject(stepError),\n );\n\n step.middleware.wrappedHandler().catch(reject);\n }\n },\n );\n }\n\n return true;\n },\n };\n\n this.state.steps.set(hashedId, step);\n this.state.hasSteps = true;\n\n const isNewStepWithHandler = !isFulfilled && !stepState && step.fn;\n if (isNewStepWithHandler) {\n // New, never-seen step with a handler (e.g. `step.run`). Kick off the\n // middleware wrapStep chain now so it runs during discovery, not later\n // in executeStep.\n //\n // This is necessary so that middleware can inject their own steps.\n // Reporting is deferred to the center of the onion so that if\n // middleware throws or injects prerequisites, the step is never\n // reported.\n const deferred = createDeferredPromise<unknown>();\n step.memoizationDeferred = deferred;\n\n setActualHandler(() => {\n pushStepToReport(step);\n return deferred.promise;\n });\n\n step.transformedResultPromise = wrappedHandler();\n step.transformedResultPromise.catch((error) => {\n reject(error);\n });\n } else {\n pushStepToReport(step);\n }\n\n return promise;\n };\n\n return createStepTools(this.options.client, this, stepHandler);\n }\n\n /**\n * Applies middleware transformations to a step, resolves ID collisions,\n * and performs memoization lookup.\n */\n private async applyMiddlewareToStep(\n opId: HashedOp,\n expectedNextStepIndexes: Map<string, number>,\n maybeWarnOfParallelIndexing: (userlandCollisionId: string) => void,\n ): Promise<MiddlewareApplicationResult> {\n // 1. Resolve initial collision with original ID\n const initialCollision = resolveStepIdCollision({\n baseId: opId.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (initialCollision.finalId !== opId.id) {\n maybeWarnOfParallelIndexing(opId.id);\n opId.id = initialCollision.finalId;\n if (initialCollision.index !== undefined) {\n opId.userland.index = initialCollision.index;\n }\n }\n\n const originalId = opId.userland.id;\n let hashedId = _internals.hashId(opId.id);\n\n // 2. Apply middleware (stepType, input extraction, deferred handler).\n // Pass preliminary memoization status so middleware sees it.\n const prepared = await this.middlewareManager.applyToStep({\n displayName: opId.displayName ?? opId.userland.id,\n hashedId,\n memoized:\n Boolean(this.state.stepState[hashedId]) &&\n typeof this.state.stepState[hashedId]?.input === \"undefined\",\n op: opId.op,\n opts: opId.opts,\n userlandId: opId.userland.id,\n });\n const { entryPoint, opName, opOpts, setActualHandler, stepInfo } = prepared;\n\n if (opName !== undefined) {\n opId.name = opName;\n }\n if (opOpts !== undefined) {\n opId.opts = opOpts;\n }\n\n // 3. If middleware changed the step ID, re-resolve collisions\n if (stepInfo.options.id !== originalId) {\n opId.id = stepInfo.options.id;\n opId.userland.id = stepInfo.options.id;\n\n const secondCollision = resolveStepIdCollision({\n baseId: stepInfo.options.id,\n expectedIndexes: expectedNextStepIndexes,\n stepsMap: this.state.steps,\n });\n if (secondCollision.finalId !== stepInfo.options.id) {\n opId.id = secondCollision.finalId;\n opId.userland.id = secondCollision.finalId;\n stepInfo.options.id = secondCollision.finalId;\n if (secondCollision.index !== undefined) {\n opId.userland.index = secondCollision.index;\n }\n }\n\n // Recompute hashedId with final ID\n hashedId = _internals.hashId(opId.id);\n stepInfo.hashedId = hashedId;\n }\n\n // 4. Final memoization lookup with potentially modified hashedId.\n // Also marks step as seen and may trigger onMemoizationEnd.\n const stepState = this.state.stepState[hashedId];\n let isFulfilled = false;\n if (stepState) {\n stepState.seen = true;\n this.state.remainingStepsToBeSeen.delete(hashedId);\n\n if (this.state.allStateUsed()) {\n await this.middlewareManager.onMemoizationEnd();\n }\n\n if (typeof stepState.input === \"undefined\") {\n isFulfilled = true;\n }\n stepInfo.memoized = isFulfilled;\n } else {\n stepInfo.memoized = false;\n }\n\n // 5. Build wrapStep chain after all mutations so middleware sees final values\n const wrappedHandler = this.middlewareManager.buildWrapStepChain(\n entryPoint,\n stepInfo,\n );\n\n return {\n hashedId,\n stepInfo,\n wrappedHandler,\n setActualHandler,\n stepState,\n isFulfilled,\n };\n }\n\n private resumeStepWithResult(resultOp: OutgoingOp, resume = true): FoundStep {\n const userlandStep = this.state.steps.get(resultOp.id);\n if (!userlandStep) {\n throw new Error(\n \"Step not found in memoization state during async checkpointing; this should never happen and is a bug in the Inngest SDK\",\n );\n }\n\n const data = undefinedToNull(resultOp.data);\n\n userlandStep.data = data;\n userlandStep.timing = resultOp.timing;\n userlandStep.op = resultOp.op;\n userlandStep.id = resultOp.id;\n\n if (resume) {\n userlandStep.fulfilled = true;\n userlandStep.hasStepState = true;\n this.state.stepState[resultOp.id] = userlandStep;\n\n userlandStep.handle();\n }\n\n return userlandStep;\n }\n\n private getUserFnToRun(): Handler.Any {\n if (!this.options.isFailureHandler) {\n return this.options.fn[\"fn\"];\n }\n\n if (!this.options.fn[\"onFailureFn\"]) {\n /**\n * Somehow, we've ended up detecting that this is a failure handler but\n * doesn't have an `onFailure` function. This should never happen.\n */\n throw new Error(\"Cannot find function `onFailure` handler\");\n }\n\n return this.options.fn[\"onFailureFn\"];\n }\n\n private initializeTimer(state: ExecutionState): void {\n if (!this.options.requestedRunStep) {\n return;\n }\n\n this.timeout = createTimeoutPromise(this.timeoutDuration);\n\n void this.timeout.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();\n state.setCheckpoint({\n type: \"step-not-found\",\n step: {\n id: this.options.requestedRunStep as string,\n op: StepOpCode.StepNotFound,\n },\n foundSteps,\n totalFoundSteps,\n });\n });\n }\n\n private getStepNotFoundDetails(): {\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n } {\n const foundSteps = [...this.state.steps.values()]\n .filter((step) => !step.hasStepState)\n .map<BasicFoundStep>((step) => ({\n id: step.hashedId,\n name: step.name,\n displayName: step.displayName,\n }))\n .sort((a, b) => a.id.localeCompare(b.id));\n\n return {\n foundSteps: foundSteps.slice(0, STEP_NOT_FOUND_MAX_FOUND_STEPS),\n totalFoundSteps: foundSteps.length,\n };\n }\n\n private initializeCheckpointRuntimeTimer(state: ExecutionState): void {\n this.devDebug(\n \"initializing checkpointing runtime timers\",\n this.options.checkpointingConfig,\n );\n\n if (this.options.checkpointingConfig?.maxRuntime) {\n const maxRuntimeMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxRuntime,\n )\n ? this.options.checkpointingConfig.maxRuntime.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxRuntime === \"string\"\n ? ms(this.options.checkpointingConfig.maxRuntime as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxRuntime as number);\n\n // 0 or negative max runtime? Skip.\n if (Number.isFinite(maxRuntimeMs) && maxRuntimeMs > 0) {\n this.checkpointingMaxRuntimeTimer = createTimeoutPromise(maxRuntimeMs);\n\n void this.checkpointingMaxRuntimeTimer.then(async () => {\n await this.middlewareManager.onMemoizationEnd();\n state.setCheckpoint({\n type: \"checkpointing-runtime-reached\",\n });\n });\n }\n }\n\n if (this.options.checkpointingConfig?.maxInterval) {\n const maxIntervalMs = Temporal.isTemporalDuration(\n this.options.checkpointingConfig.maxInterval,\n )\n ? this.options.checkpointingConfig.maxInterval.total({\n unit: \"milliseconds\",\n })\n : typeof this.options.checkpointingConfig.maxInterval === \"string\"\n ? ms(this.options.checkpointingConfig.maxInterval as StringValue) // type assertion to satisfy ms package\n : (this.options.checkpointingConfig.maxInterval as number);\n\n // 0 or negative max interval? Skip.\n if (Number.isFinite(maxIntervalMs) && maxIntervalMs > 0) {\n this.checkpointingMaxBufferIntervalTimer =\n createTimeoutPromise(maxIntervalMs);\n\n void this.checkpointingMaxBufferIntervalTimer.then(async () => {\n // Note that this will not immediately run; it will be queued like all\n // other checkpoints so that we're never running multiple checkpoints\n // at the same time and it's easier to reason about those decision\n // points.\n //\n // A change in the future may be to make this particular checkpointing\n // action immediate and have the checkpoint action itself be\n // idempotent.\n state.setCheckpoint({\n type: \"checkpointing-buffer-interval-reached\",\n });\n\n this.checkpointingMaxBufferIntervalTimer?.reset();\n });\n }\n }\n }\n}\n\n/**\n * Types of checkpoints that can be reached during execution.\n */\nexport interface Checkpoints {\n \"steps-found\": { steps: [FoundStep, ...FoundStep[]] };\n \"function-rejected\": { error: unknown };\n \"function-resolved\": { data: unknown };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n \"checkpointing-runtime-reached\": {};\n \"checkpointing-buffer-interval-reached\": {};\n}\n\ntype Checkpoint = {\n [K in keyof Checkpoints]: Simplify<{ type: K } & Checkpoints[K]>;\n}[keyof Checkpoints];\n\ntype CheckpointHandlers = Record<\n StepMode,\n {\n [C in Checkpoint as C[\"type\"]]: (\n checkpoint: C,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<ExecutionResult | undefined>;\n } & {\n \"\": (\n checkpoint: Checkpoint,\n\n /**\n * This is the number of checkpoints that have been seen before this one was\n * triggered.\n *\n * The catch-all `\"\"` checkpoint does not increment this count.\n */\n i: number,\n ) => MaybePromise<void>;\n }\n>;\n\nexport interface ExecutionState {\n /**\n * A value that indicates that we're executing this step. Can be used to\n * ensure steps are not accidentally nested until we support this across all\n * platforms.\n */\n executingStep?: Readonly<Omit<OutgoingOp, \"id\">>;\n\n /**\n * A map of step IDs to their data, used to fill previously-completed steps\n * with state from the executor.\n */\n stepState: Record<string, MemoizedOp>;\n\n /**\n * The number of steps we expect to fulfil based on the state passed from the\n * Executor.\n */\n stepsToFulfill: number;\n\n /**\n * A map of step IDs to their functions to run. The executor can request a\n * specific step to run, so we need to store the function to run here.\n */\n steps: Map<string, FoundStep>;\n\n /**\n * A flag which represents whether or not steps are understood to be used in\n * this function. This is used to determine whether or not we should run\n * some steps (such as `step.sendEvent`) inline as they are found.\n */\n hasSteps: boolean;\n\n /**\n * The core loop - a generator used to take an action upon finding the next\n * checkpoint. Manages the flow of execution and cleaning up after itself.\n */\n loop: AsyncGenerator<Checkpoint, void, void>;\n\n /**\n * A function that resolves the `Promise` returned by `waitForNextDecision`.\n */\n setCheckpoint: (data: Checkpoint) => void;\n\n /**\n * Returns whether or not all state passed from the executor has been used to\n * fulfill found steps.\n */\n allStateUsed: () => boolean;\n\n /**\n * An ordered list of step IDs that represents the order in which their\n * execution was completed.\n */\n stepCompletionOrder: string[];\n\n /**\n * An set of step IDs that have yet to be seen in this execution. Used to\n * decide when to trigger middleware based on the current state.\n */\n remainingStepsToBeSeen: Set<string>;\n\n /**\n * If defined, this is the error that purposefully thrown when memoizing step\n * state in order to support per-step errors.\n *\n * We use this so that if the function itself rejects with the same error, we\n * know that it was entirely uncaught (or at the very least rethrown), so we\n * should send a `NonRetriableError` to stop needless execution of a function\n * that will continue to fail.\n *\n * TODO This is imperfect, as this state is currently kept around for longer\n * than it needs to be. It should disappear as soon as we've seen that the\n * error did not immediately throw. It may need to be refactored to work a\n * little more smoothly with the core loop.\n */\n recentlyRejectedStepError?: StepError;\n\n /**\n * If defined, this indicates that we're running a checkpointed function run,\n * and contains the data needed to report progress back to Inngest.\n */\n checkpointedRun?: {\n fnId: string;\n appId: string;\n token?: string;\n };\n\n /**\n * A buffer of steps that are currently queued to be checkpointed.\n */\n checkpointingStepBuffer: OutgoingOp[];\n\n /**\n * Metadata collected during execution to be sent with outgoing ops.\n */\n metadata?: Map<string, Array<MetadataUpdate>>;\n}\n\nconst hashId = (id: string): string => {\n return sha1().update(id).digest(\"hex\");\n};\n\nconst hashOp = (op: OutgoingOp): OutgoingOp => {\n return {\n ...op,\n id: hashId(op.id),\n };\n};\n\n/**\n * Result of resolving a step ID collision.\n */\ninterface CollisionResolutionResult {\n /** The final ID to use (either original or with index suffix). */\n finalId: string;\n\n /** The index used, if collision was detected. */\n index?: number;\n}\n\n/** Result of applying middleware to a step. */\ninterface MiddlewareApplicationResult {\n hashedId: string;\n isFulfilled: boolean;\n setActualHandler: (handler: () => Promise<unknown>) => void;\n stepInfo: Middleware.StepInfo;\n stepState: MemoizedOp | undefined;\n wrappedHandler: () => Promise<unknown>;\n}\n\n/**\n * Resolves step ID collisions by appending an index suffix if needed.\n * Consolidates the duplicated collision detection logic.\n *\n * @param baseId - The original step ID\n * @param stepsMap - Map of existing steps (keyed by hashed ID)\n * @param expectedIndexes - Map tracking expected next index for each base ID\n * @returns The final ID to use and optional index\n */\nfunction resolveStepIdCollision({\n baseId,\n expectedIndexes,\n stepsMap,\n}: {\n baseId: string;\n expectedIndexes: Map<string, number>;\n stepsMap: Map<string, FoundStep>;\n}): CollisionResolutionResult {\n const hashedBaseId = hashId(baseId);\n\n // Check both stepsMap (steps added to state) and expectedIndexes (claimed by\n // concurrent in-progress step handlers that haven't been added to state yet).\n if (!stepsMap.has(hashedBaseId) && !expectedIndexes.has(baseId)) {\n // No collision. Claim this base ID so concurrent callers detect collision.\n expectedIndexes.set(baseId, 1);\n return { finalId: baseId };\n }\n\n // Collision detected. Find next available index\n const expectedNextIndex = expectedIndexes.get(baseId) ?? 1;\n const maxIndex = expectedNextIndex + stepsMap.size + 1;\n for (let i = expectedNextIndex; i < maxIndex; i++) {\n const indexedId = baseId + STEP_INDEXING_SUFFIX + i;\n const hashedIndexedId = hashId(indexedId);\n\n if (!stepsMap.has(hashedIndexedId)) {\n expectedIndexes.set(baseId, i + 1);\n return { finalId: indexedId, index: i };\n }\n }\n\n throw new UnreachableError(\n `Could not resolve step ID collision for \"${baseId}\" after ${stepsMap.size + 1} attempts`,\n );\n}\n\nfunction isNonEmpty<T>(arr: T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Exported for testing.\n */\nexport const _internals = { hashOp, hashId, resolveStepIdCollision };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAM,EAAE,SAAS;;;;;;;;;AAUjB,MAAM,2BAA2B;CAAE,aAAa;CAAG,WAAW;CAAK;AACnE,MAAM,iCAAiC;AAEvC,MAAaA,yBAAkD,YAAY;AACzE,QAAO,IAAI,uBAAuB,QAAQ;;AAG5C,IAAM,yBAAN,cACU,iBAEV;CACE,AAAO,UAAU,iBAAiB;CAElC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB,MAAO;CACjC,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;CASR,AAAQ;CACR,AAAQ;;;;;;;CAQR,AAAQ;;;;;;CASR,AAAQ;CAIR,YAAY,YAAqC;EAC/C,MAAMC,UAAmC;GACvC,GAAG;GACH,UAAU,WAAW,YAAY,SAAS;GAC3C;AAED,QAAM,QAAQ;;;;AAKd,MAAI,KAAK,QAAQ,aAAa,SAAS,MACrC;OAAI,CAAC,KAAK,QAAQ,eAChB,OAAM,IAAI,MAAM,gDAAgD;;AAIpE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AO;IAAG;;;AAI3C,OAAM,IAAI,iBACR,4CAA4C,OAAO,UAAU,SAAS,OAAO,EAAE,WAChF;;AAGH,SAAS,WAAc,KAA8B;AACnD,QAAO,IAAI,SAAS;;;;;AAMtB,MAAa,aAAa;CAAE;CAAQ;CAAQ;CAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inngest",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
package/version.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region src/version.ts
3
- const version = "4.0.1";
3
+ const version = "4.0.2";
4
4
 
5
5
  //#endregion
6
6
  exports.version = version;
package/version.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Generated by genversion.\nexport const version = \"4.0.1\";\n"],"mappings":";;AACA,MAAa,UAAU"}
1
+ {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Generated by genversion.\nexport const version = \"4.0.2\";\n"],"mappings":";;AACA,MAAa,UAAU"}
package/version.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
- declare const version = "4.0.1";
2
+ declare const version = "4.0.2";
3
3
  //#endregion
4
4
  export { version };
5
5
  //# sourceMappingURL=version.d.cts.map
package/version.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
- declare const version = "4.0.1";
2
+ declare const version = "4.0.2";
3
3
  //#endregion
4
4
  export { version };
5
5
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/version.ts
2
- const version = "4.0.1";
2
+ const version = "4.0.2";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/version.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Generated by genversion.\nexport const version = \"4.0.1\";\n"],"mappings":";AACA,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Generated by genversion.\nexport const version = \"4.0.2\";\n"],"mappings":";AACA,MAAa,UAAU"}