Hub CI passed on 59b4770 (amadan ci status exit 0). Not merged.
Undo and redo while diverged end as the person saw them open
On branch fix/undo-redo-while-diverged
Branch fix/undo-redo-while-diverged, head 59b4770, cut from main 4c23861. This fixes Claude Fable's findings on #29 (his second review of feat/replay-while-diverged). Not merged, not deployed. Docs has the same change on its own fix/undo-redo-while-diverged, with its own discussion.
P1: an undo or redo that puts text back
The bug: item matching (watchUndo) covered what an undo deletes, not what it re-inserts. Yjs's redoItem anchors the re-inserted text to the original item, which the rebuilt doc never holds when that text was typed on the refused x. And ySync's mirror carried no replay.
The fix is Fable's:
- A replay for every undo and redo.
aroundDispatchsees ySync's mirror of an undo or redo (isUndoRedoOperation). While diverged, it derives oneReplaceStepfrom the mirror'str.beforeand final doc (carry.mjs'sderivedStep, with the same overlap rule asreplaySteps). It leaves that asmirrored. The mirror runs in Yjs's observer phase, before the doc's'update', so the nextkeep()in the same Yjs transaction takes it;beforeTransactionclears it. - More than one view. If more than one view mirrors one undo (an undo across blocks), the entry goes as its updates.
watchUndois gone. With the derived replay in place it would double a type-over's undo.- Trade-off for Paul, as Fable flagged: an undo or redo that put the refused x back on screen now brings it back on the page and posts it, as the person saw.
Tests. Fable's 17 cases (A–Q), each held to the tab's own text, with the refused x gone unless an undo or redo put it back:
- Node: in
carry.test.mjs, through a harness that keeps the derived replay exactly as the editor does. - Real editor: in
fixtures/engines/undo.mjswith real keys (Cmd/Ctrl-Z, Cmd/Ctrl-Shift-Z, Backspace, selections), Chromium and WebKit.TestEnginesUndoAndRedoWhileARefusalIsPendingEndAsSeenholds the server to the same text. Case K, the x and "a" in one undo step, answers the x's save at once so the "a" lands after the refusal but within the x's 500 ms undo step. - Failing first: on 4c23861 seven fail in both engines, the same seven Fable's probe flagged: - A:
abforabc- C: `fora- D:bforab- I and J:forxa- K:forxa- M:twoforone two`
The other ten were already right there and stay as guards.
P2: the timing test
- Bound on growth.
carry.test.mjsnow bounds growth in CPU time (process.cpuUsage), not wall time. 4000 changes typed elsewhere may take at most 8× the CPU of 1000: linear is 4×, and the quadratic version this replaced was about 20×. The refused-text path is checked at 500 against 2000. Each takes the best of several runs, with a generous ceiling. - Result. The wall-clock version failed once here at a load average of 60 (24 ms against 301 ms). The CPU-time version passed 3 runs out of 3 at a load average of 134.
- Client count. It's still bounded to one per 500 ms window.
Nits
- An entry that only deletes what the rebuilt doc never held (Cmd-Z on the refused x alone) is no longer counted as lost; there's a Node test for that.
- No reference to
rv-undo-probe.mjsremains.
AGENTS.md
It no longer says every change is kept. It describes the derived replay, and names what still isn't kept:
- a change whose replay can't be made (the structural case);
- a change made elsewhere in the same 500 ms ID window as one on the refused text, when its own replay can't be made either;
- an undo mirrored in more than one view;
- an inspector op written on the refused text.
Validation
make cipasses.- The gate's JS/Go half passes, with 268/268 Node tests.
- The full browser suite (2025 s, load average 80–170) passed except
TestFontEnginesSlidesChangeWithoutAGapandTestLeavingAPageLetsGoOfItsStream/chromium/editor. This branch touches neither path: both are the viewer, or the editor outside divergence. Rerun alone, both pass 2 runs out of 2.
Coordination with Docs fix/safari-save-stall (#94)
This branch keeps to carry.mjs and the undo paths of editor-entry.js (aroundDispatch, the update handler, beforeTransaction). On Slides there's no overlap with #94.
Claude Fable 5.1, reviewing for session 21a32889. Review of fix/undo-redo-while-diverged at 59b4770, read as one diff against origin/main (4c23861), scratch worktree /tmp/rv7-slides. No tracked file edited; probes under /tmp/rv-probes (pfs/rv-many-probe.mjs, quad*/, the r2 ones re-run).
Verdict: ready to merge — VERDICT: APPROVE-WITH-NITS. The derived-step replay fixes the P1 as sketched: an undo or redo while diverged is replayed on the rebuilt document as the person saw it, and all seventeen cases hold in Node and in the real editor, where seven of them fail on main. Two P2s below, neither blocking: one case watchUndo handled that the derived step gives up (named in AGENTS.md, but lost says 0 for it), and the growth test's bound only catches the quadratic it was written for.
Findings
- P2 — an undo mirrored in two views is dropped whole, and counted as nothing lost. The
'many'path keeps the entry as plain updates. When the undo step spans two blocks (two views: "a" on the refused x in block 1, then "b" in block 2 within the 500 ms capture window) and the resync replays both letters under new ids, the undo's delete-only update readsnone, has no replay, and the newinserts()rule skips it without counting: the page and the server holdBlock one.a/Block two.bwhere the tab showed both undone (pfs/rv-many-probe.mjs). An undo-then-redo of the same step ends the same way withlost=1. Main'swatchUndomarked both entries undone and got this right, so it is the one narrow regression of removing it; AGENTS.md names the limit ("kept only where they integrate"), but here nothing integrates and the save line says nothing. Two fixes, both small: letmirroredcollect a replay per view (an arrayreplaytried in turn incarry, each with its ownlocate) instead of giving up at the second; and havecarrycount a delete-onlynoneentry as lost when its deletes touch ids of entries it replayed (it knows them: the structs of every entry that went down the replay path), so the "undo of the x alone" case stays uncounted and this one does not. Typing in two blocks within half a second is rare (a click between them and a key), so not blocking.
- P2 — the growth test catches the quadratic it replaced, and little else. Flipping the branch's
carryback to a fresh id per change and a state vector per update (the parent's quadratic) fails it at ratio 20.6 (10.7 s against 520 ms CPU). But each of the two halves alone passes: the state vector per update alone at ratio 7.6 (354 against 47 ms; the bound is 8), and a probe copy rebuilt per entry at ratio 5.3 while fifteen times slower in absolute terms (1.9 s for 4000, against 169 ms; the ceiling is 10 s). The bound of 8 on a 4× size leaves a quadratic term that is still small at 4000 room to pass, and the ceiling is loose enough for a 10× constant slowdown. CPU time is stable under load (the branch's own numbers held at load 70–110 here: ratios 4.2 and 3.6), so both can be tightened: a bound of 6 (linear is 4, the min-of-three gives little noise) and a ceiling near ten times the real cost (2 s elsewhere, 8 s on the refused text), or compare 500 against 4000 so the quadratic term shows. Not blocking: the regression it was written for is caught, and the flake is gone.
- Nits. The AGENTS.md sentence "a change outside the text views (an inspector op) written on the refused text" is right and new; worth adding that
lostundercounts for finding 1's shape until it is fixed. The removedundoWorldtests' coverage is all inside the seventeen cases (checked case by case). The engines fixture'spause(700)between steps relies onUNDO_CAPTURE_MSbeing 500; a constant would be safer than a number.
What I checked, and what holds
- The derived step.
derivedStepisreplaySteps's span rule as oneReplaceStep: valid wherever the content outside the span is identical (it is, byfindDiffStart/findDiffEnd), including a join or a split across paragraphs (the slice is open at both ends) and a mark change (text nodes with different marks differ). Where it cannot fit,replay's try/catch andmaybeSteprefuse it and the entry falls back to its updates — what every undo did before. The mirror is one dispatch per view per Yjs transaction, in the observer phase, beforeafterTransactionand the'update'emission (yjs 13.6.27cleanupTransactions), sokeepreadsmirroredin the same transaction;beforeTransactionclears it;heldis never set during it (the undo runs from the keymap throughgateLocal, not inside a dispatch).isUndoRedoOperationis y-prosemirror 1.3.7's own meta (transaction.origin instanceof Y.UndoManager). The phone stage binds withoutaroundDispatch, so its mirrors do not count toward'many'; the notes view does, and is one view. - Doubling and loss. My r2 probe (
PROTO=2, the prototype of this fix) on the branch's module: every case matches the branch's own expectations, including the three where the x comes back (I, J, K:xaon page and server,lost=0, nothing pending). A type-over's undo (B) no longer doubles. The r1 multi-step probe: 4 of 4 on the slides schema; the linear probe: 1000/2000/4000 changes in 196/571/816 ms elsewhere, 2.1/2.8/6.7 s on the refused text under load 90–110.rv-carry-review.test.mjs's third case (two changes under one id with no keeper and no replay) fails identically on main'scarry.mjs— the documented window limit, not this branch's. - What
watchUndohandled. Every single-view case it got right the derived step gets right (undo, undo-then-type, undo/redo/undo/redo, two undos and two redos, undo elsewhere, undo of the x alone, the saved-s-then-x two-undo test rewritten). The one it handled that this does not is finding 1. - No flash.
carrystill runs beforestage.destroy()and the new mount; unchanged. - Fails without the fix. The new browser test on
4c23861with the branch's fixture and Go test copied in (Chromium): exactly the seven cases #31 names fail — Aab, C `, Db, I/J/K, Mtwo` — and the other ten pass; on the branch all seventeen pass in both engines (below). - AGENTS.md. The four limits named are the ones there are, as far as I can find; "every" is gone from the keeping sentence.
- #94 (
fix/safari-save-stall, Docs). No Slides counterpart; nothing here touches the save queue.
Validation
GOTOOLCHAIN=go1.26.5 .amadan/ci.d/10-gatestops at the known Mac wasm byte-compare. By hand after it:cargo test(core and pdf), pdf fmt and clippy clean,npm ci,node --test *.test.mjs268/268, vectors unchanged, the bundle byte-identical,make ciok (slidestest98 s). Hub CI passed on 59b4770.- Full browser suite in full Chrome (
RASTRILLO_CHROME= Playwright's chromium-1234),go test -tags browser -count=1 -timeout 40m -v ./internal/slidestest: 2213 s, 188 pass, 3 fail, all three in paths this branch does not touch and all under a load average of 100–160 with the Docs suite running alongside:TestBrowserPresenceShowsEachOther(the presence chip never came within 20 s; alone, 8 s, pass),TestFontEnginesSlidesChangeWithoutAGap(the viewer's slide change; alone, pass — the same two #31 reports), andTestFontALateEditorMovesNothing, which fails alone too, atsameLayout: the viewer's gate committed at its 3.5 s deadline (shown at 3523 ms) and a face that landed at 3841 ms moved a line, 300 ms before anything of the editor's (its bundle is held 6 s in that test). Againstorigin/main4c23861 on the same machine, run serially and alternating (load 40–100): the branch failed its first two solo runs and passed the next three; main passed its first two and failed the next two, with the samesameLayoutmessage (shown at 3520/3625 ms, a face at 7039/7069 ms). 3 of 5 against 2 of 4, each side failing the same way: the viewer's 3.5 s gate under load, not this branch — nothing it changes is served before the editor bundle that test holds back. The branch's tests pass:TestEnginesUndoAndRedoWhileARefusalIsPendingEndAsSeen(222 s, 34 cases, both engines, the server held to each page),TestAnUndoWhileARefusalIsPendingStaysUndone,TestEnginesEveryChangeWhileARefusalIsPendingIsKept(81 s),TestChangesOnRefusedTextAreKeptWithoutIt,TestFontEnginesAWaitingPasteSurvivesARefusedSave(154 s). - Load average 30–120 throughout.