Re-executes an ancestor activity in a new dimensional thread, enabling retry loops and iterative patterns without violating the DAG constraint. The cycle activity targets a specific ancestor (typically a Hook with cycle: true) and sends execution back to that point.

Each cycle iteration runs in a fresh dimensional thread — individual activity state is isolated per iteration, while shared job state (job.maps) accumulates across iterations. This pattern enables retries, polling loops, and iterative processing.

app:
id: myapp
version: '1'
graphs:
- subscribes: retry.start
expire: 300

activities:
t1:
type: trigger

pivot:
type: hook
cycle: true # marks this activity as a cycle target
output:
maps:
retryCount: 0

do_work:
type: worker
topic: work.do
output:
schema:
type: object
properties:
result: { type: string }

retry:
type: cycle
ancestor: pivot # re-execute from this activity
input:
maps:
retryCount: # increment retry counter each cycle
'@pipe':
- ['{pivot.output.data.retryCount}', 1]
- ['{@math.add}']

done:
type: hook

transitions:
t1:
- to: pivot
pivot:
- to: do_work
do_work:
- to: retry
conditions:
code: 500 # cycle on error
- to: done
  • The ancestor field must reference an activity with cycle: true.
  • The cycle activity's input.maps override the ancestor's output data for the next iteration, allowing each cycle to pass different values.
  • Dimensional isolation ensures parallel cycle iterations don't collide.

Cycle is a Category A (Leg 1 only) activity:

  • Maps input data, resolves the re-entry dimensional address, and publishes a stream message addressed to the ancestor activity.
  • The ancestor re-enters via its Leg 2 path in the new dimension.

CycleActivity for the TypeScript interface

Hierarchy (view full)

Constructors

Properties

adjacencyList: StreamData[]
adjacentIndex: number = 0
code: number = 200
context: JobState
guidLedger: number = 0
logger: ILogger
status: StreamStatus = StreamStatus.SUCCESS

Methods

  • if the job is created/deleted/created with the same key, the 'gid' ensures no stale messages (such as sleep delays) enter the workstream. Any message with a mismatched gid belongs to a prior job and can safely be ignored/dropped.

    Parameters

    • jobGID: string
    • OptionalmsgGID: string

    Returns void

  • unhandled activity errors (activities that return an ERROR StreamMessage status and have no adjacent children to transition to) are bound to the job

    Parameters

    • data: Record<string, unknown>

    Returns void

  • Trigger the target ancestor to execute in a cycle, without violating the constraints of the DAG. Immutable individual activity state will execute in a new dimensional thread while shared job state can change. This pattern allows for retries without violating the DAG.

    Parameters

    Returns Promise<string>

  • Executes the 3-step Leg1 protocol for Category B activities (Leg1-only with children, e.g., Hook passthrough, Signal, Interrupt-another). Uses the incoming Leg1 message GUID as the GUID ledger key.

    Step A: setState + notarizeLeg1Completion + step1 markers (transaction 1) Step B: publish children + step2 markers + setStatusAndCollateGuid (transaction 2) Step C: if edge → runJobCompletionTasks + step3 markers + finalize (transaction 3)

    Parameters

    • delta: number

    Returns Promise<boolean>

    true if this transition caused the job to complete

  • Executes the 3-step Leg2 protocol using GUID ledger for crash-safe resume. Each step bundles durable writes with its concluding digit update in a single transaction.

    Parameters

    • delta: number
    • shouldFinalize: boolean

    Returns Promise<boolean>

    true if this transition caused the job to complete

  • Leg1 entry verification for Category B activities (Leg1-only with children). Returns true if this is a resume (Leg1 already completed on a prior attempt). On resume, loads the GUID ledger for step-level resume decisions.

    Returns Promise<boolean>

  • Upon entering leg 2 of a duplexed activity. Increments both the activity ledger (+1) and GUID ledger (+1). Stores the GUID ledger value for step-level resume decisions.

    Returns Promise<number>