next and Routers

REAL

next says where control goes when a step finishes. It has four forms. The server tries them in this order when it parses the YAML (NextSpec, orchestrate-core/src/playbook.rs, v3.161.2):

#FormExampleTaken on the server
1one step namenext: reportalways
2a list of namesnext: [a, b]all of them, in parallel
3a list of targets {step, when?, args?}next: [{step: a, when: …}, {step: b}]by mode, exclusive by default
4a router {spec: {mode}, arcs: [{step, when?, set?}]}see belowby mode, exclusive by default

All four in one playbook (examples/ch06/next-forms, a distributed example that CI validates against the schema):

# Chapter 6.1: the four forms of `next`, on a server. Each form is one step.
apiVersion: noetl.io/v2
kind: Playbook
metadata:
  name: next_forms
workload:
  tier: gold
workflow:
  - step: start
    tool: { kind: noop }
    next: by_name                      # 1. one step name: always taken
  - step: by_name
    tool: { kind: noop }
    next: [fan_a, fan_b]               # 2. a list of names: ALL taken (fan-out)
  - step: fan_a
    tool: { kind: noop }
    next:                              # 3. a list of {step, when, args}: exclusive by default
      - step: gold_path
        when: "{{ workload.tier == 'gold' }}"
        args: { reason: gold }
      - step: other_path
  - step: fan_b
    tool: { kind: noop }
    next:                              # 4. a router: spec.mode + arcs
      spec: { mode: inclusive }        #    inclusive = every matching arc
      arcs:
        - step: audit
          when: "{{ workload.tier in ['gold', 'silver'] }}"
        - step: notify
          set: { ctx.channel: email }  #    arc-level set: mutations for the target
  - step: gold_path
    tool: { kind: noop }
  - step: other_path
    tool: { kind: noop }
  - step: audit
    tool: { kind: noop }
  - step: notify
    tool: { kind: noop }

Exclusive and inclusive

Forms 3 and 4 decide which targets to take by mode (evaluator.rs, v3.161.2):

  • exclusive (the default): take the first target, in the order written, whose when is true or absent. Later targets are not evaluated at all; they are recorded as skipped.
  • inclusive: take every target whose when is true or absent. All are dispatched in the same pass, so they run in parallel.

A router reads its mode from next.spec.mode. A list of targets reads it from the step's spec.next_mode. If neither is set, the mode is exclusive. A misspelt mode value also means exclusive: any string other than inclusive does.

Myth

"next: [{step: a}, {step: b}] runs a and b." It runs only a. A list of targets is exclusive by default, and a target without when always matches, so the first one wins and b is skipped. To run both, write a list of names (next: [a, b]), or set spec.next_mode: inclusive on the step, or use a router with mode: inclusive.

Passing values along an arc

  • A target in form 3 may carry args, a map merged as-is into the target step's dispatch context. It is not rendered.
  • An arc in form 4 may carry set, a map whose values are rendered against the current context and written with the same ctx. / iter. / step. prefix-stripping as step-level set: (4.2). It affects the context of the step it dispatches. Unlike a step's own set:, it is not written to the event log as a ctx.updated event.

Routers do not take args, and the grammar's own comment says arc args: is not supported. Use set.

On the local runtime

The local runtime (CLI v6.4.1) implements forms 3 and 4 the way the server does, except that "in parallel" becomes "one after another" in one process. CI checks both:

  • examples/ch06/next-targets: a list of targets runs only the first, so executed_steps is ["start","a"];
  • examples/ch06/next-router-inclusive: an inclusive router runs both, so executed_steps is ["start","a","b"].

It does not implement forms 1 and 2:

# Chapter 6.1 (local, CLI 6.4.1): `next: <name>` and `next: [names]` are IGNORED locally; the run stops after `start` and still ends ok.
apiVersion: noetl.io/v2
kind: Playbook
metadata:
  name: next_names_local
workflow:
  - step: start
    tool:
      kind: rhai
      code: |
        "start"
    next: [a, b]
  - step: a
    tool:
      kind: rhai
      code: |
        "a"
  - step: b
    tool:
      kind: rhai
      code: |
        "b"
{
  "executed_steps": [
    "start"
  ],
  "final_result": "start",
  "playbook_name": "next_names_local",
  "status": "ok",
  "step_results": {
    "start": "start"
  }
}

```admonish warning title="Locally, next: b and next: [a, b] do nothing" At CLI v6.4.1, a next that is a bare name or a list of bare names is ignored. The run stops after the step, with status ok and no warning. For a playbook that must run locally too, write targets (next: [{step: b}]) or a router.


## Check your understanding

<div class="quiz-placeholder" data-quiz-name="&quot;ch06-01&quot;" data-quiz-questions="{&quot;questions&quot;:[{&quot;context&quot;:&quot;A list of TARGETS is exclusive by default, and a target without `when` always\nmatches, so the first wins and `b` is skipped. `next: [a, b]` (a list of\nNAMES) would run both.\n&quot;,&quot;id&quot;:&quot;120d7a7d-513e-4c63-8989-9105531e3686&quot;,&quot;type&quot;:&quot;MultipleChoice&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;Only `a`.&quot;},&quot;prompt&quot;:{&quot;distractors&quot;:[&quot;`a` and `b`, in parallel.&quot;,&quot;`a`, then `b`.&quot;,&quot;Neither: targets need `when`.&quot;],&quot;prompt&quot;:&quot;On a server, which steps run after `next: [{step: a}, {step: b}]`?&quot;}},{&quot;context&quot;:&quot;`NextMode` defaults to Exclusive, and any string other than `inclusive`\n(including a typo) parses as exclusive (orchestrate-core `evaluator.rs`).\n&quot;,&quot;id&quot;:&quot;352b820e-b4bd-4d60-ac18-948a02cf9026&quot;,&quot;type&quot;:&quot;MultipleChoice&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;exclusive, unless the step's `spec.next_mode` says otherwise&quot;},&quot;prompt&quot;:{&quot;distractors&quot;:[&quot;inclusive&quot;,&quot;parallel&quot;,&quot;It is a validation error.&quot;],&quot;prompt&quot;:&quot;A router omits `spec.mode`. Which mode applies?&quot;}},{&quot;context&quot;:&quot;Locally only target lists and routers are implemented. CI asserts this\n(`examples/ch06/next-names-ignored-local`).\n&quot;,&quot;id&quot;:&quot;2d031a66-6c9d-442e-8e8d-8c0c2befe8ef&quot;,&quot;type&quot;:&quot;MultipleChoice&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;Nothing: the bare-name forms are ignored locally and the run ends `ok`.&quot;},&quot;prompt&quot;:{&quot;distractors&quot;:[&quot;`a` and `b`.&quot;,&quot;`a` only.&quot;,&quot;The run fails to parse.&quot;],&quot;prompt&quot;:&quot;On the local runtime (CLI v6.4.1), a step has `next: [a, b]`. What runs after it?&quot;}}]}" data-quiz-cache-answers="true"></div>


<script type="text/javascript" src="quiz/quiz-embed.iife.js"></script><link rel="stylesheet" type="text/css" href="quiz/style.css">