Skip to content

withStepLimit ​

Throws if the total number of step executions in a single .run() call exceeds a configured maximum. A safety net for flows that use anchors and loops.

Setup ​

typescript
import { FlowBuilder } from "flowneer";
import { withStepLimit } from "flowneer/plugins/dev";

const AppFlow = FlowBuilder.extend([withStepLimit]);

Usage ​

typescript
const flow = new AppFlow<State>()
  .withStepLimit(500) // abort if more than 500 steps execute
  .anchor("loop")
  .then(async (s) => {
    await processItem(s);
    if (!s.done) return "#loop";
  });

API ​

.withStepLimit(max?: number) ​

ParameterTypeDefaultDescription
maxnumber1000Maximum total step executions per run

Error ​

When exceeded: "step limit exceeded: N > max".

Counter Resets ​

The counter resets at beforeFlow, so each .run() call starts from 0.

Relationship with withCycles ​

PluginWhat it counts
withStepLimitTotal step executions (including repeats)
withCyclesAnchor jump events only

Use withCycles for anchor-specific safeguards and withStepLimit as a global execution ceiling.