The problem starts on step two
Give a coding agent one task and it will often do something reasonable. Give it a second task that begins from the code it just wrote, and the interesting failures start. It renames a helper it invented on step one without updating the three call sites it also invented. It picks a different error-handling convention because the first one is no longer in its context window. It quietly reinterprets what "extend the parser" meant.
A recent benchmark makes this concrete. Multi-step SWE is a long-horizon benchmark of 69 software engineering tasks, each a chain of 5-15 dependent steps on a single codebase. Every step starts from the code the agent produced in the preceding steps, so early design decisions and errors carry forward. The authors report that across nine frontier models the strongest reaches a solve rate of only 18.5%, and 38 of the 69 tasks are not solved by any model. Those numbers are theirs, from that paper, on that benchmark. Treat them as a signal about difficulty, not a prediction about your repo.
The paper's argument is that one-task benchmarks miss the failure modes that matter in sustained project work. That matches what you see in practice: most of the pain is not a single wrong function, it is drift between steps. This article is a playbook for running agents across chains of work without letting that drift compound silently.
What actually compounds between steps
Three things, mostly.
Abstraction choices. If step one invents a DocumentStore interface with five methods, every later step has to live inside that shape. If the shape was wrong, the cost is paid five times over. An agent that would have chosen a flat module for a one-off task may choose a layered one when it senses a larger project, and then you are stuck with the layers.
Naming and conventions. Error types, log formats, config keys, test naming. Each is trivial alone. Together they decide whether step eight's test suite can even find step two's fixtures.
Implicit intent. The agent's reasoning on step one is gone by step four. What remains is code. If the code does not encode why a decision was made, later steps will re-derive a different why.
A senior engineer running this kind of chain does not try to make the agent smarter. They change the environment so that the cost of drift is visible early and cheap to fix.
Checkpoint design decisions between steps
The core move: after each step, the harness records what was decided, not just what was written. This is a small structured artifact, not prose. Something a later step can read and a human can diff.
Here is a runnable Node.js harness. It runs a chain of steps, asks the agent for a decision record alongside its code, validates the record against a schema, and persists it. The model call is stubbed with an injectable function so the harness is testable without a network.
// chain-harness.mjs
import { writeFile, readFile, mkdir } from 'node:fs/promises';
import { join } from 'node:path';
const REQUIRED_DECISION_KEYS = ['step', 'summary', 'interfaces', 'conventions', 'openQuestions'];
function validateDecision(record) {
if (typeof record !== 'object' || record === null) {
throw new Error('decision record must be an object');
}
for (const key of REQUIRED_DECISION_KEYS) {
if (!(key in record)) {
throw new Error(`decision record missing key: ${key}`);
}
}
if (!Array.isArray(record.interfaces)) {
throw new Error('interfaces must be an array');
}
for (const iface of record.interfaces) {
if (typeof iface.name !== 'string' || typeof iface.signature !== 'string') {
throw new Error('each interface needs name and signature strings');
}
}
return record;
}
// agentFn(step, priorDecisions) -> { code, decision }
// Replace with your real model call. Kept injectable for tests.
async function runChain({ steps, agentFn, outDir }) {
await mkdir(outDir, { recursive: true });
const decisions = [];
for (const step of steps) {
let result;
try {
result = await agentFn(step, decisions);
} catch (err) {
throw new Error(`agent failed on step ${step.id}: ${err.message}`);
}
const decision = validateDecision({ ...result.decision, step: step.id });
decisions.push(decision);
await writeFile(join(outDir, `step-${step.id}.code.txt`), result.code, 'utf8');
await writeFile(
join(outDir, `step-${step.id}.decision.json`),
JSON.stringify(decision, null, 2),
'utf8'
);
}
await writeFile(
join(outDir, 'chain.json'),
JSON.stringify(decisions, null, 2),
'utf8'
);
return decisions;
}
// --- illustrative wiring ---
const steps = [
{ id: 1, request: 'Build a CSV parser exposing parse(text) -> Row[]' },
{ id: 2, request: 'Add quoted-field support without changing parse signature' },
{ id: 3, request: 'Add streaming parseStream(readable) reusing the same Row type' }
];
async function fakeAgent(step, priorDecisions) {
return {
code: `// step ${step.id} code placeholder\n`,
decision: {
summary: `implemented: ${step.request}`,
interfaces: [{ name: 'parse', signature: 'parse(text: string): Row[]' }],
conventions: ['errors thrown as ParseError with .offset'],
openQuestions: priorDecisions.length ? [] : ['Row type not yet fixed']
}
};
}
runChain({ steps, agentFn: fakeAgent, outDir: './chain-out' })
.then((d) => console.log(`recorded ${d.length} decisions`))
.catch((err) => {
console.error(err.message);
process.exitCode = 1;
});The important part is not the file writing. It is that priorDecisions is passed into every step. The agent does not have to guess what it decided; it is told. And openQuestions is the escape valve: when step one admits the Row type is unsettled, step two can settle it deliberately rather than inheriting an accident.
This pairs naturally with the durability concerns in durable agent workflows: state, retries and merge gates β the decision log is just another piece of state that must survive a retry or a resume.
Constrain abstraction choices early
The most expensive decision in a chain is usually the first structural one. You have two levers: tell the agent what shape to use, or tell it what shape not to use.
Positive constraints are cheaper to verify. "Expose a single module with named exports; no classes; no dependency injection." That is checkable. Negative constraints ("don't over-engineer") are not.
A practical pattern is a shape budget for the first two steps: a maximum number of new files, a ban on new dependencies, and a required list of exported symbols. If step one stays flat, step four can still introduce structure when the need is real. If step one goes layered, you cannot easily go back.
This is where a lot of agent output goes wrong in a way that looks like competence. Layered architecture reads as senior. It is not senior if the problem is a 200-line parser. A senior engineer would say: keep it flat until the second consumer appears. Encode that as a rule the harness checks, not as advice in a prompt.
Write interface contracts the agent must honor
A decision record is documentation. A contract is an assertion. The difference matters because documentation drifts and assertions fail loudly.
A contract here means a small set of machine-checkable statements about the public surface: exported names, function arities, error types, and a couple of behavioral examples. The harness runs them after every step. If step three changes parse's signature, the chain stops before step four builds on the change.
// contract.mjs β run after each step
import assert from 'node:assert/strict';
export function checkContract(mod, contract) {
for (const name of contract.exports) {
assert.equal(typeof mod[name], 'function', `missing export: ${name}`);
}
for (const [name, arity] of Object.entries(contract.arities)) {
assert.equal(mod[name].length, arity, `${name} arity changed`);
}
for (const example of contract.examples) {
const actual = mod[example.fn](...example.args);
assert.deepEqual(actual, example.expected, `behavior drift in ${example.fn}`);
}
}Keep contracts small. Five to ten assertions on the public surface will catch most drift. A full test suite is a different tool; this is a tripwire. For the CI side of running these checks reliably, see testing what your LLM agent actually did in CI.
A worked chain, briefly
Hypothetical chain for a CSV parser:
- Step 1:
parse(text) -> Row[], flat module, one file. Contract:parseexported, arity 1. - Step 2: quoted fields. Contract adds a behavioral example with an embedded comma.
- Step 3:
parseStream(readable). Contract requires it to reuse the sameRowtype β checked by a shape assertion on output. - Step 4: error offsets. Contract requires
ParseError.offsetto be a number on malformed input.
At each step the harness loads the previous decision record, passes it in, runs the contract, and appends a new record. If step 3 decides to introduce a Tokenizer class, the decision record shows it and you can approve or reject before step 4.
The tradeoff: freedom versus structure
There is no free lunch here. Tighter constraints make chains auditable and resumable; looser constraints let the agent find solutions you did not anticipate.
Dimension β Loose constraints β Tight constraints Β· Reproducibility β Low; each run diverges β High; shape is pinned Β· Novel solutions β Possible β Suppressed Β· Debugging drift β Hard; intent is implicit β Easier; decisions are logged Β· Cost of a bad step 1 β High, discovered late β Lower, caught by contract Β· Suits β Exploration, prototypes β Sustained project work
The right default for long-horizon work is tight on structure and loose on implementation. Pin the interfaces and conventions; leave the internals to the agent. When you genuinely want exploration, run it as a separate short chain and promote the result into the constrained one.
Failure modes and limits
The contract becomes the spec. If your contract is too detailed, you have written the code yourself in assertion form and the agent just fills in bodies. That is sometimes what you want. It is not what you want when you are trying to learn what the model can do.
Decision records lie. An agent can write a decision record that describes what it meant to do, not what it did. Validate the record against the code β arity checks and behavioral examples do most of this work.
Context still runs out. Passing full decision history into every step grows without bound. Summarize older records; keep full detail for the last two or three steps. This is the same housekeeping problem covered in context engineering is mostly housekeeping.
Benchmark numbers do not transfer. The 18.5% figure is on a specific benchmark with specific tasks. Your repo, your conventions, and your harness will produce different results. Do not plan capacity around it.
The paper does not specify harness details. Multi-step SWE describes tasks and scoring; it does not prescribe a decision-log format or contract mechanism. The patterns above are engineering choices, not claims from the paper.
What to do on Monday
Pick one chain of three to five steps you would normally hand to a person. Add a chain.json decision log between steps. Add a contract file with five assertions on the public surface. Run it once with the agent and once with a human, and compare where they diverge. That comparison is more useful than any benchmark score for deciding how much freedom to grant.
Sources
- Multi-step SWE: Can Coding Agents Keep Building on Their Own Code Over Long Horizons? β arXiv cs.SE, 2026-11-06.