Skip to content

chore(rivetkit): fix sqlite-vfs for next-js & cf workers#4271

Merged
NathanFlurry merged 1 commit intomainfrom
02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers
Feb 24, 2026
Merged

chore(rivetkit): fix sqlite-vfs for next-js & cf workers#4271
NathanFlurry merged 1 commit intomainfrom
02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers

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 railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4271 February 23, 2026 23:34 Destroyed
@railway-app
Copy link

railway-app bot commented Feb 23, 2026

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

Service Status Web Updated (UTC)
website ❌ Build Failed (View Logs) Web Feb 24, 2026 at 3:21 am
ladle ❌ Build Failed (View Logs) Web Feb 24, 2026 at 3:20 am
frontend-inspector ❌ Build Failed (View Logs) Web Feb 24, 2026 at 3:20 am
frontend-cloud ❌ Build Failed (View Logs) Web Feb 24, 2026 at 3:20 am
mcp-hub ✅ Success (View Logs) Web Feb 23, 2026 at 11:35 pm

Copy link
Member Author

NathanFlurry commented Feb 23, 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.

@claude
Copy link

claude bot commented Feb 23, 2026

PR Review: chore(rivetkit): fix sqlite-vfs for next-js & cf workers

This is a substantial rewrite of the KV-backed SQLite VFS to align with the @rivetkit/sqlite@0.1.1 callback ABI, enabling correct operation in Next.js and Cloudflare Workers. Overall the changes are well-structured and the core fix is sound. A few observations below.


Correctness

Async callback registration (SQLITE_ASYNC_METHODS + hasAsyncMethod): Correct. The libvfs layer captures the async/sync mask at VFS registration time, so declaring all async VFS methods here ensures SQLite uses relay wrappers instead of calling them synchronously.

Raw pointer ABI (xRead, xWrite, xTruncate, xFileSize): The new signatures match the Emscripten ABI, and reading/writing via HEAPU8.subarray / #heapView().setInt32 is correct.

WASM heap growth guard (#heapView()): Well-handled. Detects buffer invalidation on heap growth and refreshes the cached DataView. The #writeInt32 / #writeBigInt64 methods correctly offset by HEAPU8.byteOffset for the general case.

delegalize: The legalized i64 → JS number conversion is correct, including the lo32 < 0 adjustment for unsigned interpretation of the lower word. Safe for files up to Number.MAX_SAFE_INTEGER (~8 PB), which is not a practical limit for actor-scoped databases.

Backward compatibility (legacy keys in xOpen / xAccess / #delete): Existing databases with filename-based keys are discovered and used transparently. xAccess checks both compact and legacy formats, ensuring SQLite can discover pre-existing databases. Data is neither silently migrated nor corrupted.


Issues

#decodeFilename trailing & for URI filenames: The state machine pushes the separator character on the preceding null byte, which means the last key=value pair is followed by a dangling &:

// Bytes: path\0key\0value\0\0
// Result: "path?key=value&"  <- trailing & before terminating null

For typical actor databases opened with a simple path (no URI parameters), SQLITE_OPEN_URI will not be set and this branch is never taken. But if a URI filename is used in the future, the malformed query string could confuse SQLite's sqlite3_uri_parameter(). Worth a comment at minimum, or removing the trailing & on loop exit.

xOpen output flags write the full flags bitfield: The old code wrote SQLITE_OPEN_READONLY ? 1 : 0 to pOutFlags; the new code writes all flags including bits like SQLITE_OPEN_MAIN_DB. The SQLite VFS spec says pOutFlags should receive the effective open mode (SQLITE_OPEN_READONLY or SQLITE_OPEN_READWRITE). SQLite only checks the readonly bit there, so no observed breakage, but it is worth aligning with the spec to avoid surprising behavior in future SQLite versions.

Legacy data is pinned to legacy key format indefinitely: Once xOpen detects a legacy-format database, it sets chunkKeyForIndex to the legacy factory and uses it for all subsequent reads and writes. This is safe and intentional, but the database never migrates to compact keys unless explicitly rebuilt. A comment in xOpen explaining the intentional non-migration would help future readers.


Minor

Double blank line between interface LoadedSqliteRuntime and the module-level constant block in vfs.ts.

getChunkKey convenience wrapper allocates a new closure per call:

export function getChunkKey(fileTag, chunkIndex) {
    return createChunkKeyFactory(fileTag)(chunkIndex);
}

This is only used in tests/compat scenarios, so the overhead is negligible. Could use a direct implementation to avoid the extra allocation if this ever appears in a hot path.


Examples

The Cloudflare Workers and Next.js example updates are clean:

  • Renaming registry.ts → actors.ts follows the established convention.
  • Input validation (Number.isFinite, Math.trunc) added to actor actions is a good defensive pattern.
  • E2E persistence check (re-resolving the actor handle and asserting count survives) is the right test for SQLite-backed state.
  • Counter.tsx optimistic update via setCount(nextCount) avoids a stale read round-trip.
  • The endpoint change in client.ts from /rivet to /api/rivet should be validated against the Cloudflare Workers handler configuration to confirm the path matches what createHandler mounts on.

Reviewed by Claude Sonnet 4.6

@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers branch from ff62be2 to a3d0b2b Compare February 24, 2026 02:39
@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_run_engine_config branch from 3d549ca to 9cd9ac5 Compare February 24, 2026 02:40
@NathanFlurry NathanFlurry mentioned this pull request Feb 24, 2026
11 tasks
@NathanFlurry NathanFlurry changed the base branch from 02-23-chore_rivetkit_fix_run_engine_config to graphite-base/4271 February 24, 2026 02:57
@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers branch from a3d0b2b to e312910 Compare February 24, 2026 03:19
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4271 February 24, 2026 03:19 Destroyed
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4271 to 02-23-chore_rivetkit_fix_run_engine_config February 24, 2026 03:20
@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers branch from e312910 to 651e504 Compare February 24, 2026 03:58
@NathanFlurry NathanFlurry marked this pull request as ready for review February 24, 2026 04:00
@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers branch from 651e504 to d3be7da Compare February 24, 2026 04:01
@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_run_engine_config branch 2 times, most recently from 40818ca to 1f4b5a7 Compare February 24, 2026 04:11
Base automatically changed from 02-23-chore_rivetkit_fix_run_engine_config to main February 24, 2026 04:11
@NathanFlurry NathanFlurry force-pushed the 02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers branch from d3be7da to 01476af Compare February 24, 2026 04:12
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4271 February 24, 2026 04:12 Destroyed
@NathanFlurry NathanFlurry merged commit 1a0527d into main Feb 24, 2026
4 of 15 checks passed
@NathanFlurry NathanFlurry deleted the 02-23-chore_rivetkit_fix_sqlite-vfs_for_next-js_cf_workers branch February 24, 2026 04:12
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