Skip to content

Verified snapshot compaction (yrs surrogate-pair bug) - #1

Merged
astherath merged 4 commits into
mainfrom
fix/gc-compaction
Oct 19, 2026
Merged

astherath merged 4 commits into
mainfrom
fix/gc-compaction

Conversation

@astherath

Copy link
Copy Markdown
Contributor

Server docs never GC in memory; a snapshot (room compaction or import) is stored only if it re-applies to the same document (state vector + digest, nothing pending): GC'd copy if smaller and verified, else uncollected if verified, else none (rooms keep the update log; import → 422 unverifiable_snapshot).

Root cause: yrs 0.28 splits a string item inside a UTF-16 surrogate pair by rounding, so item clock length and string length disagree; the GC'd encoding (and sometimes the uncollected one) is wrong. On real data one canvas (72 shapes) round-tripped to 17 and GET digest returned 500. Exhaustive delete-range test over emoji strings + an import integration test. Digest moved to engine (apps re-exports). Docs updated (architecture, canvas, import-format, v0.1.0 known limitation, CHANGELOG, configuration web_root).

…hot is stored only if it re-applies to the same document

yrs 0.28 splits a string item at a UTF-16 offset inside a surrogate pair by rounding to a
whole character, so item length and string length disagree; the GC'd (and sometimes the
uncollected) encoding of such a document is wrong. On dev1 data this turned the imported
'everyonesync' canvas (72 shapes) into a snapshot that re-applies to 17 shapes and failed
GET digest with 500.

- engine::compact: server_doc() (skip_gc) and compact_state(): GC'd copy if it round-trips
  (state vector + digest, nothing pending) and is smaller, else the uncollected state if it
  round-trips, else None.
- rooms load into server_doc and compact through compact_state (None: keep the log).
- import builds a server_doc and stores the verified snapshot; 422 unverifiable_snapshot
  when none round-trips (nothing stored).
- apps load_doc uses server_doc.
- digest moved to engine (apps re-exports it unchanged).
…able_snapshot); docs: verified compaction, new 422 code
@astherath
astherath merged commit e39e6a9 into main Oct 19, 2026
4 checks passed
@astherath
astherath deleted the fix/gc-compaction branch October 19, 2026 21:46
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.

1 participant