# Pre-registration — 2026-12-05-phayan-thai-ocr

```
run_id:        2026-12-05-phayan-thai-ocr
product:       phayan
tier:          standard
written_at:    2026-12-05T07:40:00Z, after the blind adversary (ADVERSARY.md, 27 objections) and before any OCR of a study image
workdir (W):   /Users/jakubzavada/Repositories/.in-progress/app-studies-2026-12-05/phayan-evidence
```

Renders, raw OCR output and tools live in W, because a hook refuses copying files into the skills
folder. This directory keeps the method, briefs, logs, ledger and record. Inputs frozen here:
`W/specimens.json` sha256 `aa870df775d3db4040a6d799a544605cfa00ffa9df41ea280b4289561c2f9eca`
(60 strings, S01–S60), `W/sources/NotoSansThai.ttf` sha256
`5a1c559bb539583c8a1fd99d1c5b9491e5e14478c9cd2bd0970d5c3096cc9ef8` (Noto Sans Thai 2.002, variable
wdth/wght, OFL), `W/sources/pythainlp-words_th.txt` sha256 `12bf4d04…b481` and
`W/sources/pythainlp-syllables_th.txt` sha256 `583db4f1…d412` (PyThaiNLP corpus, fetched
2026-12-05, CC0 per `W/sources/pythainlp-corpus_license.md`).

## 1. Question

For 60 short Thai sign texts rendered as one black-on-white line in Noto Sans Thai Regular by
Chromium at six text sizes (96, 40, 24, 18, 14 and 11 px; measured ink heights logged), how many does
Apple Vision (VNRecognizeTextRequest revision 3, accurate, `th-TH`) and how many does Tesseract 5.5.3
(`tha` LSTM, single line) return with exactly the right code points, and which consonant, vowel,
tone-mark and other-mark errors does each make on the identical images?

Population: these 60 author-written texts in this one rendering setup. No claim reaches photographs,
print, other fonts, other weights or other devices.

## 2. Method

### 2.1 Corpus (fixed before any OCR)

- **Study set.** `W/specimens.json` as frozen above: 20 shop and service signs, 20 wayfinding, 20
  notices; in each genre 10 with at least one tone mark U+0E48–U+0E4B and 10 with none. Written by a
  GPT Sol child (P1), not by a native reader. Every string segments completely into words of the
  PyThaiNLP `words_th.txt` list by minimum-word-count dynamic programming (checked 2026-12-05: 0 of 60
  unsegmentable); that segmentation is frozen in `W/frozen/segmentation.json` and is used for the
  per-word error report.
- **Allowed code points (frozen list).** Consonants U+0E01–U+0E2E except U+0E03 and U+0E05; vowels
  U+0E30–U+0E3A and U+0E40–U+0E44; marks U+0E47–U+0E4C. Excluded: spaces, U+0E2F, U+0E45, U+0E46,
  U+0E4D, U+0E4E, U+0E4F–U+0E5B, all non-Thai. A string with any excluded code point fails corpus
  validation.
- **Encoding validation in code** (`W/instrument/validate_corpus.py`): NFC-stable; no U+0E40 U+0E40
  (for แ); no U+0E4D U+0E32 (for ำ); no tone mark or U+0E4C directly before an above vowel or U+0E47;
  every combining mark directly follows a consonant or an allowed earlier mark in the order
  consonant, above/below vowel, tone or thanthakhat (WTT 2.0 input sequence); no two identical marks
  in a row. A corpus string that fails is a stop before rendering, recorded in AMENDMENTS.md.
- **Balance table, published before OCR** (`W/frozen/balance.json`): per genre × tone group, code
  points, consonants, the 40 px ink width, counts per mark class (above vowel, below vowel, tone,
  maitaikhu, thanthakhat), tall consonants (ป ฝ ฟ ฬ) and descender consonants (ฎ ฏ ฐ ญ ฤ).
- **Pseudo-text control (exploratory).** 20 strings built with seed 20261205: for 20 study IDs drawn
  by the seed, concatenate syllables drawn uniformly from `pythainlp-syllables_th.txt` (filtered to
  the allowed code points) until the length in code points reaches that study string's length; IDs
  P01–P20. They keep Thai orthography and drop the phrase and most word context.
- **Calibration fixtures**, never scored as study data: a white image; a two-phrase line with a
  gap of four em between the phrases; a string with a code point missing from the font cmap (must be
  refused by the generator); three neutral Thai strings not in the corpus.

### 2.2 Rendering (one generator: Playwright Chromium canvas, HarfBuzz shaping)

- `W/instrument/generate.cjs`, Node v22.22.2, Playwright 1.59.0 and its bundled Chromium (version
  logged), headless, launch flags `--disable-lcd-text --font-render-hinting=none
  --disable-font-subpixel-positioning`, `deviceScaleFactor: 1`, opaque 2D canvas.
- Font loaded only through `new FontFace('SpecimenThai', bytes)` from the pinned file, never
  `local()`; `ctx.font = "normal 400 <size>px SpecimenThai"`, default variable instance wght 400 wdth
  100, logged.
- Sizes 96, 40, 24, 18, 14, 11 px. Headline sizes 40, 24 and 14 (named in the draft); 96 is the
  anchor, 18 and 11 are secondary. No interpolation between sizes.
- Text origin on integer pixels. The ink box is found on a scratch canvas and copied into a canvas
  whose margin on every side is the integer `ceil(size / 2)` px; the outermost row and column must
  be pure white and the ink box must sit exactly at the margin, or the image is refused.
- Saved as 8-bit greyscale PNG, no alpha, pHYs 72 dpi, after asserting R = G = B and A = 255 on
  every pixel (Python 3.9.6 system interpreter, Pillow 9.5.0). Any coloured pixel is a stop.
- Per image the manifest logs text, ID, size, PNG sha256, image size, ink bbox, ink height; per size,
  the ink height of น alone (the body height of a consonant without marks), rendered the same way.
- **Font identity in code.** Every code point of every string is in the font cmap. Chrome DevTools
  Protocol `CSS.getPlatformFontsForNode` on a DOM span with the same text and family must report only
  the custom font `SpecimenThai`. Falsifier: a fixture string with a code point outside the cmap
  must be flagged.
- **Shaping in code.** `hb-shape` (HarfBuzz 14.3.0) on the same font file for every string: no glyph
  id 0, no dotted-circle glyph. Logged glyph ids and offsets.
- **Determinism.** The full set is rendered twice in separate browser launches; every PNG hash must
  match.

### 2.3 OCR arms (identical PNG bytes; one new process per image per arm)

- **V — Apple Vision.** `W/instrument/vision` (Swift, built from `vision.swift`, sha256 logged).
  VNRecognizeTextRequest, `recognitionLevel = .accurate`, `revision = 3` asserted by read-back,
  `recognitionLanguages = ["th-TH"]` asserted present in `supportedRecognitionLanguages()` for this
  request, `usesLanguageCorrection = false`, `automaticallyDetectsLanguage = false`,
  `customWords = []`, `minimumTextHeight` logged at default, compute device for the main stage set to
  the CPU (`setComputeDevice`), `topCandidates(1)`. Observations sorted by bounding-box minX, then
  minY, joined with the empty string.
- **T — Tesseract.** `/opt/homebrew/bin/tesseract` 5.5.3 (Leptonica 1.87.0), `--oem 1 --psm 7
  --dpi 72 -l tha`, `--tessdata-dir` explicit, `OMP_THREAD_LIMIT=1`, PNG on stdin, stdout captured as
  raw bytes; `tha.traineddata` sha256 and size, `--print-parameters` dump, stderr kept (an
  "Estimating resolution" line must not appear).
- **T0 — Tesseract without word lists (secondary arm).** T plus `-c load_system_dawg=0 -c
  load_freq_dawg=0`.
- **Language controls before study OCR** on the calibration strings: V with `en-US` must return
  different text from `th-TH` on at least one Thai fixture, and an invalid language code must
  error; T with `-l eng` must differ from `-l tha`. If a control output equals the `th-TH`/`tha`
  output on every fixture, the setting is not shown to act and that arm is `NOT_MEASURABLE`.
- **Completion records.** Each OCR row records exit status, observation count (V) or byte count
  (T), elapsed time. "Found nothing" is counted only with a clean completion record. Invalid UTF-8
  is an execution error. Zero retries. A persistent execution error is a paired exclusion of that
  image at that size, reported. If a runner defect is fixed after any study row exists, every study
  image is rerun in both passes and the fix is an amendment with `post_hoc: true`.
- **Order and passes.** Pass 1 runs all study and control images in one order shuffled with seed
  20261205 across genre, tone group, size and arm; pass 2 runs the same list reversed. macOS build
  and the binary hashes are logged at the start and end of each pass; an OS change between passes
  voids pass 2.
- **Exploratory phase control.** 20 study IDs drawn by seed at 14 px re-rendered with the text origin
  shifted right by 0.25, 0.5 and 0.75 px, and once with a fixed 8 px margin; all three arms, both
  passes. An outcome that flips across these variants is reported per ID.

### 2.4 Scoring (frozen definitions, `W/instrument/scoring.py`, Python 3.9.6, unicodedata 13.0.0)

- **Normalisation.** Strict UTF-8 decode of the raw bytes (raw bytes kept in base64), NFC, then
  removal of exactly these code points: Unicode 13 White_Space (U+0009–U+000D, U+0020, U+0085,
  U+00A0, U+1680, U+2000–U+200A, U+2028, U+2029, U+202F, U+205F, U+3000) and the default-ignorables
  U+00AD, U+200B, U+200C, U+200D, U+2060, U+FEFF. Lengths in code points.
- **Exact match (headline).** Normalised output equals the normalised expected string.
- **Visual-equivalent match (secondary, reported beside the headline).** Both sides further mapped
  by the frozen variant table: U+0E4D U+0E32 → U+0E33; U+0E40 U+0E40 → U+0E41; U+0E45 → U+0E32;
  a tone mark or U+0E4C followed by an above vowel or U+0E47 → the vowel first. A visual-equivalent
  match that is not an exact match is counted as an `encoding variant`.
- **Edit distance.** Levenshtein over code points; character error rate = distance / expected
  length; raw distances and lengths are published too. CER is unbounded above.
- **Alignment and error taxonomy.** One optimal alignment by dynamic programming with unit costs,
  backtracked from the end preferring diagonal (match or substitution), then deletion, then
  insertion. Code point classes: consonant (U+0E01–U+0E2E), leading vowel (U+0E40–U+0E44), following
  vowel (U+0E30, U+0E32, U+0E33, U+0E45), above vowel (U+0E31, U+0E34–U+0E37), below vowel
  (U+0E38–U+0E3A), tone (U+0E48–U+0E4B), other above mark (U+0E47, U+0E4C, U+0E4D, U+0E4E), other Thai
  (rest of U+0E00–U+0E7F), non-Thai. Each edit gets one category: consonant substitution, consonant
  deletion, consonant insertion, vowel error (either side a vowel class), tone omission, tone
  insertion, tone substitution (tone for tone), tone-to-other-mark or other-mark-to-tone
  substitution, other-mark error, non-Thai intrusion (hypothesis side outside U+0E00–U+0E7F), other.
  Consonant substitution pairs are reported with counts; no confusable list is assumed in advance.
- **Tone metrics.** In the 30 tone specimens: tone omissions and substitutions per specimen. In the
  30 no-tone specimens: false tone insertions. Reported separately, never pooled.
- **Per word.** A frozen word is wrong when any of its expected code points is substituted or
  deleted, or an insertion falls inside its span. Reported: wrong words and distinct words behind the
  failures.
- **Stability.** A strict mismatch is any image and arm whose normalised output differs between
  pass 1 and pass 2. The headline uses pass 1. A size × arm cell with any strict mismatch has its
  comparative claim withheld unless the cause is traced to a mechanical issue with a recorded remedy.

### 2.5 What is reported

Per size and arm: exact matches out of 60, visual-equivalent matches, paired table V against T
(both right, V only, T only, both wrong), median and range of CER with n, every per-item value in
the dataset. Per genre and tone group as counts with denominators. The paired difference in exact
proportion V − T with a 95 % bootstrap interval (10 000 resamples over specimens, seed 20261205).
Because the corpus is author-written and not a published standard set, every comparison is written
as "on these 60 texts". Ink heights in px per size beside every size label.

### 2.6 Calibration and falsified checks (before study OCR)

`W/instrument/test_scoring.py` holds positive and negative fixtures: unchanged string; ZWSP between
words, leading BOM, NBSP, U+3000, trailing form feed (all match after normalisation); U+001C not
removed; invalid UTF-8 (execution error); swapped tone and sara u (NFC repairs, exact); swapped tone
and above vowel (not exact, visual-equivalent); ำ against ํา (not exact, visual-equivalent); เเ
against แ; moved mark; wrong tone; blank output (all deletions); malformed runner output (execution
error); two Vision observations out of order (sorted join). Each check is falsified once: remove the
mechanism, quote the failing test, restore.

### 2.7 Replication

- **Re-execution (GPT Sol, fresh session, R-1):** given this file only, re-renders every image
  (hashes must equal M's) and reruns all three arms once on the study set; outputs compared to pass 1.
- **Independent derivation (Opus, D-1):** from the frozen definitions and raw OCR rows only, blind to
  M's aggregates, writes its own scoring and derives the headline counts, paired tables, tone metrics
  and taxonomy counts; disagreement with M is reported per cell and blocks the claim it touches.

### 2.8 Output

Rows go to `W/data/ocr-rows.jsonl`, one per image × arm × pass, appended as produced, and are
copied into this run's `data/` at the end. Fields: `run_id`, `pass_id`, `order_index`, `arm`,
`specimen_id`, `set_name`, `size_px`, `variant`, `png_sha256`, `ink_height_px`, `status`,
`raw_text_b64`, `normalized_text`, `exact_match`, `visual_match`, `edit_distance`,
`expected_length`, `tool_version`, `measured_at`.

### 2.9 What is discarded

Nothing. Execution errors stay as rows with their status. Calibration rows go to a separate file.

## 3. Expectation

- E1: at 40 px, V and T each return at least 45 of 60 exact.
- E2: at 14 px, V has more exact matches than T, with more V-only than T-only pairs.
- E3: for each of V and T, exact matches at 14 px are fewer than at 40 px.
- E4: at 11 px, T returns fewer than 30 of 60 exact.
- E5: at 40 px, on the pseudo-text control, at least one of V and T has a lower exact share than on
  the study set.
- E6: T0 returns no more exact matches than T at 40 px.
- E7: no strict mismatch between passes for any arm.
- Which error category dominates per engine: `not-predicted`.

## 4. Falsifier

- E1 false if either V or T has fewer than 45 of 60 exact at 40 px (pass 1).
- E2 false if V exact ≤ T exact at 14 px, or V-only ≤ T-only.
- E3 false for an engine if its 14 px exact count ≥ its 40 px exact count.
- E4 false if T has 30 or more exact at 11 px.
- E5 false if both V and T have an exact share on the 20 pseudo-texts at 40 px at least as high as
  on the 60 study texts.
- E6 false if T0 exact > T exact at 40 px.
- E7 false if any image × arm differs between passes after normalisation.

## 5. Abandonment condition

- The two full renders differ in any PNG hash and the cause cannot be pinned by a frozen setting:
  `METHOD_BROKEN`.
- A language control shows no effect for an arm: that arm is `NOT_MEASURABLE`; if both V and T are,
  the run ends `NOT_MEASURABLE`.
- More than 6 of 60 images in any headline size × arm end as execution errors after the frozen
  procedure: `METHOD_BROKEN`.
- Re-execution or derivation disagrees on a headline cell and no mechanical cause is found: that
  claim is withheld; if every headline cell is withheld, the run ends `METHOD_BROKEN`.
- Every arm exact on all 60 at every size: `NULL` for the size question, recorded and still reported.

## 6. Estimate

- **What the run needs from Jakub:** nothing. Synthetic text, a public OFL font, tools already on
  this Mac, no account, no production data, no install.
- Machine time: about 1 hour of OCR (about 3 300 engine calls over two passes, controls and
  replication), 5 to 7 hours wall-clock including replication, writer, three critics and the local
  preview.
- Money: 0 USD for external services; model use under the existing subscriptions.
- Claims expected in the ledger: measured (counts, rates, ink heights), sourced (engine and font
  documentation), no own-data claims except Search Console demand from Gate A.

## 7. Adversary dispositions

27 objections in `ADVERSARY.md` (A1, Opus 5.5, blind): 23 changed, 4 accepted as limitations,
0 rejected.

1. changed — one generator, Chromium canvas with pinned flags, scale 1, integer origin and margin,
   render twice and compare hashes (2.2).
2. changed — font identity by cmap coverage and CDP `getPlatformFontsForNode`, FontFace from bytes,
   variable instance logged, cmap-miss fixture (2.2).
3. changed — `hb-shape` check on the same file, no notdef or dotted circle (2.2). Glyph-level
   comparison with Chromium's internal shaping is not available from a canvas; both are HarfBuzz.
4. changed — pure-white border invariant, ink bbox, ink height, consonant body height per size (2.2).
5. changed — 8-bit grey PNG, no alpha, pHYs 72 dpi and `--dpi 72`, stderr checked (2.2, 2.3).
6. changed — encoding validation in code and dictionary segmentation against PyThaiNLP
   `words_th.txt` (2.1). The Royal Institute lookup by a Thai reader is not available: see 24.
7. changed — frozen allowed code point list (2.1).
8. changed — raw exact plus visual-equivalent through a frozen variant table, both reported, with
   fixtures (2.4, 2.6).
9. changed — explicit White_Space and default-ignorable list, code points, strict UTF-8, raw bytes
   kept, fixtures (2.4, 2.6).
10. changed — revision read-back, language support assertion, automatic detection off, empty custom
    words, minimum text height logged, top candidate; en-US, invalid code and `-l eng` controls (2.3).
11. changed — sort by minX then minY, empty joiner, wide-gap fixture (2.3).
12. changed — traineddata hash, tessdata dir, `--oem 1`, parameter dump, `OMP_THREAD_LIMIT=1` (2.3).
13. changed — CPU compute device, macOS build logged at both ends of each pass, headline defined as
    pass 1 exact count, strict mismatch rule (2.3, 2.4).
14. changed — seeded shuffle across genre, tone group, size and arm; pass 2 reversed; a new process
    per image per arm (2.3).
15. changed — completion records, zero retries, paired exclusion, full rerun on any runner fix (2.3).
16. changed — frozen taxonomy and alignment tie-break; scoring code hashed in the freeze record
    (2.4). Consonant pairs reported empirically rather than from an invented list.
17. changed — tone omission and substitution reported in the tone group, false insertions in the
    no-tone group, all above marks tracked in the taxonomy (2.4).
18. changed — balance table frozen before OCR; raw edit counts and lengths published (2.1, 2.4).
19. changed — T0 arm without word lists; the article names configurations, not engines (2.3).
20. changed — pseudo-text control from public syllables (2.1).
21. changed — sub-pixel origin and fixed-margin control at 14 px (2.3).
22. changed — 96 px anchor plus 18 and 11 px; no interpolation (2.2).
23. accepted-as-limitation — loopless Noto Sans Thai only; the looped design is not tested and the
    article says that a ranking may hold only for loopless type.
24. accepted-as-limitation — no Thai reader is available to this run, neither for a blind human
    baseline nor for a dictionary review; the article says the texts were machine-written and checked
    against a public word list only.
25. changed — ties split into both right and both wrong, CER unbounded stated, every per-item value
    published (2.4, 2.5).
26. accepted-as-limitation, partly changed — per-word errors and distinct words reported (2.4);
    genre differences are reported as differences between these texts, not sign types.
27. accepted-as-limitation — one font, one weight, one rasteriser, one Mac, no camera or print; the
    title says rendered text, not printed signs, and pooled rates are design-weighted by the 50/50
    tone split.

Count: 23 changed (1–22 and 25), 4 accepted as limitations (23, 24, 26, 27; item 26 also adds the
per-word report and is counted once, as accepted), 0 rejected.

## 8. Amendments

Append-only, in `AMENDMENTS.md` beside this file, so this file's frozen hash stays valid.

## Gate B render (Slovak)

```
## Gate B — metóda

Čo potrebujem od teba: nič. Syntetický text, verejné písmo s licenciou OFL, nástroje už na tomto
Macu, bez účtu, produkčných dát a inštalácie.

Otázka: Koľko zo 60 krátkych thajských nápisov vykreslených Chromiom v písme Noto Sans Thai pri
96, 40, 24, 18, 14 a 11 px prepíše Apple Vision (revízia 3, presný režim, th-TH) a koľko
Tesseract 5.5.3 (tha, jeden riadok) presne po kódové body, a aké chyby spoluhlások, samohlások,
tónových a iných značiek robia na tých istých obrázkoch?

Ako meriam: 60 textov (3 žánre, polovica s tónovou značkou), overených v kóde a voči slovníku
PyThaiNLP. Šedé PNG bez alfa, okraj v celých pixeloch, dvakrát vykreslené s rovnakým hashom,
zmeraná výška atramentu. Tri ramená: Vision, Tesseract, Tesseract bez slovníkov. Dva prechody
v náhodnom a opačnom poradí, nový proces na obrázok. Kontroly: jazyk en-US a eng, pseudotext
z náhodných slabík, posun o zlomok pixela. Prepočet nezávislou reláciou Opus a opakovanie Sol.

Čo čakám: pri 40 px obe aspoň 45 zo 60; pri 14 px Vision viac presných ako Tesseract; obom
klesne presnosť od 40 k 14 px; Tesseract pri 11 px menej ako 30; pseudotext horší aspoň pre
jedného; bez slovníkov Tesseract nie lepší; oba prechody zhodné.

Čo by to vyvrátilo: ktorákoľvek z týchto hraníc neplatí v prvom prechode.

Kedy končím: rozdielne dve vykreslenia → METHOD_BROKEN; jazykové nastavenie nemá účinok →
rameno NOT_MEASURABLE; viac ako 6 chýb behu v hlavnej veľkosti → METHOD_BROKEN.

Cena a čas: 0 USD externe, asi 1 h OCR, 5 až 7 h spolu.

Rozhodnutie: delegované v rámci zadania (H RESEARCH), nie priamy súhlas Jakuba.
Námietky: 27, zmenené 23, prijaté ako obmedzenie 4, zamietnuté 0.
```
# Amendments — 2026-12-05-phayan-thai-ocr

Append-only. PREREGISTRATION.md stays frozen at 60dd302365f7; each entry here clarifies or changes it.

## AM-1 — procedures the frozen text left open

- **timestamp:** 2026-12-05T07:55:00Z
- **post_hoc:** false. No OCR output of any kind existed (M1 attempt 1 stopped at corpus calibration with
  zero rows and zero renders).
- **reason:** M1 stopped on ambiguity: §2.1 named a seed but not the draw. The other gaps below were found
  by reading §2 again for the same kind of hole, so the executor does not stop on each in turn.

1. **Seeded draws (§2.1, §2.3).** `ids = sorted(study IDs)` (S01…S60). `rng = random.Random(20261205)`
   (Python 3.9.6). Target IDs = `rng.sample(ids, 20)`, in the order returned; P01…P20 take their target
   lengths from those IDs in that order. Syllable pool = the lines of `pythainlp-syllables_th.txt`,
   stripped, empty lines dropped, kept only when every code point is in the allowed list and the line passes
   the corpus encoding validation, de-duplicated keeping the first occurrence, in file order. Each pseudo
   string is built by `rng.choice(pool)` repeatedly (continuing the same `rng`) until its length in code
   points is at least the target; the overshoot is kept. A string that fails validation or equals a study
   string is discarded and the next is drawn from the same `rng`. The 20 phase-control IDs (§2.3) are the
   same 20 target IDs.
2. **Phase control (§2.3).** The offset moves the text origin along x only, by +0.25, +0.5, +0.75 px; the
   margin stays `ceil(size/2)` = 7 px. The fixed-margin variant has offset 0 and margin 8 px. Variant labels:
   `base`, `x+0.25`, `x+0.5`, `x+0.75`, `margin8`. The `base` 14 px image is the study image itself and is
   not run twice.
3. **What a pass contains (§2.3).** One job per (image, arm) for: study images (6 sizes, variant `base`),
   pseudo-text images (40 and 14 px, `base`), phase-control images (14 px, four non-base variants). Not the
   calibration fixtures, which run before pass 1 into `calibration.jsonl`. Shuffle: sort jobs by
   (set, id, size, variant, arm), then `random.Random(20261205).shuffle`; pass 2 is that list reversed.
4. **Body height (§2.2).** The ink height of the single string `น`, rendered by the same procedure at each
   of the six sizes.
5. **Balance table width (§2.1).** "Ink width at 40 px" is the ink bbox width of the 40 px study image.
6. **Visual-variant table (§2.4).** Applied to each side in one left-to-right scan: replace U+0E4D U+0E32
   with U+0E33 and U+0E40 U+0E40 with U+0E41 first, then U+0E45 with U+0E32, then swap any (tone or
   U+0E4C) directly followed by (above vowel or U+0E47); one swap per pair, no repetition.
7. **Taxonomy precedence (§2.4).** For each edit of the alignment:
   - deletion of ref code point r: consonant → consonant deletion; any vowel class → vowel error; tone →
     tone omission; other above mark → other-mark error; else other.
   - insertion of hyp code point h: h outside U+0E00–U+0E7F → non-Thai intrusion; consonant → consonant
     insertion; vowel class → vowel error; tone → tone insertion; other above mark → other-mark error;
     else other.
   - substitution r → h, first matching rule wins: h outside U+0E00–U+0E7F → non-Thai intrusion; both tone
     → tone substitution; one tone and the other an other above mark → tone-to-other-mark substitution
     (direction kept in a field); r tone (h anything else) → tone omission; h tone → tone insertion; either
     side a vowel class → vowel error; both consonant → consonant substitution; either side an other above
     mark → other-mark error; else other.
8. **Tone metrics (§2.4).** Tone-group omissions = `tone omission` + tone-to-other-mark with r a tone;
   tone-group substitutions = `tone substitution`; no-tone-group false insertions = `tone insertion` +
   tone-to-other-mark with h a tone.
9. **Per word (§2.4).** An insertion strictly between two code points of one word belongs to that word; an
   insertion at a word boundary or at either end of the string belongs to no word and is counted as a
   boundary insertion.
10. **Exclusions in aggregates (§2.4, §2.5).** An execution error is excluded from exact counts, CER and the
    paired tables for that image and arm, and listed; the denominator is reported. A blank output with a
    clean completion record is a scored non-match (all deletions).
11. **Bootstrap (§2.5).** Pure Python, `random.Random(20261205)`; per resample draw 60 specimen indices with
    replacement, compute exact proportion of arm A minus arm B over the drawn specimens (both arms must have
    a scored result; excluded specimens are dropped from the index pool first). Sort the 10 000 differences;
    the interval is element 250 to element 9749, 0-based.
12. **Statistics' wording.** "median and range" = median, minimum, maximum by Python `statistics.median`.

## AM-2 — segmentation ties, calibration fixtures, row field values

- **timestamp:** 2026-12-05T07:42:00Z (AM-1 above carries 07:55Z; the file's modification time shows it
  was written at 07:37:02Z, before this entry)
- **post_hoc:** false. No render and no OCR output of any kind existed: M1 attempt 2 stopped at corpus
  calibration with zero renders and zero rows; R-1 stopped at input preflight with zero renders and rows.
- **reason:** M1b stopped on two open procedures (segmentation ties for S13 and S58; calibration fixture
  inputs). R-1 stopped because the excerpt it received had no full input hashes. The rest below closes the
  remaining open values found on a third reading of §2, so no session stops on each in turn.

1. **Segmentation ties (§2.1).** Among the segmentations with the minimum word count, take the one whose
   word lengths in code points, read from the LAST word to the first, are lexicographically largest (at
   the last boundary where candidates differ, the longer final word wins; backward maximal matching).
   Result for the two known ties: S13 `รับ | เย็บ | ผ้าม่าน`, S58 `ห้าม | วาง | ของ | ขวาง | ทางเดิน`.
   The rule is applied in code to all 60 strings, not only these two. Chosen by the orchestrator before
   any OCR output existed; in both ties it also yields the reading a Thai speaker would give.
2. **Calibration fixtures (§2.1, §2.3, §2.6).** All rendered by `generate.cjs` at 40 px with the study
   procedure, all scored nowhere.
   - Neutral strings, IDs C01–C03: `สวัสดีครับ`, `ขอบคุณมาก`, `ยินดีต้อนรับ` (each validated by
     `validate_corpus.py`; none is a substring of a study string or contains one).
   - Two-phrase line, ID C04: `ร้านกาแฟ` drawn at the integer origin, `กรุณารอสักครู่` drawn at
     origin x + ceil(measured advance of the first phrase) + 4 × 40 px; expected text is the two phrases
     concatenated. Recorded only, not a gate.
   - White image, ID C05: 200 × 48 px, every pixel 255. Gate: each arm completes cleanly and its
     normalised output is empty; a crash or non-empty output is a runner defect to fix before pass 1.
   - Cmap miss, ID C06: `สวัสดี` + U+0B95. Gate: the generator refuses it and the CDP check flags it.
   - Language controls on C01–C03 at 40 px: V `en-US` against `th-TH`; V invalid code `zz-ZZ` (must
     error, before or at the request); T `-l eng` against `-l tha`. Rows go to `calibration.jsonl`.
3. **Ink (§2.2).** A pixel is ink when its value is below 255 on the greyscale scratch canvas; the ink
   box is the bounding box of ink pixels; ink height and width are that box's height and width in px.
4. **Row field values (§2.8).** `run_id` = `2026-12-05-phayan-thai-ocr`; `pass_id` = 1 or 2;
   `order_index` = 0-based position of the job in its pass; `arm` = `V`, `T`, `T0`; `set_name` =
   `study`, `pseudo`, `phase`; `variant` as in AM-1 item 2 (`base` for study and pseudo rows); `status`
   = `ok` or `execution_error`; `exact_match` and `visual_match` booleans, null for execution errors;
   `tool_version` = for V the vision binary sha256 and macOS build, for T and T0 the tesseract version
   line and the `tha.traineddata` sha256; `measured_at` = UTC ISO 8601 at process end. Extra fields
   (observation count, byte count, elapsed ms, stderr, exit status, error) are allowed.
5. **Per word (§2.4)** is computed for the study set only; pseudo strings have no frozen segmentation.
6. **Inputs with full hashes (§1)**, for any session that receives §2 without §1:
   `specimens.json` aa870df775d3db4040a6d799a544605cfa00ffa9df41ea280b4289561c2f9eca;
   `sources/NotoSansThai.ttf` 5a1c559bb539583c8a1fd99d1c5b9491e5e14478c9cd2bd0970d5c3096cc9ef8;
   `sources/pythainlp-words_th.txt` 12bf4d04e8d59a8b235eb9e7ac59b18e5f4d56320f25e75e9c9f8f565543b481;
   `sources/pythainlp-syllables_th.txt` 583db4f1e1244619f4963144b12c610618e44b64b8b7fd04daf753bf9eead412.
7. **R-1 hash comparison (§2.7).** R-1 writes its own render manifest; the orchestrator compares it with
   M's manifest after both exist. R-1 does not wait for M.

## AM-3 — what the font identity check compares

- **timestamp:** 2026-12-05T07:45:00Z
- **post_hoc:** false. No PNG and no OCR output existed: R-1 attempt 2 stopped at the font identity gate
  before rendering; M1 attempt 3 had written no render and no row.
- **reason:** §2.2 says `CSS.getPlatformFontsForNode` "must report only the custom font `SpecimenThai`".
  Chromium reports the family name from the font file's own name table, not the CSS alias given to
  `FontFace`, so the literal reading can never pass. R-1 observed, for every study span:
  `{"familyName":"Noto Sans Thai","postScriptName":"NotoSansThai-Regular","isCustomFont":true}`.

1. **The check (§2.2).** For every span, every entry returned by `CSS.getPlatformFontsForNode` must have
   `isCustomFont: true`, `familyName` equal to name ID 1 of the pinned file (`Noto Sans Thai`) and
   `postScriptName` equal to its name ID 6 (`NotoSansThai-Regular`); the request uses the CSS family
   `SpecimenThai` loaded from the pinned bytes, and no page in the run declares any other web font. Any entry
   with `isCustomFont: false` (a system font, including an installed Noto Sans Thai) fails the gate. The
   cmap-miss fixture C06 must still be refused by the generator and must show a non-custom entry in the
   probe; that is its falsifier.

## AM-4 — the scope of the WTT 2.0 rule in encoding validation

- **timestamp:** 2026-12-05T07:49:00Z (approximate; written between 07:47 and 07:51)
- **post_hoc:** false. No PNG and no OCR output existed: M1 attempt 3 had validated text and shaped fixed
  inputs only, and reported this as open with both candidate pools.
- **reason:** §2.1 says "every combining mark directly follows a consonant or an allowed earlier mark in the
  order consonant, above/below vowel, tone or thanthakhat (WTT 2.0 input sequence)". M1c asked whether WTT
  2.0 strict rejection also applies to pairs that contain no combining mark (for example ฤ followed by
  U+0E32). The two readings give different pseudo-text pools (9 743 against 9 742 syllables) and 17 of 20
  different pseudo strings; the study set passes under both.

1. **Scope.** The WTT 2.0 reference names the order of combining marks and nothing more. The rule is checked
   only on pairs whose second code point is a combining mark (above vowel U+0E31, U+0E34–U+0E37, below vowel
   U+0E38–U+0E3A, U+0E47, tones U+0E48–U+0E4B, U+0E4C). Pairs whose second code point is not a combining mark
   are governed by the allowed list and the other explicit rules of §2.1 only. M1c reported that checking the
   stated mark order and checking WTT composability for combining marks give the same pool of 9 743 syllables
   and the same 20 pseudo strings; that pool is the one used.

## AM-5 — the white-image fixture tests completion, not silence

- **timestamp:** 2026-12-05T07:52:07Z
- **post_hoc:** false for every study, pseudo and phase row (none existed). Made after seeing one calibration
  output, which is stated here: on C05 (200 × 48 px, every pixel 255) Tesseract exited 0 and wrote
  `b" 0\n"` for both T and T0 (R-1 attempt 3); Vision exited 0 with zero observations.
- **reason:** AM-2 item 2 made a non-empty output on C05 a runner defect. The runner passed the bytes through
  unchanged; the output is Tesseract's own behaviour, and removing it or changing a setting would change the
  method the study froze. The gate tested the wrong thing.

1. **C05 gate.** Each arm must complete cleanly (exit 0, valid UTF-8, completion record written). The output
   text is recorded in `calibration.jsonl` and reported as an observation of the engine, not as a gate. The
   `found nothing` rule of §2.3 and AM-1 item 10 is unchanged: an empty normalised output with a clean record
   is a scored non-match; a non-empty output such as `0` is scored like any other output.
2. **Reporting.** The C05 outputs of both runs (M and R-1) are reported in the article's method section as
   observed on a blank image, beside the study results, with no claim beyond that image.

## AM-6 — bootstrap index order and random stream

- **timestamp:** 2026-12-05T08:01:53Z
- **post_hoc:** false. No study, pseudo or phase OCR row existed (M1 attempt 4 stopped after calibration). R-1
  had produced pass-1-equivalent study rows in its own workdir; the orchestrator has read R-1's exact-match
  counts per size and arm. That knowledge cannot steer this item: it fixes an index order and a random stream,
  and no reading of either changes a count, only interval endpoints in the last resampling digit.

1. **Bootstrap (§2.5, AM-1 item 11).** For each comparison separately (one study size × one arm pair, pass 1):
   eligible specimens = study IDs with a scored result in both arms, sorted by ID ascending; n = their count.
   A fresh `rng = random.Random(20261205)` is created for that comparison. For each of 10 000 resamples:
   `idx = [rng.randrange(n) for _ in range(n)]`; difference = mean(exact_A[i] for i in idx) − mean(exact_B[i]
   for i in idx), exact as 1 or 0. Sort the 10 000 differences; the interval is elements 250 and 9749
   (0-based). Report n beside every interval.
2. **Aggregate questions never stop the passes.** A question about how an aggregate is computed is settled
   after both passes have run; rows are produced first.
