Skip to content

refactor(rivetkit): extract shared db utilities and improve sqlite bindings#4278

Merged
NathanFlurry merged 2 commits intomainfrom
refactor_rivetkit_extract_shared_db_utilities_and_improve_sqlite_bindings
Feb 24, 2026
Merged

refactor(rivetkit): extract shared db utilities and improve sqlite bindings#4278
NathanFlurry merged 2 commits intomainfrom
refactor_rivetkit_extract_shared_db_utilities_and_improve_sqlite_bindings

Conversation

@NathanFlurry
Copy link
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

@railway-app
Copy link

railway-app bot commented Feb 24, 2026

🚅 Deployed to the rivet-pr-4278 environment in rivet-frontend

Service Status Web Updated (UTC)
frontend-inspector ✅ Success (View Logs) Web Feb 24, 2026 at 5:01 am
mcp-hub ✅ Success (View Logs) Web Feb 24, 2026 at 4:59 am
ladle ❌ Build Failed (View Logs) Web Feb 24, 2026 at 4:58 am
website 🕒 Building (View Logs) Web Feb 24, 2026 at 4:58 am
frontend-cloud 🕒 Building (View Logs) Web Feb 24, 2026 at 4:58 am

Copy link
Member Author

NathanFlurry commented Feb 24, 2026


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

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

Base automatically changed from 02-23-chore_rivetkit_enforce_limits_on_fs_driver_kv_api_to_match_engine to main February 24, 2026 05:01
@NathanFlurry NathanFlurry merged commit c2ce406 into main Feb 24, 2026
9 of 22 checks passed
@NathanFlurry NathanFlurry deleted the refactor_rivetkit_extract_shared_db_utilities_and_improve_sqlite_bindings branch February 24, 2026 05:02
@claude
Copy link

claude bot commented Feb 24, 2026

PR Review: refactor(rivetkit): extract shared db utilities and improve sqlite bindings

This is a solid refactor that eliminates significant code duplication and adds important type safety. The new test coverage is particularly strong. A few things worth flagging:


Breaking Change: Legacy Key Removal

The removal of the legacy filename-based key format in vfs.ts is a breaking change with no migration path. The deleted code in xOpen and #delete previously fell back to the legacy key format when the compact key was not found. Any actors with data stored under the old filename-prefixed key format will silently fail to open their database after this update — they will get a new empty database instead of an error (since SQLITE_OPEN_CREATE is set). This data is not recoverable without the legacy read path. If no production actors use the legacy format this is fine, but worth calling out explicitly in the PR description.


isSqliteBindingValue Accepts number[] Arrays

In shared.ts, the Array.isArray branch accepts any number[] as a valid binding:

if (Array.isArray(value)) {
    return value.every((item) => typeof item === "number");
}

The SqliteBindings type (derived from bind_collection) accepts null | number | string | bigint | Uint8Array — a plain number[] is not a valid SQLite binding for wa-sqlite. Passing one would likely throw inside bind_collection or be silently misinterpreted. If the intent is to allow BLOB data, that should be Uint8Array (already handled) or ArrayBuffer. This branch either needs a clearer comment or should be removed.


SQL Injection Fix (positive)

The change in drizzle/mod.ts from string interpolation to a parameterized query for migration recording is a genuine correctness improvement. The old code interpolated entry.tag directly into SQL, which could fail or be exploited if tags contained single quotes. Good catch.


drizzle/mod.ts execute Routes All Parameterized Queries Through waDb.query()

In the raw execute method on the Drizzle provider, all parameterized queries go through waDb.query(), including DML (UPDATE/INSERT/DELETE). By contrast, db/mod.ts correctly dispatches to waDb.run() vs waDb.query() based on query prefix. This is pre-existing behavior, not introduced by this PR, but it means parameterized DML through the Drizzle raw access path silently returns empty rows. Worth aligning the two implementations.


Minor Notes

  • Duplicate AsyncMutex in vfs.ts: vfs.ts still has its own private AsyncMutex class (lines 180-207) with identical logic to the one now in shared.ts. Since they are in separate packages this is expected, but a comment distinguishing the two would help.
  • Redundant await in createActorKvStore: getBatch: async (keys) => { return await kv.batchGet(keys) } — the await is unnecessary when directly returning a promise.
  • Extra blank line: Two consecutive blank lines after isSQLiteModule in vfs.ts around line 100.
  • isSqliteEsmFactory guard: typeof value === "function" accepts any function. Sufficient for the use case but the name implies more specificity than it provides.

Test Coverage

The new test suite in sqlite-vfs-test is thorough and covers important edge cases: chunk boundaries, unaligned overwrites, shrink/regrow, sparse blobs, and integrity checks after reopen. The assertBytesEqual helper that reports the byte offset on mismatch is especially useful for diagnosing VFS issues. Good addition.

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