The Overall Architecture of an AI Development Harness
A file-based control layer for an AI development workflow: how it records progress, recovers from interruptions, and limits write access.
On this page · 16 sections
I once wrote a complete Workflow Harness for my own AI development process. It was called Marshall.
Harness here does not mean a Prompt template along the lines of “think first, then code, then test.” It is a control plane that lives inside the code repository: the user supplies only a goal, and the system does the rest:
- selects the stage;
- binds the current evidence;
- restricts executor permissions;
- persists run state;
- verifies dependencies and results before every state advance.
It tries to answer a question harder than “can the model write code”: once a task has crossed multiple context windows, multiple executors, and multiple tools with side effects, how does the system prove that the current result still comes from the right inputs, the right permissions, and the right execution order?
What follows describes the complete design and runtime contract of that system, not an idealized flowchart.
The Short Version
- The Harness is a control plane inside the repository, not a Prompt template: the model owns semantic judgment and the Runtime owns state and permissions.
- Rules live in the stable control plane and runtime facts live in the per-run plane; both are needed, but they carry different authority.
- Every Stage is an executable DAG and the six Executor Types are a permission model; only a
StageResultV1that has passed the completion barrier can authorize a state advance. - It suits long-running work with external calls that cannot be safely repeated and a need for auditing, not wrapping every day-to-day code change by default.
Two planes: rules and runtime facts must be kept apart
The first thing Marshall did was split rules and runtime facts into two planes. Look at the last column: the two answer different questions:
| Plane | Location | Question it answers |
|---|---|---|
| Stable control plane | A versioned rules directory inside the repository | How work is allowed to proceed, who holds which permission, and what counts as done |
| Per-run plane | An ignored per-run evidence directory | What this run actually read, did, and produced, and where it stopped |
The stable control plane contains the constitution, routes, the stage graph, the Artifact Map, Worker contracts, JSON Schemas, domain specifications, and the runtime code. The per-run plane stores state.json, the append-only event log, immutable results, Worker Reports, design or review materials, patches, and receipts.
This boundary prevents two common kinds of contamination:
- mistaking a conclusion generated by one task for a long-lived rule;
- mistaking the modification time of a long-lived document for the actual ordering of a particular run.
Stable documents define “how it should be”; the run package records “how it actually was.” Both are needed, but they carry different authority.
The end-to-end path
Following the arrows, there are eight key steps:
- Routing determines only the goal and the side-effect boundary;
stage-graph.yamldecides the nodes, dependencies, executors, and completion barriers;StateV3assigns a Lease (that is, an execution right that expires), Generation, Revision, and Fence to the current attempt;- the Context layer selects evidence from the current repository, specifications, and Providers;
- each node can be executed only by the Executor Type declared in the graph;
- results must be published as a
NodeResultV1bound to input and output Hashes; - the completion barrier confirms that every required result is still valid;
- only a
StageResultV1can authorize a state advance or a legal Transition.
It is not a Prompt-driven pipeline. It is a hybrid system in which the model owns semantic judgment and the Runtime owns state and permissions.
Who has the final say inside the control plane
The worst thing that can happen to a complex Harness is for one rule to be written out separately in several places. So the mature version made ownership explicit; in the table below, each component has exactly one responsibility:
| Component | Sole responsibility |
|---|---|
constitution.md |
Non-overridable principles for facts, authorization, and reporting |
routes/ and commands/ |
Human entry points, accepted inputs, and per-stage refusal boundaries |
stage-graph.yaml |
Node DAG, Executors, Barriers, Transitions, and Mode ceilings |
stage-artifacts.yaml |
Mapping from logical Artifact Roles to physical paths |
| Worker Schema and Runtime | The contract for exact instances, context, output, concurrency, and convergence |
templates/runtime/*.schema.json |
Data shapes that can be validated by a program |
specs/ |
Stable facts about the repository and the business domain |
| Runtime | Leases, CAS, events, recovery, permissions, and Provider execution |
Three limits follow:
- Route documents may explain a stage, but they cannot redefine node order.
- A Worker Team may describe semantic roles, but it cannot add instances on its own by going around the Worker Plan.
- Markdown may present a result, but it cannot stand in for a Hash-bound Result.
At its core, this design fights “duplicated facts.” If every layer can interpret the next step, any rarely used branch will gradually drift.
A Stage is not a label; it is an executable DAG
A DAG is a directed acyclic graph, that is, nodes run in dependency order and never loop back to themselves. Every Stage contains:
- a
purposeand its acceptable predecessors; - input bindings and a Freshness Policy;
nodes,depends_on, and Executor Types;- the required output Roles and deterministic Checks for each node;
- a
completion_barrier; - the permitted follow-on Transitions.
For example, the mature design stage is not “generate a design document.” It is:
The graph carries three constraints:
- deterministic verification and critical review look at different evidence and can run in parallel;
repair-decisionmust wait for both branches;- the Stage can end only when
final-designreaches the completion barrier.
impl, in turn, explicitly splits a code write into planning, capability issuance, low-trust execution, patch verification, trusted promotion, and target-workspace readback. The order in the graph is not a suggestion; it is a chain of permissions.
Six Executors, six different trust boundaries
The mature version did not hand every node to “one smarter Agent.” It distinguished six kinds of executor; pay attention to the last column, which lists what each one is forbidden to do:
| Executor | What it can do | What it cannot do |
|---|---|---|
parent |
Read, reason, synthesize, and produce stage artifacts | Impersonate a Provider or bypass the write boundary |
deterministic |
Pure validation or transformation: Schema, Hash, dependencies, Freshness, and so on | Make open-ended semantic judgments or perform external writes |
worker |
Produce a read-only, attributable report on one narrow question | Modify source code, complete a Stage, or draw conclusions on behalf of the main Agent |
provider |
Execute one registered, approved external operation that can be read back | Freely assemble an unauthorized Payload |
isolated-executor |
Modify allowlisted paths inside an isolated worktree under a one-time Grant | Write to the user's current workspace or widen the scope |
host |
Verify a patch and promote it into the target workspace | Author code changes |
An Executor Type is not a role name; it is a permission model. Even if the same LLM is capable of performing all of the logic, that does not entitle it to cross a trust boundary.
Why StateV3 is more than a progress JSON
StateV3 holds the projection of the current run. Beyond stage and status, it also contains:
attempt,resume_epoch, andactive_generation;- the
revisionused for CAS (Compare-And-Swap, that is, compare the version first and write only if it matches); - the current Lease and Fencing Token;
- the preceding
StageResultV1; - input, output, and Artifact Hashes;
- Nodes and Node Results;
- Worker Selection, Plan, Run, and Result;
- Question, Approval, Mutation Intent, Delivery, and Freshness;
- Late Results, Partial Commits, and the next Transition.
State updates must compare the Revision while holding the lock. Three guarantees follow:
- a Worker from an old Generation cannot write its result into a new attempt even if it arrives late;
- an expired Lease cannot keep publishing;
- after the Question Gate receives the user's answer and resumes the same Generation, a new
resume_epochdistinguishes the execution identity before the answer from the one after it.
That is the point of Fencing: cancelling an executor is not just telling it “please stop.” It also means that even if it does not stop, it has lost the right to submit a result.
Event, State, and Artifact each prove a different fact
Marshall's append-only event log is not an ordinary Debug Log. Every stateful action follows:
decision -> action -> outcome
An event contains a sequence number, parent-child relationships, a Correlation, the Hash of the previous event, and the Hash of the current event. An action must reference an existing decision, and an outcome must reference its corresponding action and can complete it only once. The Runtime reserves the Decision/Action before publishing a result; after execution, it first reads back the result projection and then appends the Outcome.
Meanwhile:
- State answers “what is the status right now”;
- Event answers “why did we get here”;
- Artifact answers “what content does the downstream actually consume.”
For example, “the design is complete” cannot be proven by a status string alone. It needs at least a StageResultV1 containing the input fingerprint, output bindings, Verification, Open Risks, the Transition, and the Event IDs of the Decision/Action/Outcome. If the bytes of a bound file change, the Hash is invalidated and the completed status can no longer be reused.
Workers are not a fixed team; they are exact instances within a single run
Although the mature version prepared roles such as domain, data runtime, security, layering, Critic, and Verifier, the real runtime authority was two objects:
WorkerSelectionV1: why Workers were or were not selected, which risk axes currently exist, and whether the task needs to be split;WorkerPlanV1: the concrete instances, stage, context, Prompt/Model/Config Hashes, read-only permissions, output paths, concurrency and repair limits, and Barriers.
Mode is divided into light, standard, and deep:
- a low-risk, single-repository change with a known path can use zero Workers;
- migrations, Backfills, IAM, production writes, cross-repository or cross-domain work, or uncertain source authority push the design toward Deep;
- when capacity is exceeded, the task is split first rather than adding Agents without limit.
A Worker Report qualifies to enter the Barrier only after passing Plan, Node, Generation, Context Hash, and Schema validation. The main Agent remains the sole synthesizer, which keeps multiple Workers from each treating a local conclusion as the final plan.
How an implementation task crosses the write boundary
The implementation stage shows this architecture's trust model most clearly:
StageWriteGrantV1 binds the repository identity, Branch, Base Commit/Tree, the precondition state of the target files, the permitted Create/Modify/Delete operations, the executor instance, Generation, Fence, use count, and expiry time. It can be used exactly once.
The Executor produces a structured Patch Bundle inside a separate worktree. What it contains is not an opaque Diff, but the existence state, Mode, content Hash, and Blob Ref of every path before and after the change. The Trusted Host re-checks that the target workspace still satisfies the preconditions, and only then promotes the patch into the checkout the user is actually working in.
Promotion here does not mean going live. It means moving from a low-trust execution area into a high-trust workspace. After a successful promotion, the target files still have to be read back and verification rerun, because success in the isolated environment does not prove the target environment is the same.
Why external writes must be Preview, Approval, Execution, Readback
Writes to Jira, PRs, comments, and other Providers cannot rest on a single “the user said it was fine.” The mature version split one external action into four parts:
- resolve the exact target and Payload;
- show the current preview and obtain confirmation for that specific content;
- have a registered Provider Adapter execute one idempotent Intent;
- re-read the ID, fields, status, and Revision from the Provider.
If the request times out, the system cannot simply retry. It must query the Provider first: the object may already have been created and only the response was lost. Otherwise the so-called “retry” produces a second Jira issue or a duplicate comment.
This chain also separates capability from authorization: the presence of a Token in the tool proves only that a write is technically possible; only when the current Intent, target, Payload, and confirmation are all still consistent does it prove that this particular write is permitted.
Recovery is not rereading the chat
After a task is interrupted, the Runtime recovers from State, Events, and immutable results:
- validate the event Hash Chain and the State Projection;
- identify expired Leases, old Generations, and incomplete Decisions/Actions;
- verify the inputs, dependencies, and Artifact Hashes of completed nodes;
- mark results that are no longer fresh as
stale, preserving the reason for invalidation; - reschedule from just before the most recent still-valid Barrier, rather than repeating side effects from the beginning.
The hard part of recovery is not “remembering where we left off,” but deciding which results still hold execution rights. Without Generation, Fence, and Idempotency, recovery easily turns into duplicate execution.
The failure modes the mature version was built to prevent
In the table below, the left column is the failure and the right column is the mechanism that guards against it:
| Failure | Mechanism |
|---|---|
| Multiple executors advancing the same Stage at the same time | Lease + Revision CAS + Fencing Token |
| An old Worker arriving late after a new round has completed | Generation / Resume Epoch validation, Late Result quarantine |
| Downstream reading artifacts left over from an old attempt | Path + SHA-256 Binding and Freshness |
| Many Workers but the risk is still not covered | Risk Profile, Required Role, and Completion Barrier |
| An Executor modifying files outside its scope | Write Allowlist, isolated worktree, Patch Verification |
| The user's workspace having changed by the time of Promotion | Base/Target Preconditions and target readback |
| Duplicate creation after a Provider timeout | Mutation Intent, Idempotency, and Live Reconciliation |
| State saying completed while the artifact does not exist | Node/Stage Result + Artifact Registry + Readback |
| The model continuing from a summary after Compaction | Runtime State and the Event Chain take precedence over chat memory |
These are all problems that only a workflow system, not a Prompt, can truly solve.
What this architecture is suited to, and what it is not
It is suited to work that:
- runs across processes for hours or days;
- makes external calls that cannot be safely repeated;
- involves multiple executors that may run concurrently or arrive late;
- needs pause, resume, auditing, and accountability tracing;
- writes to objects that are high-value and hard to roll back;
- falls under compliance requirements to prove who did what under which authorization.
It is not suited to wrapping every day-to-day code change by default. If a task that can be finished within the current session, with a clear file scope and failures that Git can undo, also has to bear the full cost of Leases, Schemas, Artifacts, Workers, Patches, and Recovery, the control plane itself becomes the main source of complexity.
Temporal's Durable Execution and AWS Step Functions both illustrate a similar boundary: persisted history, state machines, retries, and pauses are extremely valuable for genuinely long-running processes; the value comes from the process needing those properties, not from the idea that a workflow engine is warranted simply because there are “many steps.”
Reading step by step
- Goal routing: what is authorized is an outcome boundary, not “take it all the way”
- Progressive Context: how to get high-signal evidence into the context first
- Stage Graph: when a DAG is more reliable than the model's plan
- State, Event, and Artifact: how the current projection, causal history, and result content divide the work
- Workers: how to turn multiple Agents into a risk-driven evidence system
- Write Isolation: one-time write capabilities and isolated worktrees
- Patch Promotion: how candidate changes cross a trust boundary
- Verification Readback: why tests, CI, deployment, and production behavior cannot vouch for one another
References
- Unrolling the Codex agent loop: the Agent Loop between model, tools, and environment.
- Unlocking the Codex harness: Thread lifecycle, configuration, Sandbox, and the Harness service boundary.
- OpenAI Agents SDK: Agent orchestration: the different tradeoffs between LLM orchestration and code orchestration.
- Temporal Documentation: durable execution, history-based recovery, and long-running Workflows.
- AWS Step Functions workflow states: machine-readable expression of Task, Choice, Parallel, Wait, and terminal states.
Related notes
How My AI Development Workflow Changed: From a Harness to Lightweight Prompts to Enterprise Agents
First a self-built Harness to make up for what models could not do, then a cut down to lightweight Prompts and four gates after Codex 5.6, then the same principles applied to enterprise Agents. What each step removed and kept.
Agent Architecture: Should the Program or the Model Decide the Next Step
The difference between Workflow, Autonomous, and Hybrid is not the framework but who decides the next step. This article covers when each pattern fits, how each one fails, and a selection method that starts from task conditions.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]