AIFeed

The script has flipped: AI writes the logic, a compiler derives the plumbing

Original text(via HN AI)

The script has flipped: AI writes the logic, a compiler derives the plumbing

Models and agent frameworks change every few weeks. The code that moves money once should not have to change with them.

Cube Root · December 3, 2026 · 12 min read

AI agents have changed what a business application does. A request is no longer one call and one answer. An agent asks a model, waits for tools, waits for a person, and asks again. Every run is a flow of many steps, on machines that fail.

They have also changed how fast the ground moves. Models, agent frameworks and protocols change every few weeks. Code tied closely to this month's tooling is next year's rewrite.

Software as a service grew into a business worth hundreds of billions of dollars a year, and it is everywhere. Much of it is not only used but built on, and a service that is built on comes with an SDK. Through the SDKs it made its way all the way into the business logic. Teams accepted that as the price of not building it themselves. With AI writing the logic, that price has become friction: the part that should change every week is tied to the part that must not.

Here are both parts in one piece of code: the money-moving end of a bank transfer, written against an engine's SDK. The engine, MyEngine, is invented for this article; it is no product's API. The marked lines are the platform.


        Compensations undo = engine.compensations();
try {
    String posting = engine.step("debit", () -> bank.debit(t));
    undo.add(() -> engine.step("reverse", () -> bank.reverse(posting)));
    String sent = engine.step("send", () -> rail.send(posting));
    outcome = "sent " + sent;
} catch (Exception e) {
    undo.run();
    outcome = "refused by the rail - the debit is reversed";
}
      

And here is the same code, split in two.

Part 1: the business logic. It stays in your file. It is the part that changes every week, and a person can read it.


        try {
    String posting = debit.apply(t);
    String sent = send.apply(posting);
    outcome = "sent " + sent;
} catch (Exception e) {
    outcome = "refused by the rail - the debit is reversed";
}
      

Part 2: the plumbing. It moves out of the file. Nobody writes it; a compiler derives it from part 1.

Derived from part 1What it does
A step for debitRecorded as a row when it finishes; a finished step is not run again
A step for sendRuns after the debit, because it needs the posting
The undoIf the send fails, the debit is undone first, then the catch runs
RecoveryAfter a crash the work goes on from the rows

Five lines of platform left the business code, and nothing was lost. The rest of this article is about why that split is now necessary, what it saves, and what it takes to make it.

Here is the flip. Writing code used to be the cost. Now an AI writes it in a minute, and the cost is checking what it wrote. Seen that way, there are two kinds of code: one a person can check by looking at it, and one a person cannot.

Two kinds of code

Layer 1: the business logicLayer 2: the infrastructure
What it isThe rules of the business and the agent's loop: judge the risk, screen the payee, ask a person when in doubt, move the moneyDurability, calls that run in parallel safely, the undo when a step fails, knowing where the work was when the machine died
What it looks likeSmall, rule-based, one step after anotherMany machines, listeners, retries and timing; the order of things is not on the page
Writing itEasy with domain knowledge, and an AI helpsNotoriously hard, even with an AI
Who can check itAnyone who knows the business, by reading itAn extremely seasoned engineer, and not by reading alone
What should check itA personA compiler

Layer 1 stays free only if it is written with the language's own types: Function<A, B> in Java, Callable in Python, a function type in TypeScript. No SDK. Then it is tied to no model, no agent framework and no engine.

Nobody knows where AI goes next. This split is already clear, though, and it means rethinking development from its first point of contact: the IDE.

The first contact is the IDE

The first decision is made before a line of code is written: what you install.

What you installWhat it ties you to
An IDE pluginOne platform's way of writing a flow
A command-line tool or a local serverOne platform's way of running it
An SDK in the build fileOne platform's types, in every file that uses them

The SDK is the one that matters most. The moment it is installed, the code is written against that platform. When platforms change as fast as they do now, the team that installed it is the team that carries the cost of moving.

So the IDE should open in a browser. No plugin, nothing to install, and no SDK. The code is written against the language itself: pure Java, pure Python, pure TypeScript.

What an SDK looks like in the code

Here is the whole bank transfer written against the same invented SDK. MyEngine is no product's API. Real SDKs differ in their names. The shape is familiar.


        import com.myengine.sdk.Engine;
import com.myengine.sdk.Workflow;
import com.myengine.sdk.Pending;
import com.myengine.sdk.Compensations;

@Workflow
public class CoreTransferWorkflow {
    private final Engine engine = Engine.current();

    public String run(Transfer t) {
        Pending<RiskVerdict> risk = engine.async(() -> {
            Transcript question = engine.step("riskPrompt", () -> prompts.risk(t));
            LlmResponse answer = engine.step("riskModel", () -> model.ask(question));
            return engine.step("readVerdict", () -> verdicts.read(answer));
        });
        Pending<ScreeningVerdict> screening = engine.async(() ->
            engine.step("sanctions", () -> sanctions.screen(t)));
        engine.awaitAll(risk, screening);

        String decision = "approved";
        if (risk.get().level().equals("high") || screening.get().result().equals("hit")) {
            decision = engine.waitForSignal("review");
        }

        String outcome = "rejected in review";
        if (decision.equals("approved")) {
            Compensations undo = engine.compensations();
            try {
                String posting = engine.step("debit", () -> bank.debit(t));
                undo.add(() -> engine.step("reverse", () -> bank.reverse(posting)));
                String sent = engine.step("send", () -> rail.send(posting));
                outcome = "sent " + sent;
            } catch (Exception e) {
                undo.run();
                outcome = "refused by the rail - the debit is reversed";
            }
        }
        return outcome;
    }
}
      

The marked lines name the engine. They are the lines you do not want in your code. And they are only the ties you can see.

Ties you can see in the codeTies you cannot
The importsThe SDK's version in the build file, kept in step with the server's
engine.step around every effectRules on what the code between steps may do: the clock, random numbers, threads
engine.async and engine.awaitAll for parallel callsThe workers, queues and registrations a flow needs before it starts
The undo, added by handWhat a change to the code does to runs already under way

Where is the infrastructure?

One would expect to open a file and see it: here is the business logic, there is the infrastructure. There is no such file. The infrastructure is in-band: it is part and parcel of the business logic.

图表:Today: the two layers share every file, line by line.

This has three costs.

You cannot review the logic on its own. When an AI produces a flow, you want to look at it and say yes or no to the business. You cannot: every change touches both layers, so every review needs someone who knows the engine as well as the business. The logic cannot be upgraded or refined independently.

The plumbing is the hard part to get right. Platform code runs across many machines, with listeners, retries and timing between them. That is where the race conditions live. You can test for the bugs you know. You cannot test every order in which things may happen, so a test can show that a bug is there, and never that none is left.

Checking such code takes an extremely seasoned engineer, and concurrency bugs get past seasoned engineers too. If an AI writes this code again each time the logic changes, it must be checked again each time, by the few people who can. The tokens are spent on the part nobody can validate by reading.

The durable execution engines of today are carefully engineered and widely used, and they make layer 2 dependable. Most of them are libraries, and a library has to be called from the code it serves. That is useful, but it does not keep the two layers apart.

Where the tokens go

There is a third cost, and it is the one that shows up on a bill. An AI is paid by the token: for every line it reads and every line it writes. In a working session it reads the code again at each turn. So the cost grows faster than the code does: twice the code is more than twice the cost, because there is more to read, more turns to get it right, and more to read again at every turn.

The plumbing is where that cost is highest, three times over.

The cost ofWhy the plumbing costs more
Writing itIn the transfer above, 20 of the 36 lines name the engine, and they are written again whenever the logic around them changes
Getting it rightThey are the lines that take the most turns, and then a seasoned engineer
Testing itThe largest of the three

Testing is the largest because the two kinds of code are tested in different ways. Business logic is tested with examples: this transfer is risky, that one is not. A few lines each, and an AI writes them in one pass. Plumbing is tested against what might go wrong: a machine dies between the debit and the send, two answers arrive in the wrong order, a retry lands twice. Each case needs a harness of its own, and nobody can list all the cases. So the tests grow larger than the code they test, they are written in the hope of catching most of it, and every line of them is read and written by the token.

The two layers mixedThe two layers split
What the AI reads and writesBoth layers, every timeThe business logic only
A change to one ruleThe plumbing around it is read again, and often written againThe plumbing is not in the file
Getting the plumbing rightMany turns, then a seasoned engineerNo turns: a compiler derives it
The testsHarnesses for crashes, orderings and retries; many lines, never completeExamples of the business rule; a few lines
Tokens spent on plumbingA large share, and the costliestNone

A small sum shows the size of it. Suppose taking the plumbing out makes the code half as large. If the number of turns grows with the size of the code, and every turn reads all of it again, the cost does not fall to a half. It falls to about a quarter. And that counts the code only. Add the tests the plumbing needed, which are no longer written at all, and the saving is larger still.

So here is the argument, stated plainly. Infrastructure code that is generated, and entangled with the business code, will soon be an albatross around the neck of every enterprise system that carries it. Each change costs more than the last: more to read, more to test, more to have checked. And it grows with every feature the AI adds.

The cost is removed where it was highest. A compiler is not paid by the token, and a platform is tested once, by the people who build it, not again by every team that uses it.

The glue between them is harder still

There is a third piece of code. It lives at the boundary, where the business logic meets the infrastructure.

The glueThe question it answers
VersionsWhich version does a run follow, when the code changed while it was waiting?
ContractsWhen what a service is sent or answers changes, what happens to its callers?
Typed wiringDoes every call reach something of the right type, and every component the right kind of machine?
RoutingA canary, a split, a rollback: who gets the new version, and how is it taken back?
ConversationsSome end in a second, some wait days for a person. Who keeps them while they wait?
UpgradesWhat happens to the conversations under way when a new version arrives?

One might think the glue is the easy part. It is the hardest of the three.

WhyWhat it means
It has two mastersIt must fit the business code as it is today and the platform as it is today. Every publish moves one side; every platform upgrade moves the other.
It lives in timeThe old version and the new one run at the same moment. A conversation that began last week is still waiting for a person.
It fails quietlyA mistake here does not crash. It sends a good message to the wrong version, and shows up days later.

When the glue is written into the business code, it looks like this. MyEngine again, invented:


        int v = engine.version("add-sanctions-check", 1, 2);   // runs begun before the change keep the old path
if (v >= 2) {
    screening = sanctions.screen(t);
}
String rail = engine.flag("canary-rail-v2") ? "rail-v2" : "rail-v1";
      

A version check and a canary flag, in the file a person who knows banking is supposed to read. Glue should never be part of the business logic. The further it is pushed to the infrastructure side, the better.

How to solve the glue: eight rules

Take two small changes to what the risk agent answers.


        record RiskVerdict(String level) {}                  // contract 1

record RiskVerdict(String level, String reason) {}   // a field added: still contract 1

record RiskVerdict(int score) {}                     // a field removed, another kind: contract 2
      

The transfer that calls the agent was built against contract 1. Runs are under way. What should happen?

What changedThe contract?What should happen
A commentNoNothing; it is not even a new version
A settingNoThe same version; the change is recorded beside it
The code inside the risk agentNoA new version of the same contract; callers are not touched
The answer gains reasonNoAn added field is compatible: a caller that does not read it is not touched
A field a caller reads is removed, or changes its kindYesA new contract. Old callers keep contract 1, through an adapter

Behind that table are rules. They hold for any platform, whoever builds it.

RuleWhat it means
1. The contract is what a caller can seeWhat a service is sent and what it answers. A field that is added and that no caller reads does not break it; a field that is removed or changes its kind does. Everything else is not the contract.
2. A version never changesA change is a new version. The old one stays as it was.
3. The compiler works out the versionFrom what changed. Nobody types a version number, so nobody types the wrong one.
4. No contract without an endpointA contract is published together with an endpoint, even an empty one. If the code behind it is not ready, a message is held until it is, or is answered by an older version through an adapter, or the caller is told before anything is sent. A message is never left with nowhere to go.
5. Wiring is type-checked before anything runsA call that does not fit is refused when it is built, not found in production.
6. Adapters are upgraded automaticallyWhen a contract moves, the adapter between the old and the new is brought up to date by the platform, not by hand in the business code.
7. A run keeps the version it began onNew runs follow the new routing. A run that is under way finishes on the version of the code it began on.
8. Routing is cleared first, and can be undoneA canary is checked before it takes traffic. Routing changes are recorded, and the newest can be taken back exactly.

Rule 4 deserves a word. A message that finds nobody listening becomes a dead letter, and dead letters create more problems than they solve: someone has to find them, understand them and send them again. It is better that every route ends somewhere. So a new contract can be published early: until the new code is ready, its messages wait, or are answered by the older version through an adapter. A team that thought it was ready and was not loses nothing, and its callers get time to move.

Not one of these rules needs a line in the business logic. Each can be held by a compiler and a platform, which is why the glue belongs on that side:

In the business codeOn the infrastructure side
Version branches, kept until the last old run endsRules 2, 3 and 7
A wrongly typed call, found in productionRules 4 and 5
A hand-written conversion between old and newRule 6
A canary flag in the flowRule 8
A rollback by redeployingRule 8

What a person cannot check, a compiler should

Code that cannot be validated by reading it, or by testing it, has to be checked another way: by a compiler, before it runs.

Some compilers do far more of this than others. Rust is the well-known one. Its compiler refuses a data race before the program ever runs: the engineer does not hunt for that bug, because the program that has it does not compile.

The same idea belongs one level up, in the flow. A compiler that reads the business logic can derive the plumbing instead of anyone writing it. It runs two steps together only where it has shown that to be safe, and it refuses a hint that would race, naming the line. The plumbing is then not written again by an AI at each change. It is derived, the same way every time.

The same transfer, one layer only

This is what the business logic should look like. Plain Java; it imports nothing but the JDK.


        import java.util.function.Function;

public class CoreTransfer {
    private Function<Transfer, Transcript> riskPrompt;      // the AI agent's question
    private Function<Transcript, LlmResponse> riskModel;    // the model that answers
    private Function<LlmResponse, RiskVerdict> readVerdict; // its answer, read as a verdict
    private Function<Transfer, ScreeningVerdict> sanctions; // the bank's screening service
    private Function<Transfer, String> review;              // a person, minutes or hours later
    private Function<Transfer, String> debit;
    private Function<String, String> send;

    public String invoke(Transfer t) {
        Transcript question = riskPrompt.apply(t);
        LlmResponse answer = riskModel.apply(question);
        RiskVerdict risk = readVerdict.apply(answer);
        ScreeningVerdict screening = sanctions.apply(t);
        String decision = "approved";
        if (risk.level().equals("high") || screening.result().equals("hit")) {
            decision = review.apply(t);
        }
        String outcome = "rejected in review";
        if (decision.equals("approved")) {
            try {
                String posting = debit.apply(t);
                String sent = send.apply(posting);
                outcome = "sent " + sent;
            } catch (Exception e) {
                outcome = "refused by the rail - the debit is reversed";
            }
        }
        return outcome;
    }
}
      
In the codeWhat a compiler can derive
riskPrompt , riskModel , readVerdictThree steps, one after the other: each needs the answer before it
sanctions.apply(t)A step that runs beside the agent's three: it needs only the transfer
if (risk ... ││ screening ...)Waits for both answers, then decides
review.apply(t)The flow waits for a person, for minutes or for days; no thread waits with it
try { debit ... send ... }Two steps, in order
catch (Exception e)If the rail refuses, the debit is undone first, then the catch runs

Nobody wrote "run these two together". Nobody wrote the undo. An AI can write this file, and a person who knows banking can read all of it.

The separation

A compiler reads the plain code, checks it once, and produces two things. They should go to two different places.

The workerThe infrastructure
What is in itThe steps of your business logic: its calls to your systems and its blocks of code, prepared by the compiler to run one after another, or together where the compiler has shown that to be safeThe execution graph (the order, the branches, the loops), the parallel routing, the undo, and the state, all kept by the platform
Who wrote itYou, or your AINobody: it is derived
Where it runsSeparately from the platform: on your own machines or on a public cloud. Both should be offeredOn the platform
The glueNone of itAll of it: versions, typed wiring, routing
What changes itA change to the businessThe next compile

Who calls whom

The two halves talk to each other, and the direction matters. The platform should never call the worker. The worker holds the business logic. Wherever it runs, privately or publicly, no outside system should be calling into it. So every conversation is started by the worker.

StepWhat happens
1. StartThe worker is started, wherever you chose to run it
2. HandshakeThe worker opens the connection and says who it is
3. AskThe worker asks for work
4. WorkIt runs the step: your code, where you chose to run it
5. DoneIt reports the step done
6. Ask againIt asks for more

Why this is the safer way round:

  • No door is opened into the place the worker runs
  • The platform holds no address of the worker and no way in
  • Stop the worker, and no call reaches your systems
  • More work to do? Start more workers; each one asks for its own

Pulling work is not a new idea, and careful engines do it too. What is different is what sits on each side of the line: only your logic on yours, all of the plumbing on the other.

What you expect out of the box

While all of this goes on, you expect a good deal more, and none of it has anything to do with the business.

You expectMeaning
ScaleMore machines, and close to that much more work done
Machines that failThe work goes on when a few servers are down
ObservabilityWhat ran, where and how long, with nothing to add
Agent toolsA tool call that is a simple service call
Limits on toolsA say over what each tool may reach and expose
A reviewA way to look at a change before it goes live

Not one of these is a business rule. So not one of them should cost a line in the business logic.

What changes, and what you touch

What changesWhat you touch
A new modelNothing in the code: the model is chosen when the flow is deployed
A new agent patternThe loop, a few lines of ordinary code
A new business ruleThe logic; an AI writes it, you read it
The plumbingNothing: it is derived again at the next compile

The tokens go to the part a person can check. The part that must be right every time is not generated at all; it is derived.

Who can do this, and who cannot

Every engine below is carefully engineered and useful in the form it offers. Most chose a library over a compiler, which is a fair choice: there is no new toolchain to trust. The questions are the ones this article raised.

QuestionCube RootTemporalAWS Step FunctionsGoogle Cloud WorkflowsAWS Lambda durable functionsAzure Durable FunctionsInngestRestateDBOSVercel WorkflowLittleHorse
Infrastructure generated by a compiler✓✗✗✗✗✗✗✗✗✓partly
The graph, derived from plain code✓✗——✗✗✗✗✗partly✗
Parallel calls checked for races before they run✓✗partlypartly✗✗✗✗✗✗✗
Recovery without replaying your code✓✗✓partly✗✗✗✗✗✗✓
Wiring type-checked before anything runs✓✗✗✗✗✗✗✗✗✗partly
Version worked out by the compiler✓✗partlypartly✗✗✗✗✗partly✓
A safe canary, cleared by the compiler✓✗partly✗✗✗✗✗✗✗✗

✗: not described in the engine's own documentation. partly: it describes part of it. —: does not apply, the workflow is a graph declared in YAML or JSON. From each product's public documentation, read November 2026; the full table and its notes are at cube-root.com/compare.

Where we stand

This article is published by Cube Root, and the first column is ours. We built a compiler because of the argument above: it turns plain Java, TypeScript and Python into a graph of durable steps kept in PostgreSQL, and the IDE is a browser tab.

Our own limit, stated plainly: the compiler checks the code it can see. What a third-party library does inside, it takes at your word.

Use AI where its work can be checked. Use a compiler where the work must be proved.

The transfer above is one of the sample projects in the browser IDE at cube-root.com: open it, right-click and choose View execution graph. Nothing to install.

The short version of the token argument: Dude, where are my tokens?

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗