UNODEF: when prose specs die. One contract, nineteen ports, and a kernel that did not change by a byte

On the morning of June 11, the project got its first specification. a18b8242: "Add port specification; Mac port strategy now Toolbox-based". The document it added, docs/PORT-SPEC.md, opens with a sentence that I did not think twice about at the time and now think is the most important sentence in the repository: "Extracted from the x86 reference implementation. Where this file and the x86 source disagree, the source wins, report the discrepancy and update this file."

Read it again. The spec declares, in its own first paragraph, that it is not the truth. The truth is the assembly. The spec is a description of the assembly, maintained by a human noticing a difference and editing markdown. Four days later the agent wrote this diagnosis into docs/CONTRACT-ARCH.md: "That sentence is the whole problem in miniature: the contract is a secondary artifact that drifts from an implementation, reconciled only by a human noticing and editing markdown."

This essay is about the four days, the forty minutes that ended them, and what the replacement did and did not fix.

Four days as law

PORT-SPEC was already wrong when it was written, and the repository shows exactly where. On June 15 at 19:54, 4601225a ("docs: prune obsolete docs, consolidate duplicates, fix stale numbers") went through the documentation correcting the syscall count: "API count corrected 96/105 -> 106 across API_REFERENCE, ARCHITECTURE, APP_DEVELOPMENT, README". Four documents fixed. PORT-SPEC was not on the list, and at v3.34.0, two months later, section 4 of PORT-SPEC still reads "105 functions". The kernel's API table has 106 slots; 105 is the last ordinal, not the count.

That was the small one. Three and a half hours after the prune, at 23:17, 55d5a7fe: "unodef: Phase 0 — author the first UNODEF contract (no behavior change)". The commit transcribed the shipping x86 surface into a single TOML file, unodef/unodef.toml, and in doing so had to decide, for every contradiction it met, which source was right. It wrote the decisions down in a section called [discrepancies]. There are four entries, and they are the best short description I have of what prose specs do when nothing checks them:

Notice the shape of the second one. The spec was right and two other documents were wrong, and there was no way to know which without reading the assembly. A prose spec that is correct is indistinguishable, from the outside, from one that is not. The contract's answer was not to write a better document. It was to make the document the input to the build, so that being wrong would break something.

Forty minutes to the trust anchor

Phase 0 to Phase 2 took from 23:17 to 23:56 on June 15. I want to walk the commits because the order is the method.

ebb1ed9a, 23:28: "unogen: emit the contract surface for the first 5 worlds". The generator reads the TOML and emits, per CPU family, "the SHAPE of the boundary (syscall ordinals, struct offsets/sizes, FAT12 geometry, font metrics, palette, enums) — never bodies or CPU logic". Same symbols, five assembler dialects, plus a C header whose _Static_asserts "fail compilation if any offset/size drifts". And it shipped with a check: "Trust anchor (--check): 22 generated x86 constants assert-equal to the literals hand-written in kernel/kernel.asm today".

02f44e94, 23:38: "kernel: source the contract surface from unodef/gen/x86 (byte-identical)". The kernel dropped its hand-maintained equate blocks and %included the generated file instead. The message states the proof: "rebuilt with nasm -f bin -Ikernel/ (build_info.inc held constant) the kernel is byte-identical to the pre-change binary — SHA256 04b9709a..., matching the committed build/kernel.bin."

I did not take that on trust for this essay. I extracted kernel/ and unodef/ at 02f44e94 and at its parent, wrote a build_info.inc carrying the strings baked into the committed binary ("Build: 421", "UnoDOS v3.31.0"), and assembled both with nasm 2.16.01. Both produced 04b9709a2082b118..., and so does the build/kernel.bin committed at that revision. The 117-line change to kernel.asm that replaced thirty-eight hand-written constants with generated ones moved nothing in the output.

That is what "byte-identical" means here, and it is why the contract is trustworthy at all. CONTRACT-ARCH section 15 names the risk directly: "The meta-risk, 'the generator could be wrong', is answered by the Phase-1 byte-identical x86 rebuild (§16): the generator is validated against the known-good implementation before anything depends on it." The spec did not get to be the source of truth by declaration. It earned it by reproducing the artifact that was already true.

787a6bf2, 23:56: "conformance: PORT-SPEC §6 made executable (Phase 2)". The design rules at the end of PORT-SPEC, the "audit tax" list of invariants about z-order, focus stamps and owner-based reaping, became reference models with golden vectors, and each one is "paired with the HISTORICAL BUG it guards against; the runner asserts reference passes all vectors AND buggy fails >=1, proving the vectors discriminate." A test that cannot fail is not a test, and the suite checks that about itself.

The morning after: seven ports, zero bytes

June 16, 09:31 to 11:04. 245b51c8: "Phase 4: Amiga 68K consumes generated equates (byte-identical)", with its own hash in the message. 88eecc27 at 10:10: "contract: close the FAT12 'five places' — boot + stage2 + image tools", and boot.bin and stage2.bin both byte-identical. a9c24e0c: SNES, "Linked .sfc is byte-identical". 939ebba9: Genesis, MacPlus, IIGS, "All byte-identical, proof scope including the disk-loaded apps + packed images". Three assembler families (vasm, ca65, dasm) and the C header, every one producing the same bytes it produced before the constants came from a file.

The commit I find most instructive is the last one, 75d21b9c at 11:04, because it is the agent being wrong about its own plan and saying so. The 6502 ports had been deferred as a "deeper refactor". The message: "all 7 reachable-toolchain asm ports now source from the Contract. Investigating the 6502 ports showed the feared 'deeper refactor' was the wrong frame: C64 (M3 full-screen launcher) and Apple II are architecturally single_app — one disk-loaded app at a time, NO multi-window manager and NO event queue". Forcing the window ABI onto them "would FAKE an ABI they don't ship". So the contract grew a single_app profile, the two ports declared it, and a conformance rule now asserts that a single-app port honestly requires no window manager. The spec got more accurate by describing less.

The payoff, and PORT-SPEC's obituary

Here is where the contract stops being bookkeeping. The ports had drifted on a real question: x86 used a 32-byte window-table entry and every other windowing port used 16. PORT-SPEC said 32. On June 16 at 17:04, f2974722: "x86 3.1 pilot (2/2): compact win_entry 32B -> 16B clean layout (QEMU-verified)". The whole layout changed: every offset, the stride, the table size. And: "kernel.asm needed ZERO code edits — it consumes WIN_OFF_* + WIN_ENTRY_SIZE symbolically and addresses entries via win_entry_addr; regenerating flips every offset and the stride (shl 5 -> shl 4) automatically."

An ABI break became a regenerate. The x86 kernel, which four days earlier had been the definition of UnoDOS, took its new window layout from a file like any other port. CONTRACT-ARCH had said this was the intent, "x86 is demoted from 'the definition' to 'first consumer + conformance oracle'", and this is the commit where the demotion became true.

PORT-SPEC, at v3.34.0, still says "Fixed table of 16 windows, 32-byte entries". It still says 105 functions. ARCHITECTURE.md still says characters "advance by 12 pixels". Nobody fixed them, and the reason is the title of this essay: nothing depends on them anymore, so nothing breaks when they are wrong, so nobody notices. The prose spec did not die by deletion. It died by irrelevance, the same day the contract was born.

The eleven fresh ports that landed over the following day (the subject of an earlier post, and I will not retell it) were the contract's first real output: each one's generated surface is between seven lines (NES) and twenty-one (SMS), and each began from a TOML file rather than from someone else's assembly. That is the whole reason the 22-platform fleet gets a second mention in this series: not as a feat, but as the thing a machine-readable contract produces when a port no longer has to rediscover what the OS is.

The count, honestly

The arc for this essay says "20 consumers". I counted. At v3.34.0, 28 files outside unodef/ include or read its generated output or the TOML itself: the x86 kernel, both boot stages and two image tools; the seven migrated assembly ports (Amiga, Genesis, MacPlus, SNES, IIGS, C64, Apple II); the eleven fresh ports; and two host C subsystems, unofs and uno2d. That is 19 ports and 21 consuming codebases.

What is not on the list matters more. Nothing under pc64/, the modern x86-64 port that is the headline of this launch, includes or reads anything from unodef/ at v3.34.0. Neither do the PS2, Dreamcast, or hosted Mac ports, the C-core world. CONTRACT-ARCH's status paragraph says the contract ships across "the reachable asm ports + x86 and the pc64/ world (all generate from or are checked against unodef/)", and the generated-output README lists "ps2, dreamcast, mac" as the C header's consumers. I could not find the file that makes either sentence true. The contract's own documentation has drifted from the contract's code, which is exactly the disease it was built to cure, on a smaller scale.

And one more, because it is too good to leave out. On July 30, dc14e45a removed em dashes across the tree for a style rule, including from the generator's source. It did not re-run the generator. So at v3.34.0, the files under unodef/gen/, which are headed "DO NOT EDIT", no longer match what unogen.py emits: regenerating changes the header comment of 27 files and one line of profiles.txt. Not one equate value moves. The trust anchor still passes ("22 generated x86 constants match kernel.asm literals") and the conformance suite reports 71/71 at v3.34.0. (The ledger quotes 29, 38, 43 and 52 at various moments in June; those are snapshots that drifted too.) The contract protects the numbers, and it protects them completely. It protects nothing else. Prose around the numbers, even generated prose, rots at the usual rate.

The lesson

A specification survives only if something breaks when it is wrong. PORT-SPEC was careful, correct in places where two other documents were not, and written by the same agent four days earlier; none of that saved it, because nothing consumed it. UNODEF survived the 32-to-16 ABI break without a code edit, and survived my rebuilding its first consumer from scratch, because the build consumes it and a trust anchor compares it to a known-good artifact. The transferable version for a codebase that is not an operating system: find the document your team treats as authoritative and ask what fails if a number in it is wrong. If the answer is "a reader might notice", the document is already drifting, and the fix is not a better document but a consumer. Wire the numbers into the build, keep the prose for the reasons, and expect the prose to be stale anyway. The next post is what happens when the conformance suite stops being a host-side oracle and gets driven against two physical machines: 86 scripted checks, and the one-character bug the AI assistant had shipped.

Sources: https://github.com/hmofet/unodos, commits a18b8242 (June 11), 4601225a, 55d5a7fe, ae5c9e3e, ebb1ed9a, 02f44e94, 787a6bf2 (June 15), 245b51c8, 88eecc27, a9c24e0c, 939ebba9, 75d21b9c, f2974722 (June 16), dc14e45a (July 30); docs/PORT-SPEC.md, docs/CONTRACT-ARCH.md, docs/ARCHITECTURE.md, docs/UNODOS-3.1-MIGRATION.md, unodef/unodef.toml, unodef/unogen.py, unodef/gen/README.md, unodef/PHASES.md, unodef/conformance/conformance.py, all read at v3.34.0 (82a7fe90); the kernel rebuild reproduced locally with nasm 2.16.01 against 02f44e94 and its parent.

The OS in this piece runs in your browser. No install, no sign-up: boot it in a tab, or download it for any of 22 machines.

Get the next one

New essays roughly every other week: the war stories, the method, and the receipts. No spam, unsubscribe in one click.

Prefer a reader? RSS.