StaticallStaticdidChecks if an error is a HotMesh reserved error type that indicates a HotMesh interruption rather than a true error condition.
When this returns true, you can safely return rethrow the error. The workflow engine will handle the interruption automatically.
The error to check
true if the error is a HotMesh interruption
StaticdidStaticemitEmits events to the event bus provider. Topics are prefixed with the quorum namespace.
A mapping of topic => message to publish.
Optionalconfig: { If once is true, events are emitted only once.
True after emission completes.
StaticenrichAdds custom user data to the backend workflow record (writes to HASH). Runs exactly once during workflow execution.
Key-value fields to enrich the workflow record.
True when enrichment is completed.
StaticentityStaticexecSpawns a child workflow and awaits the result, or if await is false, returns immediately.
Workflow options.
Result of the child workflow.
StaticexecExecutes a hook function and awaits the signal response.
This is a convenience method that combines hook() and waitFor() operations.
Signal Injection: The signalId is automatically injected as the LAST argument
to the hooked function. The hooked function should check for this signal parameter
and emit the signal when processing is complete.
This behaves like execChild but targets the existing workflow instead of
spawning a new workflow.
Hook configuration with signal ID.
The signal result from the hooked function.
// Execute a hook and await its signal response
const result = await MemFlow.workflow.execHook({
  taskQueue: 'processing',
  workflowName: 'processData',
  args: ['user123', 'batch-process'],
  signalId: 'processing-complete'
});
// The hooked function receives the signal as the last argument:
export async function processData(userId: string, processType: string, signalInfo?: { signal: string }) {
  // ... do processing work ...
  const result = { userId, processType, status: 'completed' };
  // Check if called via execHook (signalInfo will be present)
  if (signalInfo?.signal) {
    await MemFlow.workflow.signal(signalInfo.signal, result);
  }
  return result;
}
// Alternative pattern - check if last arg is signal object
export async function myHookFunction(arg1: string, arg2: number, ...rest: any[]) {
  // ... process arg1 and arg2 ...
  const result = { processed: true, data: [arg1, arg2] };
  // Check if last argument is a signal object
  const lastArg = rest[rest.length - 1];
  if (lastArg && typeof lastArg === 'object' && lastArg.signal) {
    await MemFlow.workflow.signal(lastArg.signal, result);
  }
  return result;
}
StaticexecExecutes multiple hooks in parallel and awaits all their signal responses. This solves the race condition where Promise.all() with execHook() would prevent all waitFor() registrations from completing.
The method ensures all waitFor() registrations happen before any hooks execute, preventing signals from being sent before the framework is ready to receive them.
Array of hook configurations with unique keys
Object with keys from hookConfigs and values as the signal responses
// Execute multiple research perspectives in parallel
const results = await MemFlow.workflow.execHookBatch<{
  optimistic: OptimisticResult;
  skeptical: SkepticalResult;
}>([
  {
    key: 'optimistic',
    options: {
      taskQueue: 'agents',
      workflowName: 'optimisticPerspective',
      args: [query],
      signalId: 'optimistic-complete'
    }
  },
  {
    key: 'skeptical', 
    options: {
      taskQueue: 'agents',
      workflowName: 'skepticalPerspective',
      args: [query],
      signalId: 'skeptical-complete'
    }
  }
]);
// results.optimistic contains the OptimisticResult
// results.skeptical contains the SkepticalResult
StaticexecuteSpawns a child workflow and awaits the result, or if await is false, returns immediately.
Workflow options.
Result of the child workflow.
StaticgetReturns the current workflow context, restored from storage.
The current workflow context.
StatichookSpawns a hook from the main thread or a hook thread. If entity/workflowName are not provided, defaults to the current workflow.
Hook configuration options.
The resulting hook/stream ID.
StaticinterruptInterrupts a running job by sending an interruption request.
The ID of the job to interrupt.
Additional interruption options.
Result of the interruption, if any.
StaticisStaticproxyProvides a proxy for defined activities, ensuring deterministic replay and retry.
Optionaloptions: ActivityConfigOptional activity config (includes retryPolicy).
A proxy to call activities as if local, but durably managed by the workflow.
StaticrandomReturns a deterministic random number between 0 and 1. The number is derived from the current execution index, ensuring deterministic replay.
A deterministic pseudo-random number between 0 and 1.
StaticsearchStaticsignalSends a signal payload to any paused workflow thread awaiting this signal. This method is commonly used to coordinate between workflows, hook functions, and external events.
Unique signal identifier that matches a waitFor() call.
The payload to send with the signal.
The resulting hook/stream ID.
// Basic usage - send a simple signal with data
await MemFlow.workflow.signal('signal-id', { name: 'WarmMash' });
// Hook function signaling completion
export async function exampleHook(name: string): Promise<void> {
  const result = await processData(name);
  await MemFlow.workflow.signal('hook-complete', { data: result });
}
// Signal with complex data structure
await MemFlow.workflow.signal('process-complete', {
  status: 'success',
  data: { id: 123, name: 'test' },
  timestamp: new Date().toISOString()
});
StaticsleepSleeps the workflow for a specified duration, deterministically. On replay, it will not actually sleep again, but resume after sleep.
A human-readable duration string (e.g., '1m', '2 hours', '30 seconds').
The resolved duration in seconds.
// Basic usage - sleep for a specific duration
await MemFlow.workflow.sleepFor('2 seconds');
// Using with Promise.all for parallel operations
const [greeting, timeInSeconds] = await Promise.all([
  someActivity(name),
  MemFlow.workflow.sleepFor('1 second')
]);
// Multiple sequential sleeps
await MemFlow.workflow.sleepFor('1 seconds');  // First pause
await MemFlow.workflow.sleepFor('2 seconds');  // Second pause
StaticstartSpawns a child workflow and returns the child Job ID without awaiting its completion.
Workflow options.
The child job ID.
StatictraceExecutes a distributed trace, outputting the provided attributes to the telemetry sink (e.g. OpenTelemetry).
This trace will only run once per workflow execution by default.
Key-value attributes to attach to the trace.
Optionalconfig: { If once is true, trace only runs once.
True if tracing succeeded, otherwise false.
StaticwaitPauses the workflow until a signal with the given signalId is received.
This method is commonly used to coordinate between the main workflow and hook functions,
or to wait for external events.
A unique signal identifier shared by the sender and receiver.
The data payload associated with the received signal.
// Basic usage - wait for a single signal
const payload = await MemFlow.workflow.waitFor<PayloadType>('abcdefg');
// Wait for multiple signals in parallel
const [signal1, signal2] = await Promise.all([
  MemFlow.workflow.waitFor<Record<string, any>>('signal1'),
  MemFlow.workflow.waitFor<Record<string, any>>('signal2')
]);
// Typical pattern with hook functions
// In main workflow:
await MemFlow.workflow.waitFor<ResponseType>('hook-complete');
// In hook function:
await MemFlow.workflow.signal('hook-complete', { data: result });
The WorkflowService class provides a set of static methods to be used within a workflow function. These methods ensure deterministic replay, persistence of state, and error handling across re-entrant workflow executions.
Example