oficina / docs Public

S1a: projection log, document surface, per-block rendering, render isolation (native redesign) open

On branch perf/native-s1a

S1a of the Docs native redesign: projection log, the document surface, per-block rendering, render isolation. Spec docs/superpowers/specs/2026-11-22-native-redesign-design.md §7 (Design, Measurement), §11; plan S1a. Rebased on main d5a328a. Not merged, released or deployed. No visible change: S0's baselines are pixel-identical. Pagination is untouched (S1b).

Commits

  • 28efd51 the realtime probes on main (from perf/native-realtime-audit d23f3ca), counters under DOCS_PROBES
  • afdf102 CRDTReplica: presentedRevision, the dirty log, presentation(…, since:) returning a Presentation (projection, revision, dirty) atomically
  • e1a094e NativeTextProjection.renderBlock + DocumentBlockSpacing.Context; DocumentBlockIndex; reconcile one range
  • 278d19f DocumentSurface, per-block drawing, the five flush triggers, render isolation; tests
  • 8cc6668 the numbers (native/benchmarks/README.md), the iPhone timing probe, BUILDING.md

What it does

  • Replica (§7 D1–2). Every projection, whoever asks, moves presentedRevision; each delta logs the top-level ids it inserted or removed (last 512); any full project branch (open, recovery, reset, delta.applied nil) logs unknown. presentation(…, since:) returns the dirty set for exactly (since, revision], nil past the log or across unknown. DocsModel passes surface.appliedRevision as since; a publication its guards drop loses nothing.
  • DocumentSurface (§7 D3, 5, 6, 8). One per model, not @Observable. apply drops stale (revision ≤ applied or ≤ newest), merges dirty into pendingDirty or sets fullDiff. flushIfDeferred runs only when canRender(newest.generation) and no marked text: re-renders the dirty / new / structurally different (CRDTNode: Equatable) blocks plus any whose spacing context moved (neighbour's top margin, first/last), keeps every other block as an anchor if it is one contiguous run of the index, and reconciles each gap between anchors into its own characters (DocumentRenderReconciliation.apply(_:to:in:), same guards). Whole render only at open/after reset; iOS assigns attributedText only then. Images re-render only blocks holding them.
  • Triggers: (a) publication applied, (b) drainEdits ends, (c) compositionChanged(false)/unmarkText, (d) projectionGeneration changes or didRender advances, (e) inputPaused cleared. SwiftUI no longer retries.
  • Block index (§7 D4): .docsTopBlock runs (now also set on iOS), kept in the storage's didProcessEditing: runs before unchanged, after shifted, touched ones re-read. Provisional blocks are just runs.
  • Render isolation (§7 D9–11): DocumentEditorHost (Equatable) reads only the surface, Pages and zoom; the text view is made once per document. projection and selection are @ObservationIgnored; the toolbar reads one equality-guarded toolbarSelection; commands, word counts and DocsEditorContext read the live storage; editability and typing marks are pushed; detail, pendingTitle, draftToken, errorKey, inputPaused assign only when different (guard in their setters). ⌘K goes through model.jumpRequests.

DocsWorkspace: exactly what changed (for S2a's rebase)

  1. init: one new trailing parameter connectivity: NativeConnectivity? = nil, passed to DocsModel (tests flip the sync status with it).
  2. Two new private helpers before beginRename(): loadImages() and requestJump().
  3. editor, the if let projection = model.projection { … } branch only: now if model.showsDocument { EditorToolbar(model: model); Divider(); DocumentEditorHost(…).equatable().id(…).task(id: imageSources) { loadImages() }.onChange(of: model.jumpRequests) { requestJump() } }. EditorToolbar lost its content: argument.
  4. The two DocsToolsControls(projection:content:selection:) lines (iOS toolbar, Mac inspector) become DocsToolsControls(model: model) under if model.showsDocument.

Nothing else in the toolbar/title/inspector/chrome was touched.

Spec points that needed more than the spec said

  1. Optimistic text the replica never confirms. The dirty set only names what the replica changed, so an edit it refused (or one only a dropped publication carried) stayed on screen. The surface now also marks every block the text view edited itself (typed(around:)) for the next publication. Found by the delta-safety test.
  2. iOS typing attributes drop .docsTopBlock: typed text there has no block id until a publication draws it, so "typed text inherits the id" holds on the Mac only. Handled: a nil run belongs to the block before it (dirty marking), and a block split by a nil run is not an anchor, so it is redrawn.
  3. Font-scoped re-render has no trigger: DocsFonts.register() registers every face synchronously before the first window, and nothing registers late. I added no hook with no caller; images are block-scoped as specified.
  4. DOCS_PROBES in debug builds: the spec says "set only by the probe builds"; I define it for the debug configuration too, so swift test and test-iphone.sh can hold the hard counters as gates. Release (what ships) never has it; the probe builds pass -Xswiftc -DDOCS_PROBES to Release.
  5. Timing rule: the load average was never under 4 (12–150 for the table, 300–1,000 earlier). I ran A (main+probes) and B (branch) interleaved, three each; the first separate baseline is kept but its timings are not used.

Hard counters (exact; gates in RenderIsolationTests, Mac swift test and iPhone)

Real DocsWorkspace window: 40 keys, 10 sync-status flips, 20 selection moves, 5 peer changes. After open: whole renders 0, host body evaluations 0, iOS attributedText 0; per key 1 block render (gate ≤ 3) and 1 storage edit (2 on iOS); per peer change ≤ 1 block render; per sync-status or selection change 0 renders and 0 storage edits. Release probe at p20 and p200h, per key (A → B): whole renders 3.6–4.5 → 0, host bodies 3.6–4.5 → 0, block renders 0 → 1 (0.95 at p200h, coalesced), view updates 3.6–4.5 → 0.03 (one, at open). Line-fragment counter: S1b.

Timings (median of 3 interleaved, A → B)

| | p20 | p200h | |---|---|---| | Mac keyDown pageless, 40 keys | 1.2 → 1.4 ms (p95 19 → 2.7) | noisy both sides: A 2.4/6.4/7.0, B 6.6/6.8/2.3 | | Mac keyDown pageless, 200 keys | 1.19 → 1.29 ms, p95 18.7 → 1.4 ms | — | | Mac keyDown paged (S1b) | 65 → 65 ms | 648 → 669 ms | | stalls > 16.7 ms / 40 keys, pageless | 90 → 0 | 87–95 → 1–3 | | peer, publication → reconciled (pageless) | ≈ 1 ms | ≈ 2.8 ms | | peer, all main-thread busy (pageless) | 73 → 23 ms | 576–704 → 16–22 ms | | peer, paged (reconcile still repaginates: S1b) | 117 → 81 ms busy | 888–1,146 → 200–209 ms | | iPhone one-block publication + layout (sim, Debug) | 53 → 0.7 ms | 542 → 4.8 ms |

Targets S1a can move: iPhone per publication (≤ 4 / ≤ 8 ms) met; peer main-thread from publication to reconciled (≤ 5 / ≤ 10 ms) met; measured as all main-thread busy per peer change (which also counts network, replica answer and drawing) p20 is 23 ms. Pageless keyDown ≤ 3 ms at p20 is met (1.3–1.4); the Mac paged keyDown and stall targets wait for S1b as planned. Full table: native/benchmarks/README.md.

Tests (each seen to fail with its mechanism broken)

  • ReplicaDirtyLogTests (5): revisions on every call, exact span, Return, overflow, recovery, delta.applied nil.
  • BlockRenderEquivalenceTests: 6 seeds × 50 random edits (index 0, split/merge, multi-block paste, undo/redo, marks incl. code, block type, align; nested lists, quote, headings, image, rule, code block); per-block storage ≡ whole render after every publication. Red with neighbour re-spacing skipped.
  • BlockIndexTests: typing, Return (provisional), Backspace at block start (two runs), paste through the real text view, no publication; index = fresh runs; then the publication → whole render. Red with the shift of later runs removed.
  • DeltaSafetyTests: real DocsTextView + production replica + a peer; dropped, delayed (stale) and extra projection() publications; ja and zh marked text while the peer edits the same block and another; log limit 2 (overflow). Quiescence ≡ whole render. Red with unknown entries not forcing a full compare.
  • FlushTriggerTests (5, real DocsModel): each trigger with no later publication. Red (b, c, d, e) with the flush wired to didRender only.
  • RenderIsolationTests: above.
  • swift test: 201 tests, 0 failures, 12 skipped (env-gated probes and the snapshot gates). WorkspaceInitTests, SignedInLaunchTests, EditorRenderLoopTests, OfflineDurability, OficinaIDAdoption green. (One SignedInLaunchTests run failed once at load ~700 on the home window's replace question; 3/3 green re-run, and green in the gate run.)
  • test-iphone.sh: 14/14 (EditorRenderLoopTests 3, the S1a tests, SurfaceTimingTests).
  • check-native.sh --mutations: passed, 20 mutations caught.
  • iOS simulator build of DocsPhone: BUILD SUCCEEDED. Nothing mutates observed state in an init or body (the attach-time flush defers its model notification to the next turn).

native/scripts/snapshots.sh compare all (no baseline changed)

Mac:    docs-editor (compare, 24 images) passed; docs (compare, 22 images) passed
mac half drawn on:
  os: macOS 27.0.0
  toolchain: Xcode 27.2 Build version 27B52
  language: en
  accent: #007AFF
  locale: en_IE
  time zone: Europe/Dublin
  increase contrast: off
  reduce transparency: off
  differentiate without colour: off
  docs: baselines drawn on the same
  docs-editor: baselines drawn on the same
iPhone: docs-editor (20) + docs-editor-ax3 (4) passed; docs (32) passed
iphone half drawn on:
  os: iOS 27.0.0
  device: iPhone19,2
  runtime: 27.0 (24A434)
  toolchain: Xcode 27.2 Build version 27B52
  language: en
  locale: en_IE
  time zone: Europe/Dublin
  increase contrast: off
  reduce transparency: off
  differentiate without colour: off
  docs: baselines drawn on the same
  docs-editor: baselines drawn on the same
  docs-editor-ax3: baselines drawn on the same

Hub CI: reply below. Asking for the whole-branch review by the highest-capability model.

Hub CI at 8cc6668: amadan ci status oficina/docs -branch perf/native-s1a exits 0 (CI passed). Push token revoked and build output cleaned. Ready for the whole-branch review. Not merged, released or deployed.

Whole-branch review — Claude Fable (model id claude-fable-5-2), read-only, perf/native-s1a at 8cc6668 against main d5a328a

Verdict: APPROVE AFTER FIXES. The design from #157 is implemented as specified, and findings 1–3 below are small but must be fixed before merge. I confirmed each of the three with a throwaway test in my own review worktree (now removed); none of the branch's tests covers them.

I also ran test-iphone.sh there: 14 tests, 0 failures, 1 skipped, including EditorRenderLoopTests 3/3, so the #162 loop stays fixed. I did not re-run the full Mac swift test, the snapshots or the mutation gate; for those I relied on your run and hub CI.

Must fix

  1. High — a replace across blocks can leave the text view permanently different from the replica. DocumentSurface.swift:343-354 (typed(around:)), with :252 and :282-287. - Cause: for an edit that inserts text, typed marks only the runs holding the inserted characters. The block that lost its head to the same edit is not marked. - Scenario: select from the middle of block a into the middle of block c, and type x (or paste, or cut). If the replica's next projection leaves c unchanged, c is a single in-order run, so it is kept as an anchor. - Confirmed: four paragraphs aaa/bbb/ccc/ddd, select 1…9, type x, republish the same projection. The storage ends as aaa\nbbb\ncc\nddd\n, with both dirty: [] and dirty: nil. - Full compare does not heal it. It compares the cached node with the new node, never the storage, so "unknown" is no safety net for a storage/cache mismatch. - Reachability: the replica has to not reflect an edit the text view already showed. That means a recovery that rolls back to lastGood, or the engine clamping a range the optimistic edit did not. - Consequence: every display offset after c is off by the missing characters, so later edits land in the wrong place, silently, until something touches c. The old path healed this on every new generation with a whole reconcile. - Fix: - In typed, always mark from location - 1 through NSMaxRange(edited), so the run after the edit is included. - Keep each entry's rendered UTF-16 length, and accept an anchor only when run.length equals it. Any future mismatch is then redrawn at the next flush. - Add to DeltaSafetyTests: typing, cut and paste over a selection that spans blocks, with the command not taken.
  1. Medium — a second text view on the same surface is never drawn. DocumentSurface.swift:129-147 (attach), :184-185, :119-125 (reset). - Cause: attach rebuilds the index and calls flushIfDeferred, but nothing is "waiting" (the revision is applied and pendingDirty is empty), so the new view stays empty. The surface also goes on believing its entries are drawn. - Confirmed: publish, then attach a fresh DocsTextView. Its storage is "". - Reachability: any SwiftUI rebuild of the host without a DocsModel.open. updateNSView already expects this (surface.textView !== text). Candidates are NavigationSplitView collapsing or expanding on iPad, and S2a restructuring the view around the editor. I did not reproduce it in the app. The old per-view coordinator handled this case. - Related: reset() keeps textView. In open, showsDocument = true is followed by surface.apply before the new view exists, so a previous view that is still alive would take the first draw and the new one would get nothing. - Fix: when attach gets a different view, clear entries and order and force a whole draw. Clear textView in reset(). Add a test.
  1. Medium — observed state is assigned inside makeNSView / makeUIView for any document holding an image. DocumentSurface.swift:146 → :228 → report (:330-334) → the model's imageSourcesChanged hook, which sets imageSources. - Cause: the first draw always happens in attach, because the text view does not exist earlier. Only didRender is deferred with notifyLater; report(sources:) is not. - Confirmed: the hook fires synchronously inside attach. - Effect: it is one-shot, so there is no loop, and testOpeningAListImageAndRuleSettles passes. But it is the class of mutation the 0.1.7/0.1.8 rule forbids, and the write-up's "nothing mutates observed state in an init or body" is not true for these documents. - Fix: defer the report with didRender when notifyLater is set. Add a test.

Should fix (can follow, but before S2a merges)

  1. Medium — S1a exposes nothing observed for "the text changed", and S2a's signal fires too early. - S2a (1e1e53e) adds history and contentRevision in a didSet on projection. The merge must keep that didSet on the now @ObservationIgnored property. - projection is assigned before surface.apply, and the draw can be deferred (pending input, composition). A reader of surface.content woken by contentRevision can therefore read the old text and never be woken again. - S2a's DocsLiveWordCountSheet calls NativeTextProjection.render(projection). After the merge that is a whole render per publication while the sheet is open. - What S1a should own: - an observed contentRevision, moved after a flush has changed the storage; - an observed history (canUndo/canRedo), set in publishCurrent. toolbarSelection.canUndo is not enough, because it stays stale whenever DocumentCommands.isEnabled is false, such as a read-only document or pending input. - Then S2a's pill and word count read those and surface.content.
  1. Low — Mac menu state may go stale. DocsEditorCommands reads editor?.actions?.isEnabled from the focused value. Before, the workspace body ran on every projection or selection change and re-published that value. Now it runs only for the sync status, the title and errors. I did not test this; check Format menu enablement right after open and after a caret-only move, ideally in S2a's menu tests.
  1. Low — trigger (e) does nothing in production. canRender never reads inputPaused, and FlushTriggerTests (e) passes only because the test wraps canRender to add it. Trigger (d) is tested through projectionGeneration only, not through didRender advancing. Either state that (e) is defensive, or make canRender consult inputPaused.
  1. Low — main-thread copies of the whole text. storage.string on an NSTextStorage bridges by copying the whole document. It is used per gap (DocumentRenderReconciliation.swift:27, DocumentSurface.swift:302) and on every selection change (DocumentSurface.swift:404). Use storage.mutableString. index.positions() and Set(ids) are O(blocks) per flush, which is fine at the measured sizes.
  1. Low — isEquivalent has no production caller left. DocumentRenderReconciliation.swift:52 is now used only as the tests' oracle. Say so in its comment or move it to the test target. The iOS loop is now prevented by applying and by never assigning attributedText after open.
  1. Low — the line-fragment request counter is not on this branch. The spec lists it among S1's new counters and the write-up defers it to S1b. That is acceptable since pagination is untouched, but the S1b gate must not ship without it.

Checked and found correct

  • Dirty set (#157 r2/r3): it returns atomically with the presentation. since is surface.appliedRevision, so a publication the model drops loses nothing.
  • Stale publications: dropped in apply.
  • Unknown entries: every full project branch logs one, including log overflow, and it leads to a full compare.
  • Provisional blocks: block ranges come from .docsTopBlock runs, kept current in didProcessEditing and tested against a fresh read.
  • Gap reconciliation: everything between two anchors is replaced, so nil-id iPhone text, orphaned runs, moved blocks and duplicated ids all resolve.
  • Marked text and IME: no flush while text is marked or composing, and no publication while composing. The commit enqueues before compositionChanged(false). A cancelled composition republishes.
  • Undo and redo: they go through the engine, and their deltas name the blocks.
  • Selection: a new generation takes the replica-resolved selection, and the callbacks are muted by applying.
  • Images: the store always reassigns on load, so a reset surface gets them again.
  • Render isolation: the host reads only the surface, Pages and zoom, and the counters gate it on both platforms.
  • DOCS_PROBES in debug builds: fine, since release builds carry none of it.

Fixes for Fable's review, pushed to perf/native-s1a as five commits on 8cc6668. Head is 21ea585, and hub CI passed on it. Not merged.

  1. HIGH, an edit across blocks (ad458c5). - typed(around:) now marks from the character before the edit through the one after it. - Each block remembers the length it was drawn at. A block is kept as an anchor only when its run in the storage is that length. - New test, DeltaSafetyTests.testAReplaceAcrossBlocksTheReplicaRefusesIsUndone: it types, cuts and pastes from the middle of aaaa to the middle of cccc, and the replica takes none of it. It failed before: the storage was left at "aa…cc" with "cccc" gone. It passes now. - I did not add a storage-text check to the full-compare path. With the length check, a block whose text no longer matches what was drawn can't be kept. A same-length divergence would need the text view to edit the block, and the marking above covers that.
  2. MED, a second text view (d156793). - Attaching a different view releases the old one (its delegates and callbacks) and draws the new one whole from the newest publication. - New test, SurfaceLifecycleTests.testASecondTextViewIsDrawnWhole. It failed before (the second view stayed empty) and now also covers a later publication. - Not done as suggested: reset() does not clear textView. A new draft on iPhone, or a discard, keeps the same host, and nothing rebuilds it to attach again, so clearing it would leave the document undrawn. reset() clears the entries instead, so the next publication is drawn whole.
  3. MED, observed state assigned inside makeNSView/makeUIView (5800d1a). - The image-source report now goes with didRender: right after an ordinary flush, and on the next turn after an attach. - New test, SurfaceLifecycleTests.testAttachingTellsTheModelOnlyAfterTheUpdate. It failed before, because imageSources was reported inside the update.
  4. LOW, trigger (e) (21ea585). This needs a ruling: I did not make it real, because that would be a behaviour change. - canRender, as spec §7 Design 6 defines it, reads neither inputPaused nor renderedGeneration. So no production state waits on (e) alone, or on didRender's half of (d). - A writer paused by a refused command still holds that command as pending input, and trigger (b) draws when the queue drains. - A reader is paused for good but must keep seeing peers' changes. If canRender read inputPaused, readers would never see a peer's edit. - The other half of (d), projectionGeneration's didSet, is the one that can unblock, and FlushTriggerTests covers it through the model. - I kept the calls, which cost nothing, and their comments and the (e) test now say it is a wiring test. - Proposal: drop (e) and didRender from the spec's trigger list, or rule that canRender should change.
  5. LOW, whole-text copies on the main thread (251e24c). The per-gap reconcile, the text-only check and the selection callback read mutableString ranges now, not storage.string. There is no failing test for this one: I could not observe a copy deterministically.
  6. LOW (251e24c). isEquivalent's comment now says it has no production caller and is the tests' oracle.
  7. LOW. The line-fragment request counter is S1b's work (plan S1b item 6).

4/5 (merging with S2a): I'll wait for the coordinator's word that S2a has landed before rebasing.

Gates at 21ea585:

  • swift test (through check-native): 204 tests, 0 failures, 12 skipped.
  • check-native.sh --mutations: passed, 20 mutations caught.
  • test-iphone.sh: 17 tests, 0 failures. The one skip is the timing probe, which only runs when its documents directory is set.
  • snapshots.sh compare all: green on both platforms with no baseline changed. Mac 24 + 22 images; iPhone 20 + 4 + 32; every set says "baselines drawn on the same".
  • Hub CI exits 0.

SurfaceLifecycleTests is added to DocsPhoneTests as well. The push token is revoked.

The coordinator's two rulings are applied, at c3728a1. Hub CI passed on it. Not merged.

  • Finding 6 (accepted): there are four flush triggers, not five. 6222fd7 amends spec §7 Design 6 and the plan to list (a)–(d), where (d) is projectionGeneration changing. A new paragraph, "Two events are not triggers", says why inputPaused being cleared and didRender are not triggers: - canRender reads neither inputPaused nor renderedGeneration. - If it read inputPaused, readers, whose input stays paused, would never see a peer's edit. - A paused writer's refused command is still queued as pending input, so trigger (b) draws when the queue drains.

§11 now counts four trigger tests. In c3728a1 the code still calls the flush at both points, since it costs nothing, and the comments there say they are not triggers. The (e) test is removed: it only passed by wrapping canRender. FlushTriggerTests now covers exactly (a)–(d).

  • Finding 2: reset() keeps the text view (accepted). Spec §7 Design 3 now says attaching a different text view draws it whole, and that reset() keeps the attached view, because a new draft or a discard keeps the same host. A table at the end of the spec maps both amendments.

Gates at c3728a1:

  • swift test: 203 tests, 0 failures, 12 skipped.
  • test-iphone.sh: 16 tests, 0 failures. The one skip is the timing probe, which only runs when its documents directory is set.
  • Hub CI exits 0.
  • Only comments and tests changed in the native code, so the snapshot result from 21ea585 stands: green, with no baseline changed.

The S2a rebase is on hold until S2a lands.

Rebased onto main 2704697 (S2a landed, #169) and force-pushed. Head is e7c15d6; hub CI passed on it. Not merged. Fable, this is the merge to re-check.

How the merge resolves findings 4 and 5

  • History. DocsModel.projection stays @ObservationIgnored. Its didSet sets S2a's observed history, only when the value differs. The projection is assigned in publishCurrent, so history is set with each publication, whatever the access and whether or not input is pending. - The undo/redo pill, Tools ▸ Word count's enabled state, the iPhone toolbar's undo and redo (this was toolbarSelection.canUndo, which went stale for readers and while input was pending), canAction and DocsEditorContext.actions all read history. - showsDocument is now history.loaded.
  • Content revision. contentRevision is observed and moves after each draw into the text view: the surface's didRender hook. After an attach, that hook runs on the next turn, never inside SwiftUI's update.
  • Live word count. DocsLiveWordCountSheet, which the iPhone's Tools now uses too, counts from the projection's text and the text view's own storage. It does no render, so a publication costs only the count's walk of the projection.
  • Format inspector. DocsFormatInspector(model:) has no content: parameter any more. It reads the model's one observed toolbarSelection and acts on the live storage. Its side is an input of DocumentEditorHost(surface:paged:zoom:inspector:), and NativeDocumentTextView puts the page on S2a's DocsDeskView.
  • Jump. ⌘K from the text view's keys raises model.jumpRequests, and the window shows S2a's jump sheet (spec §1). S1a's open-home is gone.
  • Kept from S2a as they are: - the workspace's team: parameter, now with connectivity: after it; - the model's unavailable, inputBlocked, documentAccess, refreshAccess, the retry guard and the stream-reopen hook; - DocsToolsControls' sheets.
  • Two S1a adjustments: - sessionPaused is a guarded property that pushes editability to the surface, and editability is can_write && !inputBlocked. - EditorSnapshots' EditorPage keeps S2a's inspector: parameter, passed through the host.

Tests

  • New: SurfaceChromeTests (Mac). - The Format menu's enablement (DocumentCommands.isEnabled, which DocsEditorCommands disables from) follows a key and the queue draining, through observation. - History is current at a publication that arrives while input is pending, and for a reader. - The live count re-evaluates after a draw with no whole render. - The last two failed with the history's update, or the count's no-render, removed.
  • S2a's DocsHistoryObservationTests pass: the pill, Word count's enabled state, and the sheet after an edit. The sheet case now attaches a text view first, as the editor does whenever the sheet can be open, because the count reads that view's storage.

Gates at e7c15d6

  • check-native.sh --mutations: passed. That includes swift test, 232 tests, 0 failures, 12 skipped; 20 mutations caught.
  • test-iphone.sh: 16 tests, 0 failures. The one skip is the timing probe, which only runs when its documents directory is set.
  • snapshots.sh compare all: green. Mac docs (22), docs-editor (24, including the 150% screens S2a re-recorded) and docs-window (22); iPhone 20 + 4 + 32. Every set says "baselines drawn on the same", and no baseline changed.
  • The release Mac build (build-mac.sh) succeeds.
  • test-document-window.py passes in both modes, ordinary and DOCS_SMOKE_DRAFT=1: the document loads, the Format inspector toggles, the window resizes, the editor and selection persist, the caret geometry holds through Enter and typing, and the account menus work.
  • Hub CI exits 0.

Final review of S1a on S2a (git diff 2704697 e7c15d6) — Claude Fable (claude-fable-5-2). Verdict: APPROVE AFTER FIXES. One medium regression from the merge (finding 1), a small fix. Everything else holds.

Findings

  1. Medium — the toolbar and Format inspector keep their old state after typing. DocsModel.swift:477-487 (didRender), :444-451 (drainEdits' defer), :833-837 (refreshToolbarSelection). - Cause: refreshToolbarSelection keeps the old value while input is pending. After a key it runs three times, all too early: on the selection change (pending), after surface.apply (still pending, because editingTask is set until the drain returns), and in didRender. Plain typing reuses the generation, so didRender's guard generation > renderedGeneration returns before the refresh. Nothing refreshes once the queue has drained. - Confirmed with a throwaway test on the model (LoopFixture.everything, real text view), waiting for the queue to drain plus 50 ms: - Caret at the end of the heading, Enter: toolbarSelection.style stays heading1; a fresh DocumentToolbarSelection says paragraph. Generation 1 before and after. - Select three characters, type over them: hasSelection stays true (fresh: false), so Clear formatting stays enabled. - 401 pause, caret moved into the heading, 200: stored paragraph, fresh heading1. - Effect: the Mac inspector (open by default) and the iPhone toolbar show Heading 1 for a body paragraph after Enter, until the caret is moved by hand or a new generation is drawn. Commands still act on the live text, so nothing is damaged. On main the toolbar body recomputed when the queue drained; this is new with the single observed value. - Fix: refresh wherever DocumentCommands.isEnabled can turn true: in drainEdits' defer after the flush, before didRender's guard (or in the hook), when composition ends, and in the inputPaused / sessionPaused / detail setters. Add a SurfaceChromeTests case: Enter at the end of a heading, then stored equals fresh.
  1. Low — the report deferred from attach is not tied to the document. DocumentSurface.swift:238-240. - Confirmed: apply (generation 7), attach, reset() in the same turn; didRender(7) still arrives afterwards. - Effect: in the model that would set renderedGeneration to the old document's generation after an open reset it to 0. The new document's lower generations then never pass didRender's guard, and isEnabled stays false. It needs a reset between an attach and the next main-actor turn, which I could not produce through the app. - Fix: in the task, skip unless self.generation == rendered.
  1. Low — attach forgets the old drawing only while the old view is alive. DocumentSurface.swift:130-138. - textView is weak. If the old view is already gone when a rebuilt host attaches (and no reset came between), the entries stay, nothing is waiting, and the new view is blank until the next publication. - Not reproduced: I could not get the first view released inside a test, and every app path I traced resets before it publishes again. - Fix: test textView !== text instead of if let old, releasing the old view only if there is one.
  1. Note, not from this diff: a reader who is given write access again shows writable chrome but the text view stays read-only (refreshAccess sets inputPaused for a reader and nothing clears it). Same on main.

Checked and found correct

  • My findings 1–3 from 8cc6668: fixed. The cross-block replace (type, cut, paste, refusing replica), the second text view and the deferred report each have a test that passes here; mutated-length anchors are redrawn.
  • History: set in projection's didSet, so it is current at a publication with input pending and for a reader. The pill, the iPhone undo/redo, canPerform and Tools ▸ Word count read it.
  • contentRevision: moves only in the didRender hook; after an attach that is the next turn.
  • Word count: counts from the projection and the live storage, no render.
  • Mac menus in the real window (the smoke harness with a temporary probe): after focus and a selection with no typing, Bold, Italic and Word count are enabled and Undo is disabled; after one key, Undo is enabled. My old finding 5 does not occur.
  • Inspector side, Jump sheet, sessionPaused → editability: wired as described. The 401 probe shows isEditable false then true.
  • 0.1.7/0.1.8 rule: I found no observed assignment in an init, a body, or make/update of the representable. The model's init only writes with no observer yet.

Gates I ran, in a review-only worktree at e7c15d6 (removed afterwards)

  • swift test: 232 tests, 0 failures, 12 skipped.
  • test-iphone.sh: 16 tests, 0 failures, 1 skipped. The iOS loop stays fixed.
  • I did not run the snapshots, the mutation gate or the release build.

Shipping as Docs 0.1.12

Safe once finding 1 is fixed: no hang, loss or divergence risk found. I would not ship without it, since the default-open inspector shows the wrong style after an ordinary Enter. Findings 2 and 3 are a few lines each and can go in the same commit or follow.

Fixes for Fable's final check, pushed as four commits on e7c15d6. Head is 57ff648; hub CI passed on it. Not merged. Each commit carries a test that failed before its fix.

  1. MED, 5cde93f: the toolbar and inspector now follow the text once input settles. refreshToolbarSelection now runs wherever DocumentCommands.isEnabled can turn true: - when the queue drains; - on every draw, before didRender's guard (plain typing reuses its generation); - when composition ends; - in the detail, inputPaused and sessionPaused setters.

New SurfaceChromeTests cases, one per repro. Each compares the toolbar's state with one computed afresh from the live text, and all three failed before: - Return at the end of a heading: the style is now the new paragraph's. - Typing over a selection: hasSelection is false, so Clear formatting is disabled. - The caret moved into a heading during a 401 pause: after the 200, the style is Heading 1.

  1. LOW, e30fa0c: the report attach defers belongs to its document. On the next turn it runs only if the surface has not been reset in between and still shows that generation. Test: SurfaceLifecycleTests.testADeferredReportIsDroppedAfterAReset, which resets in the same turn as the attach.
  2. LOW, b3165fa: a new text view is drawn whole when the old one is gone. attach compares textView !== text, so it no longer depends on the weakly held old view still being alive. Test: SurfaceLifecycleTests.testANewTextViewIsDrawnWholeWhenTheOldOneIsGone, which waits for the first view to be released before attaching the second.
  3. Note 4, 57ff648: a reader given write access again can type. This bug was on main before S1a too. The fix is small, so I took it. - A read-only answer to refreshAccess now records its pause as its own (pausedAsReader), and a later writable answer lifts that pause only. - A refused command, a failed save, a full outbox, or a document no longer available each keep their own pause. - The flag is cleared on open and discard. - Test: SurfaceChromeTests.testAReaderGivenWriteAccessAgainCanType. It failed before: input stayed blocked and the text view was not editable.

Gates at 57ff648:

  • check-native.sh --mutations: passed. That includes swift test, 238 tests, 0 failures, 12 skipped; 20 mutations caught.
  • test-iphone.sh: 18 tests, 0 failures. The one skip is the timing probe, which only runs when its documents directory is set.
  • snapshots.sh compare all: green. Mac docs (22), docs-editor (24) and docs-window (22); iPhone 20 + 4 + 32. Every set says "baselines drawn on the same", and no baseline changed.
  • Hub CI exits 0.

Landed on main (squash) after Fable's final fixes (all with tests) and green hub CI at 57ff648. Next: Docs native 0.1.12 to Mac + TestFlight.

Docs 0.1.12 (14) released to Mac (Sparkle) and TestFlight from main 93230c0 (2026-11-24). It ships the Mac document window (S2a, #169) and per-block drawing (S1a, #170). It is native only, so there was no server deploy.

Tests on the release commit, after build-crdt.sh:

  • swift test --package-path native/apple: 238 tests, 0 failures, 12 skipped.
  • native/scripts/test-iphone.sh (iPhone 18 Pro, iOS 27.0 24A434): TEST SUCCEEDED. 18 tests, 0 failures. The one skip is SurfaceTimingTests.testOneBlockPublication, which needs DOCS_RT_AUDIT_DOCS. BlockIndex, BlockRenderEquivalence, DeltaSafety (3), EditorRenderLoop (3), FlushTrigger (4), RenderIsolation and SurfaceLifecycle (4) all passed.
  • snapshots.sh compare all: green. Mac docs (22), docs-editor (24) and docs-window (22); iPhone docs-editor 20 + AX3 4 and docs 32. Every set says "baselines drawn on the same" (macOS 27.0.0, Xcode 27.2 27B52, runtime 27.0 24A434).
  • test-document-window.py: all three PASS lines, in the letter mode and in DOCS_SMOKE_DRAFT=1 (4 PASS lines). This script builds its own debug harness on the release commit's DocsKit; it cannot drive the signed app.

Mac 0.1.12 (14), Sparkle. Notarised (id 821de4d5-96b5-4e39-a53a-c0ca16de9a8f).

  • On the unzipped release zip: spctl says Notarized Developer ID, Team Tito. Stapler validates it.
  • Entitlements are unchanged from 13: keychain groups .docs then .id, App Group 9U4A84C4WK.works.oficina, webcredentials:id.oficina.works. embedded.provisionprofile is there.
  • DocsMac --oficina-id-launch-check reported every line ok and exited 0.
  • Published to native-releases as release docs-14, feed commit 2278d5b6de8b74a2fe9b458fa332decda75a92f3. The public appcast lists 0.1.12 (14) first.
  • zip sha256 bf723a8d4b4142d0dab921c196d44d2b4a369a7b0baf8264b1116793c7e42485 (15032512 bytes). An anonymous download gives the same hash and length.

iPhone 0.1.12 (14), TestFlight.

  • Archived with Apple Distribution and the "Oficina docs iOS App Store 2026-11-14" profile.
  • The archive holds only DocsPhone.app, with no PlugIns, Frameworks or xctest, so DocsPhoneTests is not in it.
  • Info.plist has 0.1.12 / 14 and ITSAppUsesNonExemptEncryption=false.
  • Uploaded with delivery fa6e770b-ebf9-4180-a79e-af2fd84c2a88. It was VALID after about 2.5 minutes, with usesNonExemptEncryption=false already set.
  • internalBuildState is INBETATESTING. The "Oficina internal" group has access to all builds.

Deviation: oficina-distribution.keychain-db no longer unlocks with the stored password, as Equipo's TestFlight helper found on 11-23. The same Apple Distribution identity, 07E99055…, is in the login keychain, so I signed from there. The keychain search list was never changed.

Small follow-up: native/smoke/document-window/Package.resolved pins rastrillo/native at 529f356, but apple/Package.swift pins 0254817. SwiftPM re-resolves it on every smoke run, so the smoke test did run on the release pin. The committed file is just stale.

Next: Paul tries the new Mac document window and typing on iPhone build 14.