You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .agent/specs/rivetkit-core-wasm-support.md
+19-7Lines changed: 19 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,26 @@ Support a WebAssembly build of RivetKit core while keeping the existing native N
9
9
10
10
This proposal is intentionally gate-oriented: implementation should not start until the parity, rollout, and failure-mode criteria below are accepted.
11
11
12
+
## Implemented Invariants
13
+
14
+
- Remote SQL is an envoy protocol v4-only capability. Older protocol targets reject remote SQL request and response serialization with `ProtocolCompatibilityError { feature: RemoteSqliteExecution, required_version: 4, ... }`, and runtime callers map unsupported remote SQL to `sqlite.remote_unavailable` instead of a BARE decode failure.
15
+
- Wasm uses remote SQLite only. The valid SQLite driver cells are native/local/all encodings, native/remote/all encodings, and wasm/remote/all encodings; wasm/local is invalid and covered by a targeted unavailable assertion.
16
+
- Shared SQLite bind, value, result, and route types live in `rivetkit-sqlite-types`. Native and remote execution both route through the shared SQLite execution layer so statement classification, writer stickiness, migrations, `execute_write`, and manual transactions stay aligned.
17
+
-`pegboard-envoy` creates at most one remote SQL executor per active `(actor_id, sqlite_generation)`. The executor is created lazily on the first accepted SQL request, reused for that generation, and removed when the actor closes or the connection shuts down.
18
+
- Remote SQL work runs outside the pegboard-envoy WebSocket read loop in bounded workers. Accepted SQL is tracked per `(actor_id, sqlite_generation)`; actor stop rejects new SQL after stopping begins and waits for already accepted SQL before closing storage.
19
+
- Sent remote SQL requests fail with `sqlite.remote_indeterminate_result` if the WebSocket disconnects before the response arrives. Only unsent requests may be sent after reconnect.
20
+
-`rivet-envoy-client` owns native versus wasm WebSocket transport selection through mutually exclusive `native-transport` and `wasm-transport` features. `rivetkit-core` selects transport by enabling `native-runtime` or `wasm-runtime`.
21
+
- The wasm binding strategy is direct `wasm-bindgen` in `@rivetkit/rivetkit-wasm`. Native NAPI and wasm bindings both adapt into the shared TypeScript `CoreRuntime` interface; raw binding imports stay inside approved runtime adapter files.
22
+
-`scripts/cargo/check-rivetkit-core-wasm.sh` is the canonical wasm dependency gate for `rivetkit-core`.
23
+
12
24
## Current State
13
25
14
26
-`rivetkit-core` owns `ActorContext::sql()` and currently routes `exec`, `query`, `run`, `execute`, and `execute_write` through `SqliteDb`.
15
-
- With the `sqlite` feature enabled, `SqliteDb` opens `rivetkit-sqlite::NativeDatabaseHandle`, which uses native `libsqlite3-sys` plus a custom VFS.
16
-
- With the `sqlite` feature disabled, `SqliteDb`keeps the public API but returns `sqlite.unavailable` for SQL execution.
17
-
- The existing envoy SQLite protocol is page/storage oriented: `get_pages`, `get_page_range`, `commit`, staged commit, and preload hints.
18
-
-`pegboard-envoy`already validates SQLite requests and owns an `Arc<sqlite_storage::SqliteEngine>`, but it does not execute SQL text today.
19
-
- The first wasm compile probe fails before core code due to native Tokio networking: `cargocheck -p rivetkit-core --target wasm32-unknown-unknown --no-default-features` hits `mio`'s wasm unsupported error. The dependency path is primarily `rivetkit-core -> rivet-envoy-client -> tokio-tungstenite -> tokio/mio`, plus `rivet-pools`, `reqwest`, and `nix`.
27
+
- With `sqlite-local`, `SqliteDb` opens `rivetkit-sqlite::NativeDatabaseHandle`, which uses native `libsqlite3-sys` plus a custom VFS.
28
+
- With `sqlite-remote`, `SqliteDb`sends SQL through envoy remote execution. With no usable backend, the public API returns explicit structured unavailable errors.
29
+
- The envoy SQLite protocol now includes both the page/storage path and v4 SQL execution requests for `exec`, `execute`, and `execute_write`.
30
+
-`pegboard-envoy` validates remote SQL namespace, actor, generation, request size, and response size before executing through the shared SQLite execution layer.
31
+
- The canonical wasm compile and dependency check is `scripts/cargo/check-rivetkit-core-wasm.sh`.
20
32
21
33
## Phase 1: Remote SQLite SQL Execution
22
34
@@ -621,7 +633,7 @@ Run `scripts/cargo/check-rivetkit-core-wasm.sh` before claiming wasm dependency
621
633
- Decision: direct wasm-bindgen on `wasm32-unknown-unknown` is the wasm binding path for Supabase and Cloudflare.
622
634
- Decision: NAPI-RS wasm is not viable for the mainline edge-host binding because the spike showed async/callback surfaces fail in workerd when Rust tries to spawn a thread.
623
635
- Open: exact numeric defaults for SQL text, bind bytes, row count, cell bytes, response bytes, and execution timeout.
624
-
-Open: whether remote writes use durable request IDs and server-side deduplication or fail with an indeterminate-result error on lost responses.
636
+
-Decision: sent remote SQL requests fail with `sqlite.remote_indeterminate_result` on lost responses; durable request ID deduplication is a future enhancement.
625
637
- Decision: remote SQL calls already accepted before actor stopping may finish, but new calls after stopping begins are rejected.
626
638
- Open: whether workflow/agent-os are in scope for the first wasm package or deferred as explicit non-goals.
627
639
- Decision: Node wasm and WASI are follow-up targets. They do not replace Supabase and Cloudflare acceptance.
@@ -646,4 +658,4 @@ Run `scripts/cargo/check-rivetkit-core-wasm.sh` before claiming wasm dependency
- Cloudflare Workers WebAssembly API docs: https://developers.cloudflare.com/workers/runtime-apis/webassembly/
648
660
- reqwest crate docs for WebAssembly support: https://docs.rs/reqwest/latest/reqwest/
649
-
- Local compile probe: `cargocheck -p rivetkit-core --target wasm32-unknown-unknown --no-default-features` currently fails in `mio` because native Tokio networking is still included.
661
+
- Local compile gate: `scripts/cargo/check-rivetkit-core-wasm.sh`.
0 commit comments