Files
museion/docs/devlog/20261113-cold-turkey-full-tokenization_log.md
T
AlexKucera 7de8e2f7a1
CI / ci (push) Canceled after 0s
docs(devlog): cold-turkey full-tokenization opt branch
CHANGELOG [Unreleased] > Changed entry + session log + INDEX row for
the unticketed opt pass (minutes feeds skip word counting; word rail
count-only; no token array per keystroke). Suite 684.
2026-11-13 04:24:04 +01:00

6.2 KiB
Raw Blame History

Cold Turkey live tokenization — minutes skip + count-only word rail

Date: 2026-11-13 Type: opt Reference: unticketed digest finding cold-turkey-full-tokenization (argus opt pass 2026-11-09, scanned at efbde25c; branch opt/cold-turkey-full-tokenization off main 5915178)

Goal

Kill the O(document) per-keystroke tokenization on the focused writing surface: Cold Turkey feeds every editor edit through whole-document word counting even for minutes blocks whose verdict and progress ignore words entirely, and the word count itself builds a lowercased [String] token array just to return .count. Behavior byte-stable, cost down.

What Was Done

  • Re-derived the defect live at base 5915178 (tip unmoved from the scan-era drift check; the ~10 commits since efbde25c never touched the seam): PostEditorView.onTextChange → WritingLockState.feed → WritingGoalRun.update → DraftStats.words → tokens(in:) — text.split(whereSeparator: { !($0.isLetter || $0.isNumber) }).map { $0.lowercased() }, full array materialized per keystroke, main actor, for every goal type. Minutes consumers (isMet, progress, readout, completionNoteText) never read the count.
  • RED first: injected a per-call word-rail seam on update(text:countWords:) (default DraftStats.words) and pinned a minutes update takes zero word-rail trips — failed at base exactly as designed (base takes one trip per update); companion a words update takes exactly one word-rail trip pins the skip boundary; both sides of the boundary in one suite.
  • Semantic equivalence pin: word rail equals the split tokenizer over a mixed corpus (DraftStatsTests) — the old split expression kept alive as an inline reference over a corpus covering empty, whitespace-only, punctuation-only, mixed scripts (Latin/diacritics/Cyrillic/CJK/Arabic), emoji ZWJ, punctuation, decimal/comma numbers, contiguous alnum runs. Green at base by design — it is the equivalence proof, not a RED.
  • Fix (9f4d9ef): update guards on .words — a minutes run does no word work on feed at all (its accounting freezes at the arm-time baseline; currentWords was dead state for minutes runs); DraftStats.words becomes a count-only Character pass over maximal isLetter/isNumber runs — identical count by construction (split with omitted empty subsequences yields exactly the maximal runs), no array, no lowercasing. Arm-time baseline still counts once per arm through the same rail, now allocation-free. All callers unchanged.
  • Gates: focused WritingGoalTests RED 12/13 → GREEN 13/13; full unit target 684 executed / 684 passed / 0 failed / 0 skipped (681 base + 3 new); swiftformat 0 dirty; swiftlint 279 violations / 60 serious in 141 files — byte-identical to pristine base 5915178 (all pre-existing, spike/prototypes noise).

Decisions & Rationale

Decision Rationale
Per-call injectable rail seam over a global tokenizer counter The hosted suite runs Swift Testing tests in parallel — a shared static counter would race concurrent DraftStats.compute calls (which legitimately tokenize) and false-RED the zero-trips pin. The per-call closure counts exactly the production path (default argument = the real rail) with no shared state. Precedent: spawnsTicker, injectable at: — the repo's established seam style.
Minutes accounting freezes at baseline rather than being deleted WritingGoalRun's documented shape keeps baselineWords/currentWords as arm-time facts; nothing reads currentWords for a minutes run (readout/isMet/progress/note all ride the clock), so freezing is observationally identical to the old live tracking for every consumer — the smallest diff that removes the work.
words(in:) stays the ONE word-count rail (count-only inside it) Museion/AGENTS.md contract: net-words and first-draft stats can never drift. The count-only pass uses the exact same per-Character predicates as the tokenizer; the corpus pin holds the equivalence forever. Explicitly NOT a whitespace count.
DraftStats.compute's sentence-length tokens(...).count left alone Store-time (once per pass at capture), not the per-keystroke seam — one finding per branch; folding it in would scope-creep the opt.

Gotchas & Fixes

Problem Root Cause Fix
RED build failed: "Unprintable ASCII character" at DraftStatsTests:91 The patch layer's JSON escaping wrote a raw TAB (0x09) inside the " \t\n " corpus literal — Swift forbids raw tabs inside string literals (the neighboring \n escapes landed correctly, masking the asymmetry) Byte-level replace with proper \t escape; scanned all touched files for stray mid-line control bytes; amended into the RED commit (dde99c8, force-with-lease — branch unreviewed at that point, disclosed)
02:27 gateway drop killed the turn between the seam patch and the test patches Dead turn discarded; the applied seam patch survived on disk, the two unapplied test patches were lost Re-derived state from git status/diff before redoing anything (no double-apply); RED milestone committed + pushed on resume per push-at-first-commit

Files Changed

File Change Summary
Museion/WritingGoal.swift update guards on .words (minutes: no word work on feed); injectable countWords rail seam; currentWords/header docs updated to the frozen-minutes truth
Museion/DraftStats.swift words(in:) count-only Character pass — no token array, no lowercasing; equivalence documented
MuseionTests/WritingGoalTests.swift Pins: minutes zero rail trips (RED at base), words exactly one rail trip + count lands
MuseionTests/DraftStatsTests.swift Corpus equivalence pin: word rail vs the old split expression over mixed scripts/emoji/punctuation/numbers/empties
CHANGELOG.md [Unreleased] › Changed entry

Open Items & Next Steps

  • None on this seam. Observation for @aegis (NOT folded in): DraftStats.compute's sentence-length .map { tokens(in: String($0)).count } still allocates per sentence chunk at store-time — same count-only treatment would apply there if it ever shows up hot, separate finding.

Log written by hand on the brief-23 branch (daedalus).