← All posts
§ Blog

Exactly once

A headless run is only as trustworthy as its stop conditions and its side effects. Turns are a budget to cap. Writes must happen exactly once.


Exactly once

Picture the overnight job. Nobody is at the desk. A scheduler wakes a machine at one in the morning, and the machine starts a headless coding agent with --max-turns set to a sensible number. The agent has a few MCP tools attached: one reads the ticket queue, one writes follow-up records into the customer system, one drafts an email.

At seven, someone opens the run summary. It says the job finished.

That person is the human in the loop. They were not there at one in the morning, and they should not need to have been. What they need is two answers they can trust. Did the run stop where it was told to stop? Did each write leave the building exactly once?

Two recent Claude Code fixes show how easily either answer can be wrong.

Two promises, not one

A headless run makes two different promises to the person who reads it in the morning.

The first is a stop budget. Turns, spend, an explicit Stop, the end of input. These are limits. Their job is to say “no further than this”, and the run is allowed to finish early.

The second is side effect once. A record created, a message sent, a payment queued. These are not limits. Each one should happen exactly once. Not zero times because a retry gave up, and not twice because a retry did not.

I treat these as separate lines on the same service level. They fail in opposite directions. In a turn leak, the run does more than its budget allowed. In a double send, the run does one thing more often than it meant to. Both end with the same morning: a summary that says done, and a human who cannot tell what actually happened.

Turn leak

Claude Code 2.1.304 lists this fix:

Fixed a plugin keeping a headless run going past --max-turns, Stop, or ended input by spawning subagents or re-running a finished one

Read it slowly. The operator set a turn cap. The operator may even have pressed Stop, or the input may have ended. A plugin kept the run alive anyway, either by starting subagents or by running a finished one again.

It is not the only entry of its kind. A few releases earlier, 2.1.299 fixed “a mod that submits a prompt at the end of every turn keeping a headless run going past --max-turns, --max-budget-usd, an interrupt, or the end of the host’s conversation”.

The lesson is not that plugins are bad. It is that a budget is only a budget if nothing inside the run can reopen it. A cap that applies to the main conversation but not to what the conversation spawns is a polite suggestion. The person who set --max-turns believed they had set a ceiling. What they had set was the height of one room in a building with more floors.

Double send

Claude Code 2.1.307 lists the second fix:

Fixed HTTP MCP tool calls being sent twice when the connection closed mid-call; only read-only or idempotent tools are now retried

This is the oldest problem in distributed systems, arriving on a new surface. The client sends a request. The connection closes before the answer comes back. The client does not know whether the server did the work. If it retries, and the server had already done the work, the work happens twice.

For a read, that costs a few milliseconds. For a write, it is a second record, a second email, a second instruction to someone downstream. Nobody sees it at one in the morning. Somebody finds it at seven, or a customer finds it first.

The fix draws the right line: retry only what is read-only or idempotent. That line is now load-bearing. Whatever tells the client a tool is safe to repeat is carrying the weight of the whole service level. A write tool that claims to be idempotent and is not will be retried, and the retry will look exactly like diligence.

Turn leakDouble send
ReceiptClaude Code 2.1.304Claude Code 2.1.307
What brokeA plugin kept a headless run going past --max-turns, Stop or ended inputHTTP MCP tool calls sent twice when the connection closed mid-call
Which promiseStop budgetSide effect once
DirectionToo longToo often
What the operator believedThe cap was a ceiling for the whole runA dropped call had not happened
What the morning showsA finished summary and more work than was paid forA finished summary and one write too many
What the human in the loop needsWho spent each turn, including spawned workWhich calls left the building, and how many times

Turn leak vs double send

Stop means stop, once means once

The two failures share a root. Each is the system deciding, on its own, that a little more is safer than a little less.

A plugin that spawns another subagent is trying to finish the job. A client that retries a dropped call is trying to make sure the call landed. Both instincts are reasonable in an interactive session, where a person watches and can say “enough”. In a headless run there is no such person. The machine, the schedule and the job are the whole room. A reasonable instinct with nobody watching becomes an unbounded one.

Restarts belong to the same family. Claude Code 2.1.311 fixed “a finished /code-review, or another skill that runs in a sub-agent, running a second time when a cloud or background session restarts”. Codex 0.165.0, released on 27 October, “prevented queued agent messages from restarting work after an interrupt or a switch to Plan mode”. Work that had finished, or had been stopped, came back anyway. A restart has to resume the job without replaying the side effect.

None of these are scandals. They are fixes, shipped and written down in public changelogs, which is exactly where an operator should be reading. The point is what they say about the default. Out of the box, stopping and sending once are things the tooling is still learning to guarantee. Until it does, the guarantee belongs to whoever designs the job.

What the morning reader needs

If the human in the loop is a service level and not a mood, the morning summary has to carry evidence for both promises.

For the stop budget, that means an account of turns that includes everything the run spawned. Not just “40 of 40 turns used”, but which agent, plugin or subagent used them, and whether anything ran after the cap or after Stop.

For side effects, that means a ledger of every write that left the building. One line per call: which tool, which target, whether it was acknowledged, and whether it was ever retried. A write with no acknowledgement is not a failure to retry. It is a question to reconcile: look at the target system and find out whether the record exists, before anything sends it again.

Steal this

  1. Set turn and spend caps at the level of the whole run, and test that no plugin, mod or subagent can reopen them after the cap, an interrupt or Stop.
  2. Treat every MCP write as not idempotent until someone has proved otherwise. Where a write must be repeatable, give it an explicit idempotency key the target system checks.
  3. When a connection drops in the middle of a write, do not retry. Reconcile against the target system first, then decide.
  4. On restart, resume from the last confirmed step. Never replay a finished skill or a sent message because the session came back.
  5. Put two lines on the same slide as the service level: who spent each turn, and which calls left the building, with a count.

Field note from the build-in-public log. NDA-safe, no client names, rounded figures only. If this matches what you are seeing, get in touch.

§

BELOW THE LINE

PODČÁRNÍK · SIDEWAYS GLANCE, NOT A SUMMARY

On the colleague who faxed the order again, just to be sure

Office supplies were his. Once a quarter he filled in the order form by hand, forty boxes of toilet paper among other things, and fed it into the fax by the window.

Anyone who sent a fax in those years knows the ritual. You dial, you wait for the screech, you watch the page crawl in and come out the other side, and you stand there for the little slip that says OK. You do not leave the machine. Leaving the machine is how faxes go wrong.

That morning the page went through, the line clicked, and the slip came out saying Communication error. He looked at it for a long time. Then he did the responsible thing. He fed the form in again, stood through the whole screech, and this time got his OK. He initialled the slip and filed it.

On Thursday a lorry arrived with eighty boxes.

The supplier was an honest firm. They had received two orders, on the same paper, in the same handwriting, ten minutes apart, and nobody there was paid to ask whether a man wanted his toilet paper twice.

The boxes went into the stockroom, then the corridor, then the small meeting room. By spring they were a wall in the boss’s office. At the Christmas party half of accounts sat on them. Two reorganisations later, new starters were still told to take a roll home if they were passing.

Nobody blamed him. He had been careful. The first fax had arrived on Monday, whole and readable. It was the second one that cost the meeting room for a year, and a phone call to the supplier would have taken two minutes. But ringing felt like doubt. Faxing again felt like diligence.

Today the order goes out at three in the morning, and there is no screech to stand next to. When the line drops, the machine does not hesitate over the slip. It is careful in exactly his way.

ČESKY. ORIGINÁL PODČÁRNÍKU

O kolegovi, který tu objednávku faxoval ještě jednou, pro jistotu

Kancelářské potřeby měl na starosti on. Jednou za čtvrtletí vyplnil objednávku ručně, mezi jiným čtyřicet balíků toaletního papíru, a strčil ji do faxu u okna.

Kdo v těch letech faxoval, ten rituál zná. Vytočíš číslo, čekáš na pískání, koukáš, jak papír leze dovnitř a zase ven, a stojíš u toho, dokud nevyjede proužek s nápisem OK. Od faxu se neodchází. Kdo odejde od faxu, ten si koleduje.

Toho rána papír prošel, linka cvakla a proužek vyjel s nápisem Chyba spojení. Dlouho na něj koukal. Pak udělal, co udělá zodpovědný člověk. Strčil objednávku do faxu znovu, vystál celé pískání a tentokrát dostal svoje OK. Proužek parafoval a založil do šanonu.

Ve čtvrtek přijelo auto s osmdesáti balíky.

Dodavatel byl poctivá firma. Dostali dvě objednávky, na stejném papíře, stejným písmem, deset minut po sobě, a nikdo z nich nebyl placený za to, aby se ptal, jestli chce člověk toaletní papír dvakrát.

Balíky skončily ve skladu, pak na chodbě, pak v malé zasedačce. Na jaře z nich byla zeď v kanceláři šéfa. Na vánočním večírku na nich seděla půlka účtárny. Ještě po dvou reorganizacích se novým lidem říkalo, ať si vezmou roli domů, když jdou kolem.

Nikdo mu nic nevyčítal. Byl pečlivý. První fax dorazil v pondělí, celý a čitelný. Zasedačku na rok stál ten druhý, a telefon dodavateli by trval dvě minuty. Jenže zavolat vypadalo jako pochybnost. Faxovat znovu vypadalo jako svědomitost.

Dnes objednávka odchází ve tři ráno a není u čeho stát a poslouchat pískání. Když linka spadne, stroj nad proužkem neváhá. Je pečlivý přesně jako on.