Repository navigation
fix(loro.js): root shallow snapshots at the latest critical version - #1144
Merged
Merged
Conversation
loro.js rooted a shallow snapshot at the requested version, or at the meet of its heads. A branch merged after that version but forked below it is concurrent with it, so a retained op straddled the root. Checking out retained versions and returning could then reorder concurrent Text/List elements, and the root differed from a Rust export. Port Rust's latest_single_head_critical_version (dag.rs) and use it with the latest frontiers, as calc_shallow_doc_start does. The StyleStart nudge and the clamp to an existing shallow root are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
WASM Size Report
|
This was referenced Sep 29, 2026
Member
Author
|
Merged the latest Still needed on current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loro.jsrooted a shallow snapshot at the requested version, or at the meet of its heads. When a branch merged after that version had forked below it, a retained op was concurrent with the root.loro-crdtroots the snapshot at the latest single-head critical version of the requested frontiers and the latest version (#1095,calc_shallow_doc_start).Effects on
main:2@1instead of0@1for the "past version with a later branch below it" case incrates/loro/tests/shallow_root_critical.rs).Rationale
Port of Rust's
latest_single_head_critical_version(dag.rs) as#latestSingleHeadCriticalVersion. It is a max-heap descent over change spans from both frontier sets, with the same coalescing, lamport-based trimming, implicit same-peer predecessor, and empty-version fallback when a chain reaches a root.#calculateShallowStartnow calls it with the latest history frontiers. The StyleStart nudge and the clamp to an existing shallow root are unchanged. The walk only runs on shallow export and is bounded by the history between the requested version and its critical version, as in Rust.Validation
loro-js/tests/shallow-root-critical.test.ts: ports ofindependent_heads_have_no_critical_root,shared_root_multi_head_still_trims, andpast_version_with_later_branch_below_it; a concurrent-list case; and a randomized check (40 histories × several targets) that the root is critical and that the shallow doc matches the full doc at every retained version and after returning to latest. Three of the five tests fail onmain. The expected roots are the onesloro-crdt(WASM build of thismain) picks for the same documents.pnpm --dir loro-js format:check,lint,typecheck,test(252 passed),build.bench:complexity(1k–8k), 7 alternating rounds vsmain, loadavg 24–31: 284 items, none both >1.5× and >0.3 ms slower. Total 1219 ms onmain, 1172 ms here.🤖 Generated with Claude Code