Review of perf/native-realtime-engine at 69d8ae9 (whole branch against main 8e54d3a), by Claude Fable (model claude-fable-5-2), review-only session.
Verdict: APPROVE AFTER FIXES
The branch's own logic held up: I could not make minimal updates, delta projections or the segment store lose or diverge data. Fix finding 2 before merge. Finding 1 is the serious one, but it is already on main, so it can be its own change as long as it lands before the natives ship.
What I ran
- Native gate:
native/scripts/check-native.sh (Rust 1.98.0) in my own detached worktree at 69d8ae9: green, 141 Swift tests, 4 skipped, 0 failures. - Fuzz (temporary, not committed): three editors run random commands and exchange only the per-command updates. After every step I checked: - each editor against a plain yrs doc that received only those updates (projection, state vector, delete set), with gc on and off; -
project_delta replayed onto the previous projection against a fresh projection; - convergence of all three at the end.
Commands: display_edit (insert, delete, cross-block), display_paste with nested lists, undo, redo, block, attribute, format, list_indent, split, hard_break, display_autoformat, batch. display_exit_list never succeeded, so it is not covered. 40 seeds of 150 steps per pass.
- Result: with unpatched yrs the fuzz dies on finding 1. With a three-line yrs patch, 15 passes were green (2 with random order and duplicates, 13 in causal order) and one failed (finding 9).
- Both review worktrees are removed. Harness, minimal repro and the yrs patch are in
/tmp/fable-review-145/ on this machine.
Findings
1. HIGH, already on main, not a regression: vendored yrs leaves an undo-kept item under a garbage-collected parent. native/vendor/yrs-0.23.5/src/block.rs:1375 (Item::gc skips kept children even when the parent is being collected), with block.rs:415 (keep(false) clears the flag up the parent chain while a sibling is still kept) and undo.rs:508 (clear_item).
- Repro (
fable_keep.rs, deterministic on main 8e54d3a): delete a word; type a character in the same paragraph; undo; type anything (this clears the redo stack); a peer deletes that paragraph. The next Editor::snapshot panics at slice.rs:212, "Could not get parent branch info for item". The kept item's parent pointer dangles. - Silent variant (seen in the fuzz on this branch, native build): no panic, but the 18 KB snapshot cannot be integrated by a fresh doc. It projects as empty while the editor shows 23 blocks.
- In the WASM build: the same sequence through
CRDTReplica came back correct in my one run. It is reading freed memory that happened to be intact, so I would not rely on it. - Why it matters here: every compaction (
lastGood base), every new source and every stored base is a snapshot. A bad one becomes the local replica, and the stored sequence stops the server from ever correcting it. The branch is no worse than main (main snapshots after every command), and its base-plus-updates recovery heals the panic variant. - Fix: collect the children of a collected parent whatever their keep flag, as Yjs
Item.gc does. /tmp/fable-review-145/yrs-gc.patch does this and is what the passes above ran with. Add the repro as a test.
2. MEDIUM: the update sink records every transaction and only command empties it. native/crdt/src/lib.rs:52, :155.
observe_update_v1 fires for 254/255 applies too. The authority only runs command for undo and redo, so it keeps a second copy of the whole opening state plus every update of the session in WASM memory. Sources keep the opening copy until their first command.- Every
fresh(update:) also re-encodes the whole document just to fill the sink, which costs fuel and time on open and on every new source. - Failure: a large document or a long session gets closer to the 64 MiB and fuel limits, then traps and recovers in a loop.
- This is from reading the code; I did not measure it.
- Fix: record only while
command is executing, or clear in apply_origin.
3. LOW to MEDIUM: a missing segment is silent. DocsReplicaCache.swift:61 (else { continue }), :66.
- Segments carry no chain or count.
BlobStore removes a corrupt file itself before throwing .corrupt. - Failure: the
remove(key) in the catch at :66 fails (locked device, I/O error). The next load then succeeds without that segment, while a later segment's sequence says the state is complete. Whatever the segment held (peer changes, or acknowledged local edits) is never fetched again. - The same hole appears if a power loss drops one file; the store only promises to survive a process kill.
- Fix: give each segment its predecessor's name or a running index, and treat a gap like an unreadable segment.
4. LOW: a whole state stored as a segment does not trigger compaction. DocsPersistence.swift:84.
- After the 4 MB overflow (
needsWhole), commit appends the whole state as a segment but compactIfNeeded is told appended: 0. - Up to 31 whole-state segments can sit on disk and be replayed at open. Pass the whole state's size.
5. LOW: CRDTReplica.persisted drops "the first n" updates. CRDTReplica.swift:111.
- Correct only while
persist() never overlaps itself. That holds today because DocsModel.persistReplica is the only caller and goes through CoalescedRunner. - Two overlapping captures would drop updates that were never stored. Use absolute offsets.
6. LOW: command still lets {"op":"apply"} through. CRDTReplica.swift:250.
- The engine applies it and returns nothing, so
lastGood, the source state and unpersisted miss it. No caller sends it today. Reject it alongside project.
7. LOW: lastGood.data is base plus up to 256 KiB of tail in one 255 envelope.
- A document whose snapshot is within that margin of the 8 MiB limit can no longer build a fresh sandbox until it compacts.
8. Test gaps.
check-update-wire.mjs replays 8 steps into one Yjs peer, in order, and compares toString and the state vector. It has no shuffled or duplicated delivery, no delete-set comparison, and no format, attribute, list_indent, split or autoformat.- The delta test is one sequence (seeds 22 and 9, 160 steps) with no nested-list, format or remote structural edits.
- The fuzz in
/tmp/fable-review-145/fable_adversarial.rs covers these on the yrs side and could be adopted once finding 1 is fixed.
9. Unexplained, seen once.
- One in-order pass (yrs patch applied) failed at seed 39, step 22: after an
undo, the editor's delete set differed from that of the peer given only the update. - It did not recur in 12 further full in-order passes or 150 runs of that seed, and I did not capture which side had more.
- My guess is leftover memory unsafety from finding 1, but I have not shown that. It is worth one more look once finding 1 is properly fixed.
Your seven questions
- Minimal updates: sound. The update is yrs's own transaction update (new structs since
before_state plus the transaction's delete set), merged across a command's transactions. Every command kind above converged through its own update alone, with gc on and off, out of order and duplicated. A failed command can leave its writer changed with no update (23 of about 6,000 steps). CRDTReplica.command rebuilds the writer on every error path, so nothing diverges, but that rebuild is now load-bearing. - Delta projection: no mismatch found. A block's projection depends only on its own subtree.
changed_parent_types reaches the top-level ancestor, and new or re-created blocks are inserted because their identity is new. List numbering is not in the projection. The patched projection matched a fresh one after every checked step. - Position mapping: equivalent by reading (
locate, resolve, the fallback). The branch's own test checks every position, including surrogate pairs, atoms, empty blocks and the end of the document. I did not add to it. - Persistence. - Crash points in append, compaction and discard are safe by reading, and the branch's crash test covers them. - "No local edit without its outbox entry" holds: an append needs
commandsApplied == commandsDurable, re-checked with no suspension before the write. - Dropping the stored replica loses nothing. Unsent edits are in the outbox. Sent ones are appended by the send path before they are marked sent. - Two windows are better off than before, since each appends and compaction removes only what it merged. - Two processes compacting the same key could lose a segment, but I found no second process on this store. - Beyond 4 MB the record is dropped and the next persist stores the whole state. - See findings 3 to 5. - Concurrency: fine. wasmi 0.32.3's
Engine and Module are Send + Sync, and each host has its own store, memory and fuel. Sandboxes never leave the actor. DocsReplicaCache still does file and sealing work on the main actor, but less per persist than before. - U+FFFC: no real document affected. y-prosemirror only puts strings and formats in an
XmlText. Inline nodes are sibling elements. - Rebase on phase 1. - Conflicts:
Host::new and call (fuel against the shared module), sandbox.rs, and reopen (the held set against the segment loop). - Phase 1's long-document test: long_edited_document_opens_and_types must follow the new call sequence: no snapshot or project per key, project_delta, and a 255 envelope carrying base plus tail. - Echo skip: it adopts the server sequence without applying anything. That is safe only because the send path appends the sent update to the log in the same main-actor turn as posted, before .sent. Keep that order through the rebase, and add a test: crash between enqueue and persist, reopen, send, adopt the sequence, reopen. - Empty segments: echo skip will also produce segments with no update. The engine accepts them.