Skip to content

fix: preserve empty shallow-root meets across odd frontiers - #1104

Open
hngpt52 wants to merge 1 commit into
loro-dev:mainfrom
hngpt52:codex/fix-loro-1095-shallow-import
Open

hngpt52 wants to merge 1 commit into
loro-dev:mainfrom
hngpt52:codex/fix-loro-1095-shallow-import

Conversation

@hngpt52

@hngpt52 hngpt52 commented Sep 13, 2026

Copy link
Copy Markdown

Fixes #1095.

A shallow snapshot exported from a version with three, five, or seven independent heads can fail to import into an empty document with SwitchToVersionBeforeShallowRoot.

The shallow-root calculation reduces frontier heads in pairs. An empty common-ancestor result was represented by adding no IDs to the next round; an odd, unpaired head could then survive and become a root that was not common to the requested version. Returning immediately on an empty result preserves it through the reduction, while retaining the existing clamp for already-shallow documents. Snapshot formats and import guards are unchanged.

Tests cover 1–12 independent heads, shared and partially shared histories, imported state and version metadata, synchronization after import, and rejection of unavailable history. The existing boundary-import regression also now uses a valid shallow root and a JSON update with explicit boundary-plus-retained dependencies, instead of relying on the incorrect root selection. It verifies the applied state and detects use of the wrong import guard. A patch changeset is included.

Validation

  • Reproduced the original failure on the base checkout; the corrected independent-head matrix passes.
  • Final patch: 26 shallow integration tests and all 10 shallow-snapshot concurrency tests passed, including independent re-review.
  • Mutation check: the boundary-import regression fails with ImportUpdatesThatDependsOnOutdatedVersion when the import preflight uses the checkout guard, and passes after restoring the intended guard.
  • Before the final test-only fixture correction, full loro and loro-internal suites passed (549 and 526 tests respectively). Release WASM build/package checks passed: 373 Vitest tests, TypeScript, CommonJS smoke, 4 Deno tests, and 4 Bun tests. Production logic has not changed since those runs.
  • All three changed Rust files pass rustfmt; git diff --check passes.

Repository-wide formatting and Clippy have unrelated failures on the unmodified base with local Rust 1.98 (formatting differences and existing generic-btree diagnostics). The full native suites used the standard Cargo test harness because cargo-nextest was unavailable. WASM package tests used a temporary empty PostCSS configuration to avoid an unrelated parent-directory configuration. None of those local workarounds or unrelated changes is included.

Stop the pairwise reduction when no common ancestor remains. Cover independent and shared histories and retain a boundary-aware import regression.

Fixes loro-dev#1095

Agent: codex-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shallow snapshot exported at frontiers with an odd number of heads (≥3) cannot be imported into an empty document

1 participant