logstat regenerated: the worker’s report
Every function body in examples/programs/logstat/ was written again from the modules’ intents,
types, signatures, contracts, and tests, plus mo-wiki/spec/programs/02-log-analyzer.md. The
tests were not touched: the only lines the diff removes are the # body gone; regenerate markers.
Done-when
mo checkandmo testgreen onparse.mo,stats.mo,report.mo,main.mo: 6 + 10 + 7 + 8 = 31 tests, 0 failed, 0 skipped (mo test --all main.moruns all 31).- All four
# run:lines ofmain.momatch their.expectedfile byte for byte (cmp), with the exit code the# exit:line asks for: text 0, JSON 0,--top 02,.1. mo test --write --sim 100has rewritten the fourverified:lines and theexamples/programs/.mo.idssidecar.
Wall-clock
11 minutes 22 seconds, 23:49:53 to 00:01:15 UTC on 15–16 Sep 2026, from the first read of
examples/README.md to the last green run. About seven of those minutes were reading:
examples/README.md, chapters 2, 4, and 9 of the spec, the program spec, and the corpus files
stdlib/{strings,numbers,lists,maps,time,files,json}.mo, basics/{if,tuples,result,option}.mo,
programs/{count-lines,exit-code,lines-per-file}.mo, and logstat/TOOLCHAIN-BUGS.md.
Loops to green, by cause
One loop. Every other mo check, mo test, and mo run passed the first time it was run.
| # | file | diagnostic | what it was | first fix worked? |
|---|---|---|---|---|
| 1 | stats.mo | MO0403 Time.fixture() is a Time for tests; outside a test, take a Time parameter instead. | sample, the test fixture builder, is an ordinary module function, so it may not call Time.fixture() | yes: Time.from_parts(2026, 1, 1, 0, 0, 0), the same instant, written out |
Per module: parse.mo 0 failures (check and test green first run), stats.mo 1 (the row above),
report.mo 0, main.mo 0. The four program runs matched their .expected files on the first
attempt, so no loop came from the output format.
The diagnostic that earned the loop was exact: it named the call, said why it is test-only, and
named the fix (take the instant as a parameter). The one that would have misled is the one that
never fired — MO0403 is raised where a module function calls a test-only row, so the rule is
learned at the point of use, not from chapter 9’s table, which marks fixture “tests only” in a
column a reader skims past.
Bodies: 59 functions, longest 15 lines (stats.add, main.main), median 4. No shape law was hit
(70 lines, 6 parameters, depth 3). No stdlib or platform name was missing, so examples/GAPS.md
gains nothing: String.grouped, sort_by_desc, Map.update, Fs.fold_lines/list, and
Json.encode over a struct each did exactly what a body needed — the gaps program 2 found in
earlier rounds are already closed rows.
Decisions the spec did not cover
- Where the rounding happens.
summarizeroundserror_rateto three decimals andper_minuteto one, and every reader of aSummaryprints what it holds. The spec’s JSON example (0.031,40.1) fixes the shape but not the place, andJson.encodewrites a float’s own shortest spelling, so an unrounded0.16666666666666666would have reached the JSON report. The text report’s(18.8%)is thenone_decimal(error_rate * 100.0). - Nothing divided by nothing is 0.0.
rate(0, 0), a tally holding no record, and every record in one instant are all0.0rather than a NaN or an error. - A 4xx is a success. Errors are 500–599, as the spec says, so
requestssplits in two and a 404 is counted insuccesses. There is no third bucket. - What a method is. One or more capital ASCII letters, so
getisBadMethodandPATCHor any verb a future log carries parses. No fixed list of verbs. - What a path is. It must begin with
/and hold no", and nothing else is refused: a path is text between two spaces, and the quote is refused because the JSON report quotes it. - Fields are checked left to right. A line wrong in two fields names the leftmost problem (timestamp, then method, then path, then status, then duration).
- Fields are split on single spaces, empty pieces kept. So
""is one field, a double space makes six, and a date written2026-09-12 10:00:02is six fields, not a bad timestamp. - Sixteen digits or more are starred whole, and masking keeps the path’s length, so a
17-digit run becomes 17 stars. Masking happens at parse time, so the masked path is what the
tally counts: the fixture’s
4111111111111111and5500000000000004on the same route become one busiest row of 2, and no unmasked path exists anywhere downstream to leak. - How the two orders are got from stable sorts.
slow_keyis(4_294_967_295 - ms, at), so one ascending stable sort gives duration descending and, at one duration, the earlier request first.rankedsorts twice instead — by(path, method)ascending, then by count descending — because a stable descending sort keeps the ascending tie order, and a count is aUInt64with no comfortable complement to subtract from. - The span is the minimum and maximum timestamp of the records counted, not the first and
last line read, so files listed in name order with lines out of order still give one answer.
A record before
--sinceis no part of the span; a malformed line is counted whatever it would have said, since it has no readable time. - A line of only whitespace is skipped, as an empty line is, rather than counted malformed.
- A name is a log when it ends in
.logand is longer than four characters, so a file named exactly.logis not one, andloggedsorts the names it keeps. - The folder is listed by name, not by kind.
loggedtakes names, so a folder namedx.loginside the directory would be read and reportedlogstat: x.log cannot be read, exit 1, rather than skipped.list_kindswould skip it; the signature under regeneration does not carry the kind. - Every
Fscall waits at most 10 seconds. The spec sets no deadline, and the law requires one; the test that expectsSlowfromFs.fixture(delay: 1.minute)requires it to be under a minute. - Exit codes past the spec’s three. A file that cannot be read, and any read or listing past its deadline, exit 1 with one line on stderr. Only a usage error exits 2.
- What stderr says. One line,
logstat: <detail>, and the usage line isusage: logstat <dir> [--top N] [--since <ISO-8601>] [--json]. A missing directory argument prints the usage line; every other usage error prints what was wrong with the argument. - A repeated flag takes the last value (
--top 3 --top 9is 9). No test asks, and neither does the spec. - The text report’s columns are measured, not fixed. The label column is the widest label
and the value column the widest value, right-aligned; the slowest section puts three spaces
between the request and its timestamp, the busiest two between the count and the request. The
.expectedfiles and the section tests pin this; the spec’s sample only suggests it. - The JSON object is
Json.encodeof a struct.JsonSummaryandJsonSlowdeclare the key order, so the writer cannot drift from it, andjsonends its line with"\n"astextdoes.