fix: lazy-load sqlite bindings and add bun:sqlite support#1428
Open
brittianwarner wants to merge 1 commit intomainfrom
Open
fix: lazy-load sqlite bindings and add bun:sqlite support#1428brittianwarner wants to merge 1 commit intomainfrom
brittianwarner wants to merge 1 commit intomainfrom
Conversation
Remove the eager top-level require('node:sqlite') in sqlite-bindings.ts
that crashed on any runtime without node:sqlite (including Bun). The
module now lazy-loads on first AgentOs.create() and auto-selects the
right backend via runtime detection (process.versions.bun).
bun:sqlite adapter:
- BunDatabaseAdapter/BunStatementAdapter normalize API differences
- db.location() maps from db.filename, normalizes :memory: to null
- stmt.run() passes through { changes, lastInsertRowid } directly
- stmt.get() normalizes Bun's null-for-no-rows to undefined
- stmt.iterate() uses native iterate() when available
- stmt.columns() maps columnNames string[] to [{ name }] objects
- stmt.finalize() calls through to release native resources
- setReadBigInts/setAllowBareNamedParameters are documented no-ops
- constants forwarded from bun:sqlite (e.g. SQLITE_FCNTL_PERSIST_WAL)
Loading and caching:
- Promise-cached module loading prevents race conditions
- Explicit unsupported-runtime error path (not just Node fallthrough)
- createSqliteBindings() is now async (call site already in async create())
Error messages improved:
- Include running runtime version and minimum requirements
- Database/statement handle errors list open handles and common causes
- Database open errors include contextual hints (ENOENT, EACCES, corrupt)
API surface:
- Exported SqliteModule/SqliteDatabase/SqliteStatement types from index.ts
- Exported createSqliteBindingsFromModule for custom backends and testing
- JSDoc on all exported functions
Documentation:
- CLAUDE.md: added SQLite runtime requirement and Bun parity gaps
- .agent/todo/remove-sqlite-bindings.md: updated with current state
- .agent/notes/vm-friction.md: created per project policy
Tests: 55 tests across 6 suites covering lazy loading, runtime detection,
Bun adapter (mock), binding tree lifecycle, error diagnostics, VFS sync
behavior, real node:sqlite integration, and the public API entry point.
Author
|
#4550 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
require("node:sqlite")insqlite-bindings.tsthat crashed on any runtime withoutnode:sqlite(including Bun)AgentOs.create()call with promise-cached loadingbun:sqliteadapter (BunDatabaseAdapter/BunStatementAdapter) that normalizes API differences to match thenode:sqliteshapeprocess.versions.bun)Related: rivet-dev/rivet#4550 — lazy-loads
agent-os-coreon the RivetKit side to prevent the same crash at the actor layer.Changes
packages/core/src/sqlite-bindings.ts— Full refactorrequire("node:sqlite")(the crash root cause)SqliteDatabase,SqliteStatement,SqliteModuleinterfaces for runtime-agnostic abstractionBunDatabaseAdapter/BunStatementAdapterwith full API mapping:db.location()maps fromdb.filename(normalizes:memory:tonull)stmt.run()passes through{ changes, lastInsertRowid }directlystmt.get()normalizes Bun'snull-for-no-rows toundefinedstmt.iterate()uses nativeiterate()when available, falls back toall()stmt.columns()mapscolumnNamesstring[] to[{ name }]objectsstmt.finalize()calls through to release native resourcessetReadBigInts/setAllowBareNamedParameters/setAllowUnknownNamedParametersare documented no-opsconstantsforwarded frombun:sqlite(e.g.SQLITE_FCNTL_PERSIST_WAL)packages/core/src/agent-os.ts— One linebindings: createSqliteBindings(kernel)tobindings: await createSqliteBindings(kernel)(already insidestatic async create())packages/core/src/index.ts— New exportsSqliteModule,SqliteDatabase,SqliteStatementtypes for custom backendscreateSqliteBindingsandcreateSqliteBindingsFromModulepackages/core/tests/sqlite-bindings.test.ts— 55 tests across 6 suitesnode:sqliteintegration (CRUD, bigint, Uint8Array, transactions, VFS sync)createSqliteBindings)Documentation
CLAUDE.md: Added SQLite runtime requirement to Dependencies, Bun adapter parity gaps to Known VM Limitations.agent/todo/remove-sqlite-bindings.md: Updated with current state and known adapter limitations.agent/notes/vm-friction.md: Created per project policyImpact
@rivet-dev/agent-os-coreimports cleanly. SQLite features work viabun:sqlite.node:sqliteloads lazily instead of eagerly.AgentOs.create()if SQLite is needed.Testing
bun:sqlitespec