Skip to main content
Sub-steps can only be recorded under a step, meaning you need to have created a step object to add a sub-step to it. Note: You cannot create a sub-step once the step has been marked as successful or failed.

When to Use

  • Complex operations - Break down multiple distinct actions within one step
  • Debugging visibility - Track intermediate progress for troubleshooting
  • Performance analysis - Identify bottlenecks within step execution

Example

// Track granular operations within a step
const paymentStep = thread.step('payment_processed');

try {
  paymentStep.subStep('validate_card', { cardType: 'visa' }, 'success');
  paymentStep.subStep('check_fraud', { fraudScore: 0.15 }, 'success');
  paymentStep.subStep('authorize_payment', { authCode: 'AUTH-123' }, 'success');
  
  await paymentStep
    .addContext({ totalAmount: 299.99 })
    .success();
    
} catch (error) {
  paymentStep.subStep('error_handler', { error: error.message }, 'failed');
  await paymentStep.failed({ message: 'Payment failed' });
}

Properties

ParameterTypeRequiredDefaultDescription
namestringYes-Sub-step identifier
contextobjectNo{}Additional data for the sub-step
statusstringNo'success'Either 'success' or 'failed'

Key Differences from Steps

Scope - Steps operate at the thread level, while sub-steps are contained within a step. Validation - Steps are subject to contract rules and validation, whereas sub-steps have no validation applied. Notifications - Steps trigger events and notifications, but sub-steps do not emit any events.