Skip to content

chore(rivetkit): remove wasm sqlite runtime#4614

Draft
NathanFlurry wants to merge 1 commit into04-12-fix_sqlite-native_restore_native_startup_kv_preloadfrom
chore/remove-wasm-sqlite-native-only
Draft

chore(rivetkit): remove wasm sqlite runtime#4614
NathanFlurry wants to merge 1 commit into04-12-fix_sqlite-native_restore_native_startup_kv_preloadfrom
chore/remove-wasm-sqlite-native-only

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 12, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude bot commented Apr 12, 2026

PR Review: chore(rivetkit): remove wasm sqlite runtime

This PR removes the WASM/KV-backed SQLite path from RivetKit, making native SQLite via @rivetkit/rivetkit-native the only supported backend. The simplification is substantial: ~1,700 lines deleted, eliminating the WASM pool manager, KV-backed VFS, native-sqlite.ts KV channel module, native-adapter.ts, open-database.ts, and createActorKvStore. The new SqliteDatabase interface in config.ts and wrapJsNativeDatabase in native-database.ts are cleaner than the previous fallback chain.


Bug: ArrayBuffer and typed array support dropped

native-database.ts:toNativeBinding only handles Uint8Array, but the previous wrapper.js handled all ArrayBuffer views:

// old wrapper.js — handled both:
if (value instanceof ArrayBuffer) { ... Buffer.from(value) }
if (ArrayBuffer.isView(value)) { ... Buffer.from(value.buffer, value.byteOffset, value.byteLength) }

The new code only handles Uint8Array, so Int8Array, Float32Array, bare ArrayBuffer, etc. will throw. This is a silent regression if any caller passes those types.


Bug: bigint precision loss in native-database.ts

toNativeBinding uses Number(arg) for bigints, silently losing precision for values outside Number.MAX_SAFE_INTEGER (2^53 - 1). SQLite stores integers up to i64, so this is reachable. Consider throwing when the value exceeds safe integer range.


Edge case: named params with no placeholders

In toNativeBindings (native-database.ts), when a Record<string, unknown> is passed but the SQL has no named placeholders (orderedNames.length === 0), it falls through to Object.values(params) used positionally. The old native-adapter.ts threw an explicit error here. Using Object.values positionally is fragile — throwing would be safer and matches the old behavior.


Orphaned KV data

SQLITE_PREFIX (key byte 0x08) is removed from keys.ts with no cleanup or migration. Actors that previously used the KV-backed WASM SQLite path have data silently orphaned under that prefix. Confirm whether this is an intentional hard cutover and document it in the PR description — existing actors would start with an empty database.


Removed error poisoning — verify native layer handles it

The old path poisoned the KV store before acquiring the mutex on close() so in-flight queries would fail fast with a descriptive message. This mechanism is now gone. Confirm the native backend surfaces a clear error (not a hang) when the database is closed mid-query.


Static import of openDatabaseFromEnvoy

The engine driver now statically imports openDatabaseFromEnvoy at module level with no fallback. The old code used a runtime require() with a try/catch returning undefined if unavailable. Deployments without @rivetkit/rivetkit-native will now fail at import time rather than gracefully. Confirm this package is always present in all deployment targets.


Minor: duplicate interface

NativeExecBridgeResult in isolate-runtime.ts duplicates SqliteQueryResult from db/config.ts. Could reuse the existing type.


Overall

The architectural direction is correct — eliminating the WASM/KV complexity in favor of native-only is a clear win for maintainability. The dynamic actor DB bridge (dbExec, dbQuery, dbRun, dbClose refs) is well-structured and consistent with the existing KV bridge pattern.

Items to address before merging:

  1. ArrayBuffer regression — restore ArrayBuffer and ArrayBuffer.isView handling
  2. bigint precision — silent data corruption for integers > 2^53
  3. Named params edge case — throw instead of falling through to Object.values positionally
  4. Orphaned KV data — document the intentional cutover
  5. Static import — confirm @rivetkit/rivetkit-native is always present in all deployment targets

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4614

All packages published as 0.0.0-pr.4614.822b57f with tag pr-4614.

Engine binary is shipped via @rivetkit/engine-cli (platforms: linux-x64-musl, linux-arm64-musl, darwin-x64, darwin-arm64). rivetkit resolves it automatically at runtime.

Docker images:

docker pull rivetdev/engine:slim-822b57f
docker pull rivetdev/engine:full-822b57f
Individual packages
npm install rivetkit@pr-4614
npm install @rivetkit/react@pr-4614
npm install @rivetkit/rivetkit-native@pr-4614
npm install @rivetkit/workflow-engine@pr-4614

@NathanFlurry NathanFlurry force-pushed the pkg-pr-new-native-builds branch from 4bd0fb1 to ab9f56f Compare April 13, 2026 02:09
@NathanFlurry NathanFlurry force-pushed the chore/remove-wasm-sqlite-native-only branch from a145cda to 2e5abc9 Compare April 13, 2026 02:09
@NathanFlurry NathanFlurry changed the base branch from pkg-pr-new-native-builds to graphite-base/4614 April 13, 2026 02:13
@NathanFlurry NathanFlurry force-pushed the chore/remove-wasm-sqlite-native-only branch from 2e5abc9 to ac6753a Compare April 13, 2026 02:13
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4614 to main April 13, 2026 02:13
@NathanFlurry NathanFlurry force-pushed the chore/remove-wasm-sqlite-native-only branch 3 times, most recently from 9da1113 to e792448 Compare April 13, 2026 07:11
@NathanFlurry NathanFlurry changed the base branch from main to graphite-base/4614 April 13, 2026 08:24
@NathanFlurry NathanFlurry force-pushed the chore/remove-wasm-sqlite-native-only branch from e792448 to c0e0e30 Compare April 13, 2026 08:25
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4614 to 04-12-fix_sqlite-native_restore_native_startup_kv_preload April 13, 2026 08:25
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_restore_native_startup_kv_preload branch from bd95874 to ebe7c80 Compare April 13, 2026 21:07
@NathanFlurry NathanFlurry force-pushed the chore/remove-wasm-sqlite-native-only branch from c0e0e30 to 7158470 Compare April 13, 2026 21:07
@NathanFlurry NathanFlurry mentioned this pull request Apr 13, 2026
11 tasks
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