Skip to content

fix(client-db): seed resources with their Loro history, not a rebuilt doc - #1826

Closed
joepio wants to merge 1 commit into
developfrom
fix/seed-client-db-with-snapshot
Closed

joepio wants to merge 1 commit into
developfrom
fix/seed-client-db-with-snapshot

Conversation

@joepio

@joepio joepio commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Requested by Joep · project thread

Before: sometimes, when an invitee with read-only rights opened a shared drive, the browser logged [WS] SYNC_PUSH rejected for drive … has no write right on the drive. This is the failure e2e.spec.ts:106 "authorization, invite, share menu" hits on batch #1773.

After: the invitee's tab keeps the real history of what it has read. The server no longer takes it for local changes, so it never asks the tab to push them.

On a page's first database start, initClientDb copies the resources the store already holds into the new database. It sent only JSON-AD, so the database rebuilt each Loro document from its propvals under a fresh peer id. The values were the same, but the version vector was not: the server read it as ahead of its own and put the subject in pull. In the invite spec, the invitee's tab holds the drive's ontology before its own database opens. With a temporary log in handle_sync_vv_filtered, the server asked for that ontology in about 1 of 3 runs. The client had 24 ops under one new peer; the server had the same 24 ops under the owner's two peers.

How: snapshotFor exports the snapshot of a resource that has a Loro document with ops in it. Those resources are written with putResourceWithSnapshot. Everything else still goes in one putResources batch, and properties are still seeded first. This bug is already on develop (the seed loop is older than the batch). It showed up once #1771 answered stale probes with a full version-vector SYNC. #1771's server-side pull gate (b5988e9) hides the symptom for non-writers; this fixes the cause, which also affects writers (a needless push of rebuilt history).

Tests:

  • New initClientDb.seed.test.ts: a store resource with Loro history is seeded with its snapshot, and the others are batched. It fails without the fix (no putResourceWithSnapshot call) and passes with it.
  • data-browser vitest run: 1300 tests pass. The only failing file is scripts/integration-mcp.test.mjs, which fails on the base too. tsc --noEmit is clean and pnpm run -r lint passes.
  • Playwright e2e.spec.ts -g "authorization, invite" on the batch head (e5e0f2d) with the temporary server log: without the fix the gate caught a push request in 1 to 2 of every 6 runs, and every one was the drive's ontology. The seed was writing that same subject without a snapshot in the same runs (2 of 2 matched). With the fix: 8 of 8 runs passed and nothing was caught.

… doc

On a page's first database start, the seed copies what the store already
holds into the new database. It sent only JSON-AD, so the database rebuilt
each document from its propvals under a fresh peer id: the same values,
but a version vector the server reads as ahead of its own. The next full
drive reconcile then asked the tab to push those documents back.

For a read-only member that push is refused as a whole. In e2e.spec.ts:106
the invitee's tab holds the drive's ontology before its own database
opens, and about one run in three the server named that ontology in
`pull` (client 24 ops under one new peer, server the same 24 ops under the
owner's two peers), which ended in "SYNC_PUSH rejected ... has no write
right on the drive".

A resource with a Loro document is now written with its snapshot
(`putResourceWithSnapshot`), so the database keeps its real history.
Resources without one still go in one batch, properties first as before.
@joepio joepio self-assigned this Sep 25, 2026
joepio added a commit that referenced this pull request Sep 25, 2026
joepio added a commit that referenced this pull request Sep 25, 2026
#1826, #1787, #1783, #1791, #1840, #1841) (#1844)

Combined batch, green on Mancave in run 4645 on 3346a6c (CI and Downstream).

Includes #1826, #1787, #1783, #1791, #1840 and #1841, plus settled
translation catalogs.

joepio commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

Landed on develop in ef161c3 via the combined batch #1844 (green on Mancave, run 4645). Closing.


Generated by Claude Code

@joepio joepio closed this Sep 25, 2026
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