---
title: "Dynamic Node Scheduling and Output Waiting with wait_for_output"
date: "2026-11-30T11:22:02+07:00"
description: "How ADK schedules dynamic workflow nodes with ctx.run_node, and how wait_for_output keeps a node WAITING until it actually emits a real output."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/adk-workflow-wait-for-output-dynamic-scheduling.jpg"
alt: "A workflow node cycling between RUNNING and WAITING until it produces an output"
tags: ['google-adk', 'graph-workflows', 'dynamic-workflows', 'python', 'workflow-scheduling']
---

A workflow step that "returns nothing" is a genuinely ambiguous event. Did it finish with an empty result, or has it not produced its answer yet? Push `None` downstream and the next node silently processes garbage; mark the node complete and its successors fire on missing data. This ambiguity shows up constantly in real workflows — a join that must run again when one more branch arrives, an approval that is still pending, a poller that found nothing *this time*.

ADK resolves the ambiguity with a small scheduling contract: the `wait_for_output` node flag says "I am not done until I actually emit an output or a route," and the node stays in a `WAITING` state until then. This post covers that contract and the scheduler behind dynamic workflows — `ctx.run_node`, run IDs, deduplication, resume, and parallel scheduling — because the two mechanisms are halves of the same story.

## 1. The problem: completion is not the same as having an answer

In a graph workflow, node status drives everything downstream. A `COMPLETED` node releases its successors; an edge carries its `output` to the next node's `node_input`. So the definition of "completed" is load-bearing.

By default, a node is considered done when its body finishes executing — even if the body produced nothing. That default is right for ordinary functions and wrong for nodes whose whole job is to wait:

- a **join-like** node that runs once per arriving predecessor and only has a final answer after the last one
- an **approval node** whose answer arrives from outside the run
- a **polling node** that returns no result on this trigger, expecting another trigger later

## 2. What `wait_for_output` declares

`wait_for_output` is a field on `BaseNode`, the shared base every node type inherits, and it defaults to `False`:

```python
wait_for_output: bool = False
"""If True, node only transitions to COMPLETED upon yielding output or route.
Without output/route, the node enters WAITING state and downstream nodes are
not triggered, allowing predecessors to re-trigger it."""
```

Three consequences fall out of that definition:

1. **A body that finishes without output does not complete the node.** The status becomes `WAITING`, and downstream nodes are *not* triggered — no edge is followed with an empty payload.
2. **The node can be re-triggered by its predecessors.** The scheduler keeps the run around instead of discarding it, so the next activation can pick up where it left off.
3. **Route counts as output for this purpose.** A node that emits a route selects a branch, which is a terminal outcome just like a payload.

On a `Node` subclass the field is a normal annotation, so a waiting node is declared rather than orchestrated:

```python
from google.adk.workflow import Node

class ApprovalGate(Node):
    """Completes only when it actually yields an output or a route."""
    wait_for_output: bool = True
```

The flip side is documented just as bluntly: **completing execution without ever yielding output or route puts the node in an indefinite `WAITING` state — a deadlock — and ADK treats that as a configuration error.** `wait_for_output` is a promise that the node will eventually produce something, not a license to produce nothing forever.

```
          ┌──────────────┐  yields output/route   ┌────────────┐
  trigger │   RUNNING    │ ─────────────────────▶ │ COMPLETED  │──▶ successor fires
          └──────┬───────┘                        └────────────┘
                 │ body ends, no output
                 ▼                                   (wait_for_output=True)
          ┌──────────────┐   predecessor           ┌────────────┐
          │   WAITING    │ ◀── re-triggers ─────── │ downstream │
          └──────────────┘                         │ not fired  │
                                                   └────────────┘
```

The canonical example is `JoinNode` itself: it waits for every predecessor, and each firing aggregates what has arrived so far, running again as predecessors come back around rather than declaring itself done with a partial set.

## 3. The scheduler behind `ctx.run_node`

Static edges declare topology up front. Dynamic workflows put control flow in your own code — an orchestrator node that schedules children with `ctx.run_node`:

```python
from typing import Any

from google.adk import Context, Workflow
from google.adk.workflow import node

@node(name="hello_node")
def my_node(node_input: Any):
    return "Hello World"

@node(rerun_on_resume=True)
async def my_workflow(ctx: Context, node_input: str):
    result = await ctx.run_node(my_node, node_input="hello")
    return result

root_agent = Workflow(name="root_agent", edges=[("START", my_workflow)])
```

`ctx.run_node` returns the child's **output** directly, so a dynamic pipeline passes values as return values instead of shuttling them through session-state keys. Under that simplicity the scheduler is doing four jobs:

- **Fresh execution.** Each call allocates a sequential run ID per parent path and node name — `/wf@1/node_a@1`, `/wf@1/node_a@2` — so repeated executions of the same node stay distinguishable in the event log.
- **Deduplication.** If the same node path is scheduled again while its task is still running, the scheduler awaits the existing task instead of starting a duplicate; if a prior run already completed, its cached output is replayed without re-execution.
- **Resume.** After an interrupt, the scheduler lazily rehydrates node state from session events, replays what finished, and re-executes only what failed or was interrupted.
- **Waiting.** A scheduled node with `wait_for_output` that produced nothing is recorded as `WAITING` rather than `COMPLETED`, and the missing answer is surfaced to the caller as an interrupted node instead of a `None` payload.

That last point is the bridge between the two halves of this post: dynamic scheduling is where "no output yet" stops being ambiguous.

## 4. `rerun_on_resume` decides what happens after a pause

Every node carries a companion flag, `rerun_on_resume`, which controls re-entry after an interrupt — and the rule is strict enough to be enforced with an error:

- **`True` (re-entry):** the node body runs again from the top. Already-completed children are skipped and replayed from their checkpoints. **Any orchestrator that calls `ctx.run_node` must set this**, or the resume payload can never be delivered to the child. The scheduler raises if it isn't: *"Node calls ctx.run_node but has rerun_on_resume=False."*
- **`False` (handoff, the leaf default):** the resume payload becomes the node's output and is routed to the successor, bypassing the interrupted node. This is what a leaf that simply pauses for a human wants.

The mental model: orchestrators re-enter and replay their children; leaves hand off their answer.

## 5. Parallel scheduling without double work

Because `ctx.run_node` returns a coroutine, scheduling children before awaiting any of them runs them concurrently:

```python
import asyncio

@node(rerun_on_resume=True)
async def parallel_supervisor(ctx: Context, node_input: list[Any]):
    tasks = [
        ctx.run_node(worker_node, item, use_sub_branch=True)
        for item in node_input
    ]
    return await asyncio.gather(*tasks)
```

Two details matter here. `use_sub_branch=True` isolates each run's events into its own branch so the replay log stays readable, and starting every child in a synchronous loop keeps run IDs assigned in call order — which makes them deterministic across a resume. On resume, only failed or interrupted workers re-execute, including parallel ones.

When the task is simply "run this node once per list item," skip the manual loop: `node(worker, parallel_worker=True, max_parallel_workers=4)` performs the fan-out and bounds concurrency, and inherits the same resume semantics.

## 6. Putting it together: a gate that waits

A realistic combination is an orchestrator that schedules a gate in front of a side effect:

```python
@node(rerun_on_resume=True)
async def fulfillment_workflow(ctx: Context, node_input: str):
    draft = await ctx.run_node(draft_agent, node_input)

    approval = await ctx.run_node(approval_gate, draft)
    # approval_gate holds WAITING until a real output/route arrives;
    # the workflow parks instead of fulfilling an unapproved order.

    receipt = await ctx.run_node(fulfill_order, approval)
    return receipt
```

While the gate is `WAITING`, downstream nodes do not fire, the interrupt propagates to the parent, and on resume the orchestrator re-enters, replays `draft` from its checkpoint, and receives the gate's answer. The order is fulfilled exactly once — no `None` sneaks through, and no completed-without-output node masquerades as an approval.

## 7. Checklist

- [ ] Nodes that must not complete without an answer declare `wait_for_output = True`.
- [ ] Every path through such a node eventually yields an output or a route — otherwise you have built a deadlock, not a gate.
- [ ] Every orchestrator that calls `ctx.run_node` sets `rerun_on_resume=True`.
- [ ] Leaf nodes that hand a resume payload downstream keep the default `rerun_on_resume=False`.
- [ ] Parallel scheduling starts children in a synchronous loop (stable run IDs) and uses `use_sub_branch=True` to keep event branches separable.
- [ ] Per-item fan-out uses `parallel_worker=True` with an explicit `max_parallel_workers` bound instead of an ad-hoc gather.
- [ ] Checkpointing is doing the resume work: children that finished are replayed, not re-run — verify by counting model calls across a resumed invocation.

Waiting and scheduling are the two halves of trustworthy dynamic workflows: `wait_for_output` keeps the framework honest about what "done" means, and the scheduler keeps retries, resumes, and parallelism from turning that honesty into duplicated work.

## References

- https://adk.dev/graphs/dynamic/
- https://adk.dev/graphs/routes/
- https://adk.dev/graphs/data-handling/
- https://adk.dev/graphs/human-input/
- https://github.com/google/adk-python
