Dot-graph state machines: making workflow drift structurally impossible
Most workflow bugs in long-lived AI skills are not logic bugs. They are representation bugs.
There is a moment in every long-lived skill where you scroll the SKILL.md back to the top, look for the place that handles --retro, and realize you cannot find it without a search. The phases blur. Routing decisions are tucked between paragraphs. A reviewer asks “what happens after the user picks cancel here?” and the honest answer is let me read for thirty seconds.
That is the moment a procedure has outgrown prose.
I hit that wall in agent-config, my personal Claude Code workflow stack. Several of the skills had grown into five-plus-phase procedures with approval gates, loops, cleanup paths, and parallel work. They started as a few hundred lines of markdown. By the time they actually worked, they were hard to trust and harder to maintain.
The fix was not better writing. It was a different representation. (The agent-config docs cover the pattern as it stands today.)
Why Prose Alone Starts Lying
Procedural markdown is good at sequence. It is bad at topology.
If a skill is mostly linear, prose is fine — do A, then B, then C is natural-language territory. But once the workflow contains a discuss loop, a preflight decision, a cleanup sink, and a user cancel route, the author is no longer documenting a sequence. They are documenting a graph while pretending it is a paragraph.
That mismatch causes two predictable problems.
Routing scatters across the document. A skill with seven user-input gates and three loops has at least ten places where the next phase depends on a condition. The condition is a sentence in one paragraph; the destination is a phase header somewhere later; the cleanup obligation is a bullet point in a third location. There is no single place to read the macro flow.
Drift becomes invisible. When you change a routing decision in one section, you have to remember to update every other place that referenced it. Nothing checks that you did. The skill keeps mostly working — agents fill in gaps gracefully — but the documentation slowly stops describing actual behavior. You discover the divergence by hitting a bug six weeks later.
None of that means the author is sloppy. It means the document is carrying a kind of structure it was not designed to carry.
The Pattern in Three Parts
A graph-driven skill replaces one big SKILL.md with three cooperating things:
<skill>/
SKILL.md # entry doc + frontmatter
graph.dot # source of truth (Graphviz DOT)
graph.svg # rendered visualization (humans only)
nodes/ # per-node prose, one file per node
<id>.md
scripts/
walk.sh # thin wrapper around lib/graph_walker.py
render.sh # graph.dot → graph.svg
validate.py # structural integrity checkgraph.dot defines topology: what nodes exist, how they connect, and which condition labels are legal from a given source node. nodes/<id>.md files hold local instructions for one node at a time — inputs, steps, outputs, and the exact transition to record on completion. scripts/walk.sh is a thin per-skill wrapper over a shared lib/graph_walker.py that reads the graph, persists state, and refuses any transition that is not on the graph.
That last part is the whole game. The graph captures macro structure; the sidecars capture local mechanics; the walker enforces the contract between them.
The Graph Is a Contract
If the pattern stopped at “draw a diagram,” it would be nice but not transformative.
What makes it powerful is the walker enforcing the graph mechanically. Every node ends by recording its transition:
scripts/walk.sh transition --state "$STATE" \
--from ask_approval --to register --condition user_approveIf the node prose tries to move from compute_diff to address, but graph.dot only allows compute_diff -> independent_reviews, the walker refuses with a clear error and lists the valid alternatives:
ERROR: no edge from 'compute_diff' to 'address'.
Valid transitions from 'compute_diff':
compute_diff -> independent_reviewsThat changes what the documentation is. The graph is not just explanatory. It is a contract — and a runtime check enforces it every time the skill advances. When the prose and the graph disagree, the disagreement becomes an immediate error instead of a future mystery.
This is what makes “drift impossible” a credible claim. Not impossible because humans never forget — routing drift is impossible because the walker refuses any move the graph doesn’t sanction. Node prose can still get unclear or stale. That is a softer kind of rot, and the pattern doesn’t pretend to solve it. But the structural drift that used to silently break complex skills is now structurally prevented.
When Not to Use It
The pattern earns its overhead when a skill has five or more phases, user-input gates that affect routing, loops or conditional branches, or per-run artifacts that benefit from a session folder.
It is overkill when the skill is a thin CLI wrapper — linear, gh, obsidian, orbstack. These have one-shot operations with no internal state machine; a graph would just be ceremony.
A useful test: if the full workflow fits comfortably in one screen and has no meaningful branching, a graph probably buys you nothing. If you would be tempted to write the SKILL.md as a flowchart anyway — phases with decision points and arrows — that is the pattern fitting.
What graph.dot Looks Like
DOT is small enough to write by hand and strict enough to matter. The gate-and-loop fragment that shows up in almost every skill looks like this:
ask_approval [shape=diamond, fillcolor="#ffccbc", label="ask-approval"];
discuss_plan [shape=box, fillcolor="#e1f5fe", label="discuss-plan"];
register [shape=box, fillcolor="#e1f5fe", label="register"];
terminal [shape=doublecircle, fillcolor="#c8e6c9", label="terminal"];
ask_approval -> register [label="user_approve"];
ask_approval -> discuss_plan [label="user_revise"];
ask_approval -> terminal [label="user_cancel"];
discuss_plan -> ask_approval [label="discussion_done"];In ten lines, you can see the user gate, the loop, the success path, and the exit path. You don’t have to infer the shape from prose because the shape is the file. A rendered graph.svg gives reviewers a one-screen understanding of a workflow that would otherwise hide inside hundreds of lines of text.
The rendered graph for /review-pr-simple is a good size to study end-to-end — twelve nodes, seventeen edges, a discuss loop, a four-style post fork, and every cancel route converging on a single terminal sink:

You can read the macro flow at a glance: linear backbone from init to display, three coral user-input gates, one amber decision node, a discuss back-edge that returns to ask-next-action, and a four-way ask-post-style fork. The previous “phased procedure” version of this skill scattered the same routing decisions across hundreds of lines of SKILL.md prose.
Topology Shapes That Recur
Once a few skills are on the pattern, the same shapes show up again and again — and reading them off a graph is far easier than reading them out of prose.
Discuss loop. A user-input gate with three exits — approve, discuss, cancel — and a back-edge from the discuss node. The user can iterate freely; the gate is always the exit.
Cleanup sink before terminal. When a node creates state that needs teardown, every path that reaches the terminal must pass through cleanup first. The walker enforces it. Paths that bail before the cleanup-creating node skip the sink entirely — that is also a graph property the walker checks, not a convention the author has to remember.
Mode dispatch. A decision node forks into N subgraphs based on flags or input shape. /sprint-work has three modes — review, retro, normal — that share upstream context-loading and the terminal sink, but otherwise run different paths through the graph.
/skill-creator — a skill that scaffolds new skills — is a good example of those shapes stacked together. Its graph has all three:

decide-pattern is the mode-dispatch fork — one branch scaffolds a thin CLI wrapper, the other walks through the full graph-authoring flow. ask-topology-approval is a discuss loop where the user can iterate on the proposed graph before any files are written. ask-final-approval is a second loop with an iterate back-edge for revising the scaffolded skill after seeing it. Three different reasons for a back-edge, three different gates, and the whole thing fits on one screen.
In prose, that routing logic kept getting lost. In the graph, it is obvious — and the walker refuses to let any of it drift.
What Changed When Skills Moved to Graphs
The visible change is the file layout. The interesting change is what becomes easy.
Before: refactoring a routing decision meant editing prose in three places and hoping nothing else referenced it. After: edit one edge in graph.dot, the walker enforces it everywhere, and stale prose surfaces on the next run as a refused transition.
Before: onboarding a new skill meant reading the whole SKILL.md to understand the flow. After: open graph.svg, see the topology in ten seconds, then read the specific sidecar for any concern.
Before: a crashed run was a partial mess. After: .walk-state.json records exactly which node was active, which transitions had been recorded, and what run-scoped state had been persisted. The next session resumes from a known location instead of guessing.
The graph is the documentation, the enforcement, and the recovery checkpoint at once. The workflow stops being folklore the author has to remember and reviewers have to reconstruct. It becomes part of the skill’s executable design.
How This Connects to Other Work
The underlying argument — keep the LLM out of control flow, put the workflow’s structure in a deterministic substrate — has been showing up at multiple layers of the stack.
Alibaba’s SOURCE CODE AGENT framework (2025) makes the formal case at the benchmark level: encode the procedure as an executable Blueprint, run it on a deterministic engine, invoke the LLM as a tool for bounded sub-tasks, but never let it decide the workflow’s path. They report a 10.1-point Pass@1 gain over the strongest baseline on τ-bench. LangGraph and StateFlow make a similar move at the runtime layer — typed state graphs and finite state machines as the orchestration substrate.
The dot-graph skill pattern is the same thesis applied one layer down — at the skill-definition layer of a Claude Code stack, in the format the agent already runs. Different value proposition: the formal work demonstrates the architectural case with metrics; this is what the same idea looks like as a pattern you can adopt today, inside the skill format you’re already authoring. They’re complementary, not competing.
If one of your longest-lived tools lost its original author tomorrow, would its workflow still be legible and enforceable?