Simulate a flow
Run a request through the routing rules written in a diagram and check which nodes it reaches.
A diagram of a sharded database says writes for one tenant go to shard A and its two followers. Nothing checks that until someone asks "what happens to a write when shard B is down?" in a review. Flow simulation runs that question against the routing rules recorded in the diagram and shows the path a request takes.
A simulation follows the rules you wrote in the diagram. It doesn't observe real traffic or model timing, so a passing simulation shows that the diagram is consistent, not that production behaves the same way.
Describe the routing in YAML
Flow rules live in the diagram's YAML:
- A relationship can carry
when, a condition such astenant.shard == 'a', orotherwise: trueas the fallback. - A node can carry
flow:with a behavior.switchtakes exactly one matching route,fanouttakes every matching route, andquorumneeds a number of its branches to succeed, such asneed: 2. - A node can look up a row in a top-level
tablesmap, such as a tenant's shard. - Top-level
scenariosname an input to run, with an optional start node andfaults, the nodes to treat as down. - Top-level
assertionsstate what must hold:reaches,neverReaches,alwaysPassesThroughornoErrors.
# Excerpt: the client, gateway, shardB and reject nodes are omitted.
tables:
tenants:
acme: { shard: a }
globex: { shard: b }
scenarios:
- { name: Acme write, input: { tenant: acme, op: write } }
- { name: Globex write shard B down, input: { tenant: globex, op: write }, faults: [shardB] }
assertions:
- { name: Acme never touches shard B, scenarios: [Acme write], neverReaches: shardB }
nodes:
- id: router
type: c4-node
kind: component
label: Tenant router
flow: { behavior: switch, lookup: { table: tenants, key: input.tenant, as: tenant } }
- { id: shardA, type: c4-node, kind: database, label: Shard A leader, flow: { behavior: quorum, need: 2 } }
relationships:
- { from: router, to: shardA, when: "tenant.shard == 'a'" }
- { from: router, to: shardB, when: "tenant.shard == 'b'" }
- { from: router, to: reject, otherwise: true }
The flow simulation reference lists every field and rule.
Run a simulation
Select Simulate flow in the diagram toolbar. The panel lists the diagram's Assertions with their results, then a Scenario picker. Pick a scenario to see its path drawn on the canvas, and use Play to step through it. Under Custom input, enter a JSON object such as {"tenant": "acme", "op": "write"} and choose a start node, or leave Automatic start node.
Under Steps, the results list each hop with the relationship or condition that chose it. Terminals shows where each branch ended: reached, failed, dropped or error. Quorums summarizes each quorum node, such as "shardA: 2 of 2 needed (2 branches, met)". An unmet quorum ends the branch with a message such as "quorum not met at shardA: 0 of 2 needed". Warnings lists rules the run couldn't follow cleanly.
A switch with no matching route, or with more than one, is an error. Add an otherwise fallback or tighten the conditions. A run stops after 200 steps.
The panel isn't shown on phones.
From an agent
Agents call simulate_flow over MCP with a diagram id and either a scenarioName or an ad-hoc input, which can include start and faults. With checkAssertions: true, it runs every assertion and returns whether they all pass. A failed assertion is a normal result with pass: false. The tool only reads, so it needs docs:read.
An agent changing the routing can add a scenario for the case it changed, run the assertions and report the result. That result is the agent's report of what the diagram says, not a check of the running system.