The Stage Graph: Managing Task Stages with a Dependency Graph

Using a verifiable DAG to express node dependencies, execution authority, completion barriers, failure propagation, and recovery boundaries.

On this page · 19 sections

A Checklist can tell an Agent to "read the code first, then modify it, then test," but it cannot reliably express parallelism, waiting, re-entry, completion barriers, or side-effect permissions.

Once a task needs those properties, it is no longer a prompt checklist; it is an execution graph. Marshall's stage-graph.yaml is the single authority for that graph.

The Short Version

  • Once a task needs parallelism, waiting, re-entry, completion barriers, and side-effect permissions, it is an execution graph, not a prompt checklist; stage-graph.yaml is the single authority for that graph.
  • Order comes from dependency edges, not from line numbers in the YAML. The Graph also defines the Authority Flow: which result produces the authority for the next step.
  • A Completion Barrier is a set of postconditions that must all hold at once, not "the last node"; every edge is also bound to a current Result and subject to Freshness.
  • The Graph Loader is Fail Closed for the control plane. An explicit graph deserves to exist only when the task has properties such as cross-session work, unrepeatable side effects, parallelism, and recovery; "the task has many steps" is not a reason.

What a Stage Graph actually expresses

Each Stage contains six kinds of information:

purpose: the result this stage must deliver
predecessor: the predecessor stages that are allowed
input_policy: input roles, predecessor results, and freshness rules
nodes: nodes, dependencies, executors, outputs, and checks
completion_barrier: which nodes jointly determine that the stage is complete
transitions: where the stage may go after completion

Each Node, in turn, binds at least:

  • phase: the cognitive responsibility, such as perception, explore, draft, verify, critic, synthesis, or finalize;
  • executor: parent, deterministic, worker, provider, isolated-executor, or host;
  • depends_on: the Nodes that must complete first;
  • required_output_roles: the logical artifacts that must be published;
  • required_checks: the conditions the Runtime must verify;
  • an optional worker_lane: whether the node permits risk-driven parallel Workers.

Order comes from dependency edges, not from line numbers in the YAML. Being listed first does not mean running first; only the Graph carries execution semantics.

A real Design DAG

The core topology of the mature design stage is a DAG, that is, a directed acyclic graph, shown below:

The Design stage DAG: from Perception Bootstrap to Final Design, with the Question Gate join and the parallel Verifier and Critic branches; open the full-size SVG

There are three properties here that a checklist struggles to express:

  1. question-gate depends on both the main exploration and the pre-draft Specialists, which prevents questions from being thrown at the user before the exploration of discoverable facts has finished;
  2. deterministic-verifier and post-draft-critic both depend on the draft but not on each other, so they can run in parallel;
  3. repair-decision is a Join, that is, the point where parallel branches meet: only after both the mechanical verification and the semantic review have completed can it decide between repair and finalization.

final-design is the Completion Barrier, that is, the set of nodes that decides whether the Stage can complete. Even if every preceding Node is marked completed, the Stage still cannot complete as long as the bindings for the final artifact, the decision provenance, or the Jira Issue Spec are incomplete.

The Impl Graph is essentially a chain of authority

The implementation stage is closer to a strict Chain, shown below:

The Impl authority chain: nine nodes in order from Branch Gate to Spec Sync; open the full-size SVG

You cannot swap write-grant and isolated-executor here, nor can you run Promotion before Patch Verification. Once the order changes, there are two possible consequences:

  • a downstream Executor may use a capability that has not yet been issued;
  • an unverified candidate change may be written into the target workspace.

So the Graph does more than schedule work. It also defines the Authority Flow: which result produces the authority for the next step.

Why a Completion Barrier is not the same as "the last node"

In a linear flow, the end of the last node usually means the end of the stage. That is not necessarily true of a DAG.

The Completion Barrier of the mature Impl stage includes both Post-promotion Verification and Spec Sync. The reason is that code verification and stable-contract synchronization can produce two distinct results:

  • the code has been promoted correctly and passes its tests;
  • the affected stable Spec has either been updated in the same Patch or been explicitly shown to need no change.

If spec-sync were treated merely as the last node, the Runtime might not see whether the preceding verification is still valid; if it looked only at Promotion, it would mistake "the files were written successfully" for "the implementation stage is complete."

A Barrier expresses a set of postconditions that must all hold at once.

The Graph must also be bound to the Data Plane

A graph that only lists Node names is still easy to bypass. Marshall additionally requires every edge to be bound to a current Result:

NodeResultV1
  = node identity
  + dependency fingerprints
  + input fingerprint
  + output path/hash bindings
  + verification
  + decision/action/outcome events

When a downstream Node starts, it does not merely check dependency.status == completed; it also verifies the Dependency Fingerprint against the immutable Result. When a dependency's inputs or Artifacts change, the old completed status becomes invalid.

When a Stage completes, StageResultV1 then aggregates the required Node Results, Output Bindings, Open Risks, Verification, and Transition. The Graph owns the structure; the Result proves that this particular run actually satisfied it.

Freshness is the time dimension of a DAG

A static DAG describes only dependency relationships; it cannot say whether an old result is still usable today. The mature version configures an Input Policy for each Stage:

  • freshness: none: a predecessor result is usable as soon as it completes;
  • freshness: tracked: changes to the current code, a Provider, or predecessor inputs invalidate the result;
  • stale_route: block: progress cannot continue by having the model reinterpret an old summary.

For example, Design completes against Commit A, but by the time Impl starts, HEAD has moved to B. The graph structure has not changed; the Data Dependency has. The correct behavior at that point is not to leave the Design Node as completed, but to mark the affected results Stale and return to a node that can re-establish the evidence.

The Graph Loader must be strict, not "best-effort"

stage_graph.py is Fail Closed for the control plane, that is, it rejects any configuration it cannot confirm instead of guessing and continuing. Each of the following fails immediately:

  • an unknown Stage;
  • an unknown Node;
  • an empty Completion Barrier;
  • a Barrier that references a nonexistent node;
  • a Dependency cycle;
  • an illegal Transition.

This is the key difference between machine configuration and natural language. Natural language can keep a conversation going despite ambiguity; a control graph that "guesses the closest-looking node" may bypass a wait, an approval, or a write restriction.

Mechanical validation of the Graph should cover at least the following:

  • every Node ID is unique;
  • depends_on references only nodes known to the current Stage;
  • the graph is acyclic, or any explicit Loop has a maximum number of rounds and a stop condition;
  • the Barrier is non-empty and reachable;
  • every Output Role resolves in the Artifact Map;
  • every Executor Type is registered;
  • every Transition target exists, and Terminals are explicit;
  • the Join of parallel branches covers all required results;
  • the Mode and the Worker limits do not contradict each other.

When to orchestrate in code and when to leave it to the LLM

The OpenAI Agents SDK divides orchestration into two kinds: letting the LLM decide the next step from context, or fixing the order in code. The former suits open-ended problems; the latter is more predictable in speed, cost, and behavior. Marshall combines the two:

  • the Graph decides the non-interchangeable dependencies, authority, and completion conditions;
  • the Parent Agent decides how to explore and synthesize within a Node;
  • the Deterministic Executor handles Hash, Schema, and state checks;
  • Workers handle only narrow questions that can be parallelized independently.

This is more practical than either "hard-code everything" or "hand everything to the model." The key is to identify which orderings produce real consequences when they go wrong.

How errors propagate along different topologies

The mature version also annotates each Stage with a Topology and an Error Path. The table below shows how one error typically spreads under each topology:

Topology Typical error propagation
Chain An error in one step cascades into every later step
Route A misrouted dispatch means the right capability never enters the flow at all
Parallel Multiple branches produce conflicting, duplicated, or inconsistent evidence
Orchestrate A bad decomposition has each Worker solving the wrong subproblem
Loop Faulty feedback is amplified every round, producing endless rework
Hierarchy An upper-level error is amplified simultaneously by multiple lower-level instances

Graph design therefore has to consider more than the Happy Path; it has to provide different controls for each topology:

  • intermediate verification for a Chain;
  • a Barrier and Dedupe for Parallel;
  • an explicit maximum number of rounds for a Loop;
  • limits on depth and ownership for a Hierarchy.

Common failure modes

Graph and documentation drift

The Command describes one order, and the Graph executes another. The fix is to make the Graph the sole execution authority, with documentation that only explains and never copies the full Node List; the Validator checks references rather than maintaining two copies of the facts.

A Barrier that is too weak

Waiting only for "the last node" misses a failure in a parallel branch. A Barrier should describe business postconditions, not whichever box happens to look last in the UI.

A Barrier that is too strong

Putting every optional Worker into the Barrier forces even low-risk tasks to wait for irrelevant reports. An optional branch may enter the Barrier only after it has actually been chosen in Selection.

Hidden Side Effect

A parent Node quietly performs a Provider Write from inside its Prompt. The Executor Type must be bound to tool permissions; a semantic name is no substitute for a technical restriction.

Retry without Idempotency

A node is rerun from scratch after a failure, duplicating an external action. For Provider and Host Nodes, the Graph must be complemented, outside the Graph itself, by an Operation ID, Readback, and Reconciliation.

Workflow for Workflow's Sake

A task the model could have finished within a single session is nonetheless split into too many Nodes, each generating a Result. The cost of maintaining the graph exceeds the risk it controls.

When a graph deserves to exist

An explicit Stage Graph fits the following situations:

  • the task spans processes or sessions, or requires long waits;
  • there are external side effects that cannot be safely repeated;
  • multiple executors may run in parallel, fail, or arrive late;
  • recovery must resume from the most recent valid node;
  • completion requires several independent conditions to hold at once;
  • auditing requires reconstructing the actual order of execution.

It is not a fit merely because "the task has many steps." The LLM's native planning is usually more economical when all of the following hold:

  • every step needs fresh model judgment;
  • the order shifts with what is discovered;
  • failures are easy to recover from within the current Worktree.

The Task, Choice, Parallel, Wait, Succeed, and Fail states of AWS Step Functions demonstrate the value of a mechanized Workflow: these controls apply to processes that genuinely need durable execution history and strict transitions. They do not mean that every code change should first be turned into a State Machine.

References

Related notes

Working on something similar?

I'm always happy to compare notes on distributed systems, delivery, and applied AI.

[email protected]