The problem with ten implementations
Dagr is a schema language and a set of code generators. From one schema it writes a library in Swift, Rust, TypeScript, Go, C++, C, Java, Mojo or Odin, and it has a reference implementation in Python. Each must write the same bytes for the same value, and read what any of the others wrote.
Writing the tenth is not interesting work. It is the ninth again in different syntax, with the four layouts of chapter 5 multiplied by every kind of field, by optional and required, by several ways of reading. A person tires of it and starts to make mistakes. That is exactly the kind of work an AI agent is suited to, if there is a way to know that what it wrote is right.
So the method is about that second half. Three things carry it.
One: write it down first
Nothing is built in Dagr before it is written down. The repository has a directory of numbered documents. Some are the specification of the format itself, each rule with its reason. The others are plans: before a new language is started, a document says what will be built in what order, which decisions are open, and how each step will be tested.
This would be good practice with any team. With an AI it is a necessity, for a reason that is easy to overlook: the agent remembers nothing. Every working session starts from zero. What it knows about the project is what it can read at that moment. So the plan has a progress log at its end, kept up to date as the work proceeds, and a short file of standing instructions says what must never be got wrong and where each topic is written up.
The documents are the project's memory. When the code and a numbered document disagree, that is treated as a defect in one of them and resolved, and not left as prose that has gone stale.
Two: golden bytes
A specification in English can be read two ways. Bytes cannot. So beside the documents there is a body of test cases, each a small schema, a value, and the exact bytes that value must become.
- A generated corpus. A script produces a schema for each combination that matters: each layout, each kind of field, optional and required, single and in lists. That is more than a thousand cases for graphs and some hundreds more for sinks and shared buffers.
- Every implementation writes every case, and the outputs are compared with each other, byte for byte. Each also reads what the others wrote.
- Committed goldens. For rules the corpus does not reach, there are files of bytes checked into the repository, written by the Python reference. Every language must read each one and write it again identically.
The test is a comparison of bytes, and that makes it a good match for an AI. The answer is yes or no. It cannot be argued with, and nobody has to judge whether the output looks reasonable. When it fails, it says at which byte, which is usually enough to find the cause. And it turns "implement the format in Java" from a matter of judgement into a task with an end: the work is done when every case matches.
Earlier chapters met this already. The panels in this guide are small writers in JavaScript, and each is checked in the same way against Dagr's reference before it is published.
Three: tests that test the tests
Identical bytes show that valid data is handled correctly. They say nothing about data that is not valid, and a reader in C or C++ that trusts a length it was given will read memory it should not.
- Sweeps. For each case, the buffer is cut short at every possible length, and every byte is replaced by several other values. The reader must answer each of these thousands of damaged buffers with an error or with a value, and never with a crash.
- Mutation checks. A script removes one safety check from the hand-written runtime, runs the tests, and puts it back. If the tests still pass, the check was not being tested, and that is reported as a failure. It is repeated for every check.
The second of these matters more with an AI than without. An agent asked to make tests pass will sometimes write a test that cannot fail. A mutation check does not look at how a test reads. It looks at whether the test notices the fault.
What the history shows
The figures below are read from the repository's commits by a script. Choose the whole project or one of the four languages that were added most recently.
Read the times with some care.
- A commit's time is when work was recorded, not how long it took. Go's first commits fall within minutes of each other: the work was done before and committed in pieces. For Go, the history shows only that the whole port was recorded in one afternoon and evening.
- The others are spread out as they happened. C++ took about six days from its first commit to the end of its plan. C took a little over three. Java took about twenty-five hours by the clock, a night included, from the plan to the last step.
- The later ones were asked to do more. C++, C and Java each include the sweeps and mutation checks described above, and benchmarks against Protocol Buffers. The first languages did not have them at the start.
- The history is public only from July 2026. The format's design and the first two languages, Swift and Rust, are older than the commits.
Each of these ports is several thousand lines of generator and several thousand of runtime library, tested on the whole corpus. That it now takes days is not because the agent types quickly, although it does. It is because by the fourth new language, the plan had a known shape, the tests existed, and the specification had been corrected by three earlier attempts to follow it.
What a new language finds
An implementation written from the specification is also a test of the specification, and of the older implementations.
- Rules that were never written down. Several byte-level rules were known only as "what the Swift and Rust writers happen to do". A new writer did something else that was also reasonable, the comparison failed, and the rule went into the document and a case into the goldens.
- Old bugs. While the C version of the shared buffer was being written, a fault turned up that C++, Rust and Swift all had: a program that splits into two processes kept using its parent's identity when taking a lock. Three implementations had agreed with each other and all were wrong.
- Blind tests. One stress test for torn reads could not fail, because the two fields it watched happened to be copied in a single step. Writing the same test for another language exposed it.
What the tests did not catch
An honest account has a list of these as well.
- Slow code that is correct. More than once, and in more than one language, the agent wrote a way of walking a list whose cost grew with the square of its length. Every byte matched. Benchmarks found it, not tests. A benchmark is now part of the plan for each language.
- Ideas that sounded right. Several optimizations were built, measured as slower, and taken out again. Nothing is kept on the strength of an argument. A change for speed comes with a measurement.
- Agreement in error. Golden bytes show that implementations agree. If the reference is wrong, they are all wrong together, as with the lock above. An independent reading of the specification is the only defence, and each new language is one.
The pattern in what followed is the useful part: each of these became a test. A fault that is found is turned into a case that every language must pass from then on, so that it is found once.
Who does what
Almost every commit in the history names an AI model as co-author. That does not describe how the decisions were made.
- The person decides what Dagr is. Which layouts exist, what a default means, that a new language is worth having, and which of two designs to take when both work. Many of these are recorded with their date in the plans, so that a later session does not reopen them without new evidence.
- The person decides what counts as done. "Byte-identical on the whole corpus" and "no crash on any damaged buffer" are requirements set from outside. An agent asked to make them true can be checked. One asked to "write a good Java library" cannot.
- The agent does the breadth. One rule applied in ten languages and four layouts. A plan carried out step by step, with the tests run after each. Reading all of a specification again before each change, which no person does.
- The agent proposes, and is often wrong in an instructive way. A draft plan with its open questions listed is quick to produce and quick to correct.
The same holds for this guide. Its text and panels were written with the same agent, under the same rule: a panel is published when its bytes match the reference.
What carries over
Little of this is special to serialization.
- Find the check that cannot be argued with. Bytes for a format. For another project it may be a reference implementation, recorded outputs, or a property that must always hold.
- Write down what is decided and why, where the next session will read it.
- Check the checks. Remove a safeguard and see whether anything notices.
- Measure. Correct and fast are separate claims, and only one of them is covered by tests.
What changes with an AI is the price of thoroughness. A corpus of a thousand cases, a sweep over every damaged byte, a tenth implementation, a tool for looking inside a file: each was too much work to be worth it for one person, and is now a few days. The last chapter is about the tools that came out of that.
What this panel is.
- The numbers are read from the public repository by a script in the guide's repository, up to one fixed commit. The page only displays them.
- Times are the times of commits. The elapsed time shown is from the first step listed to the last.
- "Generator" is the Python code that writes a language's library, and "runtime" the hand-written library code in that language that every generated library uses. Lines include comments and blank lines.
Try it
- Look at Java's steps. Which step followed the one before it most quickly, and what might the earlier one have made easy?
- C was started with the shared buffer and Java with the reader. Find the first step of each. What might decide the order?
- Compare the length of each plan with the size of what was built from it. Which language needed the longest plan?
- Think of a project of your own. What would its golden bytes be?
- A test passes before and after a safety check is removed. Name two different things that could mean.
What comes next
Chapter 20, the last, returns to the question the guide began with. Text formats won on convenience: you can open them, search them, compare them. It shows the tools that give a binary format the same, and that were affordable to build for the reason this chapter gave.
