Skip to content

feat(core): define canonical VersionVector v0 encoding - #217

Merged
Antonov548 merged 11 commits into
mainfrom
maintenance/remove-version-vector-legacy-serde
Sep 11, 2026
Merged

Antonov548 merged 11 commits into
mainfrom
maintenance/remove-version-vector-legacy-serde

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Why

known_state is persisted across runtimes and covered by operation signatures in the stacked #157. Its bytes were implicitly defined by Rust JSON serialization; this PR gives them one explicit, canonical encoding.

What changed

  • Implement VersionVector v0 once in Rust. JavaScript uses the same codec through WASM, replacing the separate TypeScript implementation.
  • Expose a lazy @treecrdt/wasm/codec loader with synchronous encode/decode methods after loading. Reuse wasm-bindgen and Serde for the bridge.
  • Use the encoding across SQLite, PostgreSQL, N-API, WASM, and sync. known_state remains opaque bytes in the Protobuf envelope.
  • Reject JSON, zero-length blobs, malformed ranges, unsorted or duplicate replicas, and trailing bytes.
  • Test native Rust and the JavaScript/WASM bridge against shared fixtures; use engine conformance for invalid deletes and exact-byte persistence.

Encoding

All integers are unsigned and big-endian.

Part Encoding Canonical rule
Header Version 0, u32 entry count Unknown versions are rejected
Replica entry u32 ID length, raw ID, u64 frontier, u32 range count Entries are strictly sorted, unique, and nonempty
Gap range u64 start, u64 end Ranges are positive, sorted, separated, and beyond the frontier

Development reset

This is a pre-production reset: development databases and signatures using earlier version-vector encodings must be recreated. There is no legacy decoder or migration layer.

#157 is stacked on this PR and already uses this codec for operation-signature validation.

@marcus-pousette marcus-pousette added maintenance Refactor, tests, CI, release, or dependency work without intended behavior change area:core CRDT semantics, canonical log, ordering, operation identity, and core Rust labels Jul 13, 2026
@marcus-pousette
marcus-pousette force-pushed the maintenance/remove-version-vector-legacy-serde branch from b3eb407 to 83356d2 Compare July 13, 2026 15:48
@marcus-pousette
marcus-pousette force-pushed the maintenance/remove-version-vector-legacy-serde branch from 83356d2 to 99c19cf Compare September 3, 2026 10:14
@marcus-pousette marcus-pousette changed the title refactor(core): remove legacy VersionVector serde fallback feat(core): define canonical VersionVector v0 encoding Sep 3, 2026
@marcus-pousette
marcus-pousette force-pushed the maintenance/remove-version-vector-legacy-serde branch from 99c19cf to 448c355 Compare September 3, 2026 10:24
@marcus-pousette
marcus-pousette force-pushed the maintenance/remove-version-vector-legacy-serde branch from 448c355 to 09f1c64 Compare September 3, 2026 13:25
@marcus-pousette
marcus-pousette force-pushed the maintenance/remove-version-vector-legacy-serde branch from 09f1c64 to 992283a Compare September 3, 2026 13:48

@Antonov548 Antonov548 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added few comments.

@Antonov548
Antonov548 merged commit 129ba98 into main Sep 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core CRDT semantics, canonical log, ordering, operation identity, and core Rust maintenance Refactor, tests, CI, release, or dependency work without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants