feat(runtimed-wasm): WASM bindings for notebook doc operations from automerge 0.7#552
Merged
feat(runtimed-wasm): WASM bindings for notebook doc operations from automerge 0.7#552
Conversation
…om automerge 0.7 Spike C: compile NotebookHandle WASM from the same automerge crate as the daemon, eliminating the JS/Rust version mismatch that causes phantom cells. - NotebookHandle wraps NotebookDoc with wasm-bindgen exports - Cell CRUD: add_cell, delete_cell, update_source, append_source - Sync: generate_sync_message, receive_sync_message (same wire format as daemon) - Metadata: get/set - wasm-pack builds to apps/notebook/src/wasm/runtimed-wasm/ - 18 Rust tests pass, 345KB gzipped WASM
…D, sync, and concurrent merges
…ession Tests WASM byte compatibility with Rust automerge through the daemon. Validates save/load round-trips, sync between handles, and full daemon integration (create cell → execute → output via Python Session).
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.
After taking a whole run around with trying to get our frontend speaking automerge directly, I found out (yet again) that
Automerge.changeauto converts string fields toObject(Text)CRDTs even if they're intended to beStr. There's some frustration in knowing that we have to special case certain kinds of fields. This is a typing problem underneath but also has meaning for the CRDT.This PR creates a WASM binding of the
NotebookHandlefrom the sameautomerge = "0.7"crate as the daemon, solving the "phantom cell bug" that was appearing during work on #540.Root cause
When JS Automerge creates cells via object literal inside
Automerge.change(), all string fields becomeObject(Text)CRDTs. But the RustNotebookDoc::add_cell()createsid,cell_type,execution_countas scalarStrviadoc.put(). The Rustread_str()helper seesObject(Text)where it expectsScalarValue::Strand returnsNone— the cell is in the doc, sync worked, butget_cells()can't read it.This isn't a version mismatch or wire format issue. It's a fundamental JS Automerge API behavior: plain strings in object literals become collaborative Text CRDTs. The
@automerge/automergeJS package (both v2.2.x and v3.2.x) produces the same result.Solution
crates/runtimed-wasm— a thin wasm-bindgen wrapper around the sameNotebookDocoperations the daemon uses. All cell operations go throughdoc.put()(scalar Str) anddoc.put_object()(Text forsourceonly), matching the daemon's schema byte-for-byte. The frontend callsNotebookHandlemethods instead ofAutomerge.*functions.What's included
NotebookHandleWASM class:load,save,add_cell,delete_cell,update_source,append_source,get_cells,get_cells_json,get_metadata,set_metadata,generate_sync_message,receive_sync_messagewasm-pack buildoutput atapps/notebook/src/wasm/runtimed-wasm/(345KB gzip)What's NOT included
This PR is pure additive — no changes to existing code. Wiring
NotebookHandleintouseAutomergeNotebookis the next step (separate PR on the Phase 2 branch).Pragmatic vs end state
This WASM is the pragmatic unblock for Phase 2, not the permanent architecture. Once the frontend has a working Automerge doc (even via our WASM) and the Tauri relay is simplified, switching back to
@automerge/automergeJS withImmutableStringfor non-text fields is a well-scoped change. The WASM gets us to the paved path; the ecosystem (@automerge/codemirror, presence, cursors) is the destination.Part of #540.