Skip to content

chore: migrate sqlite vfs to native rust#4143

Closed
NathanFlurry wants to merge 1 commit into02-04-chore_move_sqlite-vfs_to_separate_packagefrom
02-05-chore_migrate_sqlite_vfs_to_native_rust
Closed

chore: migrate sqlite vfs to native rust#4143
NathanFlurry wants to merge 1 commit into02-04-chore_move_sqlite-vfs_to_separate_packagefrom
02-05-chore_migrate_sqlite_vfs_to_native_rust

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

This was referenced Feb 6, 2026
Copy link
Member Author

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


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 6, 2026

Pull Request Review: SQLite VFS Native Migration

This PR migrates the SQLite VFS implementation from a pure JavaScript/WASM solution to a Rust-backed native implementation with WASM fallback.

✅ Strengths

Architecture & Design

  • Clean separation between native and WASM implementations
  • Smart runtime selection with native-first fallback to WASM
  • Snapshot-based persistence maintains compatibility
  • Platform-specific package distribution with optionalDependencies

Code Quality

  • Proper N-API usage for Node.js/Bun compatibility
  • Good error handling with descriptive messages
  • Consistent API surface across implementations
  • Comprehensive test coverage

Security

  • Uses tempfile::TempDir for proper cleanup
  • Forces PRAGMA journal_mode=DELETE and synchronous=FULL
  • Bundled SQLite avoids system library risks

⚠️ Critical Issues

1. Memory Safety: Unsafe Send Implementation (lib.rs:22)
unsafe impl Send for NativeDatabase {} contains raw SQLite pointers. The Rust type system should enforce this safety, not just rely on TypeScript mutex.

2. Resource Cleanup Race (lib.rs:147-159)
The close error path calls sqlite_error with a potentially inconsistent pointer. Use sqlite3_close_v2 or null pointer even on error.

3. Performance: Snapshot on Every Exec (native.ts:76-91)
Exports and persists entire DB after every exec. For high-volume ops this is expensive. Consider dirty tracking, batching, or background persistence.

4. Code Duplication
AsyncMutex is duplicated in native.ts and wasm.ts (lines 23-50). Extract to shared module.

📝 Recommendations

High Priority:

  1. Fix unsafe Send - use proper synchronization or document safety
  2. Improve close error handling
  3. Add dirty tracking to avoid unnecessary exports
  4. Extract shared AsyncMutex
  5. Add error path tests (KV failures, corruption, concurrent access)

Medium Priority:
6. Consider streaming for large databases
7. Add performance benchmarks (native vs WASM)
8. Improve error messages
9. Validate config at construction time
10. Document WAL limitations

Low Priority:
11. Add debug logging capability
12. Document BigInt conversion behavior
13. Differentiate NULL vs empty BLOB

📊 Overall Assessment

Well-structured migration with sound architecture. However, memory safety concerns and performance optimization around snapshot-on-every-exec should be addressed.

Recommendation: Request Changes

The unsafe impl Send and close error handling should be fixed before merging. Performance concerns should be evaluated with benchmarks.

🎯 Summary

  • ✅ Architecture well-designed
  • ✅ Follows repository conventions
  • ⚠️ Memory safety concerns need addressing
  • ⚠️ Performance optimization needed
  • ❌ Error path testing insufficient
  • ❌ PR description incomplete

@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 6, 2026

Merge activity

  • Feb 6, 8:22 AM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Feb 6, 8:23 AM UTC: CI is running for this pull request on a draft pull request (#4146) due to your merge queue CI optimization settings.
  • Feb 6, 8:24 AM UTC: Merged by the Graphite merge queue via draft PR: #4146.

graphite-app bot pushed a commit that referenced this pull request Feb 6, 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 6, 2026
@graphite-app graphite-app bot deleted the 02-05-chore_migrate_sqlite_vfs_to_native_rust branch February 6, 2026 08:24
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

Comments