Skip to content

chore(rivetkit): migrate file system driver to sqlite#4206

Closed
NathanFlurry wants to merge 1 commit intomainfrom
02-16-chore_rivetkit_migrate_file_system_driver_to_sqlite
Closed

chore(rivetkit): migrate file system driver to sqlite#4206
NathanFlurry wants to merge 1 commit intomainfrom
02-16-chore_rivetkit_migrate_file_system_driver_to_sqlite

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-4206 February 16, 2026 10:47 Destroyed
@railway-app
Copy link

railway-app bot commented Feb 16, 2026

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

Service Status Web Updated (UTC)
ladle ❌ Build Failed (View Logs) Web Feb 19, 2026 at 7:57 pm
website 😴 Sleeping (View Logs) Web Feb 19, 2026 at 2:39 am
frontend-inspector ❌ Build Failed (View Logs) Web Feb 16, 2026 at 10:49 am
mcp-hub ✅ Success (View Logs) Web Feb 16, 2026 at 10:49 am
frontend-cloud ❌ Build Failed (View Logs) Web Feb 16, 2026 at 10:48 am

Copy link
Member Author

NathanFlurry commented Feb 16, 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 16, 2026

PR Review: Migrate file system driver to SQLite

This is a solid migration from in-memory array-based KV storage to SQLite for the file system driver. The abstraction layer, migration path, and test coverage are all well-considered. A few issues worth addressing before merging.


Bug: Resource leak in destroyActor when onStop throws

In global-state.ts, #closeActorKvDatabase is called inside the try block after actor.actor.onStop('destroy') (lines 696-698), but NOT in the finally block (lines 755-769). If onStop throws, the SQLite connection for that actor is never closed.

Compare with sleepActor, where #closeActorKvDatabase is correctly placed in the finally block (line 644). The pattern should be consistent. The finally block in destroyActor should include this.#closeActorKvDatabase(actorId).


Indentation inconsistencies

Both sleepActor and destroyActor have indentation inconsistencies introduced in this PR. In sleepActor, the closing brace of try and the finally keyword are indented one level too deep relative to the try opening (line 641 vs 617). In destroyActor, lines 696-698 are indented one level deeper than the surrounding code.

JavaScript does not care about indentation, so the runtime behavior is correct, but this makes the control flow hard to read. Worth fixing to avoid confusion.


Statement re-preparation on every call

In sqlite-runtime.ts, createPreparedDatabaseAdapter calls prepare(sql) inside each method invocation (run, get, all). For bun:sqlite, .query() caches prepared statements internally, so this is fine. For node:sqlite and better-sqlite3, .prepare() creates a new statement object each time. Acceptable for a local dev driver, but worth noting as a future optimization if the file-system driver sees more intensive use.


loadSqliteRuntime: silent failure when better-sqlite3 loads but provides no constructor

If better-sqlite3 loads without throwing but BetterSqlite3 ends up not being a function (neither the module itself nor .default), the code falls through to the final throw at the bottom. At that point, only the bun and node:sqlite errors are in loadErrors; there is no mention of why better-sqlite3 did not work. Unusual edge case, but could make debugging confusing.


Minor: isKvDbPopulated uses COUNT(*)

For actors with many KV entries, SELECT COUNT(*) AS count FROM kv scans the entire index. SELECT 1 FROM kv LIMIT 1 would be faster. This is only called during startup migration, so the impact is minimal.


Positive observations

  • Non-destructive migration: Legacy state files are never modified during migration, safe for rollback or debugging.
  • Idempotent migration: The isKvDbPopulated check ensures existing SQLite data is never overwritten by the legacy migration.
  • Good runtime abstraction: The SqliteRuntime/SqliteRuntimeDatabase interface cleanly isolates driver-specific differences. The normalizeParams Uint8Array-to-Buffer conversion is a smart compatibility shim.
  • Breaking change handled cleanly: Throwing when useNativeSqlite: false is set is the right call - better to fail fast with a clear message than to silently misbehave.
  • Test coverage: The migration test scenarios (fresh migration, idempotency, state file immutability) are exactly the right cases to cover.
  • Prefix scan via upper-bound: The computePrefixUpperBound approach for SQLite range scans is correct and efficient.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 19, 2026

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@4206

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@4206

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@4206

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@4206

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@4206

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@4206

@rivetkit/sqlite-vfs

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sqlite-vfs@4206

@rivetkit/traces

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/traces@4206

@rivetkit/workflow-engine

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/workflow-engine@4206

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@4206

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@4206

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@4206

commit: ee7072e

@NathanFlurry NathanFlurry force-pushed the 02-16-chore_rivetkit_migrate_file_system_driver_to_sqlite branch from ee7072e to c7cc1bf Compare February 19, 2026 19:54
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4206 February 19, 2026 19:54 Destroyed
@NathanFlurry NathanFlurry marked this pull request as ready for review February 19, 2026 22:12
@NathanFlurry NathanFlurry mentioned this pull request Feb 19, 2026
11 tasks
@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 19, 2026

Merge activity

  • Feb 19, 10:44 PM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Feb 19, 10:44 PM UTC: CI is running for this pull request on a draft pull request (#4238) due to your merge queue CI optimization settings.
  • Feb 19, 10:45 PM UTC: Merged by the Graphite merge queue via draft PR: #4238.

graphite-app bot pushed a commit that referenced this pull request Feb 19, 2026
# 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
@graphite-app graphite-app bot closed this Feb 19, 2026
@graphite-app graphite-app bot deleted the 02-16-chore_rivetkit_migrate_file_system_driver_to_sqlite branch February 19, 2026 22:45
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