Skip to content

fix(sqlite-native): restore native startup kv preload#4639

Draft
NathanFlurry wants to merge 1 commit into04-12-fix_sqlite-native_delete_metadata_before_chunk_rangefrom
04-12-fix_sqlite-native_restore_native_startup_kv_preload
Draft

fix(sqlite-native): restore native startup kv preload#4639
NathanFlurry wants to merge 1 commit into04-12-fix_sqlite-native_delete_metadata_before_chunk_rangefrom
04-12-fix_sqlite-native_restore_native_startup_kv_preload

Conversation

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

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 13, 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

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

@claude
Copy link
Copy Markdown

claude bot commented Apr 13, 2026

PR Review: fix(sqlite-native): restore native startup kv preload

This PR restores the native startup KV preload path by threading preloaded_kv through the bridge, wrapper, and VFS layers. The overall design is sound and well-structured.

Potential issue: startup_preload_put silently drops new keys

vfs.rs -- startup_preload_put only updates keys already present; it does not insert new ones. If SQLite writes a key that was in the preload, then deletes it, then writes it again, the key is not re-added to the cache. Subsequent reads fall through to the network and get the correct value, so there is no correctness bug. But the silent no-op is non-obvious. The test name update_without_growing signals the intent; a one-line comment on the function would make the invariant explicit.

Dead fields in decodePreloadedKv

wrapper.js -- decodePreloadedKv returns { entries, requestedGetKeys, requestedPrefixes }, but only entries is consumed downstream. requestedGetKeys and requestedPrefixes are decoded but appear unused. Either remove them now and restore when needed, or add a comment explaining they are reserved for future use.

Minor: unconditional clone before potentially-failing async call

vfs.rs -- kv_put and kv_delete now do keys.clone() and values.clone() before the block_on call so the clones are available for update_startup_preload afterward. The clone happens even on failure, where the copies are discarded. The preload data is small so this is not a practical concern, but it is a behavioral change from the original code.

Test coverage

The three unit tests for the helper functions are clear and cover the main cases. A higher-level integration test that constructs a VfsContext with preloaded entries and exercises the kv_get hit/miss/merge path would provide additional confidence, but is not strictly required to merge.

Positive notes

  • The binary-search-sorted layout for preload lookup is efficient and correct.
  • Keeping the preload in sync on put/delete/delete_range is the right design; stale entries cannot cause incorrect reads.
  • startup_preload: Mutex<Option<...>> clearly separates no-preload from empty-preload.
  • The comment distinguishing the startup preload from the opt-in read cache is clear and valuable.

@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_delete_metadata_before_chunk_range branch from 12c0baa to 61b5457 Compare April 13, 2026 05:38
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_restore_native_startup_kv_preload branch from db38027 to 32f2924 Compare April 13, 2026 05:38
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_delete_metadata_before_chunk_range branch from 61b5457 to bc7e3d7 Compare April 13, 2026 05:50
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_restore_native_startup_kv_preload branch 2 times, most recently from 2b4d526 to bd95874 Compare April 13, 2026 07:03
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_restore_native_startup_kv_preload branch from bd95874 to ebe7c80 Compare April 13, 2026 21:07
@NathanFlurry NathanFlurry mentioned this pull request Apr 13, 2026
11 tasks
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