notes regenerated — report
Every function body in examples/programs/notes/ was written again from the modules’ intents,
types, signatures, contracts, and tests, and from mo-wiki/spec/programs/04-web-backend.md.
The tests were not touched.
Wall clock
15 minutes 31 seconds, 00:43:37 to 00:59:08 UTC, 16 Sep 2026.
Loop count by cause
Zero failing loops. No mo check, mo test, or mo run failed at any point, so no fix was
needed and the question of whether a first fix worked never arose.
| what was run | times | failures | diagnostic codes | failing tests |
|---|---|---|---|---|
mo check (7 modules, twice over) | 14 | 0 | — | — |
mo test (7 modules) | 7 | 0 | — | — |
mo test --write (7 modules) | 7 | 0 | — | — |
mo run against a .expected (5 lines, twice over) | 10 | 0 | — | — |
Totals: 49 modules-worth of tests over the program (42 tests, 6 properties at 200 seeds each,
9 test rejects), and 5 program runs, all first-try green.
The one edit made after a module was already green was cosmetic: the two process update
bodies (service.mo, server.mo) were written two spaces too deep. mo check accepted both
before and after, so it is not counted as a loop.
Order of work: store.mo, limits.mo, note.mo, api.mo, service.mo, server.mo,
main.mo — each checked and tested before the next was started, so a module was never written
against a module that had not been proved.
What was leaned on
examples/README.md row 70 and the program spec gave the shape. The store recipe’s
implementation was written from examples/programs/jobq/store.mo, which the corpus records as
a hand copy of this very module (README row 77), less the put_all/continued jobq added and
with replayed_from back to two parameters and compact inlined, since Notes.Store declares
no whole_text or rewritten. jobq’s api.mo, server.mo, queue.mo, and main.mo were
read for idiom (response helpers, the Routed shape, the transcript masking), not for the
notes logic, which came from notes.expected, data/demo/notes.log, and the tests.
Private helpers added
Beyond the declared signatures: note.mo plain_char?; api.mo member_command,
object_of; service.mo touched, rewritten_log, held_ids, applied_change,
uncounted; server.mo first_id, let_go, looked_over, kept_of, why_of;
main.mo mended.
Decisions the spec did not cover
-
How an id is never reused. The spec says only that it must not be. The log keeps a reserved key
idsholding the first id not yet reserved, and ids are reserved a hundred at a time: a create whose next id has reachedreservedappendsSET ids <next + 100>before its own line.data/demo/notes.logopening withSET ids 101and the first create innotes.expectedcoming back asn_101fixed both the key and the size of the reservation. Replay takesnext_id = max(highest note id + 1, ids, 1). -
A create’s id is spent whether or not its line reached the log.
issuedadvancesnext_idon every path out ofwritten, including the 503s, so no id is ever handed out twice even after a failed append.Issued.floorholds by construction. -
The store key layout.
<token>/<id>, withidsthe one live key holding no slash. Soopeningcounts only keys with a slash as notes, and/health’snotesis the sum of the per-client counts rather thancount(table), which would count theidsrow. -
Listing order. Byte order over the store’s keys gives
n_1, n_10, n_2. The service test’s expected["todo 0", "todo 2", … "todo 10"]forced a sort by the number inside the id, then the first hundred. -
What
clientscounts. A client whose last note is deleted is dropped fromowners, so/health’sclientsis the number of clients that hold at least one note, not the number ever seen. -
The order of the three refusals. The method check comes before the token check, so a method a route does not have is 405 even with no token; the token check comes before the body check, so a malformed body from a client with no token is 401, not 400.
notes.expectedpins the 405-without-reaching-the-service case and no other, so the rest is a choice. -
Which paths are 405 and which 404.
/notestakes GET and POST,/notes/{id}takes GET, PUT, and DELETE; anything else under/notes/…(/notes/,/notes/n_1/x) is 404, not 405. -
The wording of every error the transcript did not pin.
notes.expectedfixes four —a request needs authorization: Bearer <token>,no route /nowhere,no such note,this route takes GET, PUT, DELETE,the body is not JSON,title is missing,title must be a string,title must be 1 to 200 bytes with no control characters. The rest were written in the same voice:the body must be a JSON object,body must be at most 60 KiB with no control characters but a newline,the log did not take the change(503),the service did not answer in time,the service holds a million notes already. -
The order a change reaches the log. A log a failed append may have torn is rewritten whole (
compact) first, then the id reservation when the change hands one out, then the change’s own line, and only then is the change applied to the table and answered. Each of the three steps keeps the books it produced, so a compaction that succeeded before a later step failed is not thrown away with its recorded size. -
A malformed body still costs a token.
Refuseis a call on the service, so the rate limiter takes a token before it is answered 400 — the module comment says so, the spec does not. A 405, a 404 route, and a 401 never reach the service and take none./healthtakes none either. -
What
outis for inran,serve, andserved_on.served_onwritesnotes: serving <dir> on 127.0.0.1:<port>tooutitself and gives back"", since serving never returns and the line belongs on stdout before the first request rather than in a valuemainwrites afterwards. -
Which command compacts.
notes serverewrites a log whose last line was cut short before it listens, so the next change starts on a line of its own;notes checkdoes not, since it only reads the folder’s log and appends its own changes tonotes.check.log.notes compactalways rewrites. -
The store’s own rules, which the recipe states but does not fix for notes. The log is
notes.log; a key is 1 to 256 bytes with no space and no control character; a value is at most 1 MiB with no line break; the table is spread over 256 small maps. -
The check script in
server.mo.script()is the one thing the spec leaves entirely open: make, look, read, rename, read, make, look, drop, read, look. Each move is checked against what the client should now hold and against what the service actually holds, a 503 is accepted only when the service holds exactly what it held before, and a request the wire lost stops the check rather than failing it. -
How the client sends a query.
notes client … GET /notes?prefix=toputs the whole target inRequest.pathand leavesqueryempty; the runtime writes the target verbatim and the server splits it back into a path and a query. (jobq’s later client splits it itself;Notes.Maindeclares noquery_oforbare, so it does not.) -
Three signatures the stripper cut in half.
ran,serve, andcheckinmain.moeach ended at: Result(String,because the continuation line went with the body. All three were restored asResult(String, Problem), which is the only type that fits their callers.
Green
mo checkandmo test: 7 modules, 0 failed, 0 skipped.mo test --writehas rewritten everyverified:line;examples/programs/.mo.idschanged only in its sevennotes/entries.- Every
# run:line matches its.expectedbyte for byte, with the exit codes the# exit:lines give (0, 0, 2, 1, 1).data/is byte-identical after the runs.